/** * Handles the plugin options. */ public function handleOptions() { global $wpdb; $this->options = get_option('wemahu'); $WemahuForms = new Wemahu_Forms($this->options); register_setting('wemahu', 'wemahu', array($WemahuForms, 'sanitizeInput')); // General options add_settings_section('wemahu_general_settings', 'Genreal Settings', array($WemahuForms, 'displaySectionInfoGeneral'), 'wemahu_settings_page'); add_settings_field('use_api', 'Allow API usage', array($WemahuForms, 'displayCheckboxInput'), 'wemahu_settings_page', 'wemahu_general_settings', array('name' => 'use_api', 'id' => 'use_api', 'group' => 'wemahu', 'desc' => 'Allows the plugin to contact nekudo.com to send and receive data. This includes signature/whitelist updates e.g.')); // Cronjob options $ModelRuleset = new ModelRuleset($wpdb); $rulesetValues = array(); $rulesetData = $ModelRuleset->getRulesets(); foreach ($rulesetData as $ruleset) { $rulesetValues[$ruleset['id']] = $ruleset['name']; } add_settings_section('wemahu_cronjob_settings', 'Cronjob Settings', array($WemahuForms, 'displaySectionInfoCronjob'), 'wemahu_settings_page'); add_settings_field('cron_ruleset', 'Cronjob ruleset', array($WemahuForms, 'displayDropdownInput'), 'wemahu_settings_page', 'wemahu_cronjob_settings', array('label_for' => 'cron_ruleset', 'name' => 'cron_ruleset', 'values' => $rulesetValues, 'id' => 'cron_ruleset', 'group' => 'wemahu', 'desc' => 'Here you can select the ruleset that will be used by wemahu cronjobs.')); add_settings_field('cron_sendmail', 'Send report email', array($WemahuForms, 'displayCheckboxInput'), 'wemahu_settings_page', 'wemahu_cronjob_settings', array('name' => 'cron_sendmail', 'id' => 'cron_sendmail', 'group' => 'wemahu', 'desc' => 'Set if the Wemahu cron script should send a report by email.')); add_settings_field('cron_emptyreport', 'Send empty reports', array($WemahuForms, 'displayCheckboxInput'), 'wemahu_settings_page', 'wemahu_cronjob_settings', array('name' => 'cron_emptyreport', 'id' => 'cron_emptyreport', 'group' => 'wemahu', 'desc' => 'Set if you want to receive and email even if the report is empty.')); add_settings_field('cron_email', 'Report email address', array($WemahuForms, 'displayTextInput'), 'wemahu_settings_page', 'wemahu_cronjob_settings', array('label_for' => 'cron_email', 'name' => 'cron_email', 'id' => 'cron_email', 'group' => 'wemahu', 'desc' => 'This is the email-address cronjob reports will be send to. Leave empty to use wordpress system email-address.', 'classes' => 'regular-text ltr')); }
/** * Inits wemahu scanner by passing necessary objects like settings and database. * */ public function initWemahu() { $rulesetId = (int) $_POST['ruleset']; if (empty($rulesetId)) { $this->returnError('No ruleset selected.'); } $ModelRuleset = new ModelRuleset($this->wpdb); $rulesetData = $ModelRuleset->getRulesetData($rulesetId); if (empty($rulesetData)) { $this->returnError('Invalid ruleset.'); } // prepare Wemahu settings: $WemahuSettings = new Wemahu\Settings(); $WemahuSettings->intervalMode = true; $WemahuSettings->useApi = (int) $this->options['use_api'] === 1 ? true : false; $WemahuSettings->audits['filecheck'] = (int) $rulesetData['filecheck'] === 1 ? true : false; $WemahuSettings->auditSettings['filecheck']['regexCheck'] = (int) $rulesetData['regex_check'] === 1 ? true : false; $WemahuSettings->auditSettings['filecheck']['hashCheck'] = (int) $rulesetData['hash_check'] === 1 ? true : false; $WemahuSettings->auditSettings['filecheck']['scanDir'] = ABSPATH; $WemahuSettings->auditSettings['filecheck']['tmpDir'] = WP_PLUGIN_DIR . '/wemahu/tmp'; $WemahuSettings->auditSettings['filecheck']['pathRegexWhitelistUser'] = WP_PLUGIN_DIR . '/wemahu/tmp/wemahu_regex_whitelist.wmdb'; if (!empty($rulesetData['scandir'])) { $WemahuSettings->auditSettings['filecheck']['scanDir'] = $rulesetData['scandir']; } $WemahuSettings->auditSettings['filecheck']['scanDir'] = rtrim($WemahuSettings->auditSettings['filecheck']['scanDir'], '/'); if (!empty($rulesetData['regex_db'])) { $WemahuSettings->auditSettings['filecheck']['pathRegexDb'] = WP_PLUGIN_DIR . '/wemahu/admin/libs/wemahu/db/' . $rulesetData['regex_db'] . '.wmdb'; } if (!empty($rulesetData['filetypes'])) { $WemahuSettings->auditSettings['filecheck']['extensionFilter'] = $rulesetData['filetypes']; } if (!empty($rulesetData['filesize_max'])) { $WemahuSettings->auditSettings['filecheck']['sizeFilter'] = $rulesetData['filesize_max']; } if (!empty($rulesetData['max_results_file'])) { $WemahuSettings->auditSettings['filecheck']['maxResultsFile'] = $rulesetData['max_results_file']; } if (!empty($rulesetData['max_results_total'])) { $WemahuSettings->auditSettings['filecheck']['maxResultsTotal'] = $rulesetData['max_results_total']; } if ($WemahuSettings->auditSettings['filecheck']['hashCheck'] === true && !empty($rulesetData['hash_check_blacklist'])) { $WemahuSettings->auditSettings['filecheck']['hashCheckBlacklist'] = explode("\n", str_replace("\r", "", $rulesetData['hash_check_blacklist'])); } // Init Wemahu: $Wemahu = new Wemahu\Wemahu(); $Wemahu->setSettings($WemahuSettings); $WemahuStorage = new Wemahu\Storage(); $Wemahu->setStorage($WemahuStorage); $WemahuDatabase = new Wemahu\WordpressDatabase($this->wpdb); $Wemahu->setDatabase($WemahuDatabase); $initResult = $Wemahu->init(); // Send Response: if ($initResult === false) { $this->JsonResponse->setError('Wemahu initialization failed.'); } $auditMessages = $Wemahu->getAuditMessages(); $auditMessagesHtml = implode('<br />', $auditMessages) . '<br />'; $this->JsonResponse->setType('init_success'); $this->JsonResponse->setData('init_msg', $auditMessagesHtml); echo $this->JsonResponse->getResponseData(); exit; }