コード例 #1
0
ファイル: ffile__commonlib.php プロジェクト: soar-team/kloxo
 static function restoreFromTrash($user, $root, $name)
 {
     $trashcont = "{$root}/.trash/.__trash_" . basename($name);
     $dst = trim(lfile_get_contents($trashcont));
     new_process_mv_rec($user, "{$root}/.trash/" . basename($name), "{$root}/{$dst}");
     lxfile_rm("{$root}/.trash/.__trash_" . basename($name));
 }
コード例 #2
0
ファイル: mebackup.php プロジェクト: soar-team/kloxo
function mebackup_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    $progname = $sgbl->__var_program_name;
    $cprogname = ucfirst($progname);
    initProgram('admin');
    lxfile_mkdir("__path_program_home/selfbackup/self/__backup");
    $backup = $login->getObject('general')->selfbackupparam_b;
    $dbf = $sgbl->__var_dbf;
    $pass = trim(lfile_get_contents("__path_program_root/etc/conf/{$progname}.pass"));
    $vd = createTempDir("/tmp", "mebackup");
    $docf = "{$vd}/mebackup.dump";
    // Issue #671 - Fixed backup-restore issue
    //	exec("exec mysqldump --add-drop-table -u $progname -p$pass $dbf > $docf");
    system("exec mysqldump --add-drop-table -u {$progname} -p{$pass} {$dbf} > {$docf}");
    $string = @date('Y-M-d') . '-' . time();
    $bfile = "{$sgbl->__path_program_home}/selfbackup/self/__backup/{$progname}-scheduled-masterselfbackup-{$string}.zip";
    lxshell_zip($vd, $bfile, array("mebackup.dump"));
    lxfile_tmp_rm_rec($vd);
    if ($backup && $backup->isOn('selfbackupflag')) {
        try {
            lxbackup::upload_to_server($bfile, basename($bfile), $backup);
        } catch (Exception $e) {
            print "Sending warning to {$login->contactemail} ..\n";
            lx_mail(null, $login->contactemail, "{$cprogname} Self Database Backup Upload Failed on " . date('Y-M-d') . " at " . date('H') . " Hours", "{$cprogname} Backup upload Failed due to {$e->getMessage()}\n");
        }
    }
    $backup->rm_last_number = 20;
    $backup->nname = 'masterselfbackup';
    lxbackup::clear_extra_backups('selfbackup', 'self', $backup);
}
コード例 #3
0
ファイル: child.php プロジェクト: digideskio/hypervm
function child_main()
{
    global $argv;
    //sleep(100);
    ob_start();
    $rem = unserialize(lfile_get_contents($argv[1]));
    unlink($argv[1]);
    if (!$rem) {
        exit;
    }
    if (isset($rem->sleep)) {
        sleep($rem->sleep);
    }
    if ($rem->__type == 'object') {
        $func = $rem->func;
        $ret = $rem->__exec_object->{$func}();
    } else {
        // Merged from 6.1.x/kloxo/bin/common/child.php	(revision 472)
        // workaround for the following php bug:
        //   http://bugs.php.net/bug.php?id=47948
        //   http://bugs.php.net/bug.php?id=51329
        if (is_array($rem->func) && count($rem->func) > 0) {
            $class = $rem->func[0];
            class_exists($class);
        }
        // ---
        $ret = call_user_func_array($rem->func, $rem->arglist);
    }
    $var = base64_encode(serialize($ret));
    ob_end_clean();
    print $var;
    exit;
}
コード例 #4
0
function security_blanket_main()
{
    global $argv;
    //sleep(100);
    $rem = unserialize(lfile_get_contents($argv[1]));
    unlink($argv[1]);
    if (!$rem) {
        exit;
    }
    // Merged from 6.1.x/kloxo/bin/common/securityblanket.php	(revision 472)
    // workaround for the following php bug:
    //   http://bugs.php.net/bug.php?id=47948
    //   http://bugs.php.net/bug.php?id=51329
    if (is_array($rem->func) && count($rem->func) > 0) {
        $class = $rem->func[0];
        class_exists($class);
    }
    // ---
    call_user_func_array($rem->func, $rem->arglist);
    $sq = new Sqlite(null, $rem->table);
    $res = $sq->getRowsWhere("nname = '{$rem->nname}'", array($rem->flagvariable));
    if ($res[0][$rem->flagvariable] === 'doing') {
        $sq->rawQuery("update {$rem->table} set {$rem->flagvariable} = 'Program Got aborted in the midst. Please try again.' where nname = '{$rem->nname}'");
    }
}
コード例 #5
0
ファイル: background.php プロジェクト: soar-team/kloxo
function background_main()
{
    global $argv;
    //sleep(100);
    $rem = unserialize(lfile_get_contents($argv[1]));
    unlink($argv[1]);
    if (!$rem) {
        exit;
    }
    if (isset($rem->sleep)) {
        sleep($rem->sleep);
    }
    if ($rem->__type == 'object') {
        $func = $rem->func;
        $rem->__exec_object->{$func}();
    } else {
        // workaround for the following php bug:
        //   http://bugs.php.net/bug.php?id=47948
        //   http://bugs.php.net/bug.php?id=51329
        if (is_array($rem->func) && count($rem->func) > 0) {
            $class = $rem->func[0];
            class_exists($class);
        }
        // ---
        call_user_func_array($rem->func, $rem->arglist);
    }
}
コード例 #6
0
ファイル: kloxo-migrate.php プロジェクト: soar-team/kloxo
function change_lxadmin_to_kloxo($filename)
{
    $string = lfile_get_contents($filename);
    if (!$string) {
        return;
    }
    $string = str_replace("Lxadmin", "Kloxo", $string);
    $string = str_replace("lxadmin", "kloxo", $string);
    file_put_contents($filename, $string);
}
コード例 #7
0
ファイル: invoicelib.php プロジェクト: soar-team/kloxo
 function getPaymentUrl()
 {
     $con = lfile_get_contents("../file/url.txt");
     $con = str_replace("%lxmonth%", $this->month, $con);
     $con = str_replace("%username%", $this->client, $con);
     $p = $this->getTotalPaid();
     $left = $this->total - $p;
     if ($left == 0) {
         return "already_paid";
     }
     $con = str_replace("%grand_total%", $left, $con);
     return $con;
 }
