View Single Post
  #6  
Old 9th October 2006, 18:14
PSIplus PSIplus is offline
Junior Member
 
Join Date: Oct 2006
Location: Vienna/Austria
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to PSIplus Send a message via AIM to PSIplus Send a message via Yahoo to PSIplus Send a message via Skype™ to PSIplus
Talking Update :-)

I overworked it a bit... And got it now running on one of my smaller servers (runs pretty stable :-) )

lighttpd.conf:
Code:
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/root/ispconfig/scripts/lighttpd.conf.php"
/root/ispconfig/scripts/lighttpd.conf.php:
Code:
#!/root/ispconfig/php/php -q
<?

$go_info["server"]["db_host"] = "localhost";
$go_info["server"]["db_name"] = "db_ispconfig";
$go_info["server"]["db_user"] = "ispconfig_root";
$go_info["server"]["db_password"] = "12345";
$go_info["server"]["db_type"] = "mysql";

mysql_connect($go_info["server"]["db_host"], $go_info["server"]["db_user"], $go_info["server"]["db_password"]) or die("Could not connect to MySQL server!");
mysql_select_db($go_info["server"]["db_name"]);

$year=date("Y");
$month=date("m");
$prefix_web="web";

$db_res=mysql_query("select isp_isp_web.doc_id,isp_isp_domain.domain_host,isp_isp_domain.domain_domain from isp_isp_domain,isp_isp_web,isp_dep where isp_dep.parent_doc_id=isp_isp_web.doc_id and isp_dep.child_doc_id=isp_isp_domain.doc_id and isp_dep.parent_doctype_id=isp_isp_web.doctype_id and isp_dep.child_doctype_id=isp_isp_domain.doctype_id");
while(list($id,$hs,$dm)=mysql_fetch_array($db_res))$ahosts[$id][]=array($hs,$dm);

list($shost,$sdomain,$docroot,$user,$group,$log,$sname)=mysql_fetch_array(mysql_query("select server_host,server_domain,server_path_httpd_root,server_httpd_user,server_httpd_group,server_path_httpd_log,dist_httpd_daemon from isp_server limit 1"));

if($shost)$sdomain="$shost.$sdomain";

echo "\n\n## Static Preferences ##\n\n";
echo "server.modules=(\"mod_access\",\"mod_cgi\",\"mod_accesslog\",\"mod_fastcgi\",\"mod_ssi\",\"mod_alias\")\n";
echo "server.errorlog=\"/var/log/lighttpd/error.log\"\n";
echo "server.pid-file=\"/var/run/lighttpd.pid\"\n";
echo "index-file.names=(\"index.html\",\"index.htm\")\n";
echo "url.access-deny=(\"~\",\".inc\")\n";
echo "server.event-handler=\"linux-sysepoll\"\n";

echo "\n\n## Dynamic Preferences ##\n\n";
echo "server.name=\"$sdomain\"\n";
echo "server.tag=\"ispconfig/lighttpd@$sdomain\"\n";
echo "server.username=\"$user\"\n";
echo "server.groupname=\"$group\"\n";
echo "server.document-root=\"$docroot/sharedip\"\n";
echo "accesslog.filename=\"$log\"\n";
//echo "#accesslog.filename=\"/var/log/lighttpd/access.log\"\n";
system("chown $user:$group $log");

echo "\n\n## Global Dirlist-Settings ##\n\n";
echo "server.dir-listing=\"enable\"\n";
echo "dir-listing.encoding=\"iso-8859-15\"\n";
echo "dir-listing.hide-dotfiles=\"enable\"\n";
echo "#dir-listing.external-css=\"/dir.css\"\n";



$db_res=mysql_query("select * from isp_isp_web");

echo "\n\n## Dynamic VHOSTS ##\n\n";

