public static final function clearEvents() { wssLog(__METHOD__ . "() triggered."); global $wpdb; $settings = WsdPlugin::getSettings(); $keepMaxEntries = (int) WpsOption::getOption('WPS_KEEP_NUM_ENTRIES_LT'); if ($keepMaxEntries < 1) { $query = "TRUNCATE " . WsdPlugin::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME); $result = $wpdb->query($query); wssLog("Deleting live traffic entries.", array('query' => $query, 'result' => $result)); return; } $optData = WpsOption::getOption(WpsSettings::LIVE_TRAFFIC_ENTRIES); if (empty($optData)) { wssLog("Option (" . WpsSettings::LIVE_TRAFFIC_ENTRIES . ") not found."); return; } $numEntries = $wpdb->get_var("SELECT COUNT(entryId) FROM " . WsdPlugin::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME)); if ($numEntries != $keepMaxEntries) { WpsOption::updateOption(WpsSettings::LIVE_TRAFFIC_ENTRIES, $numEntries); } if (intval($optData) <= $keepMaxEntries) { return; } $tableName = WsdPlugin::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME); $querySelect = "SELECT min(t.entryTime)\n FROM\n (\n SELECT\n entryTime\n FROM\n " . $tableName . "\n ORDER BY\n entryTime DESC\n LIMIT " . $keepMaxEntries . "\n ) AS t"; $deleteFromTime = $wpdb->get_var($querySelect); $queryDelete = "DELETE FROM " . $tableName . " WHERE entryTime < %s"; $result = $wpdb->query($wpdb->prepare($queryDelete, $deleteFromTime)); wssLog("Deleting live traffic entries.", array('query' => "DELETE FROM {$tableName} WHERE entryTime < {$deleteFromTime}", 'deleted' => $result)); if (false === $result) { return; } // update option $numEntries = $wpdb->get_var("SELECT COUNT(entryId) FROM " . WsdPlugin::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME)); WpsOption::updateOption(WpsSettings::LIVE_TRAFFIC_ENTRIES, $numEntries); }
public static function stopScan($completed = false, $failReason = '') { $scanID = self::$_scanID; if (empty($scanID)) { $optData = WpsOption::getOption(WpsSettings::WP_FILE_SCAN_OPTION_NAME); if (empty($optData)) { wssLog('Empty $optData. Checking db table for any incomplete scan.'); $sid = WsdWpScanner::getLastScanID_table(); if (empty($sid)) { wssLog('No incomplete scans found either.'); return; } else { wssLog("Incomplete scan found: {$sid}"); $scanID = $sid; } } else { $scanID = $optData['SCAN_ID']; if (empty($scanID)) { return; } } } $m = __METHOD__ . '() '; wssLog($m . 'triggered.'); if ($completed) { self::_markScanCompleted(); } else { wssLog('Fail reason: ' . $failReason); self::_markScanFailed($scanID, $failReason); } WsdWPScanSettings::deleteSettings(); wssLog('Scan (' . $scanID . ') marked as ' . ($completed ? 'completed' : 'failed') . ' and options deleted.' . PHP_EOL . str_repeat('=', 50)); }
function _wpsSiteActivate($mu = false, $blogID = 1) { wssLog(__FUNCTION__ . "() called with args: ", array('$mu' => $mu, '$blogID' => $blogID)); //#! check if already installed if MU if ($mu) { return WsdPlugin::networkActivate(); } else { return WsdPlugin::activate(); } }
$scanState = $scanSettings['SCAN_STATE']; $scanType = $scanSettings['SCAN_TYPE']; $scanID = $scanSettings['SCAN_ID']; //#! Check if this is a request to delete scans if (isset($_POST['deleteScan'])) { $scanID = intval($_POST['deleteScan']); wssLog('Receiving delete scan command for scan ID: ', $scanID); if (WsdWpScanner::isValidScan($scanID)) { if (!WsdWpScanner::deleteScan($scanID)) { echo '<script type="text/javascript">alert("Error: Could not delete scan. Scan ID = "+' . $scanID . ');</script>'; } } else { echo '<script type="text/javascript">alert("Invalid scan id provided: "+' . $scanID . ');</script>'; } } elseif (isset($_POST['deleteAllScans'])) { wssLog('Receiving command: delete all scans.'); if (WsdWpScanner::deleteAllScans()) { $eInfo['message'] = 'All scans have been deleted.'; } else { $eInfo['error'] = 'An error occurred while deleting the scans. Please try again in a few moments.'; } } else { // scanType if (isset($_POST['scanType'])) { $type = intval($_POST['scanType']); $eInfo['message'] = $type; $scanSettings = WsdWPScanSettings::getSettings(); $scanProgress = $scanSettings['SCAN_PROGRESS']; $scanState = $scanSettings['SCAN_STATE']; $scanType = $scanSettings['SCAN_TYPE']; $result = WsdWpScanner::registerScan($type);
static function activate() { wssLog(__METHOD__ . '() executed'); global $wpdb; $charset_collate = ''; if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } // MUST HAVE "CREATE" RIGHTS if a table is not found and needs to be created $rights = WsdInfoServer::getDatabaseUserAccessRights(); wssLog('USER RIGHTS', $rights); $hasCreateRight = in_array('CREATE', $rights['rightsHaving']); // Must have alter right for updating table $hasAlterRight = in_array('CREATE', $rights['rightsHaving']); $table1 = self::getTableName(WpsSettings::ALERTS_TABLE_NAME); $table2 = self::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME); $table3 = self::getTableName(WpsSettings::SCAN_TABLE_NAME); $table4 = self::getTableName(WpsSettings::SCANS_TABLE_NAME); if (!WsdUtil::tableExists($table1)) { wssLog("table not found: {$table1}"); if (!$hasCreateRight) { wssLog("user has no create right. cannot create table: {$table1}"); $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query1 = "CREATE TABLE IF NOT EXISTS {$table1} (\n `alertId` INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n `alertType` TINYINT NOT NULL DEFAULT 0 ,\n `alertSeverity` INT NOT NULL DEFAULT 0 ,\n `alertActionName` VARCHAR (255) NOT NULL,\n `alertTitle` VARCHAR(255) NOT NULL ,\n `alertDescription` TEXT NOT NULL ,\n `alertSolution` TEXT NOT NULL ,\n `alertDate` DATETIME NOT NULL default '0000-00-00 00:00:00',\n `alertFirstSeen` DATETIME NOT NULL default '0000-00-00 00:00:00',\n PRIMARY KEY (`alertId`) ,\n UNIQUE INDEX `alertId_UNIQUE` (`alertId` ASC) ) {$charset_collate};"; $result = @$wpdb->query($query1); if ($result === false) { //#! MySQL error $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query1}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("table created: {$table1}"); } $alterCheck = true; if (!WsdUtil::tableExists($table2)) { wssLog("table not found: {$table2}"); if (!$hasCreateRight) { $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query2 = "CREATE TABLE IF NOT EXISTS {$table2} (\n `entryId` bigint(20) unsigned NOT NULL auto_increment,\n `entryTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n `entryIp` text,\n `entryReferrer` text,\n `entryUA` text,\n `entryRequestedUrl` text,\n `entryCountry` varchar(125) not null,\n `entryCity` varchar(125) not null,\n `blogId` INT(10) NOT NULL DEFAULT 1,\n PRIMARY KEY (entryId)) {$charset_collate};"; $result = @$wpdb->query($query2); if ($result === false) { //#! MySQL error $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query2}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $alterCheck = false; wssLog("table created: {$table2}."); } if ($alterCheck) { wssLog("Alter check needed for {$table2}."); if (!$hasAlterRight) { wssLog('NO ALTER RIGHT'); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>ALTER</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } // Get columns $query = "SHOW COLUMNS FROM {$table2}"; $cols = $wpdb->get_results($query, ARRAY_A); $columns = array(); if (empty($cols)) { wssLog("Could not retrieve columns from table: {$table2}"); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query}</pre></strong>. Please inform the plugin author about this error."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } foreach ($cols as $i => $values) { if (isset($values['Field']) && !empty($values['Field'])) { array_push($columns, $values['Field']); } } $entryCountryExists = $entryCityExists = $blogIdExists = false; if (in_array('entryCountry', $columns)) { $entryCountryExists = true; } if (in_array('entryCity', $columns)) { $entryCityExists = true; } if (in_array('blogId', $columns)) { $blogIdExists = true; } //## Check for column: entryCountry wssLog("Checking for column: entryCountry"); if (!$entryCountryExists) { // alter table $q = "ALTER TABLE {$table2} ADD COLUMN `entryCountry` VARCHAR(125) NOT NULL DEFAULT '' AFTER `entryRequestedUrl`;"; $result = @$wpdb->query($q); if ($result === false) { wssLog('MySql error: ' . mysql_error()); wssLog("Error running query: {$q}"); //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("Column: entryCountry not found in table {$table2}. but was added."); } else { wssLog("column already exists: entryCountry"); } //## Check for column: entryCity wssLog("Checking for column: entryCity"); if (!$entryCityExists) { $q = "ALTER TABLE {$table2} ADD COLUMN `entryCity` VARCHAR(125) NOT NULL DEFAULT '' AFTER `entryCountry`;"; $result = @$wpdb->query($q); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("Column: entryCity not found in table {$table2}. but was added."); } else { wssLog("column already exists: entryCity"); } //## Check for column: blogId wssLog("Checking for column: blogId"); if (!$blogIdExists) { $q = "ALTER TABLE {$table2} ADD COLUMN `blogId` INT(10) NOT NULL DEFAULT 1 AFTER `entryCity`;"; $result = @$wpdb->query($q); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("Column: blogId not found in table {$table2}. but was added."); } else { wssLog("column already exists: blogid"); } wssLog("{$table2} updated successfully"); } if (!WsdUtil::tableExists($table3)) { wssLog("table not found: {$table3}"); if (!$hasCreateRight) { $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query3 = "CREATE TABLE IF NOT EXISTS {$table3} (\n `entryId` BIGINT NOT NULL AUTO_INCREMENT ,\n `scanId` INT NOT NULL ,\n `filePath` VARCHAR(1000) NOT NULL ,\n `dateModified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,\n `fileNotFound` TINYINT NOT NULL DEFAULT 0,\n PRIMARY KEY (`entryId`) ,\n UNIQUE INDEX `entryId_UNIQUE` (`entryId` ASC) ) {$charset_collate};"; $result = @$wpdb->query($query3); if ($result === false) { //#! MySQL error $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query3}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("table created: {$table3}."); } if (!WsdUtil::tableExists($table4)) { wssLog("table not found: {$table4}"); if (!$hasCreateRight) { $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query4 = "CREATE TABLE {$table4} (\n `scanId` INT NOT NULL AUTO_INCREMENT ,\n `scanStartDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n `scanEndDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n `scanResult` INT NOT NULL DEFAULT 0,\n `failReason` VARCHAR(5000) NOT NULL DEFAULT '',\n `scanType` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`scanId`) ) {$charset_collate};"; $result = @$wpdb->query($query4); if ($result === false) { //#! MySQL error $notices = WpsOption::getOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query4}</pre></strong>."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } WpsOption::addOption(WpsSettings::CAN_RUN_TASKS_OPTION_NAME, 1); return true; }
} else { // show $rssWidgetChecked = true; WpsOption::updateOption('WSD-RSS-WGT-DISPLAY', 'yes'); } // live traffic $liveTrafficEnabled = isset($_POST['chk_lt_display']) ? intval($_POST['chk_lt_display']) : 0; if (empty($liveTrafficEnabled)) { // hide $enableLiveTraffic = false; WpsOption::updateOption(WpsSettings::ENABLE_LIVE_TRAFFIC, false); } else { // show $enableLiveTraffic = true; WpsOption::updateOption(WpsSettings::ENABLE_LIVE_TRAFFIC, true); wssLog("Live traffic tool enabled."); } WpsOption::updateOption(WpsSettings::PLUGIN_SETTINGS_OPTION_NAME, $settings); $settings = WpsOption::getOption(WpsSettings::PLUGIN_SETTINGS_OPTION_NAME); } elseif (isset($_POST['deleteRssDataButton'])) { WpsOption::deleteOption(WpsSettings::FEED_DATA_OPTION_NAME); } } ?> <div class="wrap wsdplugin_content"> <h2><?php echo WPS_PLUGIN_NAME . ' - ' . __('Settings', WpsSettings::TEXT_DOMAIN); ?> </h2> <p class="clear"></p>