Ejemplo n.º 1
0
/**
 * Process the requests sent by the form submissions originated in the infosys
 * page, all forms must have a nonce field that will be checked against the one
 * generated in the template render function.
 *
 * @param  boolean $page_nonce True if the nonce is valid, False otherwise.
 * @return void
 */
function sucuriscan_infosys_form_submissions()
{
    if (SucuriScanInterface::check_nonce()) {
        // Modify the scheduled tasks (run now, remove, re-schedule).
        $allowed_actions = '(runnow|hourly|twicedaily|daily|remove)';
        if ($cronjob_action = SucuriScanRequest::post(':cronjob_action', $allowed_actions)) {
            $cronjobs = SucuriScanRequest::post(':cronjobs', '_array');
            if (!empty($cronjobs)) {
                $total_tasks = count($cronjobs);
                // Force execution of the selected scheduled tasks.
                if ($cronjob_action == 'runnow') {
                    SucuriScanInterface::info($total_tasks . ' tasks were scheduled to run in the next ten seconds.');
                    SucuriScanEvent::report_notice_event(sprintf('Force execution of scheduled tasks: (multiple entries): %s', @implode(',', $cronjobs)));
                    foreach ($cronjobs as $task_name) {
                        wp_schedule_single_event(time() + 10, $task_name);
                    }
                } elseif ($cronjob_action == 'remove') {
                    SucuriScanInterface::info($total_tasks . ' scheduled tasks were removed.');
                    SucuriScanEvent::report_notice_event(sprintf('Delete scheduled tasks: (multiple entries): %s', @implode(',', $cronjobs)));
                    foreach ($cronjobs as $task_name) {
                        wp_clear_scheduled_hook($task_name);
                    }
                } elseif ($cronjob_action == 'hourly' || $cronjob_action == 'twicedaily' || $cronjob_action == 'daily') {
                    SucuriScanInterface::info($total_tasks . ' tasks were re-scheduled to run <code>' . $cronjob_action . '</code>.');
                    SucuriScanEvent::report_notice_event(sprintf('Re-configure scheduled tasks %s: (multiple entries): %s', $cronjob_action, @implode(',', $cronjobs)));
                    foreach ($cronjobs as $task_name) {
                        wp_clear_scheduled_hook($task_name);
                        $next_due = wp_next_scheduled($task_name);
                        wp_schedule_event($next_due, $cronjob_action, $task_name);
                    }
                }
            } else {
                SucuriScanInterface::error('No scheduled tasks were selected from the list.');
            }
        }
    }
}