static function render_png($data)
 {
     $filename = SIMPLE_CACHE . "/thumbs/graphviz_" . sha1($data) . ".png";
     if (!file_exists($filename)) {
         file_put_contents($filename . ".dot", $data, LOCK_EX);
         $src = modify::realfilename($filename . ".dot");
         $target = modify::realfilename($filename);
         $result = sys_exec(sys_find_bin("dot") . " -Kdot -Tpng -o" . $target . " " . $src);
         if ($result != "") {
             sys_log_message_log("php-fail", "proc_open: " . $result);
             $filename = SIMPLE_CACHE . "/thumbs/graphviz_" . sha1($result) . ".png";
             if (!file_exists($filename)) {
                 sys_render_text($filename, $result);
             }
         }
     }
     return $filename;
 }
Beispiel #2
0
 static function exec($id, $data, $params)
 {
     $cmd = implode(":", $params);
     $matches = array();
     if (preg_match_all("|@(.*?)@|i", $cmd, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             if (count($match) != 2) {
                 continue;
             }
             $req_key = $match[1];
             if (isset($data[$req_key])) {
                 $cmd = str_replace("@" . $req_key . "@", escapeshellarg($data[$req_key]), $cmd);
             }
         }
     }
     if ($cmd == "") {
         return "";
     }
     sys_notification(sprintf("{t}System command executed: %s{/t}", $cmd));
     return sys_exec($cmd);
 }
Beispiel #3
0
function daemons_status()
{
    if (!is_file('/usr/share/artica-postfix/ressources/logs/global.status.ini')) {
        sys_exec('/usr/share/artica-postfix/bin/artica-install --status > /usr/share/artica-postfix/ressources/logs/global.status.ini 2>&1');
    }
    if (is_file('/usr/share/artica-postfix/ressources/logs/global.status.ini')) {
        $datas = @file_get_contents("/usr/share/artica-postfix/ressources/logs/global.status.ini");
        echo "<articadatascgi>{$datas}</articadatascgi>";
        return;
    }
}
 static function checkvirus($files)
 {
     if (VIRUS_SCANNER == "") {
         return "";
     }
     $files = explode("|", $files);
     foreach ($files as $file) {
         $src = modify::realfilename($file);
         $bin = modify::realfilename(VIRUS_SCANNER);
         if ($bin == "") {
             return sprintf("checkvirus: {t}unable to find %s{/t}", VIRUS_SCANNER);
         }
         $result = sys_exec($bin . " " . VIRUS_SCANNER_PARAMS . " " . $src);
         if ($result != "") {
             $match = array();
             if (VIRUS_SCANNER_DISPLAY and preg_match("|" . preg_quote(VIRUS_SCANNER_DISPLAY) . "(.*?)\n|i", $result, $match)) {
                 $result = trim($match[1]);
             }
             if (sys_strbegins($file, SIMPLE_CACHE . "/")) {
                 @unlink($file);
             }
             sys_log_message_log("php-fail", $result . " [" . $file . "]");
             return $result;
         }
     }
     return "";
 }
