function process_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    $list = parse_opt($argv);
    $exitchar = $sgbl->__var_exit_char;
    $res = new Remote();
    $res->exception = null;
    $res->ddata = "hello";
    $res->message = "hello";
    $total = file_get_contents($list['temp-input-file']);
    @lunlink($list['temp-input-file']);
    $string = explode("\n", $total);
    if (csb($total, "__file::")) {
        ob_end_clean();
        file_server(null, $total);
    } else {
        $reply = process_server_input($total);
        //fprint(unserialize(base64_decode($reply)));
        ob_end_clean();
        print "{$reply}\n{$exitchar}\n";
        flush();
    }
    exit;
}
Exemple #2
0
function fixlogdir_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    $progname = $sgbl->__var_program_name;
    $logl = lscandir_without_dot("../log");
    lxfile_mkdir("../processed_log");
    @lunlink("../log/access_log");
    @lunlink("/usr/local/lxlabs/ext/php/error.log");
    $dir = getNotexistingFile("../processed_log", "proccessed");
    system("mv ../log ../processed_log/{$dir}");
    mkdir("../log");
    $list = lscandir_without_dot("../processed_log");
    foreach ($list as $l) {
        remove_directory_if_older_than_a_day("../processed_log/{$l}", 6);
    }
    foreach ($logl as $l) {
        lxfile_touch("../log/{$l}");
    }
    lxfile_generic_chown_rec("../log", "lxlabs:lxlabs");
    //
    // Related to Issue #15
    //
    lxfile_generic_chmod_rec("../log", "0640");
    lxfile_generic_chmod_rec("../processed_log", "0640");
    lxfile_generic_chmod("../log", "0700");
    lxfile_generic_chmod("../processed_log", "0700");
    lxfile_generic_chmod("../log/lighttpd_error.log", "0644");
    lxfile_generic_chmod("../log/access_log", "0644");
    lxfile_generic_chown("../log/lighttpd_error.log", "lxlabs:root");
    lxfile_generic_chown("../log/access_log", "lxlabs:root");
    //
    os_restart_program();
}
 static function doUpdate($list)
 {
     $cmd = self::getYumCommand();
     $file = fix_nname_to_be_variable($cmd);
     $file = "__path_program_root/cache/{$file}";
     lxshell_return("yum", "-y", "install", implode(" ", $list));
     lunlink($file);
 }
Exemple #4
0
function remove_lighttpd_error_log()
{
    $f = "/home/kloxo/httpd/lighttpd/error.log";
    $s = lxfile_size($f);
    if ($s > 50 * 1024 * 1024) {
        lunlink($f);
        createRestartFile("lighttpd");
    }
}
Exemple #5
0
 static function uninstallMe()
 {
     global $gbl, $sgbl, $login, $ghtml;
     lxshell_return("service", "httpd", "stop");
     lxshell_return("rpm", "-e", "--nodeps", "httpd");
     if (file_exists("/etc/init.d/httpd")) {
         lunlink("/etc/init.d/httpd");
     }
 }
function __xenimport_get_data()
{
    lxfile_mkdir("/home/oldxenconfig-hypervm");
    $list = lscandir_without_dot("/etc/xen/oldxen");
    foreach ($list as $l) {
        $vm[] = __xenimport_parse_config("/etc/xen/oldxen/{$l}");
        //lxfile_mv("/etc/xen/$l", "/home/oldxenconfig-hypervm");
        lunlink("/etc/xen/auto/{$l}");
    }
    dprintr($vm);
    return $vm;
}
 static function doUpdate($list)
 {
     $cmd = self::getYumCommand();
     $file = fix_nname_to_be_variable(implode(" ", $cmd));
     $file = "__path_program_root/cache/{$file}";
     $plist = implode(" ", $list);
     while (true) {
         system("up2date --nox --install --nosig {$plist}", $return_value);
         if (!$return_value) {
             break;
         }
         dprint("Got error from up2date...\n");
     }
     lunlink($file);
 }
