Beispiel #1
0
 static function save_config($vars)
 {
     $out = array();
     $out[] = "<?" . "php";
     $out[] = "define('CORE_VERSION','" . CORE_VERSION . "');";
     $out[] = "define('CORE_VERSION_STRING','" . CORE_VERSION_STRING . "');";
     $out[] = "define('CORE_SGSML_VERSION','" . CORE_SGSML_VERSION . "');";
     foreach ($vars as $key => $var) {
         $out[] = "define('" . $key . "'," . $var . ");";
     }
     foreach (self::config_defaults() as $key => $var) {
         $var = setup_update::get_config_old($key, true, $var);
         $out[] = "define('" . $key . "'," . $var . ");";
     }
     $out[] = "if (TIMEZONE!='') date_default_timezone_set(TIMEZONE);\n" . "  elseif (!ini_get('date.timezone')) date_default_timezone_set(@date_default_timezone_get());";
     $out[] = "if (!ini_get('display_errors')) @ini_set('display_errors','1');";
     $out[] = "define('NOW',time());";
     $out[] = "define('LANG','" . LANG . "');";
     $out[] = "define('APC',function_exists('apc_store') and ini_get('apc.enabled'));";
     file_put_contents("simple_store/config.php", implode("\n", $out), LOCK_EX);
     if (!file_exists("simple_store/config.php") or filesize("simple_store/config.php") == 0) {
         sys_die("cannot write to: simple_store/config.php");
     }
     chmod("simple_store/config.php", 0600);
     sys_log_message_log("info", sprintf("{t}Setup: setup-data written to %s.{/t}", "simple_store/config.php"));
 }
Beispiel #2
0
 function __destruct()
 {
     $time = number_format(sys_get_microtime() - self::$time_start, 2);
     echo "<!-- " . $time . "s -->";
     if ($time > CMS_SLOW) {
         sys_log_message_log("cms-slow", sprintf("{t}%s secs{/t}", $time) . " " . $_SERVER["PATH_INFO"], var_export($_REQUEST, true));
     }
     if (DEBUG and function_exists("memory_get_usage") and function_exists("memory_get_peak_usage")) {
         echo "<!-- " . modify::filesize(memory_get_usage()) . " - " . modify::filesize(memory_get_peak_usage()) . " -->";
     }
 }
 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;
 }
 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 "";
 }
 static function write_config($no_hash, $no_hash2)
 {
     $out = array();
     $out[] = "<?php";
     $out[] = "define('CORE_VERSION','" . CORE_VERSION . "');";
     $out[] = "define('CORE_VERSION_STRING','" . CORE_VERSION_STRING . "');";
     $out[] = "define('CORE_SGSML_VERSION','" . CORE_SGSML_VERSION . "');";
     $out[] = "define('SETUP_DB_TYPE','" . SETUP_DB_TYPE . "');";
     foreach ($_POST as $key => $val) {
         $val = $_REQUEST[$key];
         if (is_array($val)) {
             $val = implode("|", $val);
         }
         if (in_array($key, array("action_sys", "token"))) {
             continue;
         }
         if ($key == "invalid_extensions") {
             $val = trim(preg_replace("|\\s*,\\s*|", ",", $val));
         }
         if ($key == "setup_db_pw") {
             $val = sys_encrypt($val, sha1($_REQUEST["setup_admin_user"]));
         }
         if (!$no_hash and $key == "setup_admin_pw") {
             $val = sha1($val);
         }
         if (!$no_hash2 and $key == "setup_admin_pw2") {
             $val = sha1($val);
         }
         if (!is_numeric($val)) {
             if (strpos($val, "\n") or strpos($val, "'")) {
                 $val = "base64_decode('" . base64_encode($val) . "')";
             } else {
                 $val = "'" . $val . "'";
             }
         }
         $key = strtoupper($key);
         if (isset(self::$bools[$key])) {
             if ($val == "1") {
                 $val = "true";
             } else {
                 $val = "false";
             }
         }
         $out[] = "define('" . $key . "'," . $val . ");";
     }
     $out[] = "if (TIMEZONE!='') date_default_timezone_set(TIMEZONE);\n" . "  elseif (!ini_get('date.timezone')) date_default_timezone_set(@date_default_timezone_get());";
     $out[] = "if (!ini_get('display_errors')) @ini_set('display_errors','1');";
     $out[] = "define('NOW',time());";
     $out[] = "define('APC',function_exists('apc_store') and ini_get('apc.enabled'));";
     $out[] = "?>";
     file_put_contents("simple_store/config.php", implode("\n", $out), LOCK_EX);
     admin::build_js($_REQUEST["lang"]);
     if (SIMPLE_CACHE != $_REQUEST["simple_cache"]) {
         self::dirs_clear_caches(SIMPLE_CACHE);
         self::dirs_clear_caches($_REQUEST["simple_cache"]);
     }
     // TODO initialize simple_store if different
     if (SIMPLE_CUSTOM != $_REQUEST["simple_custom"]) {
         self::dirs_clear_custom($_REQUEST["simple_custom"]);
     }
     if (SIMPLE_EXT != $_REQUEST["simple_ext"]) {
         self::dirs_clear_custom($_REQUEST["simple_ext"]);
     }
     sys_log_message_log("info", sprintf("{t}Setup: setup-data written to %s.{/t}", "simple_store/config.php"));
 }
