function purgesoftdeleted_activate()
{
    global $db, $cache;
    // Create task - Purge soft deleted
    // Have we already added this task?
    $query = $db->simple_select('tasks', 'tid', "file='purgesoftdeleted'", array('limit' => '1'));
    if ($db->num_rows($query) == 0) {
        // Load tasks function needed to run a task and add nextrun time
        require_once MYBB_ROOT . "/inc/functions_task.php";
        // If not then add
        $new_task = array("title" => "Purge soft deleted posts and threads", "description" => "Checks for soft deleted posts and threads and purges them automatically.", "file" => "purgesoftdeleted", "minute" => '2', "hour" => '0', "day" => '*', "month" => '*', "weekday" => '*', "enabled" => '1', "logging" => '1');
        $new_task['nextrun'] = fetch_next_run($new_task);
        $tid = $db->insert_query("tasks", $new_task);
        // Update the task and run it right now
        $cache->update_tasks();
        run_task($tid);
    }
}
/**
 * @param string $task Task request to be fulfilled.
 * @param string $db_name Path to a database containing tables required by
 * @param string $hash
 * @param string $pubkey
 * @param string $crypt
 * @param string $password
 * @param string $salt
 * @param string $iv
 * @return array|string
 * @throws \ErrorException
 */
function run_crypt_task($task, $db_name, $hash, $pubkey, $crypt = NULL, $password = NULL, $salt = NULL, $iv = NULL)
{
    $db = null;
    $success = array("result" => "success");
    $failure = array("result" => "failure");
    $error = "";
    $error_flag = false;
    $tasks = array("addClient", "studentFunction");
    try {
        $db = new ClientDeviceSQL($db_name);
    } catch (\Exception $e) {
        $failure["error"] = $e->getMessage();
        return $failure;
    }
    if (!$error_flag) {
        switch ($task) {
            case $tasks[0]:
                $success[$tasks[0]] = $db->addKey($pubkey);
                break;
            case $tasks[1]:
                if (!$db->keyAuthorized($hash)) {
                    $failure["error"] = "Key not authorized for action.";
                    return $failure;
                }
                $task_string = $db->decryptString($crypt, $hash);
                $data = parse_query($task_string);
                if (array_key_exists("function", $data) && (array_key_exists("userID", $data) || is_exception($data["function"]))) {
                    $ret = run_task($data["userID"], $data["function"], $db_name);
                    $success[$tasks[1]] = $db->encrypt_string(json_encode($ret), $hash);
                } else {
                    $error = "Malformed URL";
                    $error_flag = true;
                }
                break;
        }
    }
    if (!$error_flag) {
        return $success;
    } else {
        $failure["error"] = $error;
        return $error;
    }
}
Esempio n. 3
0
 public function end()
 {
     $this->MessageDepth = 0;
     if (count($this->Successes) + count($this->Failures) > 0) {
         $this->log("");
         $this->log($this->colors->getColoredString("Summary: ", "cyan"));
         $duration = time() - $this->StartTime;
         $timeString = $this->secondsToWords($duration);
         $this->log("Test suite [" . (count($this->Successes) + count($this->Failures)) . "] complete in " . $timeString);
         $this->log($this->colors->getColoredString(count($this->Successes) . " successes", "green", null));
         if (count($this->Failures) == 0) {
             $this->log($this->colors->getColoredString(count($this->Failures) . " failures", "green", null));
         } else {
             $this->log($this->colors->getColoredString(count($this->Failures) . " failures", "red"));
         }
         foreach ($this->Failures as $fail) {
             $this->log($this->colors->getColoredString("Failure: " . $fail, "red"));
         }
     }
     if ($this->ToDBSave) {
         $this->log_task_output(run_task("RestoreDBSaveState"));
     }
 }
Esempio n. 4
0
if ($mybb->input['action'] == "run") {
    if (!verify_post_check($mybb->input['my_post_key'])) {
        flash_message($lang->invalid_post_verify_key2, 'error');
        admin_redirect("index.php?module=tools/tasks");
    }
    ignore_user_abort(true);
    @set_time_limit(0);
    $plugins->run_hooks("admin_tools_tasks_run");
    $query = $db->simple_select("tasks", "*", "tid='" . intval($mybb->input['tid']) . "'");
    $task = $db->fetch_array($query);
    // Does the task not exist?
    if (!$task['tid']) {
        flash_message($lang->error_invalid_task, 'error');
        admin_redirect("index.php?module=tools/tasks");
    }
    run_task($task['tid']);
    $plugins->run_hooks("admin_tools_tasks_run_commit");
    // Log admin action
    log_admin_action($task['tid'], $task['title']);
    flash_message($lang->success_task_run, 'success');
    admin_redirect("index.php?module=tools/tasks");
}
if ($mybb->input['action'] == "logs") {
    $plugins->run_hooks("admin_tools_tasks_logs");
    $page->output_header($lang->task_logs);
    $sub_tabs['scheduled_tasks'] = array('title' => $lang->scheduled_tasks, 'link' => "index.php?module=tools/tasks");
    $sub_tabs['add_task'] = array('title' => $lang->add_new_task, 'link' => "index.php?module=tools/tasks&action=add");
    $sub_tabs['task_logs'] = array('title' => $lang->view_task_logs, 'link' => "index.php?module=tools/tasks&action=logs", 'description' => $lang->view_task_logs_desc);
    $page->output_nav_tabs($sub_tabs, 'task_logs');
    $table = new Table();
    $table->construct_header($lang->task);
Esempio n. 5
0
    foreach ($TaskNames as $class_name) {
        echo "- " . $class_name::class_name();
        $i = strlen($class_name);
        while ($i < $max_name_length + 4) {
            echo " ";
            $i++;
        }
        echo $class_name::get_description();
        echo "\r\n";
    }
    exit;
}
// which task?
$ThisTask = $ARGS["t"];
if (strlen($ThisTask) == 0) {
    $ThisTask = $ARGS["T"];
}
if (strlen($ThisTask) == 0) {
    $ThisTask = $ARGS["task"];
}
if (strlen($ThisTask) == 0) {
    echo "No task provided.  Please provide one with -t or --task.  Use --list to show available tasks.\r\n";
    exit;
} else {
    if (in_array($ThisTask, $TaskNames)) {
        echo run_task($ThisTask, $ARGS);
    } else {
        echo "That task cannot be found.  Use --list to show available tasks.\r\n";
        exit;
    }
}
Esempio n. 6
0
    if ($daconn) {
        $source_object = $daconn->instantiate_source_class($connectors_out_source_id);
    } else {
        $source_object = NULL;
    }
    $es = new external_services();
    $array_functions = array();
    foreach ($source_object->config["exported_functions"] as $exported_function) {
        $array_functions[] = $exported_function["group"] . "_" . $exported_function["name"];
    }
    $proxy = $es->get_proxy($PMBuserid, $array_functions);
    if (file_exists($base_path . "/admin/planificateur/catalog_subst.xml")) {
        $filename = $base_path . "/admin/planificateur/catalog_subst.xml";
    } else {
        $filename = $base_path . "/admin/planificateur/catalog.xml";
    }
    $xml = file_get_contents($filename);
    $param = _parser_text_no_function_($xml, "CATALOG");
    foreach ($param["ACTION"] as $anitem) {
        if ($type_tache == $anitem["ID"]) {
            require_once $base_path . "/admin/planificateur/" . $anitem["NAME"] . "/" . $anitem["NAME"] . ".class.php";
            $obj_type = new $anitem["NAME"]($id_tache);
            $obj_type->setEsProxy($proxy);
            $obj_type->execute();
            $obj_type->checkParams($id_planificateur);
        }
    }
}
if ($argv[1] && $argv[2] && $argv[3] && $argv[4] && $argv[5]) {
    run_task($argv[1], $argv[2], $argv[3], $argv[4], $argv[5]);
}
Esempio n. 7
0
$lang->set_language($mybb->settings['bblanguage']);
$lang->load("global");
$lang->load("messages");
if (function_exists('mb_internal_encoding') && !empty($lang->settings['charset'])) {
    @mb_internal_encoding($lang->settings['charset']);
}
require_once MYBB_ROOT . "inc/functions_task.php";
// Are tasks set to run via cron instead & are we accessing this file via the CLI?
// php task.php [tid]
if (PHP_SAPI == "cli") {
    // Passing a specific task ID
    if ($_SERVER['argc'] == 2) {
        $query = $db->simple_select("tasks", "tid", "tid='" . intval($_SERVER['argv'][1]) . "'");
        $tid = $db->fetch_field($query, "tid");
    }
    if ($tid) {
        run_task($tid);
    } else {
        run_task();
    }
} else {
    // Send our fake gif image (clear 1x1 transparent image)
    header("Content-type: image/gif");
    echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
    // If the use shutdown functionality is turned off, run any shutdown related items now.
    if ($mybb->settings['useshutdownfunc'] != 0 || $mybb->use_shutdown == true) {
        add_shutdown("run_task");
    } else {
        run_task();
    }
}
Esempio n. 8
0
/***********************************************
DAVE PHP API
https://github.com/evantahler/PHP-DAVE-API
Evan Tahler | 2011

Set this page to be fired off every minute by your cron process, and then put the logic inside this page.
The output of this page will be added to the CRON_LOG.txt file

***********************************************/
// Cron example: */1 * * * * /usr/bin/php /path/to/CRON.php > /path/to/CRON_LOG.txt
$parts = explode("/", __FILE__);
$ThisFile = $parts[count($parts) - 1];
chdir(substr(__FILE__, 0, strlen(__FILE__) - strlen($ThisFile)));
require_once "LoadEnv.php";
unset($parts);
unset($ThisFile);
load_tasks();
$CRON_OUTPUT = "STARTING CRON @ " . date("m-d-Y H:i:s") . "\r\n\r\n";
/////////////////////////////////////////////////////////////////////////
// Do Tasks
$CRON_OUTPUT .= run_task("CleanCache");
$CRON_OUTPUT .= run_task("CleanLog");
$CRON_OUTPUT .= run_task("CleanSessions");
$CRON_OUTPUT .= run_task("RemoveLargeLogs");
/////////////////////////////////////////////////////////////////////////
// End the log output
echo $CRON_OUTPUT;
$fh = fopen($CONFIG['CronLogFile'], 'a');
fwrite($fh, $CRON_OUTPUT);
fclose($fh);
exit;
Esempio n. 9
0
function upgradedone()
{
    global $db, $output, $mybb, $lang, $config, $plugins;
    ob_start();
    $output->print_header("Upgrade Complete");
    $allow_anonymous_info = get_upgrade_store("allow_anonymous_info");
    if ($allow_anonymous_info == 1) {
        require_once MYBB_ROOT . "inc/functions_serverstats.php";
        $build_server_stats = build_server_stats(0, '', $mybb->version_code, $mybb->config['database']['encoding']);
        if ($build_server_stats['info_sent_success'] == false) {
            echo $build_server_stats['info_image'];
        }
    }
    ob_end_flush();
    // Attempt to run an update check
    require_once MYBB_ROOT . 'inc/functions_task.php';
    $query = $db->simple_select('tasks', 'tid', "file='versioncheck'");
    $update_check = $db->fetch_array($query);
    if ($update_check) {
        // Load plugin system for update check
        require_once MYBB_ROOT . "inc/class_plugins.php";
        $plugins = new pluginSystem();
        run_task($update_check['tid']);
    }
    if (is_writable("./")) {
        $lock = @fopen("./lock", "w");
        $written = @fwrite($lock, "1");
        @fclose($lock);
        if ($written) {
            $lock_note = $lang->sprintf($lang->upgrade_locked, $config['admin_dir']);
        }
    }
    if (!$written) {
        $lock_note = "<p><b><span style=\"color: red;\">" . $lang->upgrade_removedir . "</span></b></p>";
    }
    // Rebuild inc/settings.php at the end of the upgrade
    if (function_exists('rebuild_settings')) {
        rebuild_settings();
    } else {
        $options = array("order_by" => "title", "order_dir" => "ASC");
        $query = $db->simple_select("settings", "value, name", "", $options);
        while ($setting = $db->fetch_array($query)) {
            $setting['value'] = str_replace("\"", "\\\"", $setting['value']);
            $settings[$setting['name']] = $setting['value'];
        }
    }
    $output->print_contents($lang->sprintf($lang->upgrade_congrats, $mybb->version, $lock_note));
    $output->print_footer();
}