Ejemplo n.º 1
0
function os_fix_fstab()
{
    $list = lfile_trim("/etc/fstab");
    foreach ($list as $l) {
        $nl = trimSpaces($l);
        $n = explode(" ", $nl);
        if ($n[1] !== "/home" && $n[1] !== '/') {
            $out[] = $l;
            continue;
        }
        if (!csa($n[3], "usrquota")) {
            $mount[] = $n[1];
            $n[3] = "{$n['3']},usrquota,grpquota";
        }
        $o = implode("\t", $n);
        $out[] = $o;
    }
    $out = implode("\n", $out);
    $out .= "\n";
    dprint($out);
    lfile_put_contents("/etc/fstab", $out);
    dprintr($mount);
    foreach ($mount as $m) {
        system("mount {$m} -o remount");
    }
}
Ejemplo n.º 2
0
 static function convertfile($oldtime, $newtime)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $file = '/var/log/kloxo/maillog';
     if (!lxfile_real($file)) {
         return null;
     }
     $fp = fopen($file, "r");
     $fsize = filesize($file);
     $ret = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("mailtraffic", "getTimeFromOriginalQmailString"));
     if ($ret < 0) {
         dprint("Could not find position\n");
         return;
     }
     $totstring = null;
     $count = 0;
     while (!feof($fp)) {
         $count++;
         if ($count > 1000000) {
             break;
         }
         $string = fgets($fp);
         $totstring .= $string;
         if (self::getTimeFromOriginalQmailString($string) > $newtime) {
             break;
         }
     }
     fclose($fp);
     $convertfile = tempnam("/tmp/", "mail_log");
     $convertfile_source = tempnam("/tmp/", "mail_log_source");
     lfile_put_contents($convertfile_source, $totstring);
     system("perl {$sgbl->__path_kloxo_httpd_root}/awstats/tools/maillogconvert.pl standard < {$convertfile_source} > {$convertfile}");
     lunlink($convertfile_source);
     return $convertfile;
 }
Ejemplo n.º 3
0
 function createDnsData()
 {
     dprint("DbActionAdd\n");
     $fdata = "";
     $tmp = "";
     $this->createPrimaryZone($this->main->nname);
     lfile_put_contents("c:/Windows/System32/drivers/etc/hosts", "127.0.0.1 {$this->main->nname}", FILE_APPEND);
     return null;
 }
Ejemplo n.º 4
0
 function createMimeType()
 {
     $result = $this->main->__var_mime_list;
     $result = merge_array_object_not_deleted($result, $this->main);
     $string = null;
     foreach ($result as $r) {
         $string .= "Addtype {$r['type']} {$r['extension']}\n";
     }
     lfile_put_contents("/etc/httpd/conf/kloxo/mimetype.conf", $string);
 }
Ejemplo n.º 5
0
 static function moveToTrash($user, $root, $name)
 {
     $trashcont = "{$root}/.trash/.__trash_" . basename($name);
     $fullpath = "{$root}/{$name}";
     lxfile_rm_rec("{$root}/.trash/" . basename($name));
     lxfile_rm_rec($trashcont);
     $res = lxuser_mkdir($user, "{$root}/.trash/");
     lfile_put_contents($trashcont, $name . "\n");
     $res = new_process_mv_rec($user, $fullpath, "{$root}/.trash");
     //unlink($f);
 }
