Пример #1
0
function lxfile_disk_free_space($dir)
{
    $dir = expand_real_root($dir);
    lxfile_mkdir($dir);
    $ret = disk_free_space($dir);
    $ret = round($ret / (1024 * 1024), 1);
    log_shell("Disk Space {$dir} {$ret}");
    return $ret;
}
Пример #2
0
function scavenge_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    log_shell("Scavenge: Start");
    initProgramlib('admin');
    log_shell("Scavenge: Collect Traffic");
    passthru("{$sgbl->__path_php_path} ../bin/gettraffic.php");
    log_shell("Scavenge: Collect Quota");
    passthru("{$sgbl->__path_php_path} ../bin/collectquota.php");
    log_shell("Scavenge: Schedule backups");
    passthru("{$sgbl->__path_php_path} ../bin/common/schedulebackup.php");
    log_shell("Scavenge: Clear Sessions");
    passthru("{$sgbl->__path_php_path} ../bin/common/clearsession.php");
    log_shell("Scavenge: Self backup");
    passthru("{$sgbl->__path_php_path} ../bin/common/mebackup.php");
    log_shell("Scavenge: Check Cluster Disk Quota");
    checkClusterDiskQuota();
    $driverapp = $gbl->getSyncClass(null, 'localhost', 'web');
    if ($driverapp === 'lighttpd') {
        log_shell("Scavenge: Restarting lighttpd");
        system("service lighttpd restart");
    }
    log_shell("Scavenge: Fix log dir");
    passthru("{$sgbl->__path_php_path} ../bin/common/fixlogdir.php");
    log_shell("Scavenge: InstallApp update");
    passthru("{$sgbl->__path_php_path} ../bin/installapp-update.phps");
    log_shell("Scavenge: Watchdog checks");
    $rs = get_all_pserver();
    foreach ($rs as $r) {
        watchdog::addDefaultWatchdog($r);
    }
    log_shell("Scavenge: Collect LxGuard info");
    lxguard::collect_lxguard();
    log_shell("Scavenge: Fix MySQL root password");
    fix_all_mysql_root_password();
    log_shell("Scavenge: Auto update Kloxo");
    auto_update();
}
Пример #3
0
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();
    }
}
Пример #4
0
 public function setInternalParam($mountpoint)
 {
     $name = $this->main->ostemplate;
     if ($this->main->isWindows()) {
         return;
     }
     if (!$mountpoint) {
         return;
     }
     if ($name === 'unknown') {
         return;
     }
     $name = strtolower($name);
     $mountpoint = expand_real_root($mountpoint);
     $result = $this->getScriptS($name);
     dprint("Distro Name {$name}, Scripts: \n");
     dprintr($result);
     $init = strtilfirst($name, "-");
     dprint("File is  {$init}.inittab\n");
     if (lxfile_exists("../file/sysfile/inittab/{$init}.inittab")) {
         dprint("Copying {$init}.inittab\n");
         $content = lfile_get_contents("../file/sysfile/inittab/{$init}.inittab");
         if ($this->main->text_inittab) {
             $content .= "\n{$this->main->text_inittab}";
         }
         lfile_put_contents("{$mountpoint}/etc/inittab", $content);
     }
     $iplist = get_namelist_from_objectlist($this->main->vmipaddress_a);
     if ($this->main->mainipaddress) {
         $main_ip = $this->main->mainipaddress;
         $iplist = array_remove($iplist, $main_ip);
     } else {
         $main_ip = array_shift($iplist);
     }
     if ($this->main->networknetmask) {
         $main_netmask = $this->main->networknetmask;
     } else {
         $main_netmask = "255.255.255.0";
     }
     $iplist = implode(" ", $iplist);
     $ipadd = $result['ADD_IP'];
     $sethostname = $result['SET_HOSTNAME'];
     $setuserpass = $result['SET_USERPASS'];
     $ipdel = $result['DEL_IP'];
     if ($this->main->networkgateway) {
         $gw = $this->main->networkgateway;
     } else {
         $gw = os_get_network_gateway();
     }
     $gwn = strtil($gw, '.') . '.0';
     $hostname = $this->main->hostname;
     if (!$hostname) {
         $hostname = os_get_hostname();
     }
     if ($result['STARTUP_SCRIPT'] != 'systemd') {
         $name = createTempDir("{$mountpoint}/tmp", 'xen-scripts');
         lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name);
         lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $name);
         lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $name);
         lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $name);
         lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $name);
         $basepath = strfrom($name, $mountpoint);
         lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\nsource /{$basepath}/{$ipdel}\n");
         $delipstring = "IPDELALL=yes chroot {$mountpoint} bash /{$basepath}/tmpfile.sh";
         log_shell($delipstring);
         log_shell(system($delipstring, $ret1) . ":return {$ret1}");
         putenv("VE_STATE=stopped");
         lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$ipadd}\n");
         $string = "IPDELALL=yes MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh";
         log_shell($string);
         log_shell(system($string, $ret1) . ":return {$ret1}");
         lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$sethostname}\n");
         $string = "HOSTNM={$hostname} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh";
         log_shell($string);
         log_shell(system($string, $ret1) . ":return {$ret1}");
         if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) {
             $rootpass = "******";
             lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$setuserpass}\n");
             $string = "USERPW={$rootpass} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh";
             log_shell($string);
             log_shell(system($string));
         }
         lxfile_rm_rec($name);
     } else {
         if ($result['STARTUP_SCRIPT'] == 'systemd') {
             $script_dir = createTempDir("{$mountpoint}", "hypervm-runonce");
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir);
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $script_dir);
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $script_dir);
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $script_dir);
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $script_dir);
             $basepath = strfrom($script_dir, $mountpoint);
             $startupdir = 'lib/systemd/system';
             $startupscript = 'fedora-startup.service';
             $setrootpass = '';
             if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) {
                 $rootpass = "******";
                 $setrootpass = "******";
             }
             $run_once_script = "#!/bin/bash\n" . "source {$basepath}/functions\n" . '(' . "IPDELALL=yes source {$basepath}/{$ipdel}" . " & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} source {$basepath}/{$ipadd}" . " & HOSTNM={$hostname} source {$basepath}/{$sethostname}" . "{$setrootpass})\n" . "service fedora-startup disable\nrm -f /{$startupdir}/{$startupscript}\nrm -rf {$basepath}";
             lfile_put_contents("{$script_dir}/hypervm-runonce.sh", $run_once_script);
             lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$startupscript}", "{$mountpoint}/{$startupdir}");
             lfile_put_contents("{$mountpoint}/{$startupdir}/{$startupscript}", lfile_get_contents("{$mountpoint}/{$startupdir}/{$startupscript}") . "ExecStart={$basepath}/hypervm-runonce.sh\n");
             system("ln -s /lib/systemd/system/fedora-startup.service {$mountpoint}/etc/systemd/system/multi-user.target.wants/fedora-startup.service");
             system("chmod 755 {$script_dir}/hypervm-runonce.sh");
         }
     }
     if ($this->main->nameserver) {
         $nlist = explode(" ", $this->main->nameserver);
         $nstring = null;
         foreach ($nlist as $l) {
             $nstring .= "nameserver {$l}\n";
         }
         lfile_put_contents("{$mountpoint}/etc/resolv.conf", $nstring);
     }
     if ($this->main->timezone) {
         lxfile_rm("{$mountpoint}/etc/localtime");
         $cmdstring = "ln -sf ../usr/share/zoneinfo/{$this->main->timezone} {$mountpoint}/etc/localtime";
         log_log("localtime", $cmdstring);
         do_exec_system('__system__', "/", $cmdstring, $out, $err, $ret, null);
         //lxfile_cp("/usr/share/zoneinfo/{$this->main->timezone}", "$mountpoint/etc/localtime");
     }
     lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0");
     lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0:0");
     $this->main->doKloxoInit($mountpoint);
 }