Beispiel #7
0
 static function shutdown()
 {
     // check execution time
     self::$time_end = number_format(sys_get_microtime() - self::$time_start, 2);
     if (self::$time_end > SYSTEM_SLOW) {
         sys_log_message_log("system-slow", sprintf("{t}%s secs{/t}", self::$time_end) . " " . basename(_sys_request_uri()), _sys_request_uri());
     }
     // process error.txt
     $size = @filesize(SIMPLE_CACHE . "/debug/error.txt");
     if ($size > 0 and $size <= 2097152 and $msgs = @file_get_contents(SIMPLE_CACHE . "/debug/error.txt")) {
         // 2M
         @unlink(SIMPLE_CACHE . "/debug/error.txt");
         $msgs = array_reverse(explode("\n", $msgs));
         foreach ($msgs as $msg) {
             if ($msg == "") {
                 continue;
             }
             $vars = unserialize($msg);
             sys_log_message($vars[0], $vars[1], $vars[2], $vars[3], true, $vars[4]);
         }
     } else {
         if ($size > 0) {
             sys_die("{t}The error logfile cannot be processed, too large:{/t} " . SIMPLE_CACHE . "/debug/error.txt");
         }
     }
     // logging
     sys_log_stat("pages", 1);
 }
Beispiel #8
0
 static function process_logout()
 {
     trigger::logout();
     if (!sys_is_guest($_SESSION["username"])) {
         sys_log_message_log("login", sprintf("{t}logout %s{/t}", $_SESSION["username"]));
     }
     session_destroy();
 }
Beispiel #9
0
                        }
                    }
                } else {
                    $counter = 0;
                    $data["delivery"] = $notification["delivery"];
                    while ($data["delivery"] < NOW and $counter < 150) {
                        $data["delivery"] = strtotime($notification["recurrence"], $data["delivery"]);
                        $counter++;
                    }
                }
            } else {
                $data["sent"] = "1";
            }
            db_update("simple_sys_notifications", $data, array("id=@id@"), array("id" => $notification["id"]));
            $log .= "ID: " . $notification["id"] . "\n";
        }
    }
    out($log);
    sys_log_message_log("info", t("{t}Sent reminders{/t}"), $log);
}
out("finished.");
@unlink($lock_file);
function out($str)
{
    if (!isset($_REQUEST["debug"])) {
        return;
    }
    echo $str . "\n";
    flush();
    @ob_flush();
}
Beispiel #10
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;
}
Beispiel #11
0
 static function displayfile($table, $filename, $index = false, $limit = true)
 {
     $size = @filesize($filename);
     $ext = self::getfileext($filename);
     if ($ext == basename($filename)) {
         $ext = self::basename($filename);
     }
     $txt_files = array("ldif", "log", "css", "csv", "eml", "rfc822", "ini", "reg", "tsv", "txt", "ics", "vcf", "lang");
     $code_files = array("bas", "bat", "c", "cmd", "cpp", "csh", "inf", "sh", "vb", "vbe", "xml", "java", "js", "pas", "php", "pl", "vbs", "vcs", "wsh", "tpl", "sql");
     $bin_files = array("doc", "docx", "xls", "xlsx", "ppt", "pptx", "tar", "zip", "gz", "tgz", "pdf", "mp3", "odt", "sxw", "ods", "sxc", "odp", "sxi", "jpg", "jpeg", "tif", "url");
     $html_files = array("htm", "html");
     $return = "";
     $return_html = "";
     $cid = str_replace("simple_", "", $table) . "_" . sha1($filename . $size . @filemtime($filename));
     if ($return = sys_cache_get($cid)) {
         if (!$index and $limit and strlen($return) > FILE_TEXT_LIMIT) {
             $return = substr($return, 0, FILE_TEXT_LIMIT) . " ...";
         }
         return trim($return);
     }
     $type = "";
     if (in_array($ext, $txt_files)) {
         $type = "text";
     } else {
         if (in_array($ext, $code_files)) {
             $type = "code";
         } else {
             if (in_array($ext, $html_files)) {
                 $type = "html";
             } else {
                 if (in_array($ext, $bin_files)) {
                     $type = "bin";
                 }
             }
         }
     }
     if ($type != "" and file_exists($filename)) {
         if ($type == "bin") {
             if (filesize($filename) != 0) {
                 if (!sys_strbegins($filename, SIMPLE_STORE . "/") and $result = validate::checkvirus($filename)) {
                     $return = "ERROR Virus scanner: " . $result;
                 } else {
                     $return = trim(self::preview_bin($filename, $ext));
                 }
             }
         } else {
             $return = trim(file_get_contents($filename, false, null, -1, $limit ? FILE_TEXT_LIMIT : 131072));
         }
         if ($return != "") {
             if ($index) {
                 $rlimit = INDEX_LIMIT;
             } else {
                 $rlimit = FILE_TEXT_LIMIT;
             }
             if ($limit and strlen($return) > $rlimit) {
                 $return = substr($return, 0, $rlimit) . " ...";
             }
             if (!self::detect_utf($return)) {
                 $return = utf8_encode($return);
             }
             if ($type == "html") {
                 $return_html = substr($return, 0, strrpos($return, ">"));
             } else {
                 if ($type != "code") {
                     $return_html = nl2br(strip_tags($return, "<a><b><i>"));
                 } else {
                     $return_html = self::highlight_string($return);
                 }
             }
         }
     }
     if ($return_html == "") {
         $return_html = " ";
     }
     if (!sys_strbegins($return, "ERROR ")) {
         sys_cache_set($cid, $return_html, FILE_TEXT_CACHE);
         if ($index) {
             return $return;
         } else {
             return trim($return_html);
         }
     } else {
         sys_log_message_log("php-fail", "displayfile: " . $return);
     }
     if ($index) {
         return "";
     }
     return sprintf("{t}Cannot create preview for %s{/t}.", $ext);
 }