Beispiel #5
0
 private static function _restore($filename)
 {
     ob_end_flush();
     $filename = str_replace(" ", "+", $filename);
     $filename = SIMPLE_STORE . "/backup/" . basename($filename);
     if (!file_exists($filename)) {
         return "{t}file not found.{/t} (" . $filename . ")";
     }
     if (filesize($filename) == 0) {
         return "{t}No entries found.{/t} (" . $filename . ")";
     }
     self::_out("{t}Extracting files{/t}: " . $filename);
     self::_out("");
     if (self::$_restore_here) {
         $ftitle = str_replace(array("__", "---", "--"), array("/", " ", " "), substr(modify::basename($filename), 0, -4));
         $ftitle = substr($ftitle, strrpos($ftitle, "/") + 1);
         $id = folders::create(substr($ftitle, 0, 40), "blank", "", $_SESSION["folder"], false);
         self::$_restore_folder = $id;
         self::_out("{t}Insert{/t}: simple_sys_tree: " . $ftitle . " [" . $id . "]");
     }
     $result = sys_exec(sys_find_bin("tar") . " -tf " . modify::realfilename($filename));
     $file_list = explode("\n", $result);
     if (count($file_list) == 0) {
         return "";
     }
     $base_dir = SIMPLE_STORE . "/restore_" . NOW . "/";
     sys_mkdir($base_dir);
     $cmd = "cd " . modify::realfilename($base_dir) . " && " . sys_find_bin("tar") . " -xf " . modify::realfilename($filename);
     if (DEBUG) {
         self::_out("TAR: " . $cmd . "\n\n");
     }
     echo sys_exec($cmd);
     $update_ids = array();
     $update_folders = array();
     $restore_maps = array();
     $xml_file = array_shift($file_list);
     self::_out("{t}Parsing{/t}: " . $xml_file);
     $xml = simplexml_load_file($base_dir . $xml_file);
     foreach ($xml->table as $data) {
         $data = get_object_vars($data->assetfolder);
         unset($data["@attributes"]);
         $id = $data["id"];
         if (!empty($data["anchor"])) {
             $existing = db_select_first("simple_sys_tree", array("id", "'' as lastmodified"), "anchor=@anchor@", "", array("anchor" => $data["anchor"]));
             if (!empty($existing["id"])) {
                 unset($data["anchor"]);
             }
         } else {
             $existing = db_select_first("simple_sys_tree", array("id", "lastmodified"), "id=@id@", "", array("id" => $id));
         }
         if (!isset($data["fdescription"])) {
             $data["fdescription"] = "";
         }
         $ftype = $data["ftype"];
         $keys = array("fsizecount", "fchsizecount", "fcount", "fchcount", "ffcount", "lft", "rgt", "flevel", "folder", "id", "ftype");
         foreach ($keys as $key) {
             unset($data[$key]);
         }
         if (isset($restore_maps[$data["parent"]])) {
             $data["parent"] = $restore_maps[$data["parent"]];
         }
         if (empty($existing["id"]) or self::$_restore_here) {
             $parent = db_select_value("simple_sys_tree", "id", "id=@id@", array("id" => $data["parent"]));
             if (empty($parent) or count($restore_maps) == 0 and self::$_restore_here) {
                 $data["parent"] = self::$_restore_folder;
             }
             $id2 = folders::create($data["ftitle"], $ftype, $data["fdescription"], $data["parent"], false);
             self::_out("{t}Insert{/t}: simple_sys_tree: " . $data["ftitle"] . " [ID " . $id . " -> parent/id: " . $data["parent"] . "/" . $id2 . "]");
             $restore_maps[$id] = $id2;
             $id = $id2;
         } else {
             $restore_maps[$id] = $existing["id"];
         }
         if (!self::$_restore_missing and (!self::$_restore_onlynewer or $data["lastmodified"] > $existing["lastmodified"])) {
             self::_out("{t}Update{/t}: simple_sys_tree " . $id);
             $error = db_update("simple_sys_tree", $data, array("id=@id@"), array("id" => $id));
             if ($error) {
                 self::_out($error);
             }
         }
     }
     foreach ($xml->table as $table_item) {
         if (!isset($table_item->asset) or count($table_item->asset) == 0) {
             continue;
         }
         foreach ($table_item->asset as $asset) {
             $table = $table_item["name"];
             if ($table == "simple_sys_tree") {
                 continue;
             }
             $data = get_object_vars($asset);
             unset($data["@attributes"]);
             foreach ($data as $dkey => $val) {
                 $obj = $asset->{$dkey};
                 if (!isset($obj["is_file"]) or $val == "") {
                     continue;
                 }
                 $file_arr[$key] = "";
                 $file_arr = explode("|", trim($val, "|"));
                 foreach ($file_arr as $key => $value) {
                     foreach ($file_list as $file) {
                         if (basename($file) != basename($value)) {
                             continue;
                         }
                         $value = $base_dir . $file;
                         break;
                     }
                     $file_arr[$key] = $value;
                 }
                 $data[$dkey] = "|" . implode("|", $file_arr) . "|";
             }
             $id = $data["id"];
             $existing = db_select_first($table, array("id", "lastmodified"), "id=@id@", "", array("id" => $id));
             $folder = $data["folder"];
             if (isset($restore_maps[$folder])) {
                 $data["folder"] = $restore_maps[$folder];
             }
             if (empty($existing["id"]) or self::$_restore_here) {
                 if (self::$_restore_missing) {
                     $data["id"] = $id;
                 } else {
                     $data["id"] = sql_genID($table) * 100;
                 }
                 self::_out("{t}Insert{/t}: " . $table . ": " . $data["id"]);
                 $error = db_insert($table, $data);
                 if ($error) {
                     self::_out($error);
                 }
                 $update_folders[$data["folder"]] = $table;
                 $update_ids[$data["folder"]][] = $data["id"];
             } else {
                 if (!self::$_restore_missing) {
                     if (!self::$_restore_onlynewer or $data["lastmodified"] > $existing["lastmodified"]) {
                         self::_out("{t}Update{/t}: " . $table . " " . $id);
                         $error = db_update($table, $data, array("id=@id@"), array("id" => $id));
                         if ($error) {
                             self::_out($error);
                         }
                         $update_folders[$data["folder"]] = $table;
                         $update_ids[$data["folder"]][] = $id;
                     }
                 }
             }
         }
     }
     if (count($update_folders) > 0) {
         foreach ($update_folders as $folder => $table) {
             if (strpos($table, "nodb_")) {
                 continue;
             }
             db_update_treesize($table, $folder);
             $ftype = str_replace("simple_", "", $table);
             $schema = db_get_schema(sys_find_module($ftype));
             if (empty($schema["views"]["display"])) {
                 continue;
             }
             if (!empty($schema["att"]["SQL_HANDLER"]) or !empty($schema["att"]["NO_SEARCH_INDEX"])) {
                 continue;
             }
             self::_out("... ");
             $fields = $schema["fields"];
             if (folder_in_trash($folder)) {
                 continue;
             }
             foreach ($update_ids[$folder] as $id) {
                 self::_out("{t}Rebuild search index{/t}: " . $table . " [" . $id . "]");
                 db_search_update($table, $id, $fields);
             }
         }
     }
     self::_out("");
     $message = "{t}Restore complete{/t}: " . str_replace(array("__", "---", "--"), array("/", "] [", " ["), substr(modify::basename($filename), 0, -4)) . "]";
     sys_log_message_log("info", $message);
     self::_out($message);
     return "";
 }
