Пример #1
0
 static function install($source, $filename)
 {
     $target = SIMPLE_EXT . substr($filename, 0, -3);
     setup::out("{t}Download{/t}: " . $source . " ...");
     if ($fz = gzopen($source, "r") and $fp = fopen($target, "w")) {
         $i = 0;
         while (!gzeof($fz)) {
             $i++;
             setup::out(".", false);
             if ($i % 160 == 0) {
                 setup::out();
             }
             fwrite($fp, gzread($fz, 16384));
         }
         gzclose($fz);
         fclose($fp);
     } else {
         sys_die("{t}Error{/t}: gzopen [2] " . $source);
     }
     setup::out();
     if (!file_exists($target) or filesize($target) == 0 or filesize($target) % 10240 != 0) {
         sys_die("{t}Error{/t}: file-check [3] Filesize: " . filesize($target) . " " . $target);
     }
     setup::out(sprintf("{t}Processing %s ...{/t}", basename($target)));
     $tar_object = new Archive_Tar($target);
     $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
     $tar_object->extract(SIMPLE_EXT);
     $file_list = $tar_object->ListContent();
     if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir(SIMPLE_EXT . $file_list[0]["filename"])) {
         sys_die("{t}Error{/t}: tar [4] " . $target);
     }
     self::update_modules_list();
     $ext_folder = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "extensions"));
     foreach ($file_list as $file) {
         sys_chmod(SIMPLE_EXT . $file["filename"]);
         setup::out(sprintf("{t}Processing %s ...{/t}", SIMPLE_EXT . $file["filename"]));
         if (basename($file["filename"]) == "install.php") {
             setup::out("");
             require SIMPLE_EXT . $file["filename"];
             setup::out("");
         }
         if (basename($file["filename"]) == "readme.txt") {
             $data = file_get_contents(SIMPLE_EXT . $file["filename"]);
             setup::out(nl2br("\n" . q($data) . "\n"));
         }
         if (!empty($ext_folder) and basename($file["filename"]) == "folders.xml") {
             setup::out(sprintf("{t}Processing %s ...{/t}", "folder structure"));
             folders::create_default_folders(SIMPLE_EXT . $file["filename"], $ext_folder, false);
         }
     }
 }
Пример #2
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 "";
 }