function __xenimport_get_data()
{
    lxfile_mkdir("/home/oldxenconfig-hypervm");
    $list = lscandir_without_dot("/etc/hypervm/");
    foreach ($list as $l) {
        if (!csb($l, "xm")) {
            continue;
        }
        if (csb($l, "xmexample")) {
            continue;
        }
        $vm[] = __xenimport_parse_config("/etc/xen/{$l}");
        //lxfile_mv("/etc/xen/$l", "/home/oldxenconfig-hypervm");
        lunlink("/etc/xen/auto/{$l}");
    }
    dprintr($vm);
    return $vm;
}
 static function readAuthorizedKey($username)
 {
     $p = os_get_home_dir($username);
     if ($p === '/tmp' && $username) {
         lxfile_mkdir("/home/{$username}");
         lxshell_return("usermod", "-d", "/home/{$username}", $username);
         lxfile_unix_chown_rec("/home/{$username}", "{$username}:{$username}");
         $p = "/home/{$username}";
     }
     if (!$p) {
         return;
     }
     $f = "{$p}/.ssh/authorized_keys";
     if (lxfile_exists("{$f}2")) {
         $s = lfile_get_contents("{$f}2");
         $s = "\n{$s}\n";
         lfile_put_contents($f, $s, FILE_APPEND);
         lunlink("{$f}2");
     }
     return lfile_get_contents($f);
 }
Exemple #10
0
 static function findTotalmailQuota($driver, $list, $oldtime, $newtime)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if (!isset($oldtime)) {
         return null;
     }
     $file = '/var/log/kloxo/maillog';
     $processedir = "/var/log/kloxo";
     $convertedfile = self::convertfile($oldtime, $newtime);
     if (!$convertedfile) {
         self::rotateLog($processedir, $file);
         return;
     }
     foreach ($list as $d) {
         $tlist[$d] = self::getmail_usage($convertedfile, $d, $oldtime, $newtime);
     }
     lunlink($convertedfile);
     self::rotateLog($processedir, $file);
     self::rotateLog("/var/log/kloxo/", "/var/log/kloxo/courier");
     self::rotateLog("/var/log/kloxo/", "/var/log/kloxo/smtp.log");
     return $tlist;
 }
Exemple #11
0
 static function initThisList($parent, $class)
 {
     // Load entire Session
     $result = null;
     $list = lscandir_without_dot("__path_program_root/session");
     foreach ($list as $l) {
         $pp = lfile_get_json_unserialize("__path_program_root/session/{$l}");
         if (!$pp) {
             lunlink("__path_program_root/session/{$l}");
             continue;
         }
         if (!$parent->isAdmin()) {
             //$result = $db->getRowsWhere("parent_clname = '" . $parent->getClName() . "'");
             if ($pp['parent_clname'] !== $parent->getClName()) {
                 continue;
             }
         }
         $result[] = $pp;
     }
     if ($result) {
         $parent->setListFromArray($parent->__masterserver, $parent->__readserver, 'ssessionlist', $result, true);
     }
     return null;
 }
 function syncCreateConf()
 {
     global $gbl, $sgbl, $login, $ghtml;
     global $global_shell_error;
     if_demo_throw_exception('cron');
     $conf_file = "__path_cron_root/{$this->main->username}";
     $list = array('minute', 'hour', 'weekday', 'ddate', 'month');
     $tfile = lx_tmp_file($conf_file);
     $cmd = null;
     if ($this->main->__var_mailto) {
         $cmd .= "MAILTO={$this->main->__var_mailto}\n";
     }
     $result = $this->main->__var_cron_list;
     foreach ($result as &$__r) {
         foreach ($list as $l) {
             $__r[$l] = unserialize(base64_decode($__r["ser_{$l}"]));
         }
     }
     $result = merge_array_object_not_deleted($result, $this->main);
     //dprintr($result);
     foreach ((array) $result as $v) {
         if ($v['ttype'] === 'simple') {
             $v['weekday'] = array('--all--');
             $v['month'] = array('--all--');
             $v['ddate'] = array('--all--');
             if ($v['simple_cron'] === 'every-day') {
                 $v['hour'] = $v['cron_day_hour'];
                 $v['minute'] = 0;
             }
             if ($v['simple_cron'] === 'every-hour') {
                 $v['hour'] = array('--all--');
                 $v['minute'] = 0;
             }
             if ($v['simple_cron'] === 'every-minute') {
                 $v['hour'] = array('--all--');
                 $v['minute'] = array('--all--');
             }
         } else {
             foreach ($v["weekday"] as &$___tq) {
                 if (is_numeric($___tq)) {
                     $___tq -= 1;
                 }
             }
         }
         foreach ($list as $l) {
             $v[$l] = $this->getCronString($v[$l]);
         }
         if (!$v['minute']) {
             $v['minute'] = 0;
         }
         $cmd .= implode("\t", array($v['minute'], $v['hour'], $v['ddate'], $v['month'], $v['weekday'], $v['command']));
         $cmd .= "\n";
     }
     lfile_put_contents($tfile, $cmd);
     if (!posix_getpwnam($this->main->username)) {
         lxfile_rm("/var/spool/cron/{$this->main->username}");
         return;
     }
     $ret = lxshell_return("crontab", "-u", $this->main->username, $tfile);
     if ($ret) {
         // Why exactly was a throw removed? backup/restore?
         //throw new lxException("adding_cron_failed", "", $global_shell_error);
         $gbl->setWarning('adding_cron_failed', '', $global_shell_error);
         $data = lfile_get_contents($tfile);
         log_log("cron_error", $data);
     }
     lunlink($tfile);
 }
