コード例 #1
0
ファイル: index.php プロジェクト: uwitec/eduoa
     $page = $b->tables_backup($tables, $structonly);
     $page = $page . $b->listbackups();
     break;
 case "generate":
     $b = new backup();
     $b->dbconnect($GonxAdmin["dbhost"], $GonxAdmin["dbuser"], $GonxAdmin["dbpass"], $GonxAdmin["dbname"]);
     $page = $b->generate();
     $page = $page . $b->listbackups();
     break;
 case "list":
     $b = new backup();
     $page = $b->listbackups();
     break;
 case "delete":
     $b = new backup();
     $page = $b->delete($fname);
     $page = $page . $b->listbackups();
     break;
 case "import":
     $b = new backup();
     $b->dbconnect($GonxAdmin["dbhost"], $GonxAdmin["dbuser"], $GonxAdmin["dbpass"], $GonxAdmin["dbname"]);
     $page = $b->import($bfile);
     $page = $page . $b->listbackups();
     break;
 case "importfromfile":
     $b = new backup();
     $b->dbconnect($GonxAdmin["dbhost"], $GonxAdmin["dbuser"], $GonxAdmin["dbpass"], $GonxAdmin["dbname"]);
     $page = $b->importfromfile();
     $page = $page . $b->listbackups();
     break;
 case "optimize":
