| | |
| | | $app->plugins->registerEvent('webdav_user_insert',$this->plugin_name,'webdav'); |
| | | $app->plugins->registerEvent('webdav_user_update',$this->plugin_name,'webdav'); |
| | | $app->plugins->registerEvent('webdav_user_delete',$this->plugin_name,'webdav'); |
| | | |
| | | $app->plugins->registerEvent('client_delete',$this->plugin_name,'client_delete'); |
| | | } |
| | | |
| | | // Handle the creation of SSL certificates |
| | | function ssl($event_name,$data) { |
| | | global $app, $conf; |
| | | |
| | | //* Only vhosts can have a ssl cert |
| | | if($data["new"]["type"] != "vhost") return; |
| | | |
| | | if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl"); |
| | | $ssl_dir = $data["new"]["document_root"]."/ssl"; |
| | |
| | | $csr_file = $ssl_dir.'/'.$domain.".csr"; |
| | | $crt_file = $ssl_dir.'/'.$domain.".crt"; |
| | | $bundle_file = $ssl_dir.'/'.$domain.".bundle"; |
| | | file_put_contents($csr_file,$data["new"]["ssl_request"]); |
| | | file_put_contents($crt_file,$data["new"]["ssl_cert"]); |
| | | if(trim($data["new"]["ssl_request"]) != '') file_put_contents($csr_file,$data["new"]["ssl_request"]); |
| | | if(trim($data["new"]["ssl_cert"]) != '') file_put_contents($crt_file,$data["new"]["ssl_cert"]); |
| | | if(trim($data["new"]["ssl_bundle"]) != '') file_put_contents($bundle_file,$data["new"]["ssl_bundle"]); |
| | | /* Update the DB of the (local) Server */ |
| | | $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'"); |
| | |
| | | $old_parent_domain_id = intval($data["old"]["parent_domain_id"]); |
| | | $new_parent_domain_id = intval($data["new"]["parent_domain_id"]); |
| | | |
| | | // If the parent_domain_id has been chenged, we will have to update the old site as well. |
| | | // If the parent_domain_id has been changed, we will have to update the old site as well. |
| | | if($this->action == 'update' && $data["new"]["parent_domain_id"] != $data["old"]["parent_domain_id"]) { |
| | | $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$old_parent_domain_id." AND active = 'y'"); |
| | | $data["new"] = $tmp; |
| | |
| | | } |
| | | else { |
| | | exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html"); |
| | | exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | if(is_file('/usr/local/ispconfig/server/conf/index/favicon.ico')) exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | if(is_file('/usr/local/ispconfig/server/conf/index/robots.txt')) exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | if(is_file('/usr/local/ispconfig/server/conf/index/.htaccess')) exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | | } |
| | | } |
| | | exec("chmod -R a+r ".escapeshellcmd($data["new"]["document_root"])."/web/"); |
| | |
| | | exec("setquota -T -u $username 604800 604800 -a &> /dev/null"); |
| | | } |
| | | |
| | | if($this->action == 'insert') { |
| | | if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) { |
| | | // Chown and chmod the directories below the document root |
| | | $this->_exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"])); |
| | | // The document root itself has to be owned by root in normal level and by the web owner in security level 20 |
| | |
| | | $this->_exec("chmod 751 ".escapeshellcmd($data["new"]["document_root"])."/*"); |
| | | $this->_exec("chmod 710 ".escapeshellcmd($data["new"]["document_root"]."/web")); |
| | | |
| | | // make temp direcory writable for the apache user and the website user |
| | | // make temp directory writable for the apache and website users |
| | | $this->_exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp")); |
| | | |
| | | // Set Log symlink to 755 to make the logs accessible by the FTP user |
| | | $this->_exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"])."/log"); |
| | | |
| | | $command = 'usermod'; |
| | | $command .= ' --groups sshusers'; |
| | |
| | | $this->_exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"]."/*")); |
| | | $this->_exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]."/")); |
| | | |
| | | // make temp direcory writable for the apache user and the website user |
| | | // make temp directory writable for the apache and website users |
| | | $this->_exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp")); |
| | | } |
| | | |
| | |
| | | if($data["new"]['php'] == 'mod') { |
| | | $master_php_ini_path = $web_config['php_ini_path_apache']; |
| | | } else { |
| | | $master_php_ini_path = $web_config['php_ini_path_cgi']; |
| | | if($data["new"]['php'] == 'fast-cgi' && file_exists($fastcgi_config["fastcgi_phpini_path"])) { |
| | | $master_php_ini_path = $fastcgi_config["fastcgi_phpini_path"]; |
| | | } else { |
| | | $master_php_ini_path = $web_config['php_ini_path_cgi']; |
| | | } |
| | | } |
| | | if($master_php_ini_path != '' && substr($master_php_ini_path,-7) == 'php.ini' && is_file($master_php_ini_path)) { |
| | | $php_ini_content .= file_get_contents($master_php_ini_path)."\n"; |
| | |
| | | $app->log("Apache status is: ".$apache_online_status_before_restart,LOGLEVEL_DEBUG); |
| | | |
| | | $app->services->restartService('httpd','restart'); |
| | | |
| | | // wait a few seconds, before we test the apache status again |
| | | sleep(2); |
| | | |
| | | //* Check if apache restarted successfully if it was online before |
| | | $apache_online_status_after_restart = $this->_checkTcp('localhost',80); |
| | |
| | | } |
| | | |
| | | // Remove the backup copy of the config file. |
| | | unlink($vhost_file.'~'); |
| | | if(@is_file($vhost_file.'~')) unlink($vhost_file.'~'); |
| | | |
| | | |
| | | //* Unset action to clean it for next processed vhost. |
| | |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | //* Check if this is a chrooted setup |
| | | if($web_config['website_basedir'] != '' && @is_file($web_config['/var/www'].'/etc/passwd')) { |
| | | if($web_config['website_basedir'] != '' && @is_file($web_config['website_basedir'].'/etc/passwd')) { |
| | | $apache_chrooted = true; |
| | | } else { |
| | | $apache_chrooted = false; |
| | |
| | | */ |
| | | public function webdav($event_name,$data) { |
| | | global $app, $conf; |
| | | |
| | | /* |
| | | * load the server configuration options |
| | | */ |
| | | $app->uses("getconf"); |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | if (($event_name == 'webdav_user_insert') || ($event_name == 'webdav_user_update')) { |
| | | /* |
| | | * load the server configuration options |
| | | */ |
| | | $app->uses("getconf"); |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | /* |
| | | * Get additional informations |
| | |
| | | */ |
| | | $sitedata = $app->db->queryOneRecord("SELECT document_root, domain FROM web_domain WHERE domain_id = " . $data['old']['parent_domain_id']); |
| | | $documentRoot = $sitedata['document_root']; |
| | | $domain = $sitedata['domain']; |
| | | |
| | | /* |
| | | * We dont't want to destroy any (transfer)-Data. So we do NOT delete any dir. |
| | | * So the only thing, we have to do, is to delete the user from the password-file |
| | | */ |
| | | $this->_writeHtDigestFile( $documentRoot . '/webdav/' . $data['old']['dir'] . '.htdigest', $data['old']['username'], $data['old']['dir'], ''); |
| | | |
| | | /* |
| | | * Next step, patch the vhost - file |
| | | */ |
| | | $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"] . '/' . $domain . '.vhost'); |
| | | $this->_patchVhostWebdav($vhost_file, $documentRoot . '/webdav'); |
| | | |
| | | /* |
| | | * Last, restart apache |
| | | */ |
| | | if($apache_chrooted) { |
| | | $app->services->restartServiceDelayed('httpd','restart'); |
| | | } else { |
| | | // request a httpd reload when all records have been processed |
| | | $app->services->restartServiceDelayed('httpd','reload'); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private function _writeHtDigestFile($filename, $username, $authname, $pwdhash ) { |
| | | $changed = false; |
| | | $in = fopen($filename, 'r'); |
| | | $output = ''; |
| | | /* |
| | | * read line by line and search for the username and authname |
| | | */ |
| | | while (preg_match("/:/", $line = fgets($in))) { |
| | | $line = rtrim($line); |
| | | $tmp = explode(':', $line); |
| | | if ($tmp[0] == $username && $tmp[1] == $authname) { |
| | | /* |
| | | * found the user. delete or change it? |
| | | */ |
| | | if ($pwdhash != '') { |
| | | $output .= $tmp[0] . ':' . $tmp[1] . ':' . $pwdhash . "\n"; |
| | | } |
| | | $changed = true; |
| | | if(is_file($filename)) { |
| | | $in = fopen($filename, 'r'); |
| | | $output = ''; |
| | | /* |
| | | * read line by line and search for the username and authname |
| | | */ |
| | | while (preg_match("/:/", $line = fgets($in))) { |
| | | $line = rtrim($line); |
| | | $tmp = explode(':', $line); |
| | | if ($tmp[0] == $username && $tmp[1] == $authname) { |
| | | /* |
| | | * found the user. delete or change it? |
| | | */ |
| | | if ($pwdhash != '') { |
| | | $output .= $tmp[0] . ':' . $tmp[1] . ':' . $pwdhash . "\n"; |
| | | } |
| | | $changed = true; |
| | | } |
| | | else { |
| | | $output .= $line . "\n"; |
| | | } |
| | | } |
| | | else { |
| | | $output .= $line . "\n"; |
| | | } |
| | | fclose($in); |
| | | } |
| | | /* |
| | | * if we didn't change anything, we have to add the new user at the end of the file |
| | |
| | | if (!$changed) { |
| | | $output .= $username . ':' . $authname . ':' . $pwdhash . "\n"; |
| | | } |
| | | fclose($in); |
| | | |
| | | |
| | | /* |
| | | * Now lets write the new file |
| | | */ |
| | | file_put_contents($filename, $output); |
| | | if(trim($output) == '') { |
| | | unlink($filename); |
| | | } else { |
| | | file_put_contents($filename, $output); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | /* |
| | | * add all the webdav-dirs to the webdav-section |
| | | */ |
| | | $files = scandir($webdavRoot); |
| | | $files = @scandir($webdavRoot); |
| | | if(is_array($files)) { |
| | | foreach($files as $file) { |
| | | if (substr($file, strlen($file) - strlen('.htdigest')) == '.htdigest') { |
| | | /* |
| | |
| | | */ |
| | | $fn = substr($file, 0, strlen($file) - strlen('.htdigest')); |
| | | $output .= "\n"; |
| | | $output .= " Alias /" . $fn . " " . $webdavRoot . "/" . $fn . "\n"; |
| | | $output .= " <Location /" . $fn . ">\n"; |
| | | $output .= " Alias /webdav/" . $fn . ' ' . $webdavRoot . '/' . $fn . "\n"; |
| | | $output .= " <Location /webdav/" . $fn . ">\n"; |
| | | $output .= " DAV On\n"; |
| | | $output .= " AuthType Digest\n"; |
| | | $output .= " AuthName \"" . $fn . "\"\n"; |
| | |
| | | $output .= " Allow from all \n"; |
| | | $output .= " </Location> \n"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /* |
| | |
| | | $app->log("Removed awstats config file: ".$awstats_conf_dir.'/awstats.'.$data["old"]["domain"].'.conf',LOGLEVEL_DEBUG); |
| | | } |
| | | } |
| | | |
| | | function client_delete($event_name,$data) { |
| | | global $app, $conf; |
| | | |
| | | $app->uses("getconf"); |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | $client_id = intval($data['old']['client_id']); |
| | | if($client_id > 0) { |
| | | |
| | | $client_dir = $web_config['website_basedir'].'/clients/client'.$client_id; |
| | | if(is_dir($client_dir) && !stristr($client_dir,'..')) { |
| | | @rmdir($client_dir); |
| | | $app->log('Removed client directory: '.$client_dir,LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | $this->_exec('groupdel client'.$client_id); |
| | | $app->log('Removed group client'.$client_id,LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | } |
| | | |
| | | //* Wrapper for exec function for easier debugging |
| | | private function _exec($command) { |
| | |
| | | |
| | | } // end class |
| | | |
| | | ?> |
| | | ?> |