Example #1
0
 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;
 }
Example #2
0
 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 "";
 }
Example #3
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 "";
 }
Example #4
0
function sys_exec($cmd, $input = "", $cwd = null)
{
    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}";
    }
    $out = "";
    $tmp = SIMPLE_CACHE . "/debug/sys_exec_" . sha1($_SESSION["username"] . NOW) . ".txt";
    $pipes = array();
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $tmp, "w"));
    if (strpos($cmd, "@file@")) {
        $tmp2 = modify::realfilename(SIMPLE_CACHE . "/debug/sys_exec_" . sha1($_SESSION["username"] . NOW) . "_2.txt");
        $cmd = str_replace("@file@", $tmp2, $cmd);
    } else {
        $tmp2 = "";
    }
    if (strpos($cmd, "@file_error@")) {
        $tmp3 = modify::realfilename(SIMPLE_CACHE . "/debug/sys_exec_" . sha1($_SESSION["username"] . NOW) . "_3.txt");
        $cmd = str_replace("@file_error@", $tmp3, $cmd);
    } else {
        $tmp3 = "";
    }
    $process = proc_open($cmd, $descriptorspec, $pipes, $cwd);
    if (is_resource($process) and isset($pipes[0])) {
        if ($input != "") {
            fwrite($pipes[0], $input);
        }
        fclose($pipes[0]);
        while (!feof($pipes[1])) {
            $out .= fgets($pipes[1], 8192);
        }
        fclose($pipes[1]);
        if ($tmp2 != "" and file_exists($tmp2)) {
            $out .= file_get_contents($tmp2);
        }
        $return_value = proc_close($process);
        if ($return_value != 0) {
            $error = file_get_contents($tmp);
            if (file_exists($tmp3) and filesize($tmp3) > 0) {
                $error .= file_get_contents($tmp3);
            }
            if ($error != "") {
                $out = "ERROR " . $error . " " . $out;
            }
        }
    } else {
        $out = "proc_open: error";
    }
    @unlink($tmp);
    if ($tmp2 != "") {
        @unlink($tmp2);
    }
    if ($tmp3 != "") {
        @unlink($tmp3);
    }
    return trim($out);
}
Example #5
0
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;
}
Example #6
0
 private static function _set_meta($data, $id, $mfolder, $ntlm)
 {
     $w = new Java("jcifs.smb.SmbFile", "smb://" . $id, $ntlm);
     $lastmodified = $w->getLastModified() / 1000;
     $sourcefile = sys_cache_get_file("cifs", $id . $lastmodified, "--" . modify::basename($id . ".meta"), true);
     if (file_exists($sourcefile)) {
         $data = sys_build_meta(file_get_contents($sourcefile), $data);
     }
     $drop = array("filedata", "folder", "created", "lastmodified", "handler", "mfolder", "dsize", "id");
     $data = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     if ($data == "") {
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         if ($w->exists()) {
             $w->delete();
         }
     } else {
         file_put_contents($sourcefile, $data, LOCK_EX);
         $in = new Java("java.io.FileInputStream", modify::realfilename($sourcefile, false));
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         $w->load($in);
     }
 }