function dbactionUpdate($subaction) { global $gbl, $sgbl, $login, $ghtml; $dir = $this->main->__var_full_directory; $dir = expand_real_root($dir); switch ($subaction) { case "full_update": $pass = $this->main->realpass; lxshell_input("{$pass}\n{$pass}\n", "pure-pw", "passwd", $this->main->nname, "-m"); lxshell_return("pure-pw", "usermod", $this->main->nname, "-d", $dir, "-m"); $this->toggleStatus(); $this->setQuota(); break; case "password": $pass = $this->main->realpass; lxshell_input("{$pass}\n{$pass}\n", "pure-pw", "passwd", $this->main->nname, "-m"); break; case "toggle_status": $this->toggleStatus(); break; case "edit": lxshell_return("pure-pw", "usermod", $this->main->nname, "-d", $dir, "-m"); $this->setQuota(); break; case "changeowner": lxshell_return("pure-pw", "usermod", $this->main->nname, "-u", $this->main->__var_username, "-d", $dir, "-m"); break; } }
static function getTrafficInfo($name) { $oldtime = time() - 40 * 3600; $newtime = time(); $file = "__path_httpd_root/{$name}/stats/{$name}-custom_log"; $file = expand_real_root($file); $fp = @lfopen($file, "r"); $total = 0; dprint("\n{$file}: " . @date('Y-m-d-H-i-s', $oldtime) . " {$newtime} " . @date('Y-m-d-H-i-s', $newtime) . "\n"); if (!$fp) { dprint("File Does Not Exist:returning Zero"); return 0; } $fsize = lfilesize($file); if ($fsize <= 10) { dprint("File Size is Less Than Zero and Returning Zero:\n"); return ""; } dprint("File Size is :{$fsize}\n\n\n"); if ($fsize > 20 * 1024) { fseek($fp, -19 * 1024, SEEK_END); $line = fgets($fp); } $i = 3; $total = 0; $count = 0; while (!feof($fp)) { $count++; $line = fgets($fp); $res[] = webtraffic::apacheLogFullString($line); } $c = 0; foreach ($res as $k => $r) { $c++; if ($count - 50 > $c) { unset($res[$k]); } } $ncount = 0; foreach ($res as $r) { if (!$r['Time']) { continue; } $file = strfrom($r['Request'], " "); $file = strtil($file, "HTTP"); $time = trim($r['Time'], "[]"); $time = strtil($time, " "); $o['realtime'] = $r['realtime']; $o['time'] = $time; $o['nname'] = $ncount; $o['file'] = $file; $o['referer'] = $r['Referer']; $o['remote_host'] = $r['Remote-Host']; $out[] = $o; $ncount++; } return $out; }
static function get_image_info($path) { //self::load_gd(); $path = expand_real_root($path); list($width, $height, $type, $attr) = getimagesize($path); $stat['image_width'] = $width; $stat['image_height'] = $height; $stat['image_type'] = $type; $stat['image_attr'] = $attr; $stat['image_content'] = lfile_get_contents($path); //dprintr($stat); return $stat; }
function dbactionAdd() { $Flag = 0; //$iisid = $this->main->__var_iisid; $name = $this->main->nname; $path = $this->main->path; //$Dir = new COM("IIS://localhost/W3SVC/$iisid/ROOT/"); //$Dir->AuthAnonymous = False; //$Dir->setInfo(); $domname = $this->main->getParentName(); $dir = "__path_httpd_root/{$domname}/dirprotect/"; $authuserfile = "{$dir}/{$this->main->getFileName()}"; lxfile_mkdir($dir); $reauthstr = expand_real_root($authuserfile); $content = "AuthName {$this->main->authname}\n"; $content .= "AuthUserFile {$reauthstr}\n"; $content .= "Require valid-user\n"; $path = "__path_httpd_root/{$domname}/httpdocs/www/{$this->main->path}"; dprint(expand_real_root($path)); lfile_put_contents("{$path}/.htlxaccess", $content); lxfile_mkdir($dir); //lfile_put_contents($path . "/.htpasswd", $fstr); $this->createUser(); }
function zipFile() { foreach ($this->main->zip_file_list as &$_t_f) { $_t_f = coreFfile::removeLeadingSlash($_t_f); $_t_f = basename($_t_f); $_t_f = "\"{$_t_f}\""; } $list = implode(" ", $this->main->zip_file_list); $oldir = getcwd(); $fullpath = expand_real_root($this->main->fullpath); /* $fz = $fullpath . "/" . $this->main->zip_file_f; if (lxfile_exists($fz)) { throw new lxexception('file_exists', 'zip_file_f', $this->main->zip_file_f); } */ $date = date("M-d-H"); //check_file_if_owned_by_and_throw("NewArchive-$date.zip", $this->main->__username_o); $ret = new_process_cmd($this->main->__username_o, $fullpath, "zip -qu -r NewArchive-{$date} {$list}"); return "{$fullpath}/NewArchive-{$date}.zip"; }
function getCustomerRoot() { $path = "__path_customer_root/{$this->customer_name}"; $path = expand_real_root($path); return $path; }
function lxfile_touch($file) { $file = expand_real_root($file); $ret = touch($file); return $ret; }
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); }
static function checkOwnership($username, $path) { // When creating new files, must not check owner if (!lfile_exists($path)) { return true; } $owner = posix_getpwuid(fileowner(expand_real_root($path))); if ($owner['name'] !== $username) { log_log("fileacc_hacking", "{$username} tried to access {$owner['name']}'s file: {$path}"); throw new lxexception('file_bad_owner_logged', ''); } return true; }
function createTempDir($dir, $name) { $dir = expand_real_root($dir); $vd = tempnam($dir, $name); if (!$vd) { throw new lxException('could_not_create_tmp_dir', ''); } unlink($vd); mkdir($vd); lxfile_generic_chmod($vd, "0700"); return $vd; }
function lxfile_unix_chown($file, $mod) { $file = expand_real_root($file); log_filesys("Chown {$file} to {$mod}"); $stat = stat($file); //dprintr($stat); if (!is_dir($file) && $stat['nlink'] > 1) { log_log("link_error", "{$file} is a hard link not chowning"); return; } if (lis_link($file)) { log_log("link_error", "{$file} is link so no chown to {$mod}"); return; } $group = null; if (csa($mod, ':')) { list($user, $group) = explode(':', $mod); } else { $user = $mod; } if (is_numeric($group)) { $group = (int) $group; } if ($group) { chgrp($file, $group); } if (is_numeric($user)) { $user = (int) $user; } $ret = chown($file, $user); if (!$ret) { dprint("Chown Error in file {$file}\n"); } return $ret; }
function lx_tmp_file($file) { global $gbl, $sgbl, $login, $ghtml; $file = expand_real_root($file); $n = preg_replace("+/+i", "_", $file); return tempnam("{$sgbl->__path_tmp}/", "lxtmp_{$n}"); //return "/tmp/" . $n; }
function lxfile_cp_rec($dirsource, $dirdest) { dprint("<b> I am here </b> "); $obj = new COM("Scripting.FilesystemObject"); $username = "******"; $dirdest = expand_real_root($dirdest); $dirsource = expand_real_root($dirsource); if (lfile_exists($dirdest) && is_dir($dirdest)) { $dirdest = $dirdest . "/" . basename($dirsource); } if (is_dir($dirsource)) { log_filesys("copyFolder {$dirsource} {$dirdest}"); $obj->CopyFolder($dirsource, $dirdest); } else { log_filesys("copyFile {$dirsource} {$dirdest}"); $obj->CopyFile($dirsource, $dirdest); } }
static function addform($parent, $class, $typetd = null) { $dir = "__path_customer_root/{$parent->getPathFromName()}"; $dir = expand_real_root($dir); $vv = array('var' => "subdomain_parent", 'val' => array('s', get_namelist_from_objectlist($parent->getList('domain')))); $vlist['nname'] = array('m', array('posttext' => ".", 'postvar' => $vv)); if ($parent->priv->isOn('document_root_flag')) { $vlist['docroot'] = array('m', array('pretext' => "{$dir}/")); } $ret['variable'] = $vlist; $ret['action'] = 'add'; return $ret; }
function dbactionUpdate($subaction) { if_demo_throw_exception('ffile'); if ($this->main->isOn('readonly')) { throw new lxexception('file_manager_is_readonly', ''); } switch ($subaction) { case "edit": lfile_put_contents($this->main->getFullPath(), $this->main->content); break; case "upload": $filename = $this->main->getFullPath() . "/{$this->main->upload_file_name}"; dprintr($this->main->upload_overwrite_f); if (!$this->main->isOn('upload_overwrite_f')) { if (lfile_exists($filename)) { throw new lxexception('file_exists_upload', 'upload_name_f'); } } getFromFileserv($this->main->__var_upload_tmp_server, $this->main->__var_upload_filepass, $filename); break; case "rename": $directory = dirname($this->main->fullpath); $new = $directory . "/" . $this->main->newname; if (lfile_exists($new)) { throw new lxexception('file_exists_rename', ''); } lxfile_mv_rec($this->main->fullpath, $new); //lxfile_unix_chown($new, $this->main->__username_o); break; case "paste": if ($this->main->paste_list) { // Hack... SPecifically checking for pasteaction. Should just use it directly in the command. $arglist[] = $this->main->__username_o; foreach ($this->main->paste_list as &$_tl) { $_tl = $this->main->root . $_tl; } //$arglist = array_merge($arglist, $this->main->paste_list); $arglist[] = $this->main->paste_list; $arglist[] = $this->main->fullpath; if ($this->main->pasteaction === 'copy') { foreach ($this->main->paste_list as $p) { lxfile_cp_rec($p, $this->main->fullpath); } } else { foreach ($this->main->paste_list as $p) { lxfile_mv_rec($p, $this->main->fullpath); } } //lxfile_unix_chown_rec($this->main->fullpath, $this->main->__username_o); } break; case "perm": throw new lxexception('no_perm_setting', ''); break; case "newdir": $i = 1; $rpath = $this->main->fullpath; $name = "/" . $this->main->newfolder_f; $path = $rpath . $name; if (lxfile_exists($path)) { throw new lxexception('file_exists', ''); } lxfile_mkdir($path); break; case "zip_file": foreach ($this->main->zip_file_list as &$_t_f) { $_t_f = coreFfile::removeLeadingSlash($_t_f); $_t_f = basename($_t_f); $_t_f = "\"{$_t_f}\""; } $list = implode(" ", $this->main->zip_file_list); $oldir = getcwd(); $fullpath = expand_real_root($this->main->fullpath); do_exec_system($this->main->__username_o, $fullpath, "c:/Progra~1/7-Zip/7z a NewArchive.zip {$list}", $out, $err, $ret, null); break; case "filedelete": foreach ($this->main->filedelete_list as $f) { ffile__common::moveToTrash($this->main->root, $f); } break; case "restore_trash": foreach ($this->main->restore_trash_list as $f) { ffile__common::restoreFromTrash($this->main->root, $f); } break; case "clear_trash": foreach ($this->main->clear_trash_list as $f) { ffile__common::clearFromTrash($this->main->root, $f); } break; case "zipextract": $fulzippath = $this->main->root . $this->main->zip_extract_dir_f; if (!lxfile_exists(null, $fulzippath)) { lxfile_mkdir($fulzippath); } else { $zipdir = new Ffile("localhost", "localhost", $this->main->root, $this->main->zip_extract_dir_f, $this->main->__username_o); $zipdir->get(); if (!$zipdir->is_dir()) { throw new lxexception("file_exists_but_not_dir", 'unzippath', $this->main->zip_extract_dir_f); } } $command = "c:/Progra~1/7-zip/7z x -y"; $dir = expand_real_root($fulzippath); $file = expand_real_root($this->main->getFullPath()); if (!csa($file, ":")) { $fullpath = getcwd() . "/{$file}"; } else { $fullpath = $file; } $oldir = getcwd(); $fullpath = expand_real_root($fullpath); do_exec_system($this->main->__username_o, $dir, "{$command} {$fullpath}", $out, $err, $ret, null); break; } }