Skip to content

Commit 566306a

Browse files
author
vogelor
committed
cgi now works with suexec (added cgi-wrapper)
1 parent 2ae58a2 commit 566306a

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

server/conf/php-cgi-starter.master

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
exec <tmpl_var name='php_cgi_bin'> \
4+
-d open_basedir=<tmpl_var name='open_basedir'> \
5+
-d upload_tmp_dir=<tmpl_var name='open_basedir'>/tmp \
6+
-d session.save_path=<tmpl_var name='open_basedir'>/tmp
7+
# -d safe_mode=${SAFE_MODE}

server/conf/vhost.conf.master

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</tmpl_if>
6868
<tmpl_if name='php' op='==' value='cgi'>
6969
# php as cgi enabled
70-
ScriptAlias /php5-cgi /usr/bin/php5-cgi
70+
ScriptAlias /php5-cgi <tmpl_var name='cgi_starter_path'><tmpl_var name='cgi_starter_script'>
7171
Action php5-cgi /php5-cgi
7272
AddHandler php5-cgi .php .php3 .php4 .php5
7373
</tmpl_if>
@@ -166,7 +166,7 @@
166166
</tmpl_if>
167167
<tmpl_if name='php' op='==' value='cgi'>
168168
# php as cgi enabled
169-
ScriptAlias /php5-cgi /usr/bin/php5-cgi
169+
ScriptAlias /php5-cgi <tmpl_var name='cgi_starter_path'><tmpl_var name='cgi_starter_script'>
170170
Action php5-cgi /php5-cgi
171171
AddHandler php5-cgi .php .php3 .php4 .php5
172172
</tmpl_if>

server/plugins-available/apache2_plugin.inc.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,53 @@ function update($event_name,$data) {
540540

541541
}
542542

543+
/**
544+
* install cgi starter script and add script alias to config.
545+
* This is needed to allow cgi with suexec (to do so, we need a bin in the document-path!)
546+
* first we create the script directory if not already created, then copy over the starter script.
547+
* TODO: we have to fetch the data from the server-settings.
548+
*/
549+
550+
if ($data["new"]["php"] == "cgi")
551+
{
552+
//$cgi_config = $app->getconf->get_server_config($conf["server_id"], 'cgi');
553+
554+
$cgi_config["cgi_starter_path"] = "/var/www/php-cgi-scripts/[system_user]/";
555+
$cgi_config["cgi_starter_script"] = "php-cgi-starter";
556+
$cgi_config["cgi_bin"] = "/usr/bin/php-cgi";
557+
558+
$cgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$cgi_config["cgi_starter_path"]);
559+
$cgi_starter_path = str_replace("[client_id]",$client_id,$cgi_starter_path);
560+
561+
if (!is_dir($cgi_starter_path))
562+
{
563+
exec("mkdir -p ".escapeshellcmd($cgi_starter_path));
564+
exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." ".escapeshellcmd($cgi_starter_path));
565+
566+
$app->log("Creating cgi starter script directory: $cgi_starter_path",LOGLEVEL_DEBUG);
567+
}
568+
569+
$cgi_tpl = new tpl();
570+
$cgi_tpl->newTemplate("php-cgi-starter.master");
571+
572+
$cgi_tpl->setVar('open_basedir',$data["new"]["document_root"]);
573+
$cgi_tpl->setVar('php_cgi_bin',$cgi_config["cgi_bin"]);
574+
575+
$cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config["cgi_starter_script"]);
576+
file_put_contents($cgi_starter_script,$cgi_tpl->grab());
577+
unset($cgi_tpl);
578+
579+
$app->log("Creating cgi starter script: $cgi_starter_script",LOGLEVEL_DEBUG);
580+
581+
582+
exec("chmod 755 $cgi_starter_script");
583+
exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $cgi_starter_script");
584+
585+
$tpl->setVar('cgi_starter_path',$cgi_starter_path);
586+
$tpl->setVar('cgi_starter_script',$cgi_config["cgi_starter_script"]);
587+
588+
}
589+
543590
$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
544591
file_put_contents($vhost_file,$tpl->grab());
545592
$app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
@@ -603,6 +650,19 @@ function delete($event_name,$data) {
603650
}
604651
}
605652

653+
//remove the php cgi starter script if available
654+
if ($data["old"]["php"] == "cgi")
655+
{
656+
// TODO: fetch the date from the server-settings
657+
$web_config["cgi_starter_path"] = "/var/www/php-cgi-scripts/[system_user]/";
658+
659+
$cgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["cgi_starter_path"]);
660+
if (is_dir($cgi_starter_path))
661+
{
662+
exec("rm -rf $cgi_starter_path");
663+
}
664+
}
665+
606666
$app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
607667

608668
// Delete the symlinks for the sites

0 commit comments

Comments
 (0)