function special_bind_restart($cmd) { global $gbl, $sgbl, $login, $ghtml; if (WindowsOs()) { return; } if (myPcntl_fork() === 0) { socket_close($sgbl->__local_socket); exec("/etc/init.d/{$cmd} restart </dev/null >/dev/null 2>&1 &"); exit; } else { myPcntl_wait(); } }
function lxfile_mkdir($dir) { $dir = expand_real_root($dir); if (lxfile_exists($dir)) { return true; } //dprint("Making directory... $dir\n"); if (WindowsOs()) { $dir = preg_replace("/\\//", "\\", $dir); } log_shell("Making directory {$dir}"); $ret = mkdir($dir, 0755, true); if (!$ret) { debugBacktrace(); } }
} return false; } function getOs() { return substr(php_uname(), 0, 7) == "Windows" ? "Windows" : "Linux"; } if (!isset($_SERVER['DOCUMENT_ROOT'])) { if (isset($_SERVER['SCRIPT_NAME'])) { $n = $_SERVER['SCRIPT_NAME']; $f = ereg_replace('\\\\', '/', $_SERVER['SCRIPT_FILENAME']); $f = str_replace('//', '/', $f); $_SERVER['DOCUMENT_ROOT'] = eregi_replace($n, "", $f); } } if (!$_SERVER['DOCUMENT_ROOT']) { $_SERVER['DOCUMENT_ROOT'] = $dir; } if (WindowsOs()) { //ini_set("include_path", ".;{$_SERVER['DOCUMENT_ROOT']}"); } else { ini_set("include_path", "{$_SERVER['DOCUMENT_ROOT']}"); } function getreal($vpath) { return $_SERVER["DOCUMENT_ROOT"] . "/" . $vpath; } function readvirtual($vpath) { readfile($_SERVER["DOCUMENT_ROOT"] . $vpath); }
function send_to_some_stream_server($type, $size, $raddress, $var, $fd) { global $gbl, $sgbl, $login, $ghtml; $exitchar = $sgbl->__var_exit_char; $remotechar = $sgbl->__var_remote_char; $con = $sgbl->__var_connection_type; if ($raddress === "localhost") { $con = "tcp"; $port = $sgbl->__var_local_port; } else { $con = "ssl"; $port = $sgbl->__var_remote_port; } print_time('server'); print_time('serverstart'); $rraddress = $raddress; if (isLocalhost($raddress)) { $rraddress = "127.0.0.1"; } $socket = stream_socket_client("{$con}://{$rraddress}:{$port}"); //$socket = fsockopen("$con://$raddress", $port); print_time('serverstart', "Fsockopen"); if ($socket <= 0) { if ($raddress === 'localhost' && !WindowsOs() && !$sgbl->isDebug()) { //20140131 OA: dont reenable this, Ive just removed. //lxshell_background("/usr/sbin/lxrestart", $sgbl->__var_program_name); throw new lxException('no_socket_connect_to_server', '', $raddress); throw new lxException('restarting_backend', '', $raddress); } else { throw new lxException('no_socket_connect_to_server', '', $raddress); } } stream_set_timeout($socket, 30000000000); //stream_context_set_option($socket, 'ssl', 'allow_self_signed', true); //stream_context_set_option($socket, 'ssl', 'verify_peer', false); $in = $var; fwrite($socket, $in); $in = "\n"; fwrite($socket, $in); $in = $exitchar; fwrite($socket, $in); $in = "\n"; fwrite($socket, $in); $totalout = null; $totalsize = 0; while (true) { $out = fgets($socket, 8092); if (!$out) { if (!$totalout) { dprint("Got Nothing\n"); } break; } if ($type === 'fileprint' || $type === 'file') { // The stream comes with a first and last character appended to it. if ($totalsize === 0 && $out[0] === 'f') { log_log("servfile", "Got failure from the servfile {$out}"); break; } if ($totalsize === 0) { $out = substr($out, 1); } $totalsize += strlen($out); if ($totalsize >= $size + 1) { $out = substr($out, 0, strlen($out) - 1); } print_or_write($fd, $out); if ($totalsize >= $size + 1) { break; } } else { //$out = trim($out); $totalout .= $out; if (csa($totalout, $exitchar)) { break; } } } fclose($socket); if ($type === 'file' || $type === 'fileprint') { return $totalsize; } if (!$totalout) { return null; } dprint("Got this much:" . strlen($totalout)); //dprint($totalout); $totalout = trim($totalout); $size = round(strlen($totalout) / 1024, 4); //dprint($totalout); //$ee = unserialize(base64_decode($totalout)); return $totalout; }
function log_load() { $mess = os_getLoadAvg(); if (!is_string($mess)) { $mess = var_export($mess, true); } $mess = trim($mess); $rf = "__path_program_root/log/{$file}"; if (WindowsOs()) { $endstr = "\r\n"; } else { $endstr = "\n"; } lfile_put_contents("/var/log/loadvg.log", time() . ' ' . @date("H:i:M/d/Y") . ": {$mess}{$endstr}", FILE_APPEND); }
function myPcntl_fork() { global $gbl, $sgbl, $login, $ghtml; if (!WindowsOs()) { $pid = pcntl_fork(); } else { // make it child $pid = 0; } return $pid; }