Exemple #13
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);
 }
Exemple #14
0
    lxfile_mkdir("{$cdir}/old");
    lxfile_mkdir("{$cdir}/cgi-bin");
    foreach ($dlist as $l) {
        if (lxfile_exists("{$cdir}/{$l->nname}")) {
            lxfile_mv_rec("{$cdir}/{$l->nname}", "{$cdir}/old/");
        }
        if (!is_link("{$cdir}/domain/{$l->nname}/www/")) {
            lxfile_mv_rec("{$cdir}/domain/{$l->nname}/www/", "{$cdir}/{$l->nname}");
        }
        /*
        	foreach($l->subweb_a as $k => $v) {
        		lxfile_mv_rec("$cdir/domain/$l->nname/subdomains/$v->nname", "$cdir/$l->nname/$v->nname");
        	}
        */
        if (!is_link("{$cdir}/domain/{$l->nname}/cgi-bin/")) {
            lxfile_mv_rec("{$cdir}/domain/{$l->nname}/cgi-bin/", "{$cdir}/cgi-bin/{$l->nname}");
        }
        lunlink("{$cdir}/domain/{$l->nname}/www");
        lxfile_symlink("{$cdir}/{$l->nname}", "{$cdir}/domain/{$l->nname}/www");
        lxfile_symlink("{$cdir}/cgi-bin/{$l->nname}", "{$cdir}/domain/{$l->nname}/cgi-bin");
        $web = $l->getObject('web');
        $web->setUpdateSubaction('full_update');
        $dirlist = $web->getList('dirprotect');
        foreach ($dirlist as $dir) {
            $dir->setUpdateSubaction('full_update');
            $dir->was();
        }
        $web->was();
    }
}
lxshell_return("__path_php_path", "../bin/misc/fixftpuserclient.phps");
Exemple #15
0
function setRemoveOldDirs()
{
    log_cleanup("Remove Old dirs");
    log_cleanup("- Remove process");
    if (lxfile_exists("/home/admin/domain")) {
        log_cleanup("- Remove dir /home/admin/domain/ if exists");
        rmdir("/home/admin/domain/");
    }
    if (lxfile_exists("/home/admin/old")) {
        log_cleanup("- Remove dir /home/admin/old/ if exists");
        rmdir("/home/admin/old/");
    }
    if (lxfile_exists("/home/admin/cgi-bin")) {
        log_cleanup("- Remove dir /home/admin/cgi-bin/ if exists");
        rmdir("/home/admin/cgi-bin/");
    }
    if (lxfile_exists("/etc/skel/Maildir")) {
        log_cleanup("- Remove dir /etc/skel/Maildir/ if exists");
        rmdir("/etc/skel/Maildir/new");
        rmdir("/etc/skel/Maildir/cur");
        rmdir("/etc/skel/Maildir/tmp");
        rmdir("/etc/skel/Maildir/");
    }
    if (lxfile_exists('kloxo.sql')) {
        log_cleanup("- Remove file kloxo.sql");
        lunlink('kloxo.sql');
    }
}
Exemple #16
0
 function dbactionDelete()
 {
     global $gbl, $sgbl, $login, $ghtml;
     lunlink("/home/lighttpd/conf/domains/{$this->main->nname}.conf");
     $this->delDomain();
 }