コード例 #8
0
ファイル: sshclientlib.php プロジェクト: lonelywoolf/hypervm
 function showRawPrint($subaction = null)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $parent = $this->getParentO();
     $v = lfile_get_contents("htmllib/filecore/sshterm-applet.htm");
     if ($parent->is__table('pserver')) {
         $v = str_replace("%username%", "root", $v);
         $ip = getFQDNforServer($parent->nname);
         $sshport = db_get_value("sshconfig", $parent->nname, "ssh_port");
         if (!$sshport) {
             $sshport = "22";
         }
         $v = str_replace("%host%", $ip, $v);
         $v = str_replace("%port%", $sshport, $v);
         $v = str_replace("%connectimmediately%", "true", $v);
     } else {
         if ($parent->is__table('client')) {
             if ($parent->isDisabled('shell') || !$parent->shell) {
                 $ghtml->print_information("pre", "updateform", "sshclient", "disabled");
                 exit;
             }
             $sshport = db_get_value("sshconfig", $parent->websyncserver, "ssh_port");
             if (!$sshport) {
                 $sshport = "22";
             }
             $ghtml->print_information("pre", "updateform", "sshclient", "warning");
             $ip = getFQDNforServer("localhost");
             $v = str_replace("%username%", $parent->username, $v);
             $v = str_replace("%host%", $ip, $v);
             $v = str_replace("%port%", $sshport, $v);
             $v = str_replace("%connectimmediately%", "true", $v);
         } else {
             $v = str_replace("%username%", "root", $v);
             $ip = $parent->getOneIP();
             $sshport = db_get_value("sshconfig", $parent->syncserver, "ssh_port");
             if (!$ip) {
                 throw new lxException("need_to_add_at_least_one_ip_to_the_vps_for_logging_in");
             }
             if (!$sshport) {
                 $sshport = "22";
             }
             $v = str_replace("%host%", $ip, $v);
             $v = str_replace("%port%", $sshport, $v);
             $v = str_replace("%connectimmediately%", "true", $v);
         }
     }
     print $v;
 }