コード例 #2
0
ファイル: core.inc.php プロジェクト: chiranjeevjain/agilebill
 function cleanup($VAR)
 {
     $alert = false;
     /*
               cleanup:  sessions
                         session auth cache
                         searches
                         saved searches
                         old task logs
                         old error logs
                         old login logs
                         old login locks
                         old temporary data
                         old backups
                         expired groups
     */
     $clean = array(array('table' => 'log_error', 'field' => 'date_orig', 'where' => '<=', 'cond' => time() - 86400 * AGILE_LOG_ERR_EXPIRE_DAYS), array('table' => 'login_log', 'field' => 'date_orig', 'where' => '<=', 'cond' => time() - 86400 * AGILE_LOGIN_LOGS_EXPIRE_DAYS), array('table' => 'session_auth_cache', 'field' => 'date_expire', 'where' => '<=', 'cond' => time()), array('table' => 'search', 'field' => 'date_expire', 'where' => '<=', 'cond' => time()), array('table' => 'search_saved', 'field' => 'date_expire', 'where' => '<=', 'cond' => time()), array('table' => 'login_lock', 'field' => 'date_expire', 'where' => '<=', 'cond' => time()), array('table' => 'temporary_data', 'field' => 'date_expire', 'where' => '<=', 'cond' => time()));
     for ($i = 0; $i < count($clean); $i++) {
         $db =& DB();
         $sql = "DELETE FROM " . AGILE_DB_PREFIX . "" . $clean[$i]['table'] . " WHERE\n                    site_id             = " . $db->qstr(DEFAULT_SITE) . " AND " . $clean[$i]['field'] . "   != " . $db->qstr('') . " AND " . $clean[$i]['field'] . "   != " . $db->qstr('0') . " AND " . $clean[$i]['field'] . " " . $clean[$i]['where'] . " " . $db->qstr($clean[$i]['cond']);
         $result = $db->Execute($sql);
     }
     ########################################################################
     ### Remove old sessions
     ########################################################################
     $sql = "DELETE FROM " . AGILE_DB_PREFIX . "session WHERE\n        \t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n        \t\tdate_last\t< " . $db->qstr(time() - 86400 * AGILE_SESS_EXPIRE_DAYS) . "   \n                AND\n                ( \n                \taffiliate_id IS NULL OR\n                \taffiliate_id = '' OR\n                \taffiliate_id = 0 OR\n                \tcampaign_id IS NULL OR\n                \tcampaign_id = '' OR\n                \tcampaign_id = 0 OR\n                \tdate_last\t< " . $db->qstr(time() - 86400 * AGILE_SESS_AFFIL_EXPIRE_DAYS) . "\n                )";
     $result = $db->Execute($sql);
     ########################################################################
     ### Remove expired group access
     ########################################################################
     $sql = "DELETE FROM " . AGILE_DB_PREFIX . "account_group WHERE\n                site_id        = " . $db->qstr(DEFAULT_SITE) . " AND\n                date_expire IS NOT NULL AND\n                date_expire > 0 AND\n                date_expire <= " . $db->qstr(time());
     $result = $db->Execute($sql);
     ########################################################################
     ### Remove old backups
     ########################################################################
     $sql = "SELECT * FROM " . AGILE_DB_PREFIX . "backup WHERE\n                site_id        = " . $db->qstr(DEFAULT_SITE) . " AND\n                date_expire   != " . $db->qstr('') . " AND\n                date_expire   != " . $db->qstr('0') . " AND\n                date_expire   != " . $db->qstr(time());
     $result = $db->Execute($sql);
     if ($result != false && $result->RecordCount() > 0) {
         while (!$result->EOF) {
             ## Delete this one..
             $arr["delete_id"] = $result->fields['id'];
             include_once PATH_MODULES . 'backup/backup.inc.php';
             $backup = new backup();
             $backup->delete($arr, $backup);
             $result->MoveNext();
         }
     }
     #########################################################################
     ### Repair/optimize DB Tables (MYSQL ONLY!)
     #########################################################################
     if (AGILE_DB_TYPE == 'mysql') {
         $db =& DB();
         $q = "SELECT name FROM " . AGILE_DB_PREFIX . "module WHERE site_id = " . $db->qstr(DEFAULT_SITE);
         $rs = $db->Execute($q);
         while (!$rs->EOF) {
             $table = $rs->fields['name'];
             $sql = "CHECK TABLE " . AGILE_DB_PREFIX . $table;
             $rscheck = $db->Execute($sql);
             if ($rscheck && $rscheck->fields['Msg_type'] == 'status' && $rscheck->fields['Msg_text'] == 'OK') {
                 $sql = "ANALYZE TABLE " . AGILE_DB_PREFIX . $table;
                 $db->Execute($sql);
             } else {
                 $sql = "REPAIR TABLE " . AGILE_DB_PREFIX . $table;
                 $db->Execute($sql);
                 $sql = "OPTIMIZE TABLE " . AGILE_DB_PREFIX . $table;
                 $db->Execute($sql);
             }
             $rs->MoveNext();
         }
     }
     #########################################################################
     ### Force the correct id keys in each table that has unique ids
     #########################################################################
     $sql = "SELECT name FROM " . AGILE_DB_PREFIX . "module WHERE\n                site_id  = " . $db->qstr(DEFAULT_SITE) . " AND\n                status   = " . $db->qstr('1') . " \n\t\t\t\tORDER BY name";
     $rs = $db->Execute($sql);
     while (!$rs->EOF) {
         $module = $rs->fields['name'];
         # check if key table exists:
         $sql = "SELECT id FROM " . AGILE_DB_PREFIX . $module . "_id ORDER BY id DESC";
         $keytable = $db->Execute($sql);
         if ($module != 'session' && $module != 'affiliate' && $keytable != false && $keytable->RecordCount() > 0) {
             $current_id = $keytable->fields['id'];
             # get the current id from the main table:
             $sql = "SELECT id FROM " . AGILE_DB_PREFIX . $module . " ORDER BY id DESC";
             $table = $db->Execute($sql);
             if ($table != false && $table->RecordCount() > 0) {
                 $last_id = $table->fields['id'];
                 # does key need updated?
                 if ($current_id < $last_id) {
                     $id = $last_id + 1;
                     $sql = "UPDATE " . AGILE_DB_PREFIX . $module . "_id\n\t\t\t\t\t\t\t\tSET \n\t\t\t\t\t\t\t\tid = " . $db->qstr($id) . " \n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tid = " . $db->qstr($current_id);
                     $db->Execute($sql);
                     $alert .= "Corrected incorrect primary key on the <u>{$module}</u> table.<br>";
                 }
             }
         }
         $rs->MoveNext();
     }
     #########################################################################
     ### Run any new upgrade files in the /upgrades directory
     #########################################################################
     @($dir = opendir(PATH_AGILE . 'upgrades'));
     while (@($file_name = readdir($dir))) {
         $display = true;
         if ($file_name != '..' && $file_name != '.') {
             # check if upgrade has been run:
             $md5 = md5($file_name);
             $sql = "SELECT data FROM " . AGILE_DB_PREFIX . "temporary_data\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tdata = " . $db->qstr($md5) . " AND\n\t\t\t\t\t\tfield1 = " . $db->qstr('upgrade');
             $rs = $db->Execute($sql);
             if ($rs->RecordCount() == 0) {
                 # Run the upgrade:
                 if (is_file(PATH_AGILE . 'upgrades/' . $file_name) && !is_dir(PATH_AGILE . 'upgrades/' . $file_name)) {
                     include_once PATH_AGILE . 'upgrades/' . $file_name;
                 }
                 $function = strtolower(preg_replace('/.php/', '', $file_name));
                 if (preg_match('/^upgrade/', $function)) {
                     if (is_callable($function)) {
                         $result = call_user_func($function);
                         #$result = true;
                     } else {
                         $result = false;
                     }
                 }
                 # If success, save so it is not run again:
                 if ($result) {
                     /* Start: SQL Insert Statement */
                     $sql = "SELECT * FROM " . AGILE_DB_PREFIX . "temporary_data WHERE id = -1";
                     $rs = $db->Execute($sql);
                     $id = $db->GenID(AGILE_DB_PREFIX . 'temporary_data_id');
                     $insert = array('id' => $id, 'site_id' => DEFAULT_SITE, 'data' => $md5, 'field1' => 'upgrade', 'date_orig' => time(), 'date_expire' => time() + 86400 * 365 * 20);
                     $sql = $db->GetInsertSQL($rs, $insert);
                     $result = $db->Execute($sql);
                     if ($result === false) {
                         global $C_debug;
                         $C_debug->error('core.inc.php', 'core :: cleanup()', $db->ErrorMsg() . "\r\n\r\n" . $sql);
                     }
                     /* End: SQL Insert Statement */
                     $alert .= "Upgraded to <u>{$file_name}</u>!<br>";
                 } else {
                     $alert .= "The <u>{$file_name}</u> upgrade failed!<br>";
                 }
             }
         }
     }
     #########################################################################
     ## Print any alerts:
     #########################################################################
     if (!empty($alert)) {
         global $C_debug;
         $C_debug->alert($alert);
     }
     return true;
 }
コード例 #3
0
ファイル: backups.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new backup();
    switch ($_REQUEST['act']) {
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = " i.website = " . $website->id;
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $sql = ' SELECT SQL_CALC_FOUND_ROWS i.*
							   FROM nv_backups i
							  WHERE ' . $where . '	
						   ORDER BY ' . $orderby . ' 
							  LIMIT ' . $max . '
							 OFFSET ' . $offset;
                    if (!$DB->query($sql, 'array')) {
                        throw new Exception($DB->get_last_error());
                    }
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    $out = array();
                    if (empty($dataset)) {
                        $rows = 0;
                    } else {
                        $rows = count($dataset);
                    }
                    for ($i = 0; $i < $rows; $i++) {
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date_created'], true), 2 => $dataset[$i]['title'], 3 => core_bytes($dataset[$i]['size']), 4 => backup::status($dataset[$i]['status']));
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            core_terminate();
            break;
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if ($_REQUEST['form-sent'] == 'true') {
                $item->load_from_post();
                try {
                    // update an existing backup
                    $item->save();
                    $id = $item->id;
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = backups_form($item);
            break;
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = backups_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webdictionary_list();
                }
            }
            break;
        case 'backup':
            if (!empty($_REQUEST['id'])) {
                // trick to generate a underground process ;)
                @set_time_limit(0);
                @ignore_user_abort(true);
                $foo = str_pad('Navigate CMS ', 2048, 'Navigate CMS  ');
                header("HTTP/1.1 200 OK");
                header("Content-Length: " . strlen($foo));
                echo $foo;
                header('Connection: close');
                ob_end_flush();
                ob_flush();
                flush();
                session_write_close();
                // now the process is running in the server, the client thinks the http request has finished
                $item->load(intval($_REQUEST['id']));
                $item->backup();
            }
            core_terminate();
            break;
        case 'restore':
            // TO DO: Restore
            break;
        case 'download':
            // download backup
            $item->load(intval($_REQUEST['id']));
            ob_end_flush();
            header('Content-type: application/zip');
            header("Content-Length: " . filesize(NAVIGATE_PRIVATE . $item->file));
            header('Content-Disposition: attachment; filename="' . basename($item->file) . '"');
            readfile(NAVIGATE_PRIVATE . $item->file);
            core_terminate();
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = backups_list();
            break;
    }
    return $out;
}