function insert() { $newDomainName = isset($_GET['newdomain']) ? $_GET['newdomain'] : null; $domainFileToCreate = NGINX_DOMAINS_DIR . $newDomainName . '.conf'; clearstatcache(); /** * Create folder "domains" in "/bin/nginx/conf", if not existant yet. * * Note: the folder is normally created during installation. * This is just a fallback, in case the user might have removed it. */ if (!is_dir(NGINX_DOMAINS_DIR)) { mkdir(NGINX_DOMAINS_DIR, 0777); } // read domain template file $tplContent = file_get_contents(WPNXM_DATA_DIR . '/config-templates/nginx-domain-conf.tpl'); // replace the host name in the domain template $content = str_replace('%%domain%%', $newDomainName, $tplContent); // write new domain file using the domain template as content file_put_contents($domainFileToCreate, $content); // Add include-line for new domain file in "\bin\nginx\conf\domains.conf" clearstatcache(); $domainsMainConfigFile = WPNXM_DIR . '\\bin\\nginx\\conf\\domains.conf'; if (!is_writable($domainsMainConfigFile) && !chmod($domainsMainConfigFile, 0777)) { exit('The "domains.conf" file is not writeable. Please modify permissions.'); } else { file_put_contents($domainsMainConfigFile, "\n # automatically added domain configuration file \n include domains/{$newDomainName}.conf;", FILE_APPEND); } // check for "COM" (php_com_dotnet.dll) if (!class_exists('COM') and !extension_loaded("com_dotnet")) { $msg = 'COM class not found. Enable the extension by adding "extension=php_com_dotnet.dll" to your php.ini.'; throw new Exception($msg); } $WshShell = new COM("WScript.Shell"); // reload nginx configuration $cmdRestartNginx = 'cmd /c "' . WPNXM_DIR . '\\bin\\nginx\\nginx.exe -p ' . WPNXM_DIR . ' -c ' . WPNXM_DIR . '\\bin\\nginx\\conf\\nginx.conf -s reload"'; $oExec = $WshShell->run($cmdRestartNginx, 0, false); // add the new virtual host to the windows .hosts file using the "hosts" tool $cmdAddHosts = 'cmd /c "' . WPNXM_DIR . '\\bin\\tools\\hosts' . ' add ' . $_SERVER['SERVER_ADDR'] . ' ' . $newDomainName . ' # added by WPN-XM"'; passthru($cmdAddHosts); // flush ipcache $cmdIpflush = 'ipconfig /flushdns'; $oExec = $WshShell->run($cmdIpflush, 0, false); // wait a second for dns flush sleep(1); // forward to new host header("Location: http://{$newDomainName}/"); }
function compile_wb($source_dir, $php_vers, $vers_plus) { // set variables for makefile $obj_tmp_dir = PATH_BASE . 'obj'; $dll_dir = PATH_BASE . "WinbinderComp\\binaries\\php-{$php_vers}xt"; $inc_dir = PATH_INC; $ms_lib = PATH_LIB; $lib_dir = PATH_BASE . "WinbinderComp\\csource\\php-{$php_vers}"; $phplib = $lib_dir . "\\php-" . $php_vers . "ts.lib"; $cl = PATH_BIN . "cl.exe"; $rc = PATH_BIN . "rc"; $link = PATH_BIN . "link"; $nmake = PATH_BIN . "nmake"; $cl = "cl"; $rc = "rc"; $link = "link"; $nmake = PATH_BIN . "nmake"; // ------------------------------------------------------------------- Compile environment $P_path = getenv('PATH'); if (strstr($P_path, PATH_BIN) === false) { $P_path = PATH_BIN . ";" . $P_path; } $P_path = putenv("PATH={$P_path}"); $P_path = putenv("INCLUDE={$inc_dir}"); $P_path = putenv("LIB={$ms_lib}"); // ------------------------------------------------------------------- Makefile template $m_comp = <<<MCOMP all: \$(DLLDIR)\\php_winbinder.dll \$(OBJS): \$(SOURCES) \t\$(cc) /nologo /MT /W3 /GX /O2 /YX /FD /c /QIfist \\ \t/D "NDEBUG" /D ZEND_DEBUG=0 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D HAVE_WIN32STD=1 \\ \t/I "\$(LIBDIR)" /I "\$(INCDIR)\\" /I "\$(LIBDIR)\\main" /I "\$(LIBDIR)\\Zend" /I "\$(LIBDIR)\\win32" /I "\$(LIBDIR)\\TSRM" /I "\$(LIBDIR)xt\\standard" \\ \t/Fo"\$(OUTDIR)\\\\" /Fd"\$(OUTDIR)\\\\" \$(SOURCES) \$(OUTDIR)\\php_winbinder.dll.res: \$(RCFILE) \$(DLLDIR)\\php_winbinder.dll: \$(OBJS) \t\$(rc) /r /fo \$(OUTDIR)\\php_winbinder.dll.res /i "\$(SRCDIR)\\" /d \$(FD) /d FILE_NAME="\\"php_winbinder.dll\\"" /d \$(PN) /d \$(PV) \$(RCFILE) \t\$(link) /nologo /dll /machine:I386 -out:\$(DLLDIR)\\php_winbinder.dll \\ \t\$(OBJS) \$(LIBS) \$(OUTDIR)\\php_winbinder.dll.res #clean temporary files: \tdel /q \$(OUTDIR)\\ *.pch \$(DLLDIR)\\php_winbinder.exp \$(DLLDIR)\\php_winbinder.lib MCOMP; if (!is_dir($obj_tmp_dir)) { if (!mkdir($obj_tmp_dir)) { // Stefano: now returns message to enable warning handling, instead of calling echo return 'Warning: could not create ' . $obj_tmp_dir; } } else { delete_files($obj_tmp_dir . '\\'); } $libs = array("user32.lib", "gdi32.lib", "comdlg32.lib", "comctl32.lib", "shell32.lib", "ole32.lib ", "oleaut32.lib", "winmm.lib", "advapi32.lib", $phplib); $c_files = array(); $h_files = array(); $rc_files = array(); $sub_dirs = array('.'); while (($s_dir = array_shift($sub_dirs)) != null) { $content = get_all_files($source_dir, $s_dir); $sub_dirs = array_merge($sub_dirs, $content['dir']); $c_files = array_merge($c_files, $content['c']); $h_files = array_merge($h_files, $content['h']); $rc_files = array_merge($rc_files, $content['rc']); } // while if (count($c_files) == 0) { // Stefano: now returns message to enable error handling, instead of calling die return 'Fatal error: source to compile not found'; } // assemble SOURCES OBJS $sources_str = "SOURCES = "; $objs_str = "OBJS = "; foreach ($c_files as $c_f) { $sources_str .= "\t\\\n\t" . $source_dir . $c_f; $objs_str .= "\t\\\n\t" . $obj_tmp_dir . "\\" . str_replace('.c', '.obj', basename($c_f)); } // assemble LIBS $libs_str = "LIBS = "; foreach ($libs as $l) { $libs_str .= "\t\\\n\t" . $l; } // get rc file if (count($rc_files) == 1) { $rc_file = $source_dir . $rc_files[0]; // should only one! } else { $rc_file = ""; } // def $def_str = "OUTDIR = {$obj_tmp_dir} \n"; $def_str .= "LIBDIR = {$lib_dir} \n"; $def_str .= "DLLDIR = {$dll_dir} \n"; $def_str .= "SRCDIR = {$source_dir} \n"; $def_str .= "INCDIR = {$inc_dir} \n"; $def_str .= "MSLIB = {$ms_lib} \n"; $def_str .= "RCFILE = {$rc_file} \n"; $def_str .= "cc = {$cl} \n"; $def_str .= "rc = {$rc} \n"; $def_str .= "link = {$link} \n"; $sources_str .= "\n\n"; $objs_str .= "\n\n"; $def_str .= "\n\n"; // stitch together makefile $make_str = $def_str . $sources_str . $objs_str . $libs_str . $m_comp; $res = file_put_contents("makefile", $make_str); // nmake run $cmd = PATH_BIN . 'nmake'; $par = ' -f makefile FD="FILE_DESCRIPTION=\\"\\\\\\"Windows Binding for PHP ' . $vers_plus . '\\\\\\"\\"" PN="PRODUCT_NAME=\\"\\\\\\"PHP ' . $vers_plus . ' php_winbinder.dll\\\\\\"\\"" PV="P_VERSION=\\"\\\\\\"' . $vers_plus . '\\\\\\"\\""'; $par = ' -f ' . PATH_BASE . 'makefile FD="FILE_DESCRIPTION=\\"\\\\\\"Windows Binding for PHP ' . $vers_plus . '\\\\\\"\\"" PN="PRODUCT_NAME=\\"\\\\\\"PHP ' . $vers_plus . ' php_winbinder.dll\\\\\\"\\"" PV="P_VERSION=\\"\\\\\\"' . $vers_plus . '\\\\\\"\\""'; // needed for PHPedit + debugger and php-4.3.10 if (!empty($_ENV['HTTP_COOKIE']) and strstr($_ENV['HTTP_COOKIE'], 'DBGSESSID') != false or PHP_VERSION == '4.3.10') { $dspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $pro = proc_open($cmd . $par, $dspec, $pipes); if (is_resource($pro)) { $result = ""; while (!feof($pipes[1])) { $result .= fgets($pipes[1], 1024); } while (!feof($pipes[2])) { $result .= fread($pipes[2], 8024); } fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); } proc_close($pro); } else { $WshShell = new COM('WScript.Shell'); $WshShell->run('cmd /K ' . $cmd . ' ' . $par . ' > ' . PATH_BASE . 'log.txt & exit', 0, true); $result = file_get_contents(PATH_BASE . 'log.txt'); unlink('log.txt'); } return $result; }
public static function executeScript($scriptAndArgs, $bPassKeys = false, $scriptDir = __DIR__) { $scriptDir = utils::normalize($scriptDir); $bWindows = substr(php_uname(), 0, 7) == 'Windows'; $cmd = $bWindows ? '"C:/Program Files/PHP.5.6.16/php.exe" ' : '/usr/bin/php -q '; $cmd .= "{$scriptDir}{$scriptAndArgs}"; if ($bPassKeys === true) { $config = lmv::config(); $cmd .= " --keys CONSUMERKEY={$config['credentials']['client_id']}" . " --keys CONSUMERSECRET={$config['credentials']['client_secret']}" . " -k MAILJET1={$config['MAILJET1']}" . " -k MAILJET2={$config['MAILJET2']}"; } else { if (is_string($bPassKeys)) { $cmd .= $bPassKeys; } } utils::log("Launching command: {$cmd}"); $result = null; if ($bWindows) { //$result =pclose (popen ("start /B \"\" $cmd", 'w')) ; //$result =exec ("start /B \"\" $cmd") ; //$result =shell_exec ("start /B \"\" $cmd") ; $com = new \COM('WScript.shell'); //$cmd .=" > C:/temp/aaa.txt 2>&1" ; $com->run($cmd, 0, false); // 0 for prod, 1 for debug } else { //$result =exec ("$cmd > /dev/null 2>&1 &") ; //$result =shell_exec ("$cmd > /dev/null 2>&1 &") ; putenv('SHELL=/bin/bash'); print `echo {$cmd} | at now 2>&1`; } return true; }