function save() { $rValue = false; if ($this->name != "" && $this->project_id != "" && $this->version != "") { global $dbh; if ($this->file_id == 0) { $this->file_id = $this->getFileID($this->name, $this->project_id, $this->version); } $sql = "INSERT INTO"; $where = ""; if ($this->file_id > 0) { $sql = "UPDATE"; $where = " WHERE file_id = " . sqlSanitize($this->file_id, $dbh); } $Event = new EventLog("files", "file_id", $this->file_id, $sql); $sql .= " files \n\t\t\t\t\t\tSET file_id \t= " . sqlSanitize($this->file_id, $dbh) . ",\n\t\t\t\t\t\t\tproject_id\t= " . returnQuotedString(sqlSanitize($this->project_id, $dbh)) . ", \n\t\t\t\t\t\t\tversion\t\t= " . returnQuotedString(sqlSanitize($this->version, $dbh)) . ", \n\t\t\t\t\t\t\tname\t\t= " . returnQuotedString(sqlSanitize($this->name, $dbh)) . ",\n\t\t\t\t\t\t\tplugin_id\t= " . returnQuotedString(sqlSanitize($this->plugin_id, $dbh)) . ",\n\t\t\t\t\t\t\tis_active\t= " . $this->is_active . $where; if (mysql_query($sql, $dbh)) { if ($this->file_id == 0) { $this->file_id = mysql_insert_id($dbh); $Event->key_value = $this->file_id; } $rValue = true; $Event->add(); } else { echo $sql . "\n"; $GLOBALS['g_ERRSTRS'][1] = mysql_error(); } } else { echo "ERROR: One missing:Name: " . $this->name . "Project: " . $this->project_id . "Version: " . $this->version; } return $rValue; }
private function logEvent($event) { $evenId = $event['event'] ? $this->findOrCreate(array('name' => $event['event']), array('name')) : null; $classId = $this->getObject($event['object']) ? $this->systemClassRepository->findOrCreate(array('name' => $this->getObject($event['object'])), array('name')) : null; if ($evenId) { $this->eventLogRepository->create(array('log_id' => $this->logRepository->getCurrentLogId(), 'event_id' => $evenId, 'class_id' => $classId)); } }
private function logEvent($event) { file_put_contents('/tmp/event.txt', $this->eventStorage->isOn() ? 'on' : 'off' . ' - event = ' . $event['event'] . ' -- object = ' . $this->getObject($event['object']) . "\n", FILE_APPEND); $evenId = $event['event'] ? $this->findOrCreate(array('name' => $event['event']), array('name')) : null; $classId = $this->getObject($event['object']) ? $this->systemClassRepository->findOrCreate(array('name' => $this->getObject($event['object'])), array('name')) : null; if ($evenId) { $this->eventLogRepository->create(array('log_id' => $this->logRepository->getCurrentLogId(), 'event_id' => $evenId, 'class_id' => $classId)); } }
public function logEvent($event) { $event = $this->makeEventArray($event); $evenId = $this->getEventId($event); if ($evenId) { $objectName = $this->getObjectName($event); $classId = $this->getClassId($objectName); $this->eventLogRepository->create(array('log_id' => $this->logRepository->getCurrentLogId(), 'event_id' => $evenId, 'class_id' => $classId)); } }
public function relayAction($request) { if (!isset($this->settings['short' . $request->area])) { return null; } $db = JFactory::getDBO(); $rewriting = array('short', 'tags', 'text', 'params'); foreach ($rewriting as $rw_name) { $this->settings[$rw_name . $request->area] = AECToolbox::rewriteEngineRQ($this->settings[$rw_name . $request->area], $request); } $log_entry = new EventLog(); $log_entry->issue($this->settings['short' . $request->area], $this->settings['tags' . $request->area], $this->settings['text' . $request->area], $this->settings['level' . $request->area], $this->settings['params' . $request->area], $this->settings['force_notify' . $request->area], $this->settings['force_email' . $request->area]); }
/** * Executes the cronjob. * * @param mixed $last_result What the last execution of this cronjob * returned. * @param Array $parameters Parameters for this cronjob instance which * were defined during scheduling. */ public function execute($last_result, $parameters = array()) { $event_log = new EventLog(); $event_log->cleanup_log_events(); if (!empty($parameters['cronjobs'])) { $delete = function ($l) { $l->delete(); }; if ($parameters['cronjobs-error'] > 0) { CronjobLog::findEachBySql($delete, "exception != 'N;' AND executed + ? < UNIX_TIMESTAMP()", array($parameters['cronjobs-error'] * 24 * 60 * 60)); } if ($parameters['cronjobs-success'] > 0) { CronjobLog::findEachBySql($delete, "exception = 'N;' AND executed + ? < UNIX_TIMESTAMP()", array($parameters['cronjobs-success'] * 24 * 60 * 60)); } } }
/** * filter_dash_module_latest_log_activity * Sets theme variables and handles logic for the * dashboard's log history module. * @param string $module_id * @return string The contents of the module */ public function filter_dash_module_latest_log_activity( $module, $module_id, $theme ) { if ( false === ( $num_logs = Modules::get_option( $module_id, 'logs_number_display' ) ) ) { $num_logs = 8; } $params = array( 'where' => array( 'user_id' => User::identify()->id ), 'orderby' => 'id DESC', /* Otherwise, exactly same timestamp values muck it up... Plus, this is more efficient to sort on the primary key... */ 'limit' => $num_logs, ); $theme->logs = EventLog::get( $params ); // Create options form /* Commented out until fully implemented or it's decided to drop completely. See https://trac.habariproject.org/habari/ticket/1233 $form = new FormUI( 'dash_logs' ); $form->append( 'text', 'logs_number_display', 'option:' . Modules::storage_name( $module_id, 'logs_number_display' ), _t('Number of items') ); $form->append( 'submit', 'submit', _t('Submit') ); $form->properties['onsubmit'] = "dashboard.updateModule({$module_id}); return false;"; */ $module['title'] = ( User::identify()->can( 'manage_logs' ) ? '<a href="' . Site::get_url('admin') . '/logs">' . _t('Latest Log Activity') . '</a>' : _t('Latest Log Activity') ); //$module['options'] = $form->get(); $module['content'] = $theme->fetch( 'dash_logs' ); return $module; }
public function filter_linkit_fetch($success) { $stats = $this->api_getstats(); EventLog::log(_t('Running dashboard fetch for 123LinkIt', 'linkit'), 'info', null, null, $stats); Options::set('linkit__stats', $stats); return $success; }
/** * Produce the content for the latest log activity block * @param Block $block The block object * @param Theme $theme The theme that the block will be output with */ public function action_block_content_latest_log_activity($block, $theme) { $params = array('where' => array('user_id' => User::identify()->id), 'orderby' => 'id DESC', 'limit' => isset($block->logs_number_display) ? $block->logs_number_display : 8); $block->logs = EventLog::get($params); $block->link = URL::get('admin', array('page' => 'logs')); $block->has_options = true; }
/** * Constructor for RenderCache * * Sets up paths and gets the list of groups from file */ public static function __static() { //Define the cache path and url self::$cache_path = HABARI_PATH . '/' . self::$rel_cache_path; self::$cache_url = Site::get_url('habari') . '/' . self::$rel_cache_path; //If the cache directory doesn't exist, make it if (!is_dir(self::$cache_path)) { mkdir(self::$cache_path, 0755); } //Enable only if the cache directory now exists and is writable self::$enabled = is_dir(self::$cache_path) && is_writeable(self::$cache_path); //Give an error if the cache directory is not writable if (!self::$enabled) { Session::error(sprintf(_t("The cache directory '%s' is not writable - the cache is disabled. The user, or group, which your web server is running as, needs to have read, write, and execute permissions on this directory."), self::$cache_path), 'RenderCache'); EventLog::log(sprintf(_t("The cache directory '%s' is not writable - the cache is disabled."), self::$cache_path), 'notice', 'RenderCache', 'habari'); return; } //Get the list of group names $group_file = self::get_group_list_file(); if (file_exists($group_file)) { self::$group_list = unserialize(file_get_contents($group_file)); } else { self::$group_list = array(); } }
public function filter_default_rewrite_rules($rules) { if ($this->current_load() > self::KILL_LOAD) { foreach ($rules as $key => $rule) { if (strpos($rule['build_str'], 'admin') !== false) { $rules[$key]['handler'] = 'UserThemeHandler'; $rules[$key]['action'] = 'display_throttle'; } } if (Options::get('throttle') == '') { EventLog::log(sprintf(_t('Kill - Load is %s'), $this->current_load())); Options::set('throttle', 'kill'); } } elseif ($this->current_load() > self::MAX_LOAD) { foreach ($rules as $key => $rule) { if ($rule['name'] == 'search') { unset($rules[$key]); } } $rules[] = array('name' => 'search', 'parse_regex' => '%^search(?:/(?P<criteria>[^/]+))?(?:/page/(?P<page>\\d+))?/?$%i', 'build_str' => 'search(/{$criteria})(/page/{$page})', 'handler' => 'UserThemeHandler', 'action' => 'display_throttle', 'priority' => 8, 'description' => 'Searches posts'); if (Options::get('throttle') == '') { EventLog::log(sprintf(_t('Restrict - Load is %s'), $this->current_load())); Options::set('throttle', 'restrict'); } } else { if (Options::get('throttle') != '') { EventLog::log(sprintf(_t('Normal - Load is %s'), $this->current_load())); Options::set('throttle', ''); } } return $rules; }
public function filter_optimize_database($result, $paramarray) { $space_saved = 0; $tables = 0; switch (DB::get_driver_name()) { case 'mysql': $q = 'SHOW TABLE STATUS WHERE data_free > 0'; $tables = DB::get_results($q); if (count($tables) > 0) { foreach ($tables as $table) { $q2 = 'OPTIMIZE TABLE ' . $table->Name; if (DB::query($q2)) { $space_saved += $table->Data_free; $tables++; } } EventLog::log('Database Tables Optimized. ' . Utils::human_size($space_saved) . ' reclaimed from ' . HabariLocale::_n('table', 'tables', $tables) . '.'); } $result = true; break; case 'sqlite': if (DB::exec('VACUUM')) { $result = true; EventLog::log('SQLite database VACUUM\'ed successfully.'); } else { $result = false; } break; default: $result = false; break; } return $result; }
function migrate() { global $conn; $sql = getMigrateQueryHeader(); $sql .= Customer::getSchemaSQL(); $sql .= CustomerCar::getSchemaSQL(); $sql .= EventLog::getSchemaSQL(); $sql .= GreaseRatEvent::getSchemaSQL(); $sql .= RepairPost::getSchemaSQL(); $sql .= RepairType::getSchemaSQL(); $sql .= User::getSchemaSQL(); if ($conn->multi_query($sql)) { do { if ($result = $conn->store_result()) { while ($row = $result->fetch_row()) { printf("%s\n", $row[0]); } $result->free(); } if ($conn->more_results()) { printf("-----------------\n"); } } while ($conn->next_result()); } $conn->close(); }
public function filter_rssblocks_update($success, $force = false) { EventLog::log('Running rrsblocks update'); $blocks = DB::get_results('SELECT b.* FROM {blocks} b WHERE b.type = ?', array('rssblock'), 'Block'); Plugins::act('get_blocks', $blocks); $success = true; foreach ($blocks as $block) { $cachename = array('rssblock', md5($block->feed_url)); if ($force || Cache::expired($cachename)) { $r = new RemoteRequest($block->feed_url); $r->set_timeout(10); $r->execute(); $feed = $r->get_response_body(); try { if (is_string($feed)) { new SimpleXMLElement($feed); // This throws an exception if the feed isn't valid Cache::set($cachename, $feed, 3600, true); } } catch (Exception $e) { $success = false; } } } Session::notice('ran rssblocks update'); return $success; }
function load($email, $password) { if ($email != "" && $password != "") { if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z.]{2,5}$', $email)) { global $addon; $addon->callHook('user_authentication', array(&$this, $email, $password)); } } if ($this->userid > 0) { $Event = new EventLog("users", "userid", $this->userid, "__auth_success"); $Event->add(); } else { $Event = new EventLog("users", "userid", $_SERVER['REMOTE_ADDR'] . ":" . $email, "__auth_failure"); $Event->add(); } return $this->userid; }
function action_comment_insert_before($comment) { // This plugin ignores non-comments and comments already marked as spam if ($comment->type == Comment::COMMENT && $comment->status != Comment::STATUS_SPAM) { $comment->status = Comment::STATUS_APPROVED; EventLog::log('Comment by ' . $comment->name . ' automatically approved.', 'info', 'autoapprove', 'autoapprove'); } return $comment; }
function action_admin_moderate_comments($action, $comments, $handler) { if ($action == 'approve' || $action == 'approved') { foreach ($comments as $c) { $this->update_post_modified($c->post_id); EventLog::log('bumped post ' . $c->post_id . ', by admin approval', 'info', 'default', 'bumping'); } } }
function action_auth_ajax_extendedlog($handler) { $log = EventLog::get(array('fetch_fn' => 'get_row', 'id' => $handler->handler_vars['log_id'], 'return_data' => true)); if (trim($log->data) == '') { $log->data = 'No additional data was logged.'; } echo $log->message . "<hr>\n"; echo $log->data; }
/** * Constructor for APCCache */ public function __construct() { $this->prefix = Options::get('private-GUID'); $this->enabled = extension_loaded('apc'); if (!$this->enabled) { Session::error(_t("The APC Cache PHP module is not loaded - the cache is disabled.", "apccache"), 'filecache'); EventLog::log(_t("The APC Cache PHP module is not loaded - the cache is disabled.", "apccache"), 'notice', 'cache', 'apccache'); } }
/** * Reject form submission (and repopulate the form) if the captcha fails. * ... * @return array Message to return upon failure **/ public function validate_captcha($unused, $control, $form) { $solvemedia_response = solvemedia_check_answer(Options::get('solvemedia__vkey'), $_SERVER["REMOTE_ADDR"], $_POST["adcopy_challenge"], $_POST["adcopy_response"], Options::get('solvemedia__hkey')); if ($solvemedia_response->is_valid) { EventLog::log(_t('Comment by %s approved by SolveMedia captcha.', array($comment->name), 'solvemedia'), 'info', 'comment', 'SolveMedia'); } else { return array(_t('Your CAPTCHA attempt did not succeed: %s', array($solvemedia_response->error), 'solvemedia')); } }
/** * gets info for a counterparty asset * @param string $asset * @return Response * */ public function get(Cache $asset_info_cache, $asset) { $asset = $asset_info_cache->get(strtoupper($asset)); if (!$asset) { $message = "The asset {$asset} could not be found"; EventLog::logError('error.getAsset', ['asset' => $asset, 'message' => $message]); return new JsonResponse(['message' => $message], 500); } return json_encode($asset); }
public function filter_activate_plugin($ok, $file) { // Don't bother loading if the gd library isn't active if (!function_exists('imagecreatefromjpeg')) { EventLog::log(_t("S3 Silo activation failed. PHP has not loaded the gd imaging library."), 'warning', 'plugin'); Session::error(_t("S3 Silo activation failed. PHP has not loaded the gd imaging library.")); $ok = false; } return $ok; }
public function action_comment_insert_before($comment) { if ($comment->type == Comment::COMMENT && $comment->status != Comment::STATUS_SPAM) { if ($this->check_comment($comment) === false) { $comment->status = Comment::STATUS_SPAM; EventLog::log(sprintf(_t("Comment by %s automatically marked as spam", 'simpleblacklist'), $comment->name), 'info', 'Simple Blacklist', 'plugin'); } } return $comment; }
function action_comment_insert_before($comment) { // This plugin ignores non-comments and comments already marked as spam if ($comment->type == Comment::COMMENT && $comment->status != Comment::STATUS_SPAM) { if (Comments::get(array('email' => $comment->email, 'name' => $comment->name, 'url' => $comment->url, 'status' => Comment::STATUS_APPROVED))->count >= Options::get('preapproved__approved_count')) { $comment->status = Comment::STATUS_APPROVED; EventLog::log('Comment by ' . $comment->name . ' automatically approved.', 'info', 'PreApproved', 'PreApproved'); } } return $comment; }
/** * Constructor for MemcacheCache * * Sets up paths etc. and reads cache index, if it exists. */ public function __construct() { $this->prefix = Options::get('GUID'); $this->enabled = extension_loaded('memcache'); if ($this->enabled) { $this->memcache = new Memcache(); $this->memcache->connect(Config::get('memcache_host', 'localhost'), Config::get('memcache_port', 11211)); $this->cache_index = $this->memcache->get('habari:cache:index'); } else { Session::error(_t("The Memcache PHP module is not loaded - the cache is disabled.", "memcache"), 'memcachecache'); EventLog::log(_t("The Memcache PHP module is not loaded - the cache is disabled.", "memcache"), 'notice', 'cache', 'memcachecache'); } }
public function action_init() { //$this->add_template('event.single', dirname(__FILE__) . '/event.single.php'); Post::add_new_type('imageset', false); Post::add_new_type('image', false); Post::add_new_type('gallery', false); CpgDb::registerTables(); //Utils::debug('tables registered!'); if (CpgDb::DB_VERSION > CpgOptions::getDbVersion()) { CpgDb::install(); EventLog::log('Updated CPG.'); CpgOptions::setDbVersion(CpgDb::DB_VERSION); } }
/** * Helper function which automatically assigns all handler_vars * into the theme and displays a theme template * * @param template_name Name of template to display ( note: not the filename ) */ protected function display($template_name) { /* * Assign internal variables into the theme ( and therefore into the theme's template * engine. See Theme::assign(). */ foreach ($this->handler_vars as $key => $value) { $this->theme->assign($key, $value); } try { $this->theme->display($template_name); } catch (Error $e) { EventLog::log($e->humane_error(), 'error', 'theme', 'habari', print_r($e, 1)); } }
public function filter_activate_plugin( $ok, $file ) { if ( Plugins::id_from_file($file) == Plugins::id_from_file(__FILE__) ) { if ( !$this->check_files() ) { EventLog::log( _t( "Habari Silo activation failed. The web server does not have permission to create the 'files' directory for the Habari Media Silo." ), 'warning', 'plugin' ); Session::error( _t( "Habari Silo activation failed. The web server does not have permission to create the 'files' directory for the Habari Media Silo." ) ); $ok = false; } // Don't bother loading if the gd library isn't active if ( !function_exists( 'imagecreatefromjpeg' ) ) { EventLog::log( _t( "Habari Silo activation failed. PHP has not loaded the gd imaging library." ), 'warning', 'plugin' ); Session::error( _t( "Habari Silo activation failed. PHP has not loaded the gd imaging library." ) ); $ok = false; } } return $ok; }
/** * Constructor for FileCache * * Sets up paths etc. and reads cache index, if it exists. */ public function __construct() { if (!defined('FILE_CACHE_LOCATION')) { define('FILE_CACHE_LOCATION', HABARI_PATH . '/user/cache/'); } $this->cache_location = FILE_CACHE_LOCATION; $this->index_file = $this->cache_location . md5('index' . Options::get('GUID')) . '.data'; $this->enabled = is_writeable($this->cache_location); if ($this->enabled) { if (file_exists($this->index_file)) { $this->cache_files = unserialize(file_get_contents($this->index_file)); } } else { Session::error(_t("The cache directory '%s' is not writable - the cache is disabled. The user, or group, which your web server is running as, needs to have read, write, and execute permissions on this directory.", array($this->cache_location)), 'filecache'); EventLog::log(_t("The cache directory '%s' is not writable - the cache is disabled.", array($this->cache_location)), 'notice', 'cache', 'habari'); } }
/** * function undelete_post * This function reverts a post's status from 'deleted' to whatever * it previously was. **/ private function undelete_post($post_id) { $post = Post::get(array('id' => $post_id, 'status' => Post::status('any'))); if ($post->status == Post::status('deleted')) { $post->status = $post->info->prior_status ? $post->info->prior_status : Post::status('draft'); unset($post->info->prior_status); $post->update(); EventLog::log(sprintf(_t('Post %1$s (%2$s) restored.'), $post->id, $post->slug), 'info', 'content', 'habari'); //scheduled post if ($post->status == Post::status('scheduled')) { Posts::update_scheduled_posts_cronjob(); } return true; } else { return false; } }