while($qline=mysql_fetch_array($db_res))
{
    $parlist=array
    (
        "id"=>$qline["doc_id"],
        "dirlist"=>true,
        "cgi"=>$qline["web_cgi"],
        "php"=>$qline["web_php"],
        "safemode"=>$qline["web_php_safe_mode"],
        "ssi"=>$qline["web_ssi"],
        "error"=>$qline["web_individual_error_pages"],
    );
    $vhlist[$qline["web_domain"]]=$parlist;
    if($qline["web_host"]&&$qline["web_host"]!="NULL") $vhlist[$qline["web_host"].".".$qline["web_domain"]]=$parlist;
    if(is_array($ahosts[$qline["doc_id"]]))
    {
        reset($ahosts[$qline["doc_id"]]);
        while(list(,list($hs,$dm))=each($ahosts[$qline["doc_id"]]))
        {
            if(!$vhlist[$dm])$vhlist[$dm]=$parlist;
            if($hs&&$hs!="NULL"&&!$vhlist["$hs.$dm"])$vhlist["$hs.$dm"]=$parlist;
        }
    }
}
reset($vhlist);
while(list($host,$parm)=each($vhlist))
{
    if(!is_dir("$docroot/$prefix_web$parm[id]/log/$year/$month"))system("mkdir -p $docroot/$prefix_web$parm[id]/log/$year/$month");
    touch("$docroot/$prefix_web$parm[id]/log/$year/$month/web.log");
    system("chown -R $user:$group $docroot/$prefix_web$parm[id]/log");
    echo "\$HTTP[\"host\"]==\"$host\" {\n";
    echo "\tserver.name=\"$host\"\n";
    echo "\tserver.document-root=\"$docroot/$prefix_web$parm[id]/web\"\n";
    echo "\taccesslog.filename=\"$docroot/$prefix_web$parm[id]/log/$year/$month/web.log\"\n";
    echo "\tserver.errorlog=\"$docroot/$prefix_web$parm[id]/log/error.log\"\n";
    echo "\tserver.dir-listing=\"".(($parm["dirlist"])?"enable":"disable")."\"\n";

    if($parm["cgi"]) echo "\n\t## CGI-Settings ##\n\tcgi.assign=(\n\t\t\".pl\"=>\"/usr/bin/perl\",\n\t\t\".py\"=>\"/usr/bin/python\",\n\t)\n";

    if($parm["php"])
    {
        echo "\n\t## FastCGI-PHP-Settings ##\n";
        echo "\tindex-file.names+=(\"index.php\")\n\n";
        echo "\tfastcgi.server=(\n";
        echo "\t    \".php\"=>(\n";
        echo "\t        \"localhost\"=>(\n";
        echo "\t            \"bin-path\"=>\"/usr/bin/php5-cgi -c /etc/php5/cgi/php".(($parm["safemode"])?"_safe":"").".ini\",\n";
        echo "\t            \"socket\"=>\"/tmp/php5-".(($parm["safemode"])?"safe-":"")."socket\",\n";
        echo "\t            \"max-procs\"=>4,\n";
        echo "\t            \"bin-environment\"=>( \n";
        echo "\t                \"PHP_FCGI_CHILDREN\"=>\"4\",\n";
        echo "\t                \"PHP_FCGI_MAX_REQUESTS\"=>\"10000\",\n";
        echo "\t                \"TMP\"=>\"$docroot/tmp\",\n";
        echo "\t                \"TEMP\"=>\"$docroot/tmp\",\n";
        echo "\t            ),\n";
        echo "\t            \"bin-copy-environment\"=>(\n";
        echo "\t                \"PATH\",\n";
        echo "\t                \"SHELL\",\n";
        echo "\t                \"USER\",\n";
        echo "\t            ),\n";
        echo "\t            \"broken-scriptfilename\"=>\"enable\"\n";
        echo "\t        )\n";
        echo "\t    )\n";
        echo "\t)\n";
    }

    if($parm["ssi"])
    {
        echo "\n\t## SSI-Settings ##\n\tssi.extension=(\".shtml\")\n";
    }

    echo "\n\t## Error-Handling ##\n";
    echo "\talias.url=(\"/error/\"=>\"$docroot/$prefix_web$parm[id]/web/error/\")\n";
    if($parm["error"])
    {
        /*
        ErrorDocument 400 /error/invalidSyntax.html
        ErrorDocument 401 /error/authorizationRequired.html
        ErrorDocument 403 /error/forbidden.html
        ErrorDocument 404 /error/fileNotFound.html
        ErrorDocument 405 /error/methodNotAllowed.html
        ErrorDocument 500 /error/internalServerError.html
        ErrorDocument 503 /error/overloaded.html
        AliasMatch ^/~([^/]+)(/(.*))? /var/www/web12/user/$1/web/$3
        AliasMatch ^/users/([^/]+)(/(.*))? /var/www/web12/user/$1/web/$3
        */
    }

    echo "}\n\n";
}

?>
It works pretty well and even sets the permissions on startup :-)

However, someday I should use the config.inc stuff to connect to mysql...

And: You should update the apache_reload-function to restart lighttpd instead of apache, I've done it, but I forgot where... But this solution is VERY stable...

You can adapt the settings below "Static Preferences" with values from ispconfig...

Yes, and I made php a bit more secure by creating php_safe.ini für safemode, set open_basedir to /var/www there and as tempdir /var/www/tmp ... However, it would be absolutely easy to use the suexec-stuff and improve this even more, maybe I'll do this someday ;-)

Have Fun!
__________________
PSIplus' Site
Reply With Quote