Beispiel #6
0
function sys_find_bin($program)
{
    if (strpos(PHP_OS, "WIN") === false) {
        $ret = sys_exec("which " . $program);
        if (file_exists($ret)) {
            return $ret;
        }
        if (file_exists(sys_custom("tools/bin_deb/" . $program)) and USE_DEBIAN_BINARIES) {
            $program = sys_custom("tools/bin_deb/" . $program);
            if (!is_executable($program)) {
                chmod($program, 0744);
            }
            putenv("HOME=" . sys_custom_dir("./tools/bin_deb/"));
        }
        return $program;
    } else {
        if ($program == "dot") {
            $file = sys_custom("tools/bin_win32/graphviz/bin/dot.exe");
        } else {
            $file = sys_custom("tools/bin_win32/" . $program . ".exe");
        }
        if (file_exists($file)) {
            return modify::realfilename($file);
        }
        return $program . ".exe";
    }
}
Beispiel #7
0
    $content = "";
    if ($code != "") {
        ob_start();
        eval($code);
        $content = ob_get_contents();
        ob_end_clean();
    }
    $title = "PHP Console (PHP " . phpversion() . ")";
    if ($content != "") {
        $content = "<pre>" . q($content) . "</pre>";
    }
} else {
    if ($_REQUEST["console"] == "sys") {
        $content = "";
        if ($code != "") {
            $content = sys_exec(str_replace("\n", "&", trim($code)));
        }
        $title = "SYS Console: " . getcwd() . " @ " . $_SERVER["SERVER_NAME"] . " [" . $_SERVER["SERVER_SOFTWARE"] . "]";
        if ($content != "") {
            $content = "<pre>" . q($content) . "</pre>";
        }
    } else {
        $content = "";
        $title = "SQL Console:&nbsp; " . SETUP_DB_USER . " @ " . SETUP_DB_NAME . "&nbsp; [" . SETUP_DB_TYPE . " " . sgsml_parser::sql_version() . "] ";
        if ($code != "") {
            if (($data = sql_fetch($code, false)) === false) {
                $content .= sql_error();
            } else {
                if (is_array($data) and count($data) > 0) {
                    $content .= show_table($data, isset($_REQUEST["full_texts"]), isset($_REQUEST["vertical"]));
                } else {
function _download_resize($row_filename)
{
    $row_filename_resize = SIMPLE_CACHE . "/thumbs/" . sha1($row_filename) . "_" . filemtime($row_filename) . "_" . $_REQUEST["image_width"] . "_" . $_REQUEST["image_height"] . ".jpg";
    if (file_exists($row_filename_resize)) {
        return $row_filename_resize;
    }
    $src_files = array("gif", "jpg", "jpeg", "png");
    $ext = modify::getfileext($row_filename);
    $new_width = "";
    $new_height = "";
    if (empty($_REQUEST["image_width"]) and empty($_REQUEST["image_height"])) {
        $new_width = 250;
        $new_height = 200;
    }
    if (isset($_REQUEST["image_width"]) and is_numeric($_REQUEST["image_width"]) and $_REQUEST["image_width"] > 0) {
        $new_width = $_REQUEST["image_width"];
    }
    if (isset($_REQUEST["image_height"]) and is_numeric($_REQUEST["image_height"]) and $_REQUEST["image_height"] > 0) {
        $new_height = $_REQUEST["image_height"];
    }
    if ($new_width != "" or $new_height != "") {
        $resize = "-resize \"" . $new_width . "x" . $new_height . ">\"";
    }
    if ($resize != "" or !in_array($ext, $src_files)) {
        $result = "";
        $src = modify::realfilename($row_filename);
        $target = modify::realfilename($row_filename_resize);
        $result = sys_exec(sys_find_bin("convert") . " -quality 50 " . $resize . " " . $src . "[0] " . $target);
        if ($result == "") {
            $row_filename = $row_filename_resize;
        } else {
            sys_log_message_log("php-fail", "proc_open: " . $result);
        }
        if ($result != "" and in_array($ext, $src_files)) {
            list($width, $height) = @getimagesize($row_filename);
            if ($width != "" and $height != "") {
                if ($width != $new_width or $height != $new_height) {
                    $prop = $width / $height;
                    if ($width != $new_width and $height != $new_height) {
                        $new_height2 = round($new_width / $prop);
                        if ($new_height2 > $new_height) {
                            $new_width = round($new_height * $prop);
                        }
                    } else {
                        if ($width != $new_width) {
                            $new_height = round($new_width / $prop);
                        } else {
                            $new_width = round($new_height * $prop);
                        }
                    }
                    $image_p = imagecreatetruecolor($new_width, $new_height);
                    imagecopyresized($image_p, imagecreatefromstring(file_get_contents($row_filename)), 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                    imagejpeg($image_p, $row_filename_resize, 50);
                    $row_filename = $row_filename_resize;
                }
            }
        }
    }
    return $row_filename;
}
Beispiel #9
0
 static function preview_bin($filename, $ext)
 {
     if (!function_exists("proc_open")) {
         return "ERROR {t}Cannot call 'proc_open'. Please remove 'proc_open' from 'disable_functions' in php.ini and disable 'safe_mode'.{/t}";
     }
     $result = "";
     switch ($ext) {
         case "zip":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("unzip") . " -l -V " . $src);
             $result = substr($result, strpos($result, "\n") + 1);
             break;
         case "tar":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("tar") . " -tf " . $src);
             break;
         case "gz":
         case "tgz":
             if (!strpos(strtolower($filename), ".tar.gz") and !strpos(strtolower($filename), ".tgz")) {
                 break;
             }
             $src = self::realfilename($filename);
             $cmd = sys_find_bin("gzip") . " -cd " . $src . " | " . sys_find_bin("tar") . " -t";
             if (strpos(PHP_OS, "WIN") !== false) {
                 $cmd = str_replace("/", "\\", $cmd);
             }
             $result = sys_exec($cmd);
             break;
         case "ppt":
             $tmp = SIMPLE_CACHE . "/debug/sys_exec_" . md5($_SESSION["username"] . NOW) . ".ppt";
             copy($filename, $tmp);
             $result = sys_exec(sys_find_bin("ppthtml") . " " . self::realfilename($tmp));
             unlink($tmp);
             if ($pos = strpos($result, "<BODY")) {
                 $result = substr($result, $pos);
             }
             $result = utf8_decode(strip_tags($result));
             break;
         case "doc":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("catdoc") . " -d utf-8 " . $src);
             break;
         case "xls":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("xls2csv") . " -d utf-8 " . $src);
             // $result = sys_exec(sys_find_bin("xlhtml")." -nh ".$src);
             break;
         case "docx":
         case "xlsx":
         case "pptx":
         case "ods":
             // oo-xls
         // oo-xls
         case "sxc":
         case "odt":
             // oo-doc
         // oo-doc
         case "sxw":
         case "odp":
             // oo-ppt
         // oo-ppt
         case "sxi":
             if ($ext == "docx") {
                 $file = "word/document.xml";
                 $replace = array("</w:p>" => "\n");
             } else {
                 if ($ext == "xlsx") {
                     $file = "xl/sharedStrings.xml";
                     $replace = array("</si>" => " ");
                 } else {
                     if ($ext == "pptx") {
                         $file = "ppt/slides/*.xml";
                         $replace = array("</a:p>" => "\n");
                     } else {
                         $file = "content.xml";
                         $replace = array("</text:p>" => "\n");
                     }
                 }
             }
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("unzip") . " -p " . $src . " " . $file);
             $result = utf8_decode(strip_tags(str_replace(array_keys($replace), array_values($replace), $result)));
             break;
         case "url":
             $match = array();
             preg_match("/^URL=(.+)/m", file_get_contents($filename), $match);
             if (!empty($match[1])) {
                 $result = "<a href='" . q(trim($match[1])) . "' target='_blank'>" . modify::basename(substr($filename, 0, -4)) . "</a>";
             }
             break;
         case "pdf":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("pdfinfo") . " " . $src);
             $result .= sys_exec(sys_find_bin("pdftotext") . " " . $src . " @file@");
             break;
         case "mp3":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("mp3info") . " -x " . $src);
             $result = substr($result, strpos($result, "\n") + 1);
             break;
         case "jpg":
         case "jpeg":
             $src = self::realfilename($filename);
             $result = sys_exec(sys_find_bin("exiv2") . " " . $src);
             $result = str_replace("\r", "", $result) . "\n";
             $result = preg_replace("!(^.*No Exif.*|File ?name.*|File ?size.*|MIME type.*|.*?:\\s*)\n!im", "", $result);
             $gps = sys_exec(sys_find_bin("exiv2") . " -PEnv " . $src);
             $match = array();
             preg_match("!GPSLatitude\\s+(\\d+)/(\\d+) (\\d+)/(\\d+) (\\d+)/(\\d+)!", $gps, $match);
             $match2 = array();
             preg_match("!GPSLongitude\\s+(\\d+)/(\\d+) (\\d+)/(\\d+) (\\d+)/(\\d+)!", $gps, $match2);
             if (is_array($match) and count($match) == 7 and is_array($match2) and count($match2) == 7) {
                 $latitude = $match[1] / $match[2] + $match[3] / $match[4] / 60 + $match[5] / $match[6] / 3600;
                 if (!preg_match("/GPSLatitudeRef\\s+N/", $gps)) {
                     $latitude *= -1;
                 }
                 $longitude = $match2[1] / $match2[2] + $match2[3] / $match2[4] / 60 + $match2[5] / $match2[6] / 3600;
                 if (!preg_match("/GPSLongitudeRef\\s+E/", $gps)) {
                     $longitude *= -1;
                 }
                 $result .= "GPS: <a target='_blank' href='http://maps.google.com/?ll={$latitude},{$longitude}'>Google Maps</a>";
             }
             break;
     }
     return $result;
 }