daniel
2008-06-08 61d290c124aa65c9ad2edd183617b92660f92289
commit | author | age
18341e 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class apache2_plugin {
32     
33     var $plugin_name = 'apache2_plugin';
e2d6ed 34     var $class_name = 'apache2_plugin';
18341e 35     
9cb713 36     // private variables
T 37     var $action = '';
38     
18341e 39         
T 40     /*
41          This function is called when the plugin is loaded
42     */
43     
44     function onLoad() {
45         global $app;
46         
47         /*
48         Register for the events
49         */
50         
0a466d 51         
T 52         
53         $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'ssl');
54         $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'ssl');
55         $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'ssl');
56         
18341e 57         $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'insert');
T 58         $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'update');
59         $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'delete');
60         
af8f1b 61         $app->plugins->registerEvent('server_ip_insert',$this->plugin_name,'server_ip');
T 62         $app->plugins->registerEvent('server_ip_update',$this->plugin_name,'server_ip');
63         $app->plugins->registerEvent('server_ip_delete',$this->plugin_name,'server_ip');
64         
18341e 65     }
0a466d 66     
T 67     // Handle the creation of SSL certificates
68     function ssl($event_name,$data) {
69         global $app, $conf;
70         
71         if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
72         $ssl_dir = $data["new"]["document_root"]."/ssl";
73         $domain = $data["new"]["domain"];
74         $key_file = $ssl_dir.'/'.$domain.".key.org";
75           $key_file2 = $ssl_dir.'/'.$domain.".key";
76           $csr_file = $ssl_dir.'/'.$domain.".csr";
77           $crt_file = $ssl_dir.'/'.$domain.".crt";
78         
79         //* Create a SSL Certificate
80         if($data["new"]["ssl_action"] == 'create') {
81             $rand_file = $ssl_dir."/random_file";
82             $rand_data = md5(uniqid(microtime(),1));
83             for($i=0; $i<1000; $i++){
84                 $rand_data .= md5(uniqid(microtime(),1));
85                 $rand_data .= md5(uniqid(microtime(),1));
86                 $rand_data .= md5(uniqid(microtime(),1));
87                 $rand_data .= md5(uniqid(microtime(),1));
88             }
89             file_put_contents($rand_file, $rand_data);
90
91             $ssl_password = substr(md5(uniqid(microtime(),1)), 0, 15);
92             
93             $ssl_cnf = "        RANDFILE               = $rand_file
94
95         [ req ]
96         default_bits           = 1024
97         default_keyfile        = keyfile.pem
98         distinguished_name     = req_distinguished_name
99         attributes             = req_attributes
100         prompt                 = no
101         output_password        = $ssl_password
102
103         [ req_distinguished_name ]
4132c6 104         C                      = ".$data['new']['ssl_country']."
T 105         ST                     = ".$data['new']['ssl_state']."
106         L                      = ".$data['new']['ssl_locality']."
107         O                      = ".$data['new']['ssl_organisation']."
108         OU                     = ".$data['new']['ssl_organisation_unit']."
0a466d 109         CN                     = $domain
4132c6 110         emailAddress           = webmatser@".$data['new']['domain']."
0a466d 111
T 112         [ req_attributes ]
113         challengePassword              = A challenge password";
114             
115             $ssl_cnf_file = $ssl_dir."/openssl.conf";
4132c6 116             file_put_contents($ssl_cnf_file,$ssl_cnf);
0a466d 117             
T 118             $rand_file = escapeshellcmd($rand_file);
119             $key_file = escapeshellcmd($key_file);
120             $key_file2 = escapeshellcmd($key_file2);
121             $ssl_days = 3650;
122             $csr_file = escapeshellcmd($csr_file);
026b48 123             $config_file = escapeshellcmd($ssl_cnf_file);
4132c6 124             $crt_file = escapeshellcmd($crt_file);
0a466d 125
T 126             if(is_file($ssl_cnf_file)){
4132c6 127                   exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 1024 && openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file && openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -in $csr_file -out $crt_file -days $ssl_days -config $config_file && openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
026b48 128                 $app->log("Creating SSL Cert for: $domain",LOGLEVEL_DEBUG);
0a466d 129             }
T 130
131             exec("chmod 400 $key_file2");
4132c6 132             @unlink($config_file);
T 133             @unlink($rand_file);
0a466d 134             $ssl_request = file_get_contents($csr_file);
T 135             $ssl_cert = file_get_contents($crt_file);
4132c6 136             $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data["new"]["domain"]."'");
T 137             $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
0a466d 138         }
T 139         
140         //* Save a SSL certificate to disk
141         if($data["new"]["ssl_action"] == 'save') {
026b48 142             $ssl_dir = $data["new"]["document_root"]."/ssl";
T 143             $domain = $data["new"]["domain"];
144               $csr_file = $ssl_dir.'/'.$domain.".csr";
145               $crt_file = $ssl_dir.'/'.$domain.".crt";
146             $bundle_file = $ssl_dir.'/'.$domain.".bundle";
147             file_put_contents($csr_file,$data["new"]["ssl_request"]);
148             file_put_contents($crt_file,$data["new"]["ssl_cert"]);
149             if(trim($data["new"]["ssl_bundle"]) != '') file_put_contents($bundle_file,$data["new"]["ssl_bundle"]);
4132c6 150             $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
026b48 151             $app->log("Saving SSL Cert for: $domain",LOGLEVEL_DEBUG);
T 152         }
153         
154         //* Delete a SSL certificate
155         if($data["new"]["ssl_action"] == 'del') {
156             $ssl_dir = $data["new"]["document_root"]."/ssl";
157             $domain = $data["new"]["domain"];
158               $csr_file = $ssl_dir.'/'.$domain.".csr";
159               $crt_file = $ssl_dir.'/'.$domain.".crt";
160             $bundle_file = $ssl_dir.'/'.$domain.".bundle";
161             unlink($csr_file);
162             unlink($crt_file);
163             unlink($bundle_file);
4132c6 164             $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data["new"]["domain"]."'");
026b48 165             $app->log("Deleting SSL Cert for: $domain",LOGLEVEL_DEBUG);
0a466d 166         }
T 167         
168         
169     }
170     
18341e 171     
T 172     function insert($event_name,$data) {
173         global $app, $conf;
174         
9cb713 175         $this->action = 'insert';
e2d6ed 176         // just run the update function
T 177         $this->update($event_name,$data);
18341e 178         
T 179         
180     }
181     
182     
183     function update($event_name,$data) {
184         global $app, $conf;
185         
9cb713 186         if($this->action != 'insert') $this->action = 'update';
a35764 187         
T 188         if($data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
189             // This is not a vhost, so we need to update the parent record instead.
190             $parent_domain_id = intval($data["new"]["parent_domain_id"]);
4fae7e 191             $tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id." AND active = 'y'");
a35764 192             $data["new"] = $tmp;
T 193             $data["old"] = $tmp;
194         }
195         
196         
18341e 197         // load the server configuration options
T 198         $app->uses("getconf");
199         $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
200         
e2d6ed 201         if($data["new"]["document_root"] == '') {
T 202             $app->log("document_root not set",LOGLEVEL_WARN);
a35764 203             return 0;
T 204         }
205         if($data["new"]["system_user"] == 'root' or $data["new"]["system_group"] == 'root') {
206             $app->log("Websites can not be owned by the root user or group.",LOGLEVEL_WARN);
e2d6ed 207             return 0;
T 208         }
209         
210         //print_r($data);
211         
212         // Check if the directories are there and create them if nescessary.
213         if(!is_dir($data["new"]["document_root"]."/web")) exec("mkdir -p ".$data["new"]["document_root"]."/web");
313e33 214         if(!is_dir($data["new"]["document_root"]."/web/error")) exec("mkdir -p ".$data["new"]["document_root"]."/web/error");
T 215         //if(!is_dir($data["new"]["document_root"]."/log")) exec("mkdir -p ".$data["new"]["document_root"]."/log");
e2d6ed 216         if(!is_dir($data["new"]["document_root"]."/ssl")) exec("mkdir -p ".$data["new"]["document_root"]."/ssl");
T 217         if(!is_dir($data["new"]["document_root"]."/cgi-bin")) exec("mkdir -p ".$data["new"]["document_root"]."/cgi-bin");
218         
e2c5f8 219         // Remove the symlink for the site, if site is renamed
T 220         if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
a91fdb 221             if(is_dir($data["old"]["document_root"]."/log")) exec('rm -rf '.$data["old"]["document_root"]."/log");
D 222             if(is_link('/var/log/ispconfig/httpd/'.$data["old"]["domain"])) unlink('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
e2c5f8 223         }
T 224         
313e33 225         // Create the symlink for the logfiles
a91fdb 226         if(!is_dir($data["new"]["document_root"]."/log")) exec('mkdir -p '.$data["new"]["document_root"]."/log");
D 227         if(!is_link('/var/log/ispconfig/httpd/'.$data["new"]["domain"])) {
228             exec("ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"]);
229             $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/log /var/log/ispconfig/httpd/".$data["new"]["domain"],LOGLEVEL_DEBUG);
641781 230         }
a91fdb 231     
e2c5f8 232         // Get the client ID
15d78a 233         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["new"]["sys_groupid"]));
T 234         $client_id = intval($client["client_id"]);
235         unset($client);
e2c5f8 236         
T 237         // Remove old symlinks, if site is renamed
238         if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
239             $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
240             if(is_array($tmp_symlinks_array)) {
241                 foreach($tmp_symlinks_array as $tmp_symlink) {
242                     $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
318ace 243                     $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
e2c5f8 244                     // Remove trailing slash
T 245                     if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
246                     // create the symlinks, if not exist
247                     if(!is_link($tmp_symlink)) {
248                         exec("rm -f ".escapeshellcmd($tmp_symlink));
249                         $app->log("Removed Symlink: rm -f ".$tmp_symlink,LOGLEVEL_DEBUG);
250                     }
251                 }
252             }
253         }
254         
255         // Create the symlinks for the sites
15d78a 256         $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
0a466d 257         if(is_array($tmp_symlinks_array)) {
T 258             foreach($tmp_symlinks_array as $tmp_symlink) {
259                 $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
260                 $tmp_symlink = str_replace("[website_domain]",$data["new"]["domain"],$tmp_symlink);
261                 // Remove trailing slash
262                 if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
263                 // create the symlinks, if not exist
264                 if(!is_link($tmp_symlink)) {
265                     exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
266                     $app->log("Creating Symlink: ln -s ".$data["new"]["document_root"]."/ ".$tmp_symlink,LOGLEVEL_DEBUG);
267                 }
15d78a 268             }
T 269         }
e2d6ed 270         
e2c5f8 271         
9cb713 272         if($this->action == 'insert') {
T 273             // Copy the error pages
274             $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
275             exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
c6d48b 276             exec("chmod -R +r ".$error_page_path);
e2d6ed 277         
9cb713 278             // copy the standard index page
T 279             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");
c6d48b 280             exec("chmod +r ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
9cb713 281         }
30aa08 282         
e2d6ed 283         // Create group and user, if not exist
T 284         $app->uses("system");
285         
286         $groupname = escapeshellcmd($data["new"]["system_group"]);
287         if($data["new"]["system_group"] != '' && !$app->system->is_group($data["new"]["system_group"])) {
288             exec("groupadd $groupname");
289             $app->log("Adding the group: $groupname",LOGLEVEL_DEBUG);
290         }
291         
292         $username = escapeshellcmd($data["new"]["system_user"]);
293         if($data["new"]["system_user"] != '' && !$app->system->is_user($data["new"]["system_user"])) {
910093 294             exec("useradd -d ".escapeshellcmd($data["new"]["document_root"])." -g $groupname $username -s /bin/false");
e2d6ed 295             $app->log("Adding the user: $username",LOGLEVEL_DEBUG);
T 296         }
297         
a35764 298         // Set the quota for the user
T 299         if($username != '' && $app->system->is_user($username)) {
300             if($data["new"]["hd_quota"] > 0){
301                 $blocks_soft = $data["new"]["hd_quota"] * 1024;
302                 $blocks_hard = $blocks_soft + 1024;
303               } else {
304                 $blocks_soft = $blocks_hard = 0;
305               }
306             exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
307             exec("setquota -T -u $username 604800 604800 -a &> /dev/null");
308         }
309         
310         
311         
e2d6ed 312         // Chown and chmod the directories
T 313         exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
314         
c6d48b 315         
e2d6ed 316         // Create the vhost config file
T 317         $app->load('tpl');
318         
319         $tpl = new tpl();
320         $tpl->newTemplate("vhost.conf.master");
321         
322         $vhost_data = $data["new"];
a35764 323         $vhost_data["web_document_root"] = $data["new"]["document_root"]."/web";
026b48 324         
T 325         // Check if a SSL cert exists
326         $ssl_dir = $data["new"]["document_root"]."/ssl";
327         $domain = $data["new"]["domain"];
328           $key_file = $ssl_dir.'/'.$domain.".key";
329           $crt_file = $ssl_dir.'/'.$domain.".crt";
330         $bundle_file = $ssl_dir.'/'.$domain.".bundle";
331         
4132c6 332         if($data["new"]["ssl"] == 'y' && @is_file($crt_file) && @is_file($key_file)) {
026b48 333             $vhost_data["ssl_enabled"] = 1;
T 334             $app->log("Enable SSL for: $domain",LOGLEVEL_DEBUG);
335         } else {
336             $vhost_data["ssl_enabled"] = 0;
337             $app->log("Disable SSL for: $domain",LOGLEVEL_DEBUG);
338         }
339         
340         if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;
341         
a35764 342         //$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
e2d6ed 343         $tpl->setVar($vhost_data);
T 344         
a35764 345         // Rewrite rules
T 346         $rewrite_rules = array();
347         if($data["new"]["redirect_type"] != '') {
348             $rewrite_rules[] = array(    'rewrite_domain'     => $data["new"]["domain"],
349                                         'rewrite_type'         => $data["new"]["redirect_type"],
350                                         'rewrite_target'     => $data["new"]["redirect_path"]);
351         }
352         
353         // get alias domains (co-domains and subdomains)
4fae7e 354         $aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND active = 'y'");
e2d6ed 355         $server_alias = '';
a35764 356         if(is_array($aliases)) {
T 357             foreach($aliases as $alias) {
358                 $server_alias .= $alias["domain"].' ';
359                 $app->log("Add server alias: $alias[domain]",LOGLEVEL_DEBUG);
360                 // Rewriting
361                 if($alias["redirect_type"] != '') {
362                     $rewrite_rules[] = array(    'rewrite_domain'     => $alias["domain"],
363                                                 'rewrite_type'         => $alias["redirect_type"],
364                                                 'rewrite_target'     => $alias["redirect_path"]);
365                 }
366             }
e2d6ed 367         }
T 368         $tpl->setVar('alias',trim($server_alias));
df7382 369         if(count($rewrite_rules) > 0) {
T 370             $tpl->setVar('rewrite_enabled',1);
371         } else {
372             $tpl->setVar('rewrite_enabled',0);
373         }
a35764 374         $tpl->setLoop('redirects',$rewrite_rules);
e2d6ed 375         
9b9ba4 376         /** 
D 377          * install fast-cgi starter script and add script aliasd config 
378          * first we create the script directory if not already created, then copy over the starter script
379          * settings are copied over from the server ini config for now
380          * TODO: Create form for fastcgi configs per site.
381          */
382         
383         if ($data["new"]["php"] == "fast-cgi")
384         {
6a95c8 385             $fastcgi_config = $app->getconf->get_server_config($conf["server_id"], 'fastcgi');
D 386             
387             $fastcgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$fastcgi_config["fastcgi_starter_path"]);
61d290 388             $fastcgi_starter_path = str_replace("[client_id]",$client_id,$fastcgi_starter_path);
D 389             
9b9ba4 390             if (!is_dir($fastcgi_starter_path))
D 391             {
61d290 392                 exec("mkdir -p ".escapeshellcmd($fastcgi_starter_path));
D 393                 exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($fastcgi_starter_path));
6a95c8 394                 
D 395                 
396                 $app->log("Creating fastcgi starter script directory: $fastcgi_starter_path",LOGLEVEL_DEBUG);
9b9ba4 397             }
D 398             
399             $fcgi_tpl = new tpl();
400             $fcgi_tpl->newTemplate("php-fcgi-starter.master");
401                 
6a95c8 402             $fcgi_tpl->setVar('php_ini_path',$fastcgi_config["fastcgi_phpini_path"]);
9b9ba4 403             $fcgi_tpl->setVar('document_root',$data["new"]["document_root"]);
6a95c8 404             $fcgi_tpl->setVar('php_fcgi_children',$fastcgi_config["fastcgi_children"]);
D 405             $fcgi_tpl->setVar('php_fcgi_max_requests',$fastcgi_config["fastcgi_max_requests"]);
406             $fcgi_tpl->setVar('php_fcgi_bin',$fastcgi_config["fastcgi_bin"]);
9b9ba4 407                 
61d290 408             $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config["fastcgi_starter_script"]);
9b9ba4 409             file_put_contents($fcgi_starter_script,$fcgi_tpl->grab());
D 410             unset($fcgi_tpl);
6a95c8 411             
D 412             $app->log("Creating fastcgi starter script: $fcgi_starter_script",LOGLEVEL_DEBUG);
413             
9b9ba4 414             
D 415             exec("chmod 755 $fcgi_starter_script");
416             exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $fcgi_starter_script");
417
6a95c8 418             $tpl->setVar('fastcgi_alias',$fastcgi_config["fastcgi_alias"]);
9b9ba4 419             $tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path);
D 420             
421         }
422         
e2d6ed 423         $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
T 424         file_put_contents($vhost_file,$tpl->grab());
425         $app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
426         unset($tpl);
427         
428         // Set the symlink to enable the vhost
429         $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["new"]["domain"].'.vhost');
430         if($data["new"]["active"] == 'y' && !is_link($vhost_symlink)) {
431             symlink($vhost_file,$vhost_symlink);
432             $app->log("Creating the symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
433         }
434         
435         // Remove the symlink, if site is inactive
436         if($data["new"]["active"] == 'n' && is_link($vhost_symlink)) {
437             unlink($vhost_symlink);
438             $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
439         }
440         
6724a4 441         // remove old symlink and vhost file, if domain name of the site has changed
318ace 442         if($this->action == 'update' && $data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"]) {
T 443             $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
444             unlink($vhost_symlink);
445             $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
6724a4 446             $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
T 447             unlink($vhost_file);
448             $app->log("Removing File $vhost_file",LOGLEVEL_DEBUG);
318ace 449         }
T 450         
e2d6ed 451         // request a httpd reload when all records have been processed
T 452         $app->services->restartServiceDelayed('httpd','reload');
18341e 453         
T 454     }
455     
456     function delete($event_name,$data) {
457         global $app, $conf;
458         
e2d6ed 459         // load the server configuration options
T 460         $app->uses("getconf");
461         $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
462         
463         // Deleting the vhost file, symlink and the data directory
464         $vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
465         unlink($vhost_symlink);
466         $app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
467         
468         $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
469         unlink($vhost_file);
470         $app->log("Removing vhost file: $vhost_file",LOGLEVEL_DEBUG);
471         
472         $docroot = escapeshellcmd($data["old"]["document_root"]);
473         if($docroot != '' && !stristr($docroot,'..')) exec("rm -rf $docroot");
a91fdb 474         
5a8b3e 475         
a91fdb 476         //remove the php fastgi starter script if available
D 477         if ($data["old"]["php"] == "fast-cgi")
478         {
479             $fastcgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["fastcgi_starter_path"]);
480             if (is_dir($fastcgi_starter_path))
481             {
482                     exec("rm -rf $fastcgi_starter_path");
483             }
484         }
485         
e2d6ed 486         $app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
18341e 487         
0a466d 488         // Delete the symlinks for the sites
T 489         $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
490         $client_id = intval($client["client_id"]);
491         unset($client);
492         $tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
493         if(is_array($tmp_symlinks_array)) {
494             foreach($tmp_symlinks_array as $tmp_symlink) {
495                 $tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
496                 $tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
497                 // Remove trailing slash
498                 if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
499                 // create the symlinks, if not exist
500                 if(is_link($tmp_symlink)) {
4132c6 501                     unlink($tmp_symlink);
0a466d 502                     $app->log("Removing symlink: ".$tmp_symlink,LOGLEVEL_DEBUG);
T 503                 }
504             }
505         }
506         // end removing symlinks
507         
eded9d 508         // Delete the log file directory
T 509         $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
510         if($data["old"]["domain"] != '' && !stristr($vhost_logfile_dir,'..')) exec("rm -rf $vhost_logfile_dir");
511         $app->log("Removing website logfile directory: $vhost_logfile_dir",LOGLEVEL_DEBUG);
512         
6a95c8 513         //delete the web user
D 514         $command = 'userdel';
515         $command .= ' '.$data["old"]["system_user"];            
516         exec($command);
18341e 517     }
T 518     
af8f1b 519     //* This function is called when a IP on the server is inserted, updated or deleted
T 520     function server_ip($event_name,$data) {
521         global $app, $conf;
522         
523         // Here we write the name virtualhost directives
524         // NameVirtualHost IP:80
525         // NameVirtualHost IP:443
526         
527     }
528     
18341e 529
T 530 } // end class
531
532 ?>