Esempio n. 1
0
 static function process_action_sys()
 {
     @set_time_limit(900);
     switch ($_REQUEST["action_sys"]) {
         case "maintenance":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             $lock_file = SIMPLE_STORE . "/maintenance.lck";
             if (!file_exists($lock_file)) {
                 touch($lock_file);
                 sys_log_message_alert("info", "{t}Maintenance mode{/t}: {t}Active{/t}");
             } else {
                 unlink($lock_file);
                 sys_log_message_alert("info", "{t}Maintenance mode{/t}: {t}Inactive{/t}");
             }
             break;
         case "clear_locking":
             self::_remove_locks();
             dirs_create_empty_dir(SIMPLE_STORE . "/locking");
             sys_log_message_log("clean", "{t}Locking{/t}");
             break;
         case "clear_output":
             dirs_create_empty_dir(SIMPLE_CACHE . "/smarty");
             dirs_create_empty_dir(SIMPLE_CACHE . "/output");
             dirs_create_empty_dir(SIMPLE_CACHE . "/artichow");
             dirs_create_empty_dir(SIMPLE_CACHE . "/thumbs");
             dirs_create_empty_dir(SIMPLE_CACHE . "/lang");
             self::build_css();
             self::build_js();
             self::build_icons();
             sys_log_message_log("clean", "{t}Output{/t}");
             break;
         case "clear_debug":
             dirs_create_empty_dir(SIMPLE_CACHE . "/debug");
             sys_log_message_log("clean", "{t}Debug-dir{/t}");
             break;
         case "clear_cms":
             dirs_create_empty_dir(SIMPLE_CACHE . "/cms");
             sys_log_message_log("clean", "{t}CMS{/t}");
             break;
         case "clear_ip":
             dirs_create_empty_dir(SIMPLE_CACHE . "/ip");
             if (APC) {
                 apc_clear_cache("user");
             }
             sys_log_message_log("clean", "IP");
             break;
         case "clear_schema":
             dirs_create_empty_dir(SIMPLE_CACHE . "/schema");
             if (APC) {
                 apc_clear_cache("user");
             }
             sys_log_message_log("clean", "{t}Schema{/t}");
             break;
         case "clear_schemadata":
             dirs_create_empty_dir(SIMPLE_CACHE . "/schema_data");
             dirs_create_empty_dir(SIMPLE_CACHE . "/preview");
             if (APC) {
                 apc_clear_cache("user");
             }
             sys_log_message_log("clean", "{t}Schema data{/t}");
             break;
         case "clear_email":
             dirs_create_empty_dir(SIMPLE_CACHE . "/imap");
             dirs_create_empty_dir(SIMPLE_CACHE . "/pop3");
             sys_log_message_log("clean", "{t}E-mail{/t}");
             break;
         case "clean_notifications":
             db_delete("simple_sys_notifications", array("sent='1'"), array());
             sql_table_optimize("simple_sys_notifications");
             sys_log_message_log("clean", "{t}Notifications{/t}");
             break;
         case "clear_upload":
             dirs_create_empty_dir(SIMPLE_CACHE . "/upload");
             sys_log_message_log("clean", "{t}Uploaded files{/t}");
             break;
         case "clean_tables":
             db_optimize_tables();
             sys_log_message_log("clean", "{t}Optimize Tables{/t}");
             break;
         case "clean_statistics":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             db_delete("simple_sys_stats", array(), array());
             sql_table_optimize("simple_sys_stats");
             sys_log_message_log("clean", "{t}Statistics{/t}");
             break;
         case "clean_events":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             db_delete("simple_sys_events", array(), array());
             $folder = db_select_value("simple_sys_tree", "id", "ftype=@type@", array("type" => "sys_events"));
             if (!empty($folder)) {
                 db_delete("simple_sys_search", array("folder=@folder@"), array("folder" => $folder));
             }
             sql_table_optimize("simple_sys_events");
             sql_table_optimize("simple_sys_search");
             sys_log_message_log("clean", "{t}Events{/t}");
             break;
         case "clean_trash":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash"));
             if (!empty($trash)) {
                 $folders = db_select("simple_sys_tree", array("id", "fmountpoint"), "parent=@parent@", "", "", array("parent" => $trash));
                 if (is_array($folders) and count($folders) > 0) {
                     foreach ($folders as $folder) {
                         if (!empty($folder["fmountpoint"])) {
                             continue;
                         }
                         folders::delete($folder["id"]);
                     }
                 }
             }
             dirs_create_empty_dir(SIMPLE_STORE . "/trash");
             sys_log_message_log("clean", "{t}Trash{/t}");
             sys_redirect("index.php?" . sys::$urladdon);
             break;
         case "clean_cache":
             $dirs = array(SIMPLE_STORE . "/cron", SIMPLE_CACHE . "/imap", SIMPLE_CACHE . "/pop3", SIMPLE_CACHE . "/smarty", SIMPLE_CACHE . "/cms", SIMPLE_CACHE . "/cifs", SIMPLE_CACHE . "/gdocs", SIMPLE_CACHE . "/lang", SIMPLE_CACHE . "/output", SIMPLE_CACHE . "/artichow", SIMPLE_CACHE . "/thumbs", SIMPLE_CACHE . "/schema");
             foreach ($dirs as $dir) {
                 self::_dirs_clean_dir($dir, 2592000);
             }
             // 30 days
             self::_remove_locks();
             $dirs = array(SIMPLE_CACHE . "/schema_data", SIMPLE_CACHE . "/preview", SIMPLE_STORE . "/locking", SIMPLE_CACHE . "/upload", SIMPLE_CACHE . "/ip", SIMPLE_CACHE . "/debug", SIMPLE_CACHE . "/updater", SIMPLE_CACHE . "/backup");
             foreach ($dirs as $dir) {
                 self::_dirs_clean_dir($dir, 86400);
             }
             // 1 day
             sys_log_message_log("clean", "{t}Clean Cache{/t}");
             sys_redirect("index.php?" . sys::$urladdon);
             break;
         case "clear_setup":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             @unlink("simple_store/config.php");
             @unlink("simple_store/config_old.php");
             header("Location: index.php");
             exit;
             break;
         case "backup":
             self::_create_backup($_SESSION["folder"]);
             self::_out("<br><a href='index.php?folder=^system/!sys_nodb_backups'>{t}Continue{/t}</a>");
             exit;
             break;
         case "restore_newer":
             self::$_restore_onlynewer = true;
             echo self::_restore($_REQUEST["file"]);
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "restore":
             echo self::_restore($_REQUEST["file"]);
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "restore_here":
             self::$_restore_here = true;
             echo self::_restore($_REQUEST["file"]);
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "restore_missing":
             self::$_restore_missing = true;
             echo self::_restore($_REQUEST["file"]);
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "rebuild_search":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             self::rebuild_schema(true);
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "clear_session":
             if (!sys_validate_token()) {
                 sys_die("{t}Invalid security token{/t}");
             }
             db_delete("simple_sys_session", array(), array());
             if (APC) {
                 apc_clear_cache("user");
             }
             sys_log_message_log("clean", "{t}Sessions{/t}");
             self::_out("<br><a href='index.php'>{t}Continue{/t}</a>");
             exit;
             break;
         case "phpinfo":
             echo "System time: " . date("c") . "<br>";
             echo "Database time: " . sgsml_parser::sql_date();
             phpinfo();
             exit;
             break;
     }
 }
Esempio n. 2
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();
}