Exemple #17
0
 static function removeOtherDriver($driverapp)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($driverapp === 'bind') {
         lxshell_return("service", "djbdns", "stop");
         lxshell_return("chkconfig", "named", "on");
         $pattern = 'include "/etc/kloxo.named.conf";';
         $file = "/var/named/chroot/etc/named.conf";
         $comment = "//Kloxo";
         addLineIfNotExistInside($file, $pattern, $comment);
         touch("/var/named/chroot/etc/kloxo.named.conf");
         chown("/var/named/chroot/etc/kloxo.named.conf", "named");
         lxshell_return("rpm", "-e", "djbdns");
         lunlink("/etc/init.d/djbdns");
     } else {
         lxshell_return("service", "named", "stop");
         lxshell_return("rpm", "-e", "--nodeps", "bind");
         lxshell_return("rpm", "-e", "--nodeps", "bind-chroot");
         lxshell_return("chkconfig", "djbdns", "on");
     }
 }
Exemple #18
0
function do_serve_file($fd, $rem)
{
    $file = $rem->filename;
    $file = basename($file);
    $file = "__path_serverfile/{$file}";
    if (!lxfile_exists($file)) {
        log_log("servfile", "datafile {$file} dosn't exist, exiting");
        print_or_write($fd, "fFile Doesn't {$file} Exist...\n\n\n\n");
        return false;
    }
    $array = lfile_get_unserialize($file);
    lunlink($file);
    $realfile = $array['filename'];
    $pass = $array['password'];
    if ($fd) {
        dprint("Got request for {$file}, realfile: {$realfile}\n");
    }
    log_log("servfile", "Got request for {$file} realfile {$realfile}");
    if (!($pass && $pass === $rem->password)) {
        print_or_write($fd, "fPassword doesn't match\n\n");
        return false;
    }
    if (is_dir($realfile)) {
        // This should neverhappen. The directories are zipped at cp-fileserv and tar_to_filserved then itself.
        $b = basename($realfile);
        lxfile_mkdir("__path_serverfile/tmp/");
        $tfile = tempnam("__path_serverfile/tmp/", "{$b}.tar");
        $list = lscandir_without_dot($realfile);
        lxshell_tar($realfile, $tfile, $list);
        $realfile = $tfile;
    }
    $fpr = lfopen($realfile, "rb");
    if (!$fpr) {
        print_or_write($fd, "fCouldn't open {$realfile}\n\n");
        return false;
    }
    print_or_write($fd, "s");
    while (!feof($fpr)) {
        $written = print_or_write($fd, fread($fpr, 8092));
        if ($written <= 0) {
            break;
        }
    }
    // Just send a newline so that the fgets will break after reading. This has to be removed after the file is read.
    print_or_write($fd, "\n");
    fclose($fpr);
    fileserv_unlink_if_tmp($realfile);
    return true;
}
Exemple #19
0
function checkRestart()
{
    if (if_demo()) {
        return;
    }
    log_log("cron_exec", "Check service restarts...\n");
    $res = lscandir_without_dot("__path_program_etc/.restart");
    if ($res === false) {
        dprint(".restart does not exist... Creating\n");
        lxfile_mkdir("__path_program_etc/.restart");
        lxfile_generic_chown("__path_program_etc/.restart", "lxlabs");
    }
    foreach ((array) $res as $r) {
        if (csb($r, "._restart_")) {
            $cmd = strfrom($r, "._restart_");
        }
        lunlink("__path_program_etc/.restart/{$r}");
        dprint("Restarting {$cmd}\n");
        switch ($cmd) {
            case 'lxcollectquota':
                log_log("cron_exec", "Start collecting Quota's\n");
                exec_justdb_collectquota();
                break;
            case 'openvz_tc':
                log_log("cron_exec", "Start openvz_tc script\n");
                exec_openvz_tc();
                break;
            default:
                log_log("cron_exec", "Restarting {$cmd}\n");
                exec_with_all_closed("/etc/init.d/{$cmd} restart");
                break;
        }
    }
}
 function do_restore($docd)
 {
     $srv = new COM("SQLDMO.SQLServer");
     $srv->LoginSecure = true;
     try {
         $srv->Connect("localhost,1433");
     } catch (Exception $e) {
         throw new lxException('MsSql Connection is Failed', '', '');
     }
     $sBAKFilePath = "C:/SQL_Backup";
     if (!is_dir($sBAKFilePath)) {
         mkdir($sBAKFilePath, 0777);
     }
     $dir = "{$sBAKFilePath}/mssql";
     $mode = 0700;
     $sBAKFilePath = $dir . mt_rand(0, 9999999);
     mkdir($sBAKFilePath, $mode);
     $docf = "{$sBAKFilePath}/{$this->main->dbname}.bak";
     $ret = lxshell_unzip_with_throw($sBAKFilePath, $docd);
     if (!lxfile_exists($docf)) {
         throw new lxException('could_not_find_matching_dumpfile_for_db', '', '');
     }
     $bkp = new COM("SQLDMO.Restore");
     $dbname = $this->main->dbname;
     $bkp->Database = $dbname;
     $bkp->Files = $docf;
     $bkp->ReplaceDatabase = True;
     $bkp->SQLRestore($srv);
     print "\nRestored\n";
     $srv->DisConnect();
     lunlink($docf);
     lxfile_tmp_rm_rec($sBAKFilePath);
 }