Ejemplo n.º 6
0
function lxshell_expect($strtype, $cmd)
{
    global $gbl, $sgbl, $login, $ghtml;
    $a = array("ntfsresize" => "expect \"Are you sure you want to proceed (y/[n])? \"\nsend \"y\\r\"\n\n");
    $t = lx_tmp_file("expect");
    $string = $a['ntfsresize'];
    lfile_put_contents($t, "spawn {$cmd}\n{$string}");
    log_shell("expect {$t} {$cmd}");
    system("expect {$t}");
    //lunlink($t);
}
Ejemplo n.º 7
0
 function createUser()
 {
     $domname = $this->main->getParentName();
     $dir = "__path_httpd_root/{$domname}/dirprotect/";
     $authuserfile = "{$dir}/{$this->main->getFileName()}";
     $fstr = null;
     foreach ($this->main->diruser_a as $v) {
         $crypt = crypt($v->param, $this->genSalt());
         $fstr .= "{$v->nname}:{$crypt}";
         //$fstr .= $v->nname . ':' . $v->param . "\n";
     }
     lfile_put_contents($authuserfile, $fstr);
 }
Ejemplo n.º 8
0
 function dosyncToSystem()
 {
     global $gbl, $sgbl, $login;
     if (if_demo()) {
         return;
     }
     $_filepath = "__path_real_etc_root/hosts.deny";
     $string = null;
     foreach ((array) $this->main->__var_hostlist as $v) {
         $string .= "ALL: {$v['hostname']}\n";
     }
     if ($this->isDeleted() != "delete") {
         $string .= "ALL: {$this->main->hostname}\n";
     }
     lfile_put_contents($_filepath, $string);
 }
Ejemplo n.º 9
0
 function createDavSuexec()
 {
     $string = null;
     $uid = os_get_uid_from_user($this->main->__var_system_username);
     $gid = os_get_gid_from_user($this->main->__var_system_username);
     $string .= "#!/bin/sh\n";
     $string .= "export MUID={$uid}\n";
     $string .= "export GID={$gid}\n";
     $string .= " export PHPRC=/usr/local/lxlabs/ext/php/etc/php.ini\n";
     $string .= "export TARGET=<%program%>\n";
     $string .= "export NON_RESIDENT=1\n";
     $string .= "exec lxsuexec \$*\n";
     $st = str_replace("<%program%>", "/usr/local/lxlabs/ext/php/bin/php_cgi", $string);
     lfile_put_contents("__path_httpd_root/{$this->main->getParentName()}/davsuexec.sh", $st);
     lxfile_unix_chmod("__path_httpd_root/{$this->main->getParentName()}/davsuexec.sh", "0755");
 }
Ejemplo n.º 10
0
 function createDnsData()
 {
     dprint("DbActionAdd\n");
     $fdata = "";
     $tmp = "";
     $this->createPrimaryZone($this->main->nname);
     lfile_put_contents("c:/Windows/System32/drivers/etc/hosts", "127.0.0.1 {$this->main->nname}", FILE_APPEND);
     return;
     if ($this->main->ns_rec_a != '') {
         foreach ($this->main->ns_rec_a as $value) {
             $this->createNSRecord($this->main->nname, $value->nname);
         }
     }
     if ($this->main->mx_rec_a != '') {
         foreach ($this->main->mx_rec_a as $o) {
             $this->createMxRecord($this->main->nname, 'something', $o->param, $o->nname);
         }
     }
     if ($this->main->a_rec_a) {
         foreach ($this->main->a_rec_a as $o) {
             $key = $o->nname;
             $value = $o->param;
             if ($o->param === null) {
                 continue;
             }
             $this->createARecord($this->main->nname, $key, $value);
         }
     }
     if ($this->main->cn_rec_a != '') {
         foreach ($this->main->cn_rec_a as $o) {
             $key = $o->nname;
             $value = $o->param;
             if ($o->param === null) {
                 continue;
             }
             $key .= ".{$this->main->nname}.";
             if ($value !== "__base__") {
                 $value = "{$value}.{$this->main->nname}.";
             } else {
                 $value = "{$this->main->nname}.";
             }
             $fdata .= $tmp;
         }
     }
 }
