plugins->registerEvent('server_insert','apps_vhost_plugin','insert'); $app->plugins->registerEvent('server_update','apps_vhost_plugin','update'); } function insert($event_name,$data) { global $app, $conf; $this->update($event_name,$data); } // The purpose of this plugin is to rewrite the main.cf file function update($event_name,$data) { global $app, $conf; // get the config $app->uses("getconf"); $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); // Dont just copy over the virtualhost template but add some custom settings $content = file_get_contents($conf["rootpath"]."/conf/apache_apps.vhost.master"); $vhost_conf_dir = $web_config['vhost_conf_dir']; $vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir']; $apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername']; $web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port']; $web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip']; $content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content); $content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content); $content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content); $content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); $content = str_replace('{apps_vhost_basedir}', $web_config['website_basedir'], $content); // comment out the listen directive if port is 80 or 443 if($web_config['apps_vhost_ip'] == 80 or $web_config['apps_vhost_ip'] == 443) { $content = str_replace('{vhost_port_listen}', '#', $content); } else { $content = str_replace('{vhost_port_listen}', '', $content); } file_put_contents("$vhost_conf_dir/apps.vhost", $content); $app->services->restartServiceDelayed('httpd','restart'); } } // end class ?>