Exemple #21
0
 function top_level_network_restore()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $machine = $this->main->__var_machine;
     $backupfilepass = $this->main->__var_backupfilepass;
     $docd = tempnam("/tmp", "network_restore");
     dprint("Top Level Restore.. Got the remote file..\n");
     dprint($machine);
     dprintr($backupfilepass);
     dprint("\n");
     getFromFileserv($machine, $backupfilepass, $docd);
     $this->do_restore($docd);
     lunlink($docd);
 }
Exemple #22
0
function checkRestart()
{
    if (if_demo()) {
        return;
    }
    $res = lscandir_without_dot("__path_program_etc/.restart");
    if ($res === false) {
        dprint(".restart does not exist... Creating\n");
        lxfile_mkdir("__path_program_etc/.restart");
        lxfile_generic_chown("__path_program_etc/.restart", "lxlabs");
    }
    foreach ((array) $res as $r) {
        if (csb($r, "._restart_")) {
            $cmd = strfrom($r, "._restart_");
        }
        lunlink("__path_program_etc/.restart/{$r}");
        dprint("Restarting {$cmd}\n");
        // THe 3,4 etc are the tcp ports of this program, and it should be closed, else some programs will grab it.
        //exec("/etc/init.d/$cmd restart  </dev/null >/dev/null 2>&1 3</dev/null 4</dev/null 5</dev/null 6</dev/null &");
        switch ($cmd) {
            case 'lxcollectquota':
                exec_justdb_collectquota();
                break;
            case 'openvz_tc':
                exec_openvz_tc();
                break;
            default:
                exec_with_all_closed("/etc/init.d/{$cmd} restart");
                break;
        }
    }
}
Exemple #23
0
 function getAndUnzipSkeleton($ip, $filepass, $dir)
 {
     $oldir = getcwd();
     // File may be a variable path.
     dprintr($filepass);
     $file = $filepass['file'];
     // The thing is this needs to be executed even on secondary master and then the primary master would be down.
     // So if we cannot connect back, we just continue. Skeleton is not an important thing.
     try {
         getFromFileserv($ip, $filepass, "{$dir}/{$file}");
     } catch (exception $e) {
         return;
     }
     lxfile_generic_chown("{$dir}/{$file}", $this->username);
     lxshell_unzip($this->username, $dir, "{$dir}/{$file}");
     lunlink("{$dir}/{$file}");
     $this->replaceVariables("{$dir}/index.html");
     // --- also copy /home/kloxo/httpd/user-logo.png to each domain path
     if (lxfile_exists("../file/user-logo.png")) {
         lxfile_cp("../file/user-logo.png", "{$dir}/images/logo.png");
     }
 }
 function do_restore($docd)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $dbadmin = $this->main->__var_dbadmin;
     $dbpass = $this->main->__var_dbpassword;
     $vd = tempnam("/tmp", "mysqldump");
     lunlink($vd);
     mkdir($vd);
     $docf = "{$vd}/mysql-{$this->main->dbname}.dump";
     $ret = lxshell_unzip_with_throw($vd, $docd);
     if (!lxfile_exists($docf)) {
         throw new lxException('could_not_find_matching_dumpfile_for_db', '', '');
     }
     $cont = lfile_get_contents($docf);
     if ($this->main->dbpassword) {
         $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, "-p{$this->main->dbpassword}", $this->main->dbname);
     } else {
         $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, $this->main->dbname);
     }
     if ($ret) {
         log_restore("Mysql restore failed.... Copying the mysqldump file {$docf} to {$sgbl->__path_kloxo_httpd_root}...");
         lxfile_cp($docf, "__path_kloxo_httpd_root");
         throw new lxException('mysql_error_could_not_restore_data', '', '');
     }
     lunlink($docf);
     lxfile_tmp_rm_rec($vd);
 }