Пример #5
0
function exec_with_all_closed_output($cmd)
{
    global $gbl, $sgbl, $login, $ghtml;
    $string = null;
    for ($i = 1; $i < 60; $i++) {
        $string .= " {$i}</dev/null";
    }
    //debugBacktrace();
    //dprint($string);
    chmod("{$sgbl->__path_program_root}/cexe/closeallinput", 0755);
    //exec("$cmd > /dev/null 2>&1 &");
    $res = shell_exec("{$sgbl->__path_program_root}/cexe/closeallinput '{$cmd}' 2>/dev/null");
    log_shell("Closed Exec output: {$res} :  {$sgbl->__path_program_root}/cexe/closeallinput '{$cmd}'");
    return trim($res);
}
Пример #6
0
function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input)
{
    //dprint("<hr>$dir <hr> ");
    global $gbl, $sgbl, $login, $ghtml;
    global $global_shell_out, $global_shell_error, $global_shell_ret;
    global $global_dontlogshell;
    $path = "{$sgbl->__path_lxmisc}";
    $fename = tempnam($sgbl->__path_tmp, "system_errr");
    $execcmd = null;
    if ($username !== '__system__') {
        $execcmd = "{$path} -u {$username}";
        chmod($path, 0700);
    }
    $oldpath = null;
    if ($dir) {
        lxfile_mkdir($dir);
        $oldpath = getcwd();
        chdir($dir);
    }
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $fename, "a"));
    os_set_path();
    $process = proc_open("{$cmd}", $descriptorspec, $pipes);
    $out = null;
    if (is_resource($process)) {
        // $pipes now looks like this:
        // 0 => writeable handle connected to child stdin
        // 1 => readable handle connected to child stdout
        // Any error output will be appended to $fename
        if ($input) {
            fwrite($pipes[0], $input);
        }
        fclose($pipes[0]);
        while (!feof($pipes[1])) {
            $out .= fgets($pipes[1], 1024);
        }
        fclose($pipes[1]);
        // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        $ret = proc_close($process);
    }
    $err = lfile_get_contents($fename);
    unlink($fename);
    $tcwd = getcwd();
    if ($ret) {
        log_shell_error("{$err}: [({$username}:{$tcwd}) {$cmd}]");
    }
    if ($global_dontlogshell) {
        log_log("other_cmd", "{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]");
    } else {
        log_shell("{$ret}: {$err} [({$username}:{$tcwd}) {$cmd}]");
    }
    $global_shell_ret = $ret;
    $global_shell_out = $out;
    $global_shell_error = $err;
    if ($oldpath) {
        chdir($oldpath);
    }
}
Пример #7
0
function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input)
{
    global $gbl, $sgbl, $login, $ghtml;
    global $global_shell_out, $global_shell_error, $global_shell_ret;
    dprint("<hr> {$dir} <br> {$cmd} <hr> ");
    $path = "{$sgbl->__path_lxmisc}";
    $fename = tempnam($sgbl->__path_tmp, "system_errr");
    $execcmd = null;
    /*
    	if ($username !== '__system__') {
    		$execcmd = "$path -u $username";
    	}
    */
    os_set_path();
    $sh = new COM("Wscript.shell");
    if ($dir) {
        if (!csa($dir, ':')) {
            $dir = getcwd() . "/{$dir}";
        }
        $sh->currentDirectory = $dir;
    }
    $out = null;
    $ret = 0;
    $err = null;
    dprint("\n ** mmmmmm {$dir} {$cmd} **\n");
    $cmdobject = $sh->Exec($cmd);
    if ($input) {
        $cmdobject->StdIn->Write($input);
    }
    $out = $cmdobject->StdOut->ReadAll();
    $err = $cmdobject->StdErr->ReadAll();
    $ret = 0;
    $sh->currentDirectory = $sgbl->__path_program_htmlbase;
    /*
    	function ReadAllFromAny($ret)
        {
    		if (!($ret->StdOut->AtEndOfStream)){
      	      $Ret=$ret->StdOut->ReadAll();
    		  return $Ret;
    		}
    		if (!($ret->StdErr->AtEndOfStream)){
    			$Ret="STDERR: ".$ret->StdErr->ReadAll();
    		    return $Ret;
    		}
            return -1;
    	}*/
    if ($ret) {
        log_shell_error("{$err}: [({$username}:{$dir}) {$cmd}]");
    }
    log_shell("{$ret}: {$err} [({$username}:{$dir}) {$cmd}]");
    $global_shell_ret = $ret;
    $global_shell_out = $out;
    $global_shell_error = $err;
}
Пример #8
0
 static function fixErrorLog($name)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $file = "/home/kloxo/httpd/lighttpd/error.log";
     $cmd = "grep -i {$name} {$file} > /home/httpd/{$name}/stats/{$name}-error_log";
     log_shell($cmd);
     system($cmd);
     $size = lxfile_size($file);
     if ($size > 50 * 1024 * 1024) {
         $nfile = getNotexistingFile(dirname($file), $file);
         lxfile_mv($file, $nfile);
         createRestartFile("lighttpd");
     }
 }
Пример #9
0
function exec_with_all_closed_output($cmd)
{
    global $gbl, $sgbl, $login, $ghtml;
    chmod("{$sgbl->__path_program_root}/cexe/closeallinput", 0755);
    $res = shell_exec("{$sgbl->__path_program_root}/cexe/closeallinput '{$cmd}' 2>/dev/null");
    log_shell("Closed Exec output: {$res} :  {$sgbl->__path_program_root}/cexe/closeallinput '{$cmd}'");
    return trim($res);
}