Ejemplo n.º 1
0
 *  Инициализация приложения происходит автоматически
 *  при первом обращении к классу Application
 *  (например след строке - App final класс который оборачивается над экземпляром Application).
 *  В будущем вообще необходимо исключить какую либо инициализацию в ядре.
 *  При использовании Скриптоцыда как библиотеки все должно происходить 
 *  через инициализацию в классе приложения(Application) Который можно унаследовать
 *  И там уже пределить и параметры БД и другие параметры.
 */
$APPLICATION = $APP = App::getInstance();
$APPLICATION->setTitle(Storage::get()->SITE_NAME);
$APPLICATION->setDescr($descr);
$DB = App::DB();
// $APP->DB; //App::get()->DB;
Storage::add("DB", $DB);
if (!isset($_SESSION['WEB_SERFER'])) {
    $_SESSION['WEB_SERFER'] = array("IP" => $_SERVER["REMOTE_ADDR"], "BROWSER" => $_SERVER["HTTP_USER_AGENT"], "WEB_ID" => md5(GetRandom(8) . $_SERVER["REMOTE_ADDR"]));
}
$_SESSION['WEB_SERFER']["LAST_ACTIVITY"] = time();
$USER = App::USER();
$bIsAdmin = $USER->IsAdmin();
Storage::add("USER", $USER);
// [Рудименты]
if (Storage::exists("APP_TEMPLATE")) {
    App::get()->templateName = Storage::get("APP_TEMPLATE");
}
if (!Storage::exists("SITE_NAME")) {
    Storage::add("SITE_NAME", "");
}
if (!Storage::exists("SITE_DESCRIPTION")) {
    Storage::add("SITE_DESCRIPTION", "");
}
Ejemplo n.º 2
0
function mkDump($console_run = false, $dump_options = NULL)
{
    global $DOCUMENT_ROOT, $SUB_FOLDER, $DOMAIN_NAME, $HTTP_FILES_PATH, $HTTP_ROOT_PATH, $HTTP_DUMP_PATH, $TMP_FOLDER, $HTTP_IMAGES_PATH, $DUMP_FOLDER, $HTTP_TEMPLATE_PATH, $ADMIN_PATH;
    $nc_core = nc_Core::get_object();
    // Check permissions if running from web
    if (!$console_run) {
        if (!checkPermissions($HTTP_DUMP_PATH, $DOCUMENT_ROOT)) {
            return;
        }
        if (!checkPermissions($HTTP_ROOT_PATH . "tmp/", $DOCUMENT_ROOT)) {
            return;
        }
    }
    // Determine what items to backup
    // Default settings (as in 5.0.2):
    $dump_items = array('template' => true, 'files' => true, 'images' => true, 'modules' => true, 'everything' => false, 'sql' => true);
    $include_standalone_script = false;
    // Modify settings if options specified
    //
    // NOTE: modifications rely on default settings. If you're changing default settings above, you have to review this part of code too.
    if ($dump_options) {
        // Modify items based on mode selection
        $backup_mode = "data";
        if (isset($dump_options['mode'])) {
            switch ($dump_options['mode']) {
                case 'full':
                    $dump_items['everything'] = true;
                    $backup_mode = "full";
                    break;
                case 'sql':
                    $backup_mode = "sql";
                    $dump_items['template'] = false;
                    $dump_items['files'] = false;
                    $dump_items['images'] = false;
                    $dump_items['modules'] = false;
                    break;
            }
        }
        // Determine if standalone restore script should be included
        if (isset($dump_options['standalone']) && ($dump_options['standalone'] = true)) {
            $include_standalone_script = true;
        }
    }
    DeleteFilesInDirectory($TMP_FOLDER);
    $dump_file = array();
    // Pack appropriate items
    if ($dump_items['template']) {
        $dump_file[] = nc_tgz_create($TMP_FOLDER . "netcat_template.tgz", ltrim($HTTP_TEMPLATE_PATH, "/"));
    }
    if ($dump_items['files']) {
        $dump_file[] = nc_tgz_create($TMP_FOLDER . "netcat_files.tgz", ltrim($HTTP_FILES_PATH, "/"));
    }
    if ($dump_items['images']) {
        $dump_file[] = nc_tgz_create($TMP_FOLDER . "images.tgz", trim($HTTP_IMAGES_PATH, "/"));
    }
    if ($dump_items['modules']) {
        $dump_file[] = nc_tgz_create($TMP_FOLDER . "modules.tgz", ltrim($HTTP_ROOT_PATH, "/") . "modules");
    }
    if ($dump_items['everything']) {
        // "everything" mode includes all existing items altogether. Maybe, just exclude it?
        $exclude_dirs = array($nc_core->TMP_FOLDER, $nc_core->DOCUMENT_ROOT . $nc_core->SUB_FOLDER . $nc_core->HTTP_TEMPLATE_PATH, $nc_core->FILES_FOLDER, $nc_core->DOCUMENT_ROOT . $nc_core->SUB_FOLDER . $nc_core->HTTP_IMAGES_PATH, $nc_core->MODULE_FOLDER, $nc_core->DUMP_FOLDER);
        foreach ($exclude_dirs as $ex_dir) {
            //echo "Creating tag $ex_dir/.exclude_from_everything<br />\n";
            touch($ex_dir . '.exclude_from_everything');
        }
        $dump_file[] = nc_tgz_create($TMP_FOLDER . "everything.tgz", '.', '', '.exclude_from_everything');
        foreach ($exclude_dirs as $ex_dir) {
            unlink($ex_dir . '/.exclude_from_everything');
        }
    }
    // Create SQL dump
    if ($dump_items['sql']) {
        MakeBackUp();
    }
    // Add standalone script if requested
    if ($include_standalone_script) {
        // Hosts that miss tar, mysql and/or mysqldump utilities (such as Windows) needs these classes to make restore script work
        file_put_contents($TMP_FOLDER . '/restore.php', file_get_contents($DOCUMENT_ROOT . $ADMIN_PATH . 'dump/mysql.class.php') . "\n\n\n");
        file_put_contents($TMP_FOLDER . '/restore.php', file_get_contents($DOCUMENT_ROOT . $ADMIN_PATH . 'dump/PEAR5.php') . "\n?>\n\n", FILE_APPEND);
        file_put_contents($TMP_FOLDER . '/restore.php', preg_replace('/include_once\\ .PEAR5.php.\\;/', '', file_get_contents($DOCUMENT_ROOT . $ADMIN_PATH . 'dump/PEAR.php')) . "\n?>\n\n", FILE_APPEND);
        file_put_contents($TMP_FOLDER . '/restore.php', preg_replace('/require_once\\ .PEAR.php.\\;/', '', file_get_contents($DOCUMENT_ROOT . $SUB_FOLDER . $HTTP_ROOT_PATH . 'require/lib/Tar.php')) . "\n?>\n\n", FILE_APPEND);
        file_put_contents($TMP_FOLDER . '/restore.php', '<?php $dump_options = ' . var_export($dump_options, true) . '; ?>' . "\n\n\n", FILE_APPEND);
        file_put_contents($TMP_FOLDER . '/restore.php', file_get_contents($DOCUMENT_ROOT . $ADMIN_PATH . 'dump/functions.php') . "\n\n\n", FILE_APPEND);
        file_put_contents($TMP_FOLDER . '/restore.php', file_get_contents($DOCUMENT_ROOT . $ADMIN_PATH . 'dump/restore.php') . "\n\n\n", FILE_APPEND);
    }
    // Compress final archive
    $file = date("YmdHis") . "_" . $DOMAIN_NAME . "_" . $backup_mode . "_" . GetRandom(5);
    $dump_file[] = nc_tgz_create($DUMP_FOLDER . "{$file}.tgz", ltrim($HTTP_ROOT_PATH, "/") . "tmp");
    DeleteFilesInDirectory($TMP_FOLDER);
    // Check results
    $dump_success = true;
    foreach ($dump_file as $_check) {
        if (!$_check) {
            $dump_success = false;
            break;
        }
    }
    if ($dump_success) {
        if (!$console_run) {
            nc_print_status(str_replace("%FILE", "{$file}.tgz", TOOLS_DUMP_CREATED), "ok");
        } else {
            echo "Backup created: {$file}.tgz\n";
            return 0;
        }
    } else {
        if (!$console_run) {
            nc_print_status(TOOLS_DUMP_CREATION_FAILED, "error");
        } else {
            echo "Backup creation failed: {$file}.tgz\n";
            return 1;
        }
    }
}
Ejemplo n.º 3
0
 public static function GetHash($arFields = array())
 {
     $hash = md5(substr(base64_encode(md5(GetRandom(5) . time() . join(':', $arFields))), 0, 10));
     return $hash;
 }
Ejemplo n.º 4
0
function alphanumericPass($length, $cc)
{
    $srt_array = array();
    for ($a = 0; $a <= $cc; $a++) {
        $p = GetRandom(1);
        if (!in_array($p, $srt_array)) {
            $srt_array[] = $p;
        } else {
            $a--;
            continue;
        }
    }
    return $srt_array;
}