Exemple #25
0
 static function unInstallMe()
 {
     lxshell_return("service", "djbdns", "stop");
     lxshell_return("rpm", "-e", "djbdns");
     lunlink("/etc/init.d/djbdns");
 }
Exemple #26
0
 function do_restore($docd)
 {
     // Issue #671 - Fixed backup-restore issue
     global $gbl, $sgbl, $login, $ghtml;
     $dbadmin = $this->main->__var_dbadmin;
     $dbpass = $this->main->__var_dbpassword;
     $dbname = $this->main->dbname;
     $vd = tempnam("/tmp", "mysqldump");
     lunlink($vd);
     mkdir($vd);
     //	$docf = "$vd/mysql-{$this->main->dbname}.dump";
     $docf = "{$vd}/mysql-{$dbname}.dump";
     $ret = lxshell_unzip_with_throw($vd, $docd);
     if (!lxfile_exists($docf)) {
         throw new lxException('could_not_find_matching_dumpfile_for_db', '', '');
     }
     /*
     	// Issue #671 - how about for large data?
     	$cont = lfile_get_contents($docf);
     
     	if ($this->main->dbpassword) {
     		$ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, "-p{$this->main->dbpassword}", $this->main->dbname);
     	} else {
     		$ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, $this->main->dbname);
     	}
     
     	if ($ret) {
     		log_restore("Mysql restore failed.... Copying the mysqldump file $docf to $sgbl->__path_kloxo_httpd_root...");
     		lxfile_cp($docf, "__path_kloxo_httpd_root");
     		throw new lxException('mysql_error_could_not_restore_data', '', '');
     	}
     
     	lunlink($docf);
     	lxfile_tmp_rm_rec($vd);
     */
     $arg[0] = $sgbl->__path_mysqlclient_path;
     $arg[1] = "-u";
     $arg[2] = $dbadmin;
     if ($dbpass) {
         $arg[3] = "-p'{$dbpass}'";
     } else {
         $arg[3] = "";
     }
     $arg[4] = $dbname;
     $cmd = implode(" ", $arg);
     $link = mysql_connect('localhost', $dbadmin, $dbpass);
     $result = mysql_query("CREATE DATABASE IF NOT EXISTS {$dbname}", $link);
     try {
         system("{$cmd} < {$docf}");
         lunlink($docf);
         lxfile_tmp_rm_rec($vd);
     } catch (Exception $e) {
         throw new lxException('Error: ' . $e->getMessage(), $dbname);
     }
 }