Пример #3
0
 private static function _import_delete($folder, $id, $tname, $module)
 {
     $where = array("folder=@folder@");
     if ($id[0] == "_") {
         $where[] = "id=@id@";
     } else {
         $where[] = "syncid=@id@";
     }
     $row_id = db_select_value($tname, "id", $where, array("id" => trim($id, "_"), "folder" => $folder));
     if (!empty($row_id)) {
         $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash"));
         if (empty($trash)) {
             sys_warning("{t}Error{/t}: {t}Trash folder not found.{/t}");
             return;
         }
         $id = folders::create(sys_date("{t}m/d/Y{/t}"), "blank", "", $trash, true);
         $id2 = folders::create($module, str_replace("simple_", "", $tname), "", $id, true);
         $data = array("folder" => $id2, "history" => sprintf("{t}Item deleted by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
         db_update($tname, $data, array("id=@id@"), array("id" => $row_id));
         db_update_treesize($tname, $folder);
         db_search_delete($tname, $row_id, $folder);
         sys_log_stat("deleted_records", 1);
     }
 }
Пример #4
0
function install()
{
    setup::out('
    <html>
    <head>
	<title>Simple Groupware & CMS</title>
	<style>
	  body { width:526px; margin:10px auto; }
	  body, a { color: #666666; font-size: 13px; font-family: Arial, Helvetica, Verdana, sans-serif; }
	  a { color: #0000FF; }
	</style>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
	<div style="border-bottom: 1px solid #666666; letter-spacing: 2px; font-size: 18px; font-weight: bold;">Simple Groupware ' . CORE_VERSION_STRING . '</div>
  ');
    $_SESSION["groups"] = array();
    $_SESSION["username"] = "******";
    $_SESSION["password"] = "";
    $_SESSION["permission_sql"] = "1=1";
    $_SESSION["permission_sql_read"] = "1=1";
    $_SESSION["permission_sql_write"] = "1=1";
    define("SETUP_DB_TYPE", $_REQUEST["db_type"]);
    $update = sgsml_parser::table_column_exists("simple_sys_tree", "id");
    setup::out('<img src="http://www.simple-groupware.de/cms/logo.php/' . CORE_VERSION . '/' . SETUP_DB_TYPE . '/' . PHP_VERSION . '/' . (int) $update . '" style="width:1px; height:1px;">', false);
    setup::out(t("{t}Processing %s ...{/t}", "schema updates"));
    setup_update::change_database_pre();
    if (SETUP_DB_TYPE == "sqlite") {
        sql_query("begin");
        admin::rebuild_schema(false);
        sql_query("commit");
    } else {
        admin::rebuild_schema(false);
    }
    setup_update::change_database_post();
    setup::out(t("{t}Processing %s ...{/t}", "sessions"));
    db_delete("simple_sys_session", array(), array());
    setup::out(t("{t}Processing %s ...{/t}", "default groups"));
    $groups = array("admin_calendar", "admin_news", "admin_projects", "admin_bookmarks", "admin_contacts", "admin_inventory", "admin_helpdesk", "admin_organisation", "admin_files", "admin_payroll", "admin_surveys", "admin_hr", "admin_intranet", "users_self_registration");
    foreach ($groups as $group) {
        trigger::creategroup($group);
    }
    setup_update::database_triggers();
    setup::out(t("{t}Processing %s ...{/t}", "folder structure"));
    $count = db_select_value("simple_sys_tree", "id", array());
    if (empty($count)) {
        $folders = "modules/core/folders.xml";
        if (!empty($_REQUEST["folders"]) and file_exists(sys_custom($_REQUEST["folders"]))) {
            $folders = $_REQUEST["folders"];
        }
        if (SETUP_DB_TYPE == "sqlite") {
            sql_query("begin");
            folders::create_default_folders($folders, 0, true);
            sql_query("commit");
        } else {
            folders::create_default_folders($folders, 0, true);
        }
    }
    setup_update::database_folders();
    setup::out(t("{t}Processing %s ...{/t}", "css"));
    admin::build_css();
    setup::out(t("{t}Processing %s ...{/t}", "js"));
    admin::build_js();
    setup::out(t("{t}Processing %s ...{/t}", "icons"));
    admin::build_icons();
    setup::out(t("{t}Processing %s ...{/t}", "config.php"));
    $vars = array("SETUP_DB_TYPE" => "'" . $_REQUEST["db_type"] . "'", "SETUP_DB_HOST" => "'" . $_REQUEST["db_host"] . "'", "SETUP_DB_NAME" => "'" . $_REQUEST["db_name"] . "'", "SETUP_DB_USER" => "'" . $_REQUEST["db_user"] . "'", "SETUP_DB_PW" => "'" . sys_encrypt($_REQUEST["db_pw"], sha1($_REQUEST["admin_user"])) . "'", "SETUP_ADMIN_USER" => "'" . $_REQUEST["admin_user"] . "'", "SETUP_ADMIN_PW" => "'" . (isset($_REQUEST["auto_update"]) ? $_REQUEST["admin_pw"] : sha1($_REQUEST["admin_pw"])) . "'");
    setup::save_config($vars);
    setup::install_footer();
    db_optimize_tables();
}
Пример #5
0
 static function delete_items($folder, $view, $items, $mode = "delete")
 {
     if (empty($folder) or empty($view) or !is_array($items) or $mode == "") {
         return;
     }
     $sgsml = new sgsml($folder, $view, $items);
     $tname = $sgsml->tname;
     $handler = $sgsml->handler;
     if (!isset($sgsml->buttons[$mode]) or $mode == "delete" and count($items) == 0) {
         return;
     }
     if ($mode == "empty") {
         $sgsml->where = array("folder in (@folders@)");
     }
     if ($mode == "purgeall") {
         $sgsml->where = array();
     }
     if (in_array($mode, array("purge", "purgeall"))) {
         $delete = true;
     } else {
         $delete = false;
     }
     if (folder_in_trash($folder)) {
         $delete = true;
     }
     if ($handler == "") {
         $file_fields = $sgsml->get_fields_by_type("files");
     } else {
         $file_fields = array();
     }
     if (!empty($sgsml->att["TRIGGER_DELETE"])) {
         $fields = array("*");
     } else {
         if (isset($sgsml->fields["notification"])) {
             $fields = array("id", "folder", "notification");
             foreach ($sgsml->fields as $key => $field) {
                 if (isset($field["REQUIRED"]) and $field["SIMPLE_TYPE"] != "files" and !in_array($key, $fields)) {
                     $fields[] = $key;
                 }
             }
         } else {
             $fields = array("id");
         }
         $fields = array_unique(array_merge($fields, $file_fields));
     }
     $rows = $sgsml->get_rows($fields);
     if (!is_array($rows) or count($rows) == 0 or count($rows) < count($items)) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     if ($delete) {
         foreach ($rows as $row) {
             foreach ($file_fields as $field) {
                 $files = explode("|", $row[$field]);
                 sys_unlink($files);
             }
             $data = array("id" => $row["id"], "folder" => $folder);
             db_delete($tname, array("id=@id@"), $data, array("handler" => $handler));
         }
     } else {
         $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash"));
         if (empty($trash)) {
             exit("{t}Error{/t}: {t}Trash folder not found.{/t}");
         }
         foreach ($rows as $row) {
             $id = folders::create(sys_date("{t}m/d/Y{/t}"), "blank", "", $trash, true);
             $tid = folders::create($sgsml->att["MODULENAME"], str_replace("simple_", "", $tname), "", $id, true);
             $data = array("folder" => $tid, "history" => sprintf("{t}Item deleted by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
             db_update($tname, $data, array("id=@id@"), array("id" => $row["id"]), array("handler" => $handler));
             db_update_treesize($tname, $tid);
             if (!isset($row["notification"])) {
                 $row["notification"] = "";
             }
             $tree_notification = db_select_value("simple_sys_tree", "notification", "id=@id@", array("id" => $folder));
             if ($tree_notification) {
                 $row["notification"] .= "," . $tree_notification;
             }
             if (!empty($row["notification"])) {
                 $smtp_data = self::build_notification($tname, $sgsml->fields, $row, $data, $id);
                 asset_process_trigger("sendmail", $row["id"], $smtp_data);
             }
             if (!empty($sgsml->att["TRIGGER_DELETE"])) {
                 asset_process_trigger($sgsml->att["TRIGGER_DELETE"], $row["id"], $row, $tname);
             }
             db_update("simple_sys_tree", array("history" => "[" . $row["id"] . "/details] " . $data["history"]), array("id=@id@"), array("id" => $folder));
             db_search_delete($tname, $row["id"], $folder);
             db_notification_delete($tname, $row["id"]);
         }
     }
     db_update_treesize($tname, $folder);
     sys_log_stat("deleted_records", count($rows));
 }
Пример #6
0
function folder_build_selfolder($tfolder, $tview)
{
    if (!is_numeric($tfolder)) {
        $url = sys_parse_folder($tfolder);
        $handler = $url["handler"];
        $mfolder = $url["mfolder"];
        $level = substr_count($url["path"], "/") - 1;
        $sel_folder = db_select_first("simple_sys_tree", array("fmountpoint", "flevel"), array("id=@id@", $_SESSION["permission_sql_read"]), "", array("id" => (int) $mfolder));
        if (!empty($sel_folder["flevel"])) {
            $level += $sel_folder["flevel"] - substr_count($sel_folder["fmountpoint"], "/") + 1;
            $mp = $sel_folder["fmountpoint"];
        } else {
            $mp = "";
        }
        $sel_folder = array("id" => $tfolder, "ftitle" => basename($tfolder), "fdescription" => "", "children" => array(), "lft" => 1, "rgt" => 2, "ftype" => "sys_nodb_" . $handler, "fcount" => 0, "fsizecount" => 0, "fchcount" => 0, "fchsizecount" => 0, "ffcount" => 0, "flevel" => $level, "quota" => 0, "anchor" => "", "folders" => "", "icon" => "", "notification" => "", "fmountpoint" => $mp, "rights" => db_get_rights($mfolder, $tview));
    } else {
        if (db_get_right($tfolder, "read")) {
            $sel_folder = db_select_first("simple_sys_tree", "*", array("id=@id@"), "", array("id" => $tfolder));
        } else {
            $sel_folder = db_select_first("simple_sys_tree", "*", $_SESSION["permission_sql_read"], "lft asc");
            if (DEBUG and empty($sel_folder)) {
                folders::create_default_folders("modules/core/folders.xml", 0, true);
                sys_die("tree created.");
            }
            if (!empty($_REQUEST["iframe"]) and $tfolder != 1) {
                sys_die("{t}Access denied.{/t}");
            }
        }
        if (!is_array($sel_folder)) {
            sys_die("ERROR " . sql_error());
        }
        if (count($sel_folder) == 0) {
            sys_die("{t}Access denied.{/t} <a href='index.php?logout'>{t}Login/-out{/t}</a>");
        }
        $sel_folder["quota"] = db_get_quota($sel_folder);
        $sel_folder["rights"] = db_get_rights($sel_folder["id"], $tview);
    }
    return $sel_folder;
}
Пример #7
0
 /**
  * Move or copy a folder (ccp = cut-copy-paste)
  * - exit on failure
  *
  * @param int|string $source Source folder ID or string (/Workspace/.../)
  * @param int|string $target Target folder ID or string (/Workspace/.../)
  * @param string $operation cut or copy
  * @return int Source folder ID
  */
 static function folder_ccp($source, $target, $operation)
 {
     self::_require_access($source, "write");
     self::_require_access($target, "write");
     if ($operation == "cut") {
         if (!folders::move($source, $target)) {
             exit("{t}The folder cannot be moved.{/t}");
         }
     } else {
         if (!folders::copy($source, $target)) {
             exit("{t}The folder cannot be copied.{/t}");
         }
     }
     return $source;
 }
Пример #8
0
 static function runxml($id, $data, $params)
 {
     list($file, $parent_anchor) = $params;
     $home = folder_from_path("^" . $parent_anchor);
     if (!empty($home) and file_exists(sys_custom($file))) {
         sys_notification(sprintf("{t}Processing %s ...{/t}", $file));
         $folder = folders::create_default_folders($file, $home, false, $data);
         sys_notification(sprintf("{t}Folder structure created.{/t} (%s)", modify::getpath($folder) . " / "));
     }
     return "";
 }
Пример #9
0
 static function database_folders()
 {
     $parent = folder_from_path("^system");
     if (!empty($parent)) {
         $row_id = folder_from_path("!sys_nodb_backups");
         if (empty($row_id)) {
             folders::create("{t}Backups{/t}", "sys_nodb_backups", "", $parent, false);
         }
         $row_id = folder_from_path("^trash");
         if (empty($row_id)) {
             folders::create("{t}Trash{/t}", "blank", "", $parent, false, array("anchor" => "trash"));
         }
         $row_id = folder_from_path("!sys_notifications");
         if (empty($row_id)) {
             folders::create("{t}Notifications{/t}", "sys_notifications", "{t}Delivery{/t}: cron.php", $parent, false);
         }
         $row_id = folder_from_path("^customize");
         if (empty($row_id)) {
             folders::create("{t}Customize{/t}", "blank", "", $parent, false, array("anchor" => "customize"));
         }
         $row_id = folder_from_path("!sys_console");
         if (empty($row_id)) {
             $id = folders::create("{t}Console{/t}", "sys_console", "", $parent, false, array());
             folders::import_data("modules/core/data_console.xml", $id);
         }
     }
     $parent = folder_from_path("^customize");
     $row_id = folder_from_path("!sys_custom_fields");
     if (empty($row_id) and !empty($parent)) {
         folders::create("{t}Fields{/t}", "sys_custom_fields", "{t}Customization rules\nfor modules based on sgsML{/t}", $parent, false);
     }
     $parent = folder_from_path("^workspace");
     $row_id = folder_from_path("^extensions");
     if (!empty($parent) and empty($row_id)) {
         folders::create("{t}Extensions{/t}", "blank", "", $parent, false, array("anchor" => "extensions"));
     }
 }