Ejemplo n.º 11
0
 function createMainFile()
 {
     global $gbl, $sgbl, $login, $ghtml;
     list($base, $end) = reversedns::getBaseEnd($this->main->nname, $this->main->__var_rdnsrange);
     $string = null;
     $transferstring = null;
     if ($this->main->__var_transferip) {
         $transferstring = "allow-transfer { {$this->main->__var_transferip}; };";
     }
     foreach ($this->main->__var_reverse_list as $k => $v) {
         if ($k === $base) {
             continue;
         }
         $string .= "zone \"{$k}.in-addr.arpa\" {type master; file \"{$sgbl->__path_named_path}/{$k}.in-addr.arpa\"; {$transferstring}};\n\n";
     }
     $string .= "zone \"{$base}.in-addr.arpa\" {type master; file \"{$sgbl->__path_named_path}/{$base}.in-addr.arpa\"; {$transferstring}};\n\n";
     lfile_put_contents("__path_named_chroot/etc/lxreverse.conf", $string);
 }
Ejemplo n.º 12
0
 function changeSuperAdminPass()
 {
     if ($this->nname === 'superadmin') {
         $oldpass = getAdminDbPass();
         $newp = client::createDbPass($this->realpass);
         $return = lfile_put_contents("__path_super_pass", $newp);
         if (!$return) {
             log_log("admin_error", "Admin pass change failed  {$last_error}");
             throw new lxException("could_not_change_superadmin_pass", '');
         }
         $return = $sql->setPassword($newp);
         if ($return) {
             $return = lfile_put_contents("__path_super_pass", $oldpass);
             log_log("admin_error", "mysqladmin Failed . {$out}");
             throw new lxException("could_not_change_superadmin_pass", '');
         }
     }
 }
Ejemplo n.º 13
0
function create_mysql_db($type, $opt, $admin_pass)
{
    global $gbl, $sgbl, $login, $ghtml;
    $progname = $sgbl->__var_program_name;
    $db = $sgbl->__var_dbf;
    if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) {
        print "Need db Root User and password --db-rootuser, --db-rootpassword \n";
        exit;
    }
    if ($sgbl->__var_database_type === 'mysql') {
        // TODO: REPLACE MYSQL_CONNECT
        // TUT TUT naughty programmer... We are creating the db now XD
        $req = mysqli_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']);
    } else {
        if ($sgbl->__var_database_type === 'mssql') {
            $req = mssql_connect("localhost,{$sgbl->__var_mssqlport}");
        } else {
            $req = new PDO("sqlite:{$db}");
        }
    }
    if (!$req) {
        print "Could not Connect to Database on localhost using root user: "******"\n";
    }
    //$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql");
    $dp = randomString(9);
    $dbadminpass = client::createDbPass($dp);
    $dbname = $sgbl->__var_dbf;
    $pguser = $sgbl->__var_admin_user;
    if ($sgbl->__var_database_type === 'mysql') {
        @mysqli_query($req, "CREATE DATABASE {$dbname}");
        mysqli_query($req, "GRANT ALL ON {$dbname}.* TO '{$pguser}'@'localhost' IDENTIFIED BY '{$dbadminpass}';");
    } else {
        if ($sgbl->__var_database_type === 'mssql') {
            mssql_query("create database {$dbname};");
            mssql_query("use master ");
            mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';");
            mssql_query("use {$dbname} ");
            mssql_query("grant all to {$pguser}");
        } else {
        }
    }
    lfile_put_contents("__path_admin_pass", $dbadminpass);
    lxfile_generic_chown("__path_admin_pass", "lxlabs");
}
Ejemplo n.º 14
0
function create_mysql_db($type, $opt, $admin_pass)
{
    global $gbl, $sgbl, $login, $ghtml;
    $progname = $sgbl->__var_program_name;
    if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) {
        print "Need db Root User and password --db-rootuser, --db-rootpassword \n";
        exit;
    }
    if ($sgbl->__var_database_type === 'mysql') {
        $req = mysql_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']);
    } else {
        if ($sgbl->__var_database_type === 'mssql') {
            $req = mssql_connect("localhost,{$sgbl->__var_mssqlport}");
        } else {
            $req = new PDO("sqlite:{$sgbl->__var_dbf}");
        }
    }
    if (!$req) {
        print "Could not Connect to Database on localhost using root user\n";
    }
    //$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql");
    $dp = randomString(9);
    $dbadminpass = client::createDbPass($dp);
    $dbname = $sgbl->__var_dbf;
    $pguser = $sgbl->__var_admin_user;
    if ($sgbl->__var_database_type === 'mysql') {
        @mysql_query("create database {$dbname}");
        mysql_query("grant all on {$dbname}.* to '{$pguser}'@'localhost' identified by '{$dbadminpass}';");
    } else {
        if ($sgbl->__var_database_type === 'mssql') {
            mssql_query("create database {$dbname};");
            mssql_query("use master ");
            mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';");
            mssql_query("use {$dbname} ");
            mssql_query("grant all to {$pguser}");
        } else {
        }
    }
    lfile_put_contents("__path_admin_pass", $dbadminpass);
    lxfile_generic_chown("__path_admin_pass", "lxlabs");
}
Ejemplo n.º 15
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);
 }
