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(); }
function cp_dbfile() { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; lxfile_cp("../sbin/{$progname}db", "/usr/bin/{$progname}db"); lxfile_generic_chmod("/usr/bin/{$progname}db", "0755"); }
function updateUpdate($param) { lxfile_mkdir("img/custom"); if ($_FILES['upload']['tmp_name']) { lxfile_rm("img/custom/{$this->nname}.gif"); lxfile_mv($_FILES['upload']['tmp_name'], "img/custom/{$this->nname}.gif"); lxfile_generic_chmod("img/custom/{$this->nname}.gif", "0755"); } return $param; }
function parse_mapping($root, $m, $parent_path) { $a = $m->children('http://apstandard.com/ns/1/php')->attributes(); $spath = $m->attributes()->url; $parent_path = "{$parent_path}/{$spath}"; if ($a) { dprintr($a); if ((string) $a->writable === 'true') { lxfile_generic_chmod("{$root}/{$parent_path}", "0775"); dprint("{$parent_path} Is writable\n"); } } else { dprint("{$parent_path} Not writable\n"); } foreach ($m->mapping as $mp) { parse_mapping($root, $mp, $parent_path); } }
function createDiruserfile() { $dir = '__path_httpd_root/' . $this->main->getParentName() . '/__dirprotect'; $dirfile = $dir . '/' . $this->main->getFileName(); $chownug = $this->main->__var_username . ':apache'; if (!lxfile_exists($dir)) { lxuser_mkdir($chownug, $dir); lxfile_generic_chmod($dir, '0750'); } lxfile_rm($dirfile); if ($this->main->status == 'on') { $fstr = ''; foreach ($this->main->diruser_a as $v) { $fstr .= $v->nname . ':' . crypt($v->param) . "\n"; } lxuser_put_contents($chownug, $dirfile, $fstr); lxfile_generic_chmod($dirfile, '0750'); } }
} } 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"); // if (!lxfile_exists($cafile)) { lxfile_cp("__path_program_htmlbase/htmllib/filecore/program.ca", $cafile); lxfile_generic_chown($cafile, "lxlabs"); }
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"); } } }
function doStatsPageProtection() { $filename = $this->getStatsProtectFileName(); $dir = dirname($filename); $owner = "{$this->username}:apache"; $password = crypt($this->stats_password); $content = "{$this->stats_username}:{$password}\n"; lxuser_mkdir($owner, $dir); lxfile_generic_chmod($dir, '750'); lxuser_put_contents($owner, $filename, $content); lxfile_generic_chmod($filename, '750'); }
/** * Changes file mode * * @param $username * @param $file path to the file * @param $mod mode of the specified file */ function lxuser_chmod($username, $file, $mod) { // I'm not sure how we should implement this method ??? lxfile_generic_chmod($file, $mod); //lxfile_generic_chown($file, $username); ??? }
function securityBlanketExec($table, $nname, $variable, $func, $arglist) { $rem = new Remote(); $rem->table = $table; $rem->nname = $nname; $rem->flagvariable = $variable; $rem->func = $func; $rem->arglist = $arglist; $name = tempnam("/tmp", "security"); lxfile_generic_chmod($name, "700"); lfile_put_contents($name, serialize($rem)); lxshell_background("__path_php_path", "../bin/common/securityblanket.php", $name); }
<?php include_once "htmllib/lib/include.php"; initProgram('admin'); $list = posix_getpwnam('admin'); if (!$list) { os_create_system_user('admin', $login->password, 'admin', '/sbin/nologin', '/home/admin'); lxfile_unix_chown_rec("/home/admin", "admin"); //fixes issue #515 lxfile_generic_chmod("/home/admin", "0770"); lxshell_return("__path_php_path", "../bin/misc/fixwebdnsfullupdate.php"); lxshell_return("__path_php_path", "../bin/misc/fixftpuserclient.phps"); }
function show_content($param) { $this->getContent(); if (coreFfile::is_image($this->nname)) { remove_if_older_than_a_minute_dir("tmp"); $thumb = tempnam("tmp/", "image"); lfile_put_contents($thumb, $this->image_content); lxfile_generic_chmod($thumb, "0755"); $vlist['image_content'] = array('I', array("width" => 50, "height" => 50, "value" => "{$thumb}")); $vlist['image_width'] = null; $vlist['image_height'] = null; //$vlist['image_type'] = null; $vlist['copy_old_image_flag_f'] = null; $dir = dirname($this->nname); $name = basename($this->nname); $vlist['old_image_name_f'] = array('m', "{$dir}/copy-{$name}"); $vlist['__v_button'] = "Resize"; } else { if ($this->isOn('not_full_size')) { $vlist['fake_f'] = array('M', "Showing only the last {$this->numlines} KiloBytes of the file"); } $vlist['content'] = null; $vlist['__v_button'] = ""; } return $vlist; }
function do_restore($docd) { global $gbl, $sgbl, $login, $ghtml; $name = $this->main->getPathFromName('nname'); $fullpath = "{$sgbl->__path_customer_root}/{$name}/"; lxfile_mkdir($fullpath); lxshell_unzip_with_throw($fullpath, $docd); lxfile_generic_chown_rec($fullpath, "{$this->main->username}:{$this->main->username}"); lxfile_generic_chown($fullpath, "{$this->main->username}:apache"); lxfile_generic_chmod($fullpath, "0750"); }
static function createTmpDirIfitDoesntExist($file, $real) { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $vd = tempnam("/tmp", "backup"); if (!$vd) { throw new lxException('could_not_create_tmp_dir', ''); } lunlink($vd); mkdir($vd); // // This is not a chmod inside the VM! // dont try to change it as restore will fail // lxfile_generic_chmod($vd, "0700"); if ($real) { lxshell_unzip_with_throw($vd, $file); } else { if ($sgbl->isKloxoForRestore()) { try { lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata")); } catch (Exception $e) { lxshell_unzip_with_throw($vd, $file, array("*lxadmin.file", "*lxadmin.metadata")); } } else { lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata")); } } // // This is not a chmod inside the VM! // dont try to change it as restore will fail // Extra added by dterweij lxfile_generic_chmod($vd, "0700"); return $vd; }
static function createTmpDirIfitDoesntExist($file, $real) { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $vd = tempnam("/tmp", "backup"); if (!$vd) { throw new lxException('could_not_create_tmp_dir', ''); } lunlink($vd); mkdir($vd); lxfile_generic_chmod($vd, "0700"); if ($real) { lxshell_unzip_with_throw($vd, $file); } else { if ($sgbl->isKloxoForRestore()) { try { lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata")); } catch (Exception $e) { lxshell_unzip_with_throw($vd, $file, array("*lxadmin.file", "*lxadmin.metadata")); } } else { lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata")); } } return $vd; }