Exemple #27
0
function updateApplicableToSlaveToo()
{
    global $gbl, $sgbl, $login, $ghtml, $osversion;
    print "Download 3rdparty\n";
    // Fixes #303 and #304
    download_thirdparty();
    print "Installing binaries\n";
    lxfile_cp("__path_program_root/cexe/lxxen", "/usr/bin");
    lxfile_cp("__path_program_root/cexe/lxopenvz", "/usr/bin");
    print "Fixing binaries permissions\n";
    lxfile_generic_chmod("/usr/bin/lxopenvz", "6755");
    lxfile_generic_chmod("/usr/bin/lxxen", "6755");
    print "Install missing rpm packages if any";
    install_if_package_not_exist("rrdtool");
    print "-rrdtool-";
    install_if_package_not_exist("ntfsprogs");
    print "-ntfsprogs-";
    install_if_package_not_exist("parted");
    print "-parted-";
    install_if_package_not_exist("kpartx");
    print "-kpartx-";
    install_if_package_not_exist("dhcp");
    print "-dhcp-";
    install_if_package_not_exist("openssl");
    print "-openssl-";
    install_if_package_not_exist("openssl-devel");
    print "-openssl-devel-\n";
    system("chkconfig dhcpd on");
    print "Enable dhcpd at system startup\n";
    if (lxfile_exists("/etc/xen")) {
        lxfile_mkdir("/etc/xen/hypervm");
        if (!lxfile_exists("/boot/hypervm-xen-vmlinuz")) {
            system("cd /boot ; ln -sf vmlinuz-2.6-xen hypervm-xen-vmlinuz; ln -sf initrd-2.6-xen.img hypervm-xen-initrd.img");
        }
        $list = lscandir_without_dot("/etc/xen/auto");
        foreach ($list as $l) {
            $dir = strtil($l, ".cfg");
            lunlink("/etc/xen/auto/{$l}");
            if (lxfile_exists("/home/xen/{$dir}/{$l}")) {
                lxfile_symlink("/home/xen/{$dir}/{$l}", "/etc/xen/auto/{$l}");
            }
        }
    }
    if (lxfile_exists("/var/log/loadvg.log")) {
        lunlink("/var/log/loadvg.log");
    }
    if (lxfile_exists("/etc/vz")) {
        lxfile_cp("__path_program_root/file/sysfile/openvz/ve-vps.basic.conf-sample", "/etc/vz/conf");
        print "Set NEIGHBOUR_DEVS=all to vz.conf\n";
        vps__openvz::staticChangeConf("/etc/vz/vz.conf", "NEIGHBOUR_DEVS", "all");
    }
    print "Fixing openvz repo\n";
    // add openvz.repo
    lxfile_cp("../file/openvz.repo", "/etc/yum.repos.d/openvz.repo");
    print "Fixing lxcenter repo\n";
    // add lxcenter.repo
    $osversion = find_os_version();
    print "- Your OS {$osversion}\n";
    $cont = our_file_get_contents("../file/lxcenter.repo");
    $cont = str_replace("%distro%", $osversion, $cont);
    our_file_put_contents("/etc/yum.repos.d/lxcenter.repo", $cont);
    print "Fix RHN\n";
    fix_rhn_sources_file();
    print "Fix ipconntrack\n";
    fix_ipconntrack();
    if (lxfile_exists("/home/hypervm/xen/template")) {
        print "Check Xen windows-lxblank.img template\n";
        system("echo hypervm-windows > /home/hypervm/xen/template/windows-lxblank.img");
    }
    print "Fix memory graph\n";
    memoryGraphFix();
    print "Fix permission of closeallinput\n";
    lxfile_unix_chmod("../cexe/closeallinput", "0755");
    print "Fix LxEtc\n";
    installLxetc();
    print "Check binaries\n";
    system("cp ../sbin/lxrestart /usr/sbin/");
    system("chown root:root /usr/sbin/lxrestart");
    system("chmod 755 /usr/sbin/lxrestart");
    system("chmod ug+s /usr/sbin/lxrestart");
    system("chmod 777 /tmp");
    system("chmod o+t /tmp");
    print "Create script dir\n";
    copy_script();
    if (!lxfile_exists("/usr/local/lxlabs/kloxo/")) {
        print "Remove /usr/local/lxlabs/kloxo/ as it should not be here!\n";
        system("rmdir /usr/local/lxlabs/kloxo/httpdocs/ >/dev/null 2>&1");
        system("rmdir /usr/local/lxlabs/kloxo/ >/dev/null 2>&1");
    }
    if (!lxfile_exists("/var/named/chroot/etc/kloxo.named.conf")) {
        if (lxfile_exists("/var/named/chroot/etc/lxadmin.named.conf")) {
            remove_line("/var/named/chroot/etc/named.conf", "lxadmin.named.conf");
            $pattern = 'include "/etc/kloxo.named.conf";';
            $file = "/var/named/chroot/etc/named.conf";
            $comment = "//Kloxo";
            @addLineIfNotExistInside($file, $pattern, $comment);
            @lxfile_mv("/var/named/chroot/etc/lxadmin.named.conf", "/var/named/chroot/etc/kloxo.named.conf");
        }
    }
}
Exemple #28
0
 static function removeOtherDriver($driverapp)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($driverapp === 'bind') {
         lxshell_return("service", "djbdns", "stop");
         lxshell_return("chkconfig", "named", "on");
         $pattern = 'include "/etc/global.options.named.conf";';
         $file = "/var/named/chroot/etc/named.conf";
         $comment = "//Global_options_file";
         addLineIfNotExist($file, $pattern, $comment);
         $options_file = "/var/named/chroot/etc/global.options.named.conf";
         $example_options = "acl \"lxcenter\" {\n";
         $example_options .= " localhost;\n";
         $example_options .= "};\n\n";
         $example_options .= "options {\n";
         $example_options .= " max-transfer-time-in 60;\n";
         $example_options .= " transfer-format many-answers;\n";
         $example_options .= " transfers-in 60;\n";
         $example_options .= " auth-nxdomain yes;\n";
         $example_options .= " allow-transfer { \"lxcenter\"; };\n";
         $example_options .= " allow-recursion { \"lxcenter\"; };\n";
         $example_options .= " recursion no;\n";
         $example_options .= " version \"LxCenter - 1.0\";\n";
         $example_options .= "};\n\n";
         $example_options .= "# Remove # to see all DNS queries\n";
         $example_options .= "#logging {\n";
         $example_options .= "# channel query_logging {\n";
         $example_options .= "# file \" /var/log / named_query . log\";\n";
         $example_options .= "# versions 3 size 100M;\n";
         $example_options .= "# print-time yes;\n";
         $example_options .= "# };\n\n";
         $example_options .= "# category queries {\n";
         $example_options .= "# query_logging;\n";
         $example_options .= "# };\n";
         $example_options .= "#};\n";
         if (!lfile_exists($options_file)) {
             touch($options_file);
             chown($options_file, "named");
         }
         $cont = lfile_get_contents($options_file);
         $pattern = "options";
         if (!preg_match("+{$pattern}+i", $cont)) {
             file_put_contents($options_file, "{$example_options}\n");
         }
         $pattern = 'include "/etc/kloxo.named.conf";';
         $file = "/var/named/chroot/etc/named.conf";
         $comment = "//Kloxo";
         addLineIfNotExistInside($file, $pattern, $comment);
         touch("/var/named/chroot/etc/kloxo.named.conf");
         chown("/var/named/chroot/etc/kloxo.named.conf", "named");
         lxshell_return("rpm", "-e", "djbdns");
         lunlink("/etc/init.d/djbdns");
     } else {
         lxshell_return("service", "named", "stop");
         lxshell_return("rpm", "-e", "--nodeps", "bind");
         lxshell_return("rpm", "-e", "--nodeps", "bind-chroot");
         lxshell_return("chkconfig", "djbdns", "on");
     }
 }