Ejemplo n.º 16
0
 static function createDhcpConfFile($slist)
 {
     $list = os_get_allips();
     foreach ($list as $l) {
         $base = strtil($l, ".");
         $subnet[$base] = null;
     }
     $string = null;
     $string .= "ddns-update-style interim;\n";
     $string .= "ignore client-updates;\n\n\n";
     $string .= self::getSubnetString($k, $slist);
     /*
     	foreach($subnet as $k => $v) {
     		$string .= self::getSubnetString($k, $slist);
     	}
     */
     foreach ($slist as $s) {
         $string .= self::getHostString($s);
     }
     lfile_put_contents("/etc/dhcpd.conf", $string);
     createRestartFile("dhcpd");
 }
Ejemplo n.º 17
0
 function dbactionUpdate($subaction)
 {
     $name = sslcert::getSslCertnameFromIP($this->main->nname);
     $path = "__path_ssl_root";
     $contentscer = $this->main->text_crt_content;
     $contentskey = $this->main->text_key_content;
     $contentsca = trim($this->main->text_ca_content);
     if (!$contentscer || !$contentskey) {
         throw new lxException("certificate_key_file_empty", '');
     }
     sslcert::checkAndThrow($contentscer, $contentskey, $name);
     lfile_put_contents("{$path}/{$name}.crt", $contentscer);
     lfile_put_contents("{$path}/{$name}.key", $contentskey);
     $contentpem = "{$contentscer}\n{$contentskey}";
     lfile_put_contents("{$path}/{$name}.pem", $contentpem);
     if ($contentsca) {
         lfile_put_contents("{$path}/{$name}.ca", $contentsca);
     } else {
         lxfile_cp("htmllib/filecore/program.ca", "{$path}/{$name}.ca");
     }
     createRestartFile($this->main->__var_webdriver);
 }
Ejemplo n.º 18
0
function add_line_to_secondary_mycnf($master, $slavepass)
{
    global $gbl, $sgbl, $login, $ghtml;
    if (!lxfile_exists("/etc/secondary_master.copy.my.cnf")) {
        lxfile_cp("/etc/my.cnf", "/etc/secondary_master.copy.my.cnf");
    }
    $list = lfile_trim("/etc/my.cnf");
    foreach ($list as $k => $l) {
        if (check_if_skip($l)) {
            continue;
        }
        $ll[] = $l;
        if ($l == '[mysqld]') {
            $ll[] = "server-id=2";
            $ll[] = "master-host={$master}";
            $ll[] = "master-user=lxlabsslave";
            $ll[] = "master-password={$slavepass}";
        }
    }
    lfile_put_contents("/etc/my.cnf", implode("\n", $ll));
    system("service mysqld restart");
}
Ejemplo n.º 19
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");
 }
Ejemplo n.º 20
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");
}
Ejemplo n.º 21
0
 static function findTotaltrafficUsage($list, $oldtime, $newtime)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if (!isset($oldtime)) {
         return null;
     }
     $file = '/var/log/lxinterfacetraffic.log';
     $processedir = "/var/log/";
     $processfile = $file;
     lxshell_return("__path_php_path", "../bin/common/iptraffic.php");
     $globaliplist = null;
     foreach ($list as $d) {
         foreach ($d->viflist as $iface) {
             $tlist[$d->nname] = self::get_usage($processfile, $iface, $oldtime, $newtime);
             $globalifacelist[] = $iface;
         }
     }
     lfile_put_contents("__path_program_etc/xeninterface.list", implode("\n", $globalifacelist));
     $stat = stat($file);
     if ($stat['size'] >= 10 * 1024 * 1024) {
         lxfile_mv($file, getNotexistingFile($processedir, basename($file)));
     }
     return $tlist;
 }
Ejemplo n.º 22
0
 static function createWebmailConfig()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $fdata = null;
     $webmaildef = $login->getObject('general')->generalmisc_b->webmail_system_default;
     if ($webmaildef === '--chooser--' || !isset($webmaildef)) {
         $webmaildefpath = '';
     } else {
         $webmaildefpath = "{$webmaildef}/";
     }
     $webdata = null;
     $webdata .= "<VirtualHost ";
     $webdata .= self::staticcreateVirtualHostiplist("80") . " ";
     $webdata .= self::staticcreateVirtualHostiplist("443") . " ";
     $webdata .= ">\n\n";
     $webdata .= "\tServerName webmail\n";
     $webdata .= "\tServerAlias webmail.*\n\n";
     $webdata .= "\tDocumentRoot \"{$sgbl->__path_kloxo_httpd_root}/webmail/{$webmaildefpath}\"\n\n";
     $webdata .= "\t<IfModule mod_suphp.c>\n";
     $webdata .= "\t\tSuPhp_UserGroup lxlabs lxlabs\n";
     $webdata .= "\t</IfModule>\n\n";
     $webdata .= "</VirtualHost>\n\n";
     $webmailfile = "/home/apache/conf/webmails/webmail.conf";
     lfile_put_contents($webmailfile, $webdata);
 }
Ejemplo n.º 23
0
} else {
    if ($sgbl->isKloxo() && !$sgbl->isDebug()) {
        $php_st .= "cgi.assign\t=\t\t\t\t\t\t   (\".php\" => \"/usr/local/lxlabs/kloxo/file/phpsuexec.sh\" )\n";
    } else {
        $php_st .= "cgi.assign\t=\t\t\t\t\t\t   (\".php\" => \"/usr/local/lxlabs/ext/php/bin/php_cgi\" )\n";
    }
}
foreach ($list as &$l) {
    $l = preg_replace("/__cgi_or_fcgi__/", $php_st, $l);
    $l = preg_replace("/__program_name__/", $sgbl->__var_program_name, $l);
    $l = preg_replace("/__program_disable_nonssl__/", $nonsslhash, $l);
    $l = preg_replace("/__program_port__/", $nonsslport, $l);
    $l = preg_replace("/__program_sslport__/", $sslport, $l);
    $l = preg_replace("/__program_user__/", $user, $l);
}
lfile_put_contents("../file/lighttpd.conf", implode("", $list));
$pemfile = "__path_program_root/etc/program.pem";
$cafile = "__path_program_root/etc/program.ca";
if (!lxfile_exists($pemfile)) {
    lxfile_cp("__path_program_htmlbase/htmllib/filecore/program.pem", $pemfile);
    lxfile_generic_chown($pemfile, "lxlabs");
}
// Merged from 6.1.x/kloxo/bin/common/misc/fixlighty.php	(revision 472)
lxfile_touch("__path_program_root/log/lighttpd_error.log");
lxfile_touch("__path_program_root/log/access_log");
lxfile_generic_chmod("__path_program_root/log", "0700");
lxfile_generic_chown("__path_program_root/log", "lxlabs:lxlabs");
lxfile_generic_chmod("__path_program_root/log/lighttpd_error.log", "0644");
lxfile_generic_chmod("__path_program_root/log/access_log", "0644");
lxfile_generic_chown("__path_program_root/log/lighttpd_error.log", "lxlabs:root");
lxfile_generic_chown("__path_program_root/log/access_log", "lxlabs:root");
Ejemplo n.º 24
0
 static function docreatestatsConf($inp, $outp, $domain, $stats_name, $stats_password)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $filecontents = lfile($inp);
     foreach ($filecontents as &$f) {
         if (preg_match("/_lx_domain_name_/", $f)) {
             $f = preg_replace("/_lx_domain_name_/", $domain, $f);
         }
         if (preg_match("/_lx__path_httpd_root/", $f)) {
             $f = preg_replace("/_lx__path_httpd_root/", $sgbl->__path_httpd_root, $f);
         }
         $regexdom = str_replace('.', '\\.', $domain);
         $regexdom .= "\$";
         if (preg_match("/_lxregex_domain_name_/", $f)) {
             $f = preg_replace("/_lxregex_domain_name_/", $regexdom, $f);
         }
         if (preg_match("/_lx_authentic_user/", $f)) {
             $f = preg_replace("/_lx_authentic_user/", $stats_name, $f);
         }
         if (preg_match("/_lx_dns_lookup_/", $f)) {
             $f = preg_replace("/_lx_dns_lookup_/", "1", $f);
         }
         $st_pro = "0";
         if ($stats_password) {
             $st_pro = "1";
         }
         if (preg_match("/_lx_stats_protect/", $f)) {
             $f = preg_replace("/_lx_stats_protect/", $st_pro, $f);
         }
     }
     $filecontents = implode("", $filecontents);
     lxfile_mkdir(dirname($outp));
     lfile_put_contents($outp, $filecontents);
     lxfile_generic_chmod($outp, "0744");
 }
Ejemplo n.º 25
0
 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));
 }
Ejemplo n.º 26
0
}
if (!posix_getpwnam('dnscache')) {
    system("useradd dnscache");
}
if (!posix_getpwnam('axfrdns')) {
    system("useradd axfrdns");
}
if (!lxfile_exists("/var/tinydns")) {
    system("tinydns-conf tinydns dnslog /var/tinydns 127.0.0.1");
}
if (!lxfile_exists("/var/axfrdns")) {
    system("axfrdns-conf axfrdns dnslog /var/axfrdns /var/tinydns 0.0.0.0");
}
//  Project issue #949 - Hardcode 0.0.0.0
//  $list = os_get_allips();
//
//  $out = implode("/", $list);
//
$out = "0.0.0.0\n";
//
//  Kloxo development version has this file refactored
//  LxCenter DT05022014
//
lfile_put_contents("/var/tinydns/env/IP", "{$out}");
if (!lxfile_exists("/var/dnscache")) {
    system("dnscache-conf dnscache dnslog /var/dnscache 127.0.0.1");
}
lfile_put_contents("/var/axfrdns/tcp", ":allow");
system("cd /var/axfrdns;  /usr/local/bin/tcprules tcp.cdb tcp.tmp < tcp");
lfile_put_contents("/var/dnscache/env/IP", "127.0.0.1");
Ejemplo n.º 27
0
function iptraffic_main_v6()
{
    global $global_dontlogshell;
    $res = lxshell_output("ip6tables", "-nvx", "-L", "FORWARD");
    $res = explode("\n", $res);
    $outgoing = null;
    foreach ($res as $r) {
        // First column may have spaces because of the number of digits in the column
        $r = trim($r, ' ');
        // Trim internal spaces
        $r = trimSpaces($r);
        $list = explode(' ', $r);
        if (stripos($r, "source") !== false && stripos($r, "destination") !== false) {
            // header, get important columns number
            for ($i = 0; $i < count($list); $i++) {
                if ($list[$i] == "bytes") {
                    $byteIdx = $i;
                }
                // Removing 1, because the header has an extra field cause of 'target' column
                // FIXME: any better idea?
                if ($list[$i] == "source") {
                    $srcIdx = $i - 1;
                }
                if ($list[$i] == "destination") {
                    $dstIdx = $i - 1;
                }
            }
        }
        if (count($list) != 7) {
            continue;
        }
        $list[$dstIdx] = explode("/", $list[$dstIdx])[0];
        $list[$srcIdx] = explode("/", $list[$srcIdx])[0];
        if (csb($list[$dstIdx], "::")) {
            // Just make sure that we don't calculate this goddamn thing twice, which would happen if there are multiple copies of the same rule. So mark that we have already read it in the sourcelist.
            // OA: Since we dont care lines that have a rule set (fixed above), this wont happen
            if (!isset($sourcelist[$list[$srcIdx]])) {
                $outgoing[$list[$srcIdx]][] = $list[$byteIdx];
                $sourcelist[$list[$srcIdx]] = true;
            }
        } else {
            if (csb($list[$srcIdx], "::")) {
                if (!isset($dstlist[$list[$dstIdx]])) {
                    $incoming[$list[$dstIdx]][] = $list[$byteIdx];
                    $dstlist[$list[$dstIdx]] = true;
                }
            }
        }
    }
    if (!$outgoing) {
        return;
    }
    if (!isset($incoming)) {
        return;
    }
    $realtotalincoming = calculateRealTotal($incoming);
    $realtotaloutgoing = calculateRealTotal($outgoing);
    foreach ($realtotaloutgoing as $k => $v) {
        $vpsid = get_vpsid_from_ipaddress($k);
        if ($vpsid === 0) {
            continue;
        }
        if (!isset($vpsoutgoing[$vpsid])) {
            $vpsoutgoing[$vpsid] = 0;
        }
        if (!isset($vpsincoming[$vpsid])) {
            $vpsincoming[$vpsid] = 0;
        }
        $vpsoutgoing[$vpsid] += $realtotaloutgoing[$k];
        $vpsincoming[$vpsid] += $realtotalincoming[$k];
    }
    $ret = array();
    foreach ($vpsincoming as $k => $v) {
        $ret[$k]['in'] = $vpsincoming[$k];
        $ret[$k]['out'] = $vpsoutgoing[$k];
        $tot = $vpsincoming[$k] + $vpsoutgoing[$k];
        execRrdTraffic("openvzv6-{$k}", $tot, "-{$vpsincoming[$k]}", $vpsoutgoing[$k]);
        $stringa[] = time() . " " . date("d-M-Y:H:i") . " openvzv6-{$k} {$tot} {$vpsincoming[$k]} {$vpsoutgoing[$k]}";
    }
    if ($stringa) {
        $string = implode("\n", $stringa);
        lfile_put_contents("__path_iptraffic_file" . "v6", "{$string}\n", FILE_APPEND);
    }
    lxshell_return("ip6tables", "-Z", "FORWARD");
    return $ret;
}
Ejemplo n.º 28
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);
 }
Ejemplo n.º 29
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);
 }
Ejemplo n.º 30
0
 static function setProgramSsl($contentpem, $contentsca)
 {
     lfile_put_contents("../etc/program.pem", $contentpem);
     if ($contentsca) {
         lfile_put_contents("../etc/program.ca", $contentsca);
     }
     lxfile_unix_chown("../etc/program.pem", "lxlabs:lxlabs");
     lxfile_unix_chown("../etc/program.ca", "lxlabs:lxlabs");
 }