function remove_lighttpd_error_log() { $f = "/home/kloxo/httpd/lighttpd/error.log"; $s = lxfile_size($f); if ($s > 50 * 1024 * 1024) { lunlink($f); createRestartFile("lighttpd"); } }
static function readSingleMail($name) { $ret['message'] = lxshell_output("__path_program_root/bin/misc/qmHandle", "-m{$name}"); $oldtime = time() - 7200; $newtime = time() - 500; $fp = fopen("/var/log/kloxo/maillog", "r"); $fsize = lxfile_size("/var/log/kloxo/maillog"); $ot = date("Y-m-d:H-i"); dprint("Start time: {$ot}\n"); $res = FindRightPosition($fp, $fsize, $oldtime, $newtime, array("mailtraffic", "getTimeFromOriginalQmailString")); if ($res < 0) { $ret['log'] = null; return $ret; } //$s = fgets($fp); dprint("here {$s}\n"); takeToStartOfLine($fp); takeToStartOfLine($fp); //$s = fgets($fp); dprint("here {$s}\n"); $delivery = null; while (!feof($fp)) { $s = fgets($fp); if (!$delivery) { if (csa($s, "starting delivery") && csa($s, "msg {$name}")) { $delivery = preg_replace("/.*delivery ([^:]*):.*/", "\$1", $s); $delivery = trim($delivery); dprint("Deliver num: {$delivery}*\n"); continue; } } else { dprint("{$s}\n"); if (csa($s, "delivery {$delivery}:")) { dprint("{$s}\n"); $ret['log'] = $s; break; } } } return $ret; }
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; }
function lxfile_dstat($dir, $duflag) { $dir = expand_real_root($dir); $list = lscandir_without_dot($dir); $ret = null; foreach ($list as $l) { $stat = lstat("{$dir}/{$l}"); get_file_type("{$dir}/{$l}", $stat); remove_unnecessary_stat($stat); if ($duflag && is_dir("{$dir}/{$l}") || $l === ".trash") { $stat['size'] = lxfile_dirsize("{$dir}/{$l}", true); } else { $stat['size'] = lxfile_size("{$dir}/{$l}"); } $stat['name'] = "{$dir}/{$l}"; $ret[] = $stat; } //dprintr($ret); return $ret; }
static function readMaillog() { $date = time() - 24 * 3600 * 2; $logfile = "/var/log/kloxo/maillog"; $fp = fopen($logfile, "r"); $fsize = lxfile_size($logfile); FindRightPosition($fp, $fsize, $date, time(), array("mailtraffic", "getTimeFromOriginalQmailString")); while (!feof($fp)) { $s = fgets($fp); $s = trim($s); if (!csa($s, "lx-sending")) { continue; } $v = strfrom($s, "mail for"); $id = $v; if (!isset($total[$id])) { $total[$id] = 1; } else { $total[$id]++; } } return $total; }
public function doRealCreate() { global $gbl, $sgbl, $login, $ghtml; $nname = $this->main->nname; lx_core_lock("{$nname}.create"); $this->createRootPath(); lxfile_mkdir($this->main->configrootdir); $this->setDhCP(); if ($this->main->isWindows()) { $templatefile = "__path_program_home/xen/template/{$this->main->ostemplate}"; } else { $templatefile = "__path_program_home/xen/template/{$this->main->ostemplate}.tar.gz"; } $this->main->getOsTemplateFromMaster($templatefile); if (!lxfile_real($templatefile)) { log_error("could not create vm. Could not download {$templatefile}"); lfile_put_contents("__path_program_root/tmp/{$nname}.createfailed", "Could not download {$templatefile}"); exit; } $size = 0; if ($this->main->isWindows()) { $size = lxfile_size($templatefile); $size = $size / (1024 * 1024); } try { $this->createConfig(); $this->setMemoryUsage(); $this->setCpuUsage(); $this->setSwapUsage(); $this->createSwap(); $this->createDisk($size); } catch (Exception $e) { log_error("could not create vm. Error was {$e->getMessage()}"); lfile_put_contents("__path_program_root/tmp/{$nname}.createfailed", "{$e->getMessage()}"); exit; } if (!$this->main->isWindows()) { $mountpoint = $this->mount_this_guy(); lxshell_return("tar", "-C", $mountpoint, "--numeric-owner", "-xpzf", $templatefile); $this->setInternalParam($mountpoint); $this->copyKernelModules(); lxfile_cp("../file/sysfile/xen/fstab", "{$mountpoint}/etc/fstab"); lunlink("{$mountpoint}/etc/mtab"); } else { if (!$this->main->isBlankWindows()) { $templatefile = expand_real_root($templatefile); lxshell_return("parted", "-s", $this->main->maindisk, "mklabel", "msdos"); $this->runParted(); $partition = $this->getPartition(); lxshell_return("ntfsfix", $partition); //lxshell_return("dd", "if=$templatefile", "of={$this->main->maindisk}"); lxshell_return("ntfsclone", "--restore-image", "--force", "-O", $partition, $templatefile); $this->kpart_remove(); $this->expandPartitionToImage(); //lxshell_return("ntfsclone", "-O", $loop, $templatefile); //lo_remove($loop); } } $this->main->status = 'On'; try { $this->toggleStatus(); } catch (Exception $e) { } $this->postCreate(); }
function cp_fileserv($file) { lxfile_mkdir("__path_serverfile"); lxfile_generic_chown("__path_serverfile", "lxlabs:lxlabs"); $file = expand_real_root($file); dprint("Fileserv copying file {$file}\n"); if (is_dir($file)) { $list = lscandir_without_dot($file); $res = tar_to_fileserv($file, $list); $res['type'] = "dir"; return $res; } else { $res['type'] = 'file'; } $basebase = basename($file); $base = basename(ltempnam("__path_serverfile", $basebase)); $pass = md5($file . time()); $ar = array('filename' => $file, 'password' => $pass); lfile_put_serialize("__path_serverfile/{$base}", $ar); lxfile_generic_chown("__path_serverfile/{$base}", "lxlabs"); $res['file'] = $base; $res['pass'] = $pass; //$stat = llstat("__path_serverfile/$base"); $res['size'] = lxfile_size($file); return $res; }
static function fixErrorLog($name) { global $gbl, $sgbl, $login, $ghtml; $file = "/home/kloxo/httpd/lighttpd/error.log"; $cmd = "grep -i {$name} {$file} > /home/httpd/{$name}/stats/{$name}-error_log"; log_shell($cmd); system($cmd); $size = lxfile_size($file); if ($size > 50 * 1024 * 1024) { $nfile = getNotexistingFile(dirname($file), $file); lxfile_mv($file, $nfile); createRestartFile("lighttpd"); } }