Exemple #29
0
 function getFromRemote($p)
 {
     $filepass = $this->main->filepass;
     getFromRemote($this->main->pasteserver_realip, $filepass[$p], $this->main->fullpath, $p);
     return;
     $bp = basename($p);
     if ($filepass[$p]['type'] === 'dir') {
         $tfile = lx_tmp_file("__path_tmp", "lx_{$bp}");
         getFromFileserv($this->main->pasteserver, $this->main->filepass[$p], $tfile);
         lxfile_mkdir("{$this->main->fullpath}/{$bp}");
         lxshell_unzip("__system__", "{$this->main->fullpath}/{$bp}", $tfile);
         lunlink($tfile);
     } else {
         getFromFileserv($this->main->pasteserver, $this->main->filepass[$p], "{$this->main->fullpath}/{$bp}");
     }
 }
Exemple #30
0
<?php

include_once "htmllib/lib/include.php";
initProgram('admin');
$login->loadAllObjects('client');
$list = $login->getList('client');
foreach ($list as $c) {
    $dlist = $c->getList('domain');
    $d = getFirstFromList($dlist);
    lunlink("/home/{$c->nname}/www");
    lxfile_symlink("/home/{$c->nname}/domain/{$d->nname}/www", "/home/{$c->nname}/www");
    foreach ($dlist as $l) {
        $web = $l->getObject('web');
        $web->setUpdateSubaction('full_update');
        $web->was();
    }
}