コード例 #9
0
 static function getCurrentIps()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $contents = lfile_get_contents("/etc/network/interfaces");
     $string = preg_replace('/[\\n]+/', "\n", $contents);
     $array = explode("auto", $string);
     foreach ($array as $a12) {
         $a[] = self::getArrayFromString($a12);
     }
     foreach ($a as $single) {
         if (count($single) >= 3) {
             $ret[] = $single;
         }
     }
     return $ret;
 }
コード例 #10
0
ファイル: vncviewerlib.php プロジェクト: lonelywoolf/hypervm
 function showRawPrint($subaction = null)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $parent = $this->getParentO();
     $lgg = $parent->getVncLogin();
     $v = lfile_get_contents("htmllib/filecore/vncviewer-applet.html");
     $port = 5900 + $lgg[0];
     //$port = 5900;
     $v = str_replace("%port%", $port, $v);
     $v = str_replace("%host%", $lgg[1], $v);
     $ghtml->print_curvy_table_start("100");
     print "You are actually logging into the vncviewer (<b>{$lgg['1']}:{$port}</b>) on the HOST machine, which is the direct console graphical login for the vps. The password is your Control Panel password for the vps. You can also login to this vnc port <b> \"{$lgg['1']}:{$port}\" </b> using a vnc client, and there too on a successful login, you will be logged into the vps. Note that you don't need an ipaddress to be configured on the vps to use this facility. You are basically connecting to the HOST through vnc,  which gives you the console access to the vps. <br>";
     $ghtml->print_curvy_table_end("100");
     print "<table cellpadding=0 cellspacing=0 height=10> <tr> <td ></td> </tr> </table> ";
     print $v;
 }
コード例 #11
0
ファイル: initlib.php プロジェクト: lonelywoolf/hypervm
function add_admin($pass)
{
    global $gbl, $sgbl, $login, $ghtml;
    $client = new Client(null, null, 'admin');
    $login = $client;
    $client->initThisDef();
    $client->priv->pserver_num = 'Unlimited';
    $client->priv->maindomain_num = 'Unlimited';
    $client->priv->vps_num = 'Unlimited';
    $client->priv->client_num = 'Unlimited';
    $client->ddate = time();
    $ddb = new Sqlite(null, "client");
    if (!$ddb->existInTable("nname", 'admin')) {
        if ($sgbl->dbg > 0) {
            $pass = '******';
            $res['contacemail'] = '*****@*****.**';
        }
        $res['password'] = crypt($pass);
        $res['cttype'] = 'admin';
        $res['cpstatus'] = 'on';
        if (if_demo()) {
            $res['email'] = "*****@*****.**";
        }
        $client->create($res);
        $client->driverApp = new client__sync(null, null, 'admin');
        $client->was();
        lxfile_mkdir("__path_client_root/{$client->nname}");
        lxfile_generic_chown("__path_client_root/{$client->nname}", "lxlabs");
    }
    $notif = new Notification(null, null, $client->getClName());
    $notif->initThisDef();
    $notif->dbaction = 'add';
    $notif->text_newaccountmessage = lfile_get_contents("__path_program_root/file/welcome.txt");
    $notif->parent_clname = $client->getClName();
    $notif->write();
    $display = new sp_SpecialPlay(null, null, $client->getClName());
    $display->initThisDef();
    $display->parent_clname = $client->getClName();
    $display->dbaction = 'add';
    $display->write();
}
コード例 #12
0
ファイル: consolesshlib.php プロジェクト: lonelywoolf/hypervm
 function showRawPrint($subaction = null)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $parent = $this->getParentO();
     $parent->makeSureTheUserExists();
     $lgg = $parent->getLogin();
     $sshport = db_get_value("sshconfig", $parent->syncserver, "ssh_port");
     if (!$sshport) {
         $sshport = "22";
     }
     $v = lfile_get_contents("htmllib/filecore/sshterm-applet.htm");
     $ip = $lgg[1];
     $v = str_replace("%username%", $lgg[0], $v);
     $v = str_replace("%host%", $ip, $v);
     $v = str_replace("%port%", $sshport, $v);
     $v = str_replace("%connectimmediately%", "true", $v);
     $string = $login->getKeyword("console_message");
     $string = str_replace("%username%", "<font style='font-weight:bold'>{$lgg['0']}@{$ip}:{$sshport} </font>", $string);
     print " <table cellpadding=0 cellspacing=0 width=80%> <tr> <td > {$string} <br> </td> </tr> </table>  \n";
     print $v;
 }
