@@ -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