rendered paste body<?php/* * Info: Quick Hack for lighttpd to use syscp backend. * Creator: wese [at] gmx [dot] at * * Notes: Use on your own risks * * Req: * Module - auth * Module - fastcgi (for php support) * * Progress Subject: * [ok] Safemode * [ok] Open_Basedir * [ok] Directorylisting * [ok] htaccess / Directory protection * * > Warning: if lighty is restartet without the required htpasswd files * > lighty will stop! * * [pending] Custom ErrorPages * > Didnt care about yet. */ // comment this out if you not want to use the SysCP Backend require_once("/var/www/syscp/lib/userdata.inc.php"); mysql_connect($sql['host'], $sql['user'], $sql['password']) or die("Could not connect to MySQL server!"); mysql_select_db($sql['db']); // Domain und VHOST Einstellungen $db_res=mysql_query( "SELECT `panel_domains`.`domain` as domain, `panel_domains`.`documentroot` as docroot, `panel_domains`.`openbasedir` as openbasedir, `panel_domains`.`safemode` as safemode, `panel_customers`.`guid` as uid, `panel_customers`.`guid` as gid, `panel_customers`.`loginname` as loginname, `panel_domains`.`speciallogfile` as speciallogfile FROM `panel_domains` LEFT JOIN `panel_customers` ON `panel_domains`.`customerid` = `panel_customers`.`customerid` WHERE `panel_domains`.`deactivated` = 0 AND `panel_customers`.`deactivated` = 0;"); while($db_row=mysql_fetch_assoc($db_res)) $syscp_vhosts[] = $db_row; // Syscp Settings $db_res=mysql_query( "SELECT `panel_settings`.`varname` as varname, `panel_settings`.`value` as value FROM `panel_settings`;"); while($syscp_settings_row=mysql_fetch_assoc($db_res)) $syscp_settings[$syscp_settings_row["varname"]] = $syscp_settings_row["value"]; foreach($syscp_vhosts as $vhost) { echo "\$HTTP[\"host\"] == \"" . $vhost["domain"] . "\" {\n"; echo "\tserver.name = \"" . $vhost["domain"] . "\"\n"; echo "\tserver.document-root = \"" . $vhost["docroot"] . "\"\n"; echo "\taccesslog.filename = \"" . $syscp_settings["logfiles_directory"] . $vhost["loginname"] . (($vhost["speciallogfile"]==1)? ( "-" . $vhost["domain"] ) : "" ) . "-access.log\"\n"; echo "\tserver.errorlog = \"" . $syscp_settings["logfiles_directory"] . $vhost["loginname"] . (($vhost["speciallogfile"]==1)? ( "-" . $vhost["domain"] ) : "" ) . "-error.log\"\n"; //echo "\n\t## FastCGI-PHP-Settings ##\n\n"; echo "\n"; echo "\tindex-file.names+=(\"index.php\")\n"; echo "\tfastcgi.server=(\n"; echo "\t\t\".php\" => (\n"; echo "\t\t\t\"localhost\" => (\n"; // Open_Basedir // stolen from cron_task $_phpappendopenbasedir = (($syscp_settings['phpappendopenbasedir'] != '') ? ':' . $syscp_settings['phpappendopenbasedir'] : ''); $_open_basedir=$vhost["docroot"].$_phpappendopenbasedir; // ($domain['openbasedir_path'] == '1') // is ignored, due to lack of interesst. FIXME echo "\t\t\t\t\"bin-path\" => \"/usr/bin/php5-cgi -d open_basedir=" . $_open_basedir . " -d safe_mode=" . (($vhost["safemode"])?"On":"Off") . " -c /etc/php5/cgi/php.ini\",\n"; echo "\t\t\t\t\"socket\" => \"/tmp/php5-socket\",\n"; echo "\t\t\t\t\"max-procs\" => \"4\",\n"; echo "\t\t\t\t\"docroot\" => \"". $vhost["docroot"] ."\",\n"; // ++ CHECKME echo "\t\t\t\t\"check-local\" => \"enable\",\n"; // ++ CHECKME echo "\t\t\t\t\"bin-environment\" => (\n"; echo "\t\t\t\t\t\"PHP_FCGI_CHILDREN\" => \"4\",\n"; echo "\t\t\t\t\t\"PHP_FCGI_MAX_REQUESTS\" => \"10000\",\n"; echo "\t\t\t\t\t\"TMP\" => \"/tmp\",\n"; echo "\t\t\t\t\t\"TEMP\" => \"/tmp\"\n"; echo "\t\t\t\t),\n"; echo "\t\t\t\t\"bin-copy-environment\" => (\n"; echo "\t\t\t\t\t\"PATH\",\n"; echo "\t\t\t\t\t\"SHELL\",\n"; echo "\t\t\t\t\t\"USER\"\n"; echo "\t\t\t\t),\n"; echo "\t\t\t\t\"broken-scriptfilename\" => \"enable\"\n"; echo "\t\t\t)\n"; echo "\t\t)\n"; echo "\t)\n"; // .htaccess / Directory Protection $db_res=mysql_query( "SELECT `panel_htpasswds`.`id` as id, `panel_htpasswds`.`customerid` as customerid, `panel_htpasswds`.`path` as path, `panel_htpasswds`.`username` as username FROM `panel_htpasswds` WHERE `panel_htpasswds`.`path` LIKE '". $vhost["docroot"] ."%';"); if(mysql_num_rows($db_res)>0) { unset($syscp_htaccess); while($syscp_htaccess_row = mysql_fetch_assoc($db_res)) $syscp_htaccess[] = $syscp_htaccess_row; foreach ($syscp_htaccess as $syscp_diroptions) { $htpasswd_filename = $syscp_settings["apacheconf_directory"] . 'htpasswd/' . $syscp_diroptions['customerid'] . '-' . $syscp_diroptions['id'] . '-' . md5($syscp_diroptions['path']) . '.htpasswd'; $HTTP_url = preg_replace("/^" . str_replace("/","\/",$vhost["docroot"]) . "/" , "" , $syscp_diroptions["path"]); echo "\t\$HTTP[\"url\"] =~ \"^/" . $HTTP_url ."\" {\n"; echo "\t\tauth.backend = \"htpasswd\"\n"; echo "\t\tauth.backend.htpasswd.userfile = \"" . $htpasswd_filename ."\"\n"; echo "\t\tauth.require = (\n"; echo "\t\t\t\"". $syscp_diroptions['path'] ."\" => (\n"; echo "\t\t\t\t\"method\" => \"digest\",\n"; echo "\t\t\t\t\"realm\" => \"Protected\",\n"; echo "\t\t\t\t\"require\" => \"valid-user\"\n"; echo "\t\t\t)\n"; echo "\t\t)\n"; echo "\t}\n"; } // end if num_rows } // end .htaccess-foreach // .htaccess / Directory Listing $db_res=mysql_query( "SELECT `panel_htaccess`.`id` as id, `panel_htaccess`.`customerid` as customerid, `panel_htaccess`.`path` as path FROM `panel_htaccess` WHERE `panel_htaccess`.`path` LIKE '". $vhost["docroot"] ."%';"); if(mysql_num_rows($db_res)>0) { unset($syscp_htaccess); while($syscp_htaccess_row = mysql_fetch_assoc($db_res)) $syscp_htaccess[] = $syscp_htaccess_row; $HTTP_url = preg_replace("/^" . str_replace("/","\/",$vhost["docroot"]) . "/" , "" , $syscp_diroptions["path"]); foreach ($syscp_htaccess as $syscp_diroptions) { echo "\$HTTP[\"url\"] =~ \"^/" . $HTTP_url . "\" { \n"; echo "\tdir-listing.activate = \"enable\""; echo "}\n"; } // end if num_rows } // end .htaccess-foreach echo "}\n\n"; } // end vhost-foreach mysql_close();?>