コード例 #13
0
 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);
 }
コード例 #14
0
 function dbactionUpdate($subaction)
 {
     if (if_demo()) {
         throw new lxException("demo", $v);
     }
     if ($this->main->ssh_port && !($this->main->ssh_port > 0)) {
         throw new lxException('invalid_ssh_port', 'ssh_port', '');
     }
     dprint($this->main->ssh_port);
     $this->main->ssh_port = trim($this->main->ssh_port);
     if (!$this->main->ssh_port) {
         $port = "22";
     } else {
         $port = $this->main->ssh_port;
     }
     if (lxfile_exists("/etc/fedora-release")) {
         $str = lfile_get_contents("../file/template/sshd_config-fedora-2");
     } else {
         $str = lfile_get_contents("../file/template/sshd_config");
     }
     $str = str_replace("%ssh_port%", $port, $str);
     if ($this->main->isOn('without_password_flag')) {
         $wt = 'without-password';
     } else {
         $wt = 'yes';
     }
     if ($this->main->isOn('disable_password_flag')) {
         $pwa = 'no';
     } else {
         $pwa = 'yes';
     }
     $str = str_replace("%permit_root_login%", $wt, $str);
     $str = str_replace("%permit_password%", $pwa, $str);
     $ret = lfile_put_contents("/etc/ssh/sshd_config", $str);
     if (!$ret) {
         throw new lxException('could_not_write_config_file', '', '');
     }
     exec_with_all_closed("/etc/init.d/sshd restart");
 }
コード例 #15
0
function add_line_to_master_mycnf()
{
    global $gbl, $sgbl, $login, $ghtml;
    $dbf = $sgbl->__var_dbf;
    if (!lxfile_exists("/etc/primary_master.copy.my.cnf")) {
        lxfile_cp("/etc/my.cnf", "/etc/primary_master.copy.my.cnf");
    }
    $v = lfile_get_contents("/etc/my.cnf");
    if (csa($v, "binlog-do-db")) {
        print "Line already exists in /etc/my.cnf\n";
        return;
    }
    $list = lfile_trim("/etc/my.cnf");
    foreach ($list as $k => $l) {
        $ll[] = $l;
        if ($l == '[mysqld]') {
            $ll[] = "log-bin=mysql-bin";
            $ll[] = "binlog-do-db={$dbf}";
            $ll[] = "server-id=1";
        }
    }
    lfile_put_contents("/etc/my.cnf", implode("\n", $ll));
    system("service mysqld restart");
}
コード例 #16
0
ファイル: coreFfilelib.php プロジェクト: digideskio/hypervm
 static function getFile($stat, $file, $lines = null)
 {
     if (!lfile_exists($file)) {
         $stat['not_full_size'] = 'off';
         $stat['content'] = null;
         return $stat;
     }
     $size = lxfile_size($file);
     if ($size > 1000 * 1000) {
         $lines = 20;
     }
     if ($lines) {
         $getsize = $lines * 1000;
         $stat['not_full_size'] = 'on';
         $stat['content'] = lxfile_tail($file, $getsize);
         $stat['numlines'] = $lines;
     } else {
         $stat['not_full_size'] = 'off';
         $stat['content'] = lfile_get_contents($file);
     }
     return $stat;
 }
コード例 #17
0
ファイル: weblib.php プロジェクト: zseand/kloxo
 function replaceVariables($filename)
 {
     $cont = lfile_get_contents($filename);
     $cont = str_replace("<%domainname%>", $this->nname, $cont);
     $cont = str_replace("<%contactemail%>", $this->__var_parent_contactemail, $cont);
     $cont = str_replace("<%clientname%>", $this->__var_clientname, $cont);
     lxuser_put_contents($this->username, $filename, $cont);
 }
コード例 #18
0
ファイル: pservercorelib.php プロジェクト: soar-team/kloxo
 function syncPasswordCommon()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $login->password = $this->password;
     if (!lfile_exists('__path_slave_db')) {
         return;
     }
     $rmt = unserialize(lfile_get_contents('__path_slave_db'));
     $rmt->password = $this->password;
     //$rmt->realpass = $this->realpass;
     lfile_put_contents('__path_slave_db', serialize($rmt));
 }
コード例 #19
0
ファイル: iptraffic.php プロジェクト: hypervm-ng/hypervm-ng
function get_bytes_for_interface($l)
{
    static $net;
    if (!$net) {
        $net = lfile_get_contents("/proc/net/dev");
        $net = explode("\n", $net);
    }
    foreach ($net as $n) {
        $n = trimSpaces($n);
        if (!csb($n, "vif-{$l}:")) {
            continue;
        }
        $n = strfrom($n, "vif-{$l}:");
        $n = trimSpaces($n);
        $b = explode(" ", $n);
        $total = $b[0] + $b[8];
        // It seems for xen it is the reverse. The input for the vif is the output for the virtual machine.
        return array('total' => $total, 'incoming' => $b[8], 'outgoing' => $b[0]);
    }
    return 0;
}
コード例 #20
0
ファイル: lxclient.php プロジェクト: lonelywoolf/hypervm
 function getSkinColor()
 {
     static $col;
     $dir = $this->getSkinDir();
     if ($col) {
         return $col;
     }
     if (lxfile_exists("__path_program_htmlbase/{$dir}/base_color")) {
         $col = trim(lfile_get_contents("__path_program_htmlbase/{$dir}/base_color"));
     } else {
         $col = "b1c0f0";
     }
     return "{$col}";
 }
コード例 #21
0
ファイル: vps__xenlib.php プロジェクト: digideskio/hypervm
 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);
 }
コード例 #22
0
 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);
 }
コード例 #23
0
ファイル: lxlib.php プロジェクト: zseand/kloxo
function change_db_pass()
{
    global $gbl, $sgbl, $login, $ghtml;
    $pass = randomString(10);
    $newp = client::createDbPass($pass);
    $oldpass = lfile_get_contents("__path_admin_pass");
    $username = $sgbl->__var_program_name;
    $sql = new Sqlite(null, "client");
    //$sql->rawQuery("grant all on kloxo.* to kloxo@'localhost' identified by $newp");
    //$sql->rawQuery("grant all on kloxo.* to kloxo@'%' identified by $newp");
    //$return = $sql->setPassword($newp);
    //exec("mysqladmin -u $username -p$oldpass password $newp 2>&1", $out, $return);
    exec("echo 'set Password=Password(\"{$newp}\")' | mysql -u {$username} -p{$oldpass} 2>&1", $out, $return);
    if ($return) {
        $out = implode(" ", $out);
        log_log("admin_error", "mysql change password Failed {$out}");
        throw new lxException("could_not_change_admin_pass", '', $out);
    }
    $return = lfile_put_contents("__path_admin_pass", $newp);
    if (!$return) {
        log_log("admin_error", "Admin pass change failed  {$last_error}");
        throw new lxException("could_not_change_admin_pass", '', $last_error);
    }
}
コード例 #24
0
ファイル: resetpassword.php プロジェクト: lonelywoolf/hypervm
include_once "htmllib/lib/include.php";
if (!os_isSelfSystemOrLxlabsUser()) {
    print "Must be Root \n";
    exit;
}
if (!isset($argv[1])) {
    print "Usage: {$argv['0']} <master/slave> <password>\n";
    exit;
}
if ($argv[1] === 'master') {
    initProgram('admin');
    $login->password = crypt($argv[2]);
    $login->realpass = $argv[2];
    $login->setUpdateSubaction('password');
    $login->createSyncClass();
    $login->was();
} else {
    if ($argv[1] === 'slave') {
        if (!lxfile_exists("__path_slave_db")) {
            print "Not Slave\n";
            exit;
        }
        $rmt = unserialize(lfile_get_contents('__path_slave_db'));
        $rmt->password = crypt($argv[2]);
        lfile_put_contents('__path_slave_db', serialize($rmt));
    } else {
        print "first argument is master/slave\n";
        exit;
    }
}
コード例 #25
0
ファイル: linuxfslib.php プロジェクト: zseand/kloxo
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);
    }
}
コード例 #26
0
ファイル: lxserverlib.php プロジェクト: zseand/kloxo
function reload_lxserver_password()
{
    global $gbl, $sgbl, $login, $ghtml;
    static $time;
    $stat = llstat("__path_admin_pass");
    $cur = $stat['mtime'];
    if ($cur > $time) {
        $rmt = lfile_get_contents("__path_admin_pass");
        $login->password = $rmt;
        $time = $cur;
    }
}
コード例 #27
0
ファイル: sslcertlib.php プロジェクト: lonelywoolf/hypervm
 static function add($parent, $class, $param)
 {
     if (isset($param['upload'])) {
         if ($param['upload'] === 'uploadfile') {
             $key_file = $_FILES['ssl_key_file_f']['tmp_name'];
             $crt_file = $_FILES['ssl_crt_file_f']['tmp_name'];
             $ca_file = $_FILES['ssl_ca_file_f']['tmp_name'];
             if (!$key_file || !$crt_file) {
                 throw new lxException("key_crt_files_needed");
             }
             $param['text_key_content'] = file_get_contents($key_file);
             $param['text_crt_content'] = file_get_contents($crt_file);
             if ($ca_file && lxfile_exists($ca_file)) {
                 $param['text_ca_content'] = lfile_get_contents($ca_file);
             }
         }
         sslcert::checkAndThrow($param['text_crt_content'], $param['text_key_content']);
         $param['upload_status'] = 'on';
     } else {
         $param['upload_status'] = 'off';
     }
     $param['certname'] = $param['nname'];
     return $param;
 }
コード例 #28
0
ファイル: lib.php プロジェクト: lonelywoolf/hypervm
function setup_scpid($cont)
{
    global $global_dontlogshell;
    $global_dontlogshell = true;
    $home = os_get_home_dir("root");
    $file = "{$home}/.ssh/authorized_keys2";
    lxfile_mkdir("{$home}/.ssh");
    lxfile_unix_chmod("{$home}/.ssh", "0700");
    addLineIfNotExistInside($file, "\n{$cont}", '');
    lxfile_unix_chmod($file, "0700");
    $global_dontlogshell = false;
    return lfile_get_contents("/etc/ssh/ssh_host_rsa_key.pub");
}
コード例 #29
0
ファイル: remotelib.php プロジェクト: soar-team/kloxo
function remote_main()
{
    global $gbl, $sgbl, $login, $ghtml, $g_dbf;
    global $argv;
    ob_start();
    $args = parse_opt($argv);
    $gbl->is_master = false;
    $gbl->is_slave = false;
    if (isset($args['install-type']) && $args['install-type'] === 'master') {
        $login = new Client(null, null, 'master');
        $gbl->is_master = true;
        $login->get();
    } else {
        $login = new Client(null, null, 'slave');
        //$login->initThisDef();
        $gbl->is_slave = true;
        $rmt = unserialize(lfile_get_contents("__path_slave_db"));
        $login->password = $rmt->password;
    }
    $login->cttype = 'admin';
    // This is to prevent the socket already used error. If use a strict single interface, the socket operations happen through our own functions, and we can set the reuse option.
    $rmt = unserialize(base64_decode($ghtml->frm_rmt));
    $res = do_remote($rmt);
    print_time('full', 'timing');
    $res->message = ob_get_contents();
    $val = base64_encode(serialize($res));
    while (@ob_end_clean()) {
    }
    print $val;
    exit;
}
コード例 #30
0
ファイル: web__apachelib.php プロジェクト: soar-team/kloxo
 function sslsysnc($ipad)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $ssl_root = $sgbl->__path_ssl_root;
     $ssl_cert = null;
     foreach ((array) $this->main->__var_ipssllist as $ip) {
         // Get the first certificate;
         if (!$ipad) {
             $ssl_cert = sslcert::getSslCertnameFromIP($ip['nname']);
             break;
         }
         if ($ip['ipaddr'] === $ipad) {
             $ssl_cert = sslcert::getSslCertnameFromIP($ip['nname']);
             break;
         }
     }
     if (!$ssl_cert) {
         return;
     }
     $string = null;
     $certificatef = "{$ssl_root}/{$ssl_cert}.crt";
     $keyfile = "{$ssl_root}/{$ssl_cert}.key";
     $cafile = "{$ssl_root}/{$ssl_cert}.ca";
     sslcert::checkAndThrow(lfile_get_contents($certificatef), lfile_get_contents($keyfile), $ssl_cert);
     $string .= "\tSSLEngine On \n";
     $string .= "\tSSLCertificateFile {$certificatef}\n";
     $string .= "\tSSLCertificateKeyFile {$keyfile}\n";
     $string .= "\tSSLCACertificatefile {$cafile}\n\n";
     return $string;
 }