/** 
  * Returns a log entry by ID
  */
 public static function getByID($logID)
 {
     $db = Loader::db();
     $r = $db->Execute("select * from Logs where logID = ?", array($logID));
     if ($r) {
         $row = $r->FetchRow();
         $obj = new LogEntry();
         $obj->setPropertiesFromArray($row);
         return $obj;
     }
 }
Ejemplo n.º 2
0
function checkLogin()
{
    session_start();
    if (!$_SESSION["member"] or !($_SESSION["member"] = Member::getMember($_SESSION["member"]->getValue("id")))) {
        $_SESSION["member"] = "";
        header("Location: login.php");
        exit;
    } else {
        $logEntry = new LogEntry(array("memberId" => $_SESSION["member"]->getValue("id"), "pageUrl" => basename($_SERVER["PHP_SELF"])));
        $logEntry->record();
    }
}
Ejemplo n.º 3
0
 /**
  * Schreibt einen Fehler in die DB
  * @static
  * @param int|string Error-Level
  * @param string Fehlermeldung
  * @param string Datei, in der der Fehler aufgetreten ist
  * @param int Zeilennummer
  */
 private static function log($level, $message, $file, $line, $sender = NULL)
 {
     $entry = new LogEntry();
     $entry->level = self::level2string($level);
     $entry->message = $message;
     $entry->file = $file;
     $entry->line = $line;
     $entry->sender = $sender;
     $entry->log = 'php';
     $entry->save();
     if (DEV_MODE) {
         echo $message . "\n" . $file . ":" . line;
     }
 }
Ejemplo n.º 4
0
 /**
  * Constructs a new formatter suitable for given entry.
  * @param LogEntry $entry
  * @return LogFormatter
  */
 public static function newFromEntry(LogEntry $entry)
 {
     global $wgLogActionsHandlers;
     $fulltype = $entry->getFullType();
     $wildcard = $entry->getType() . '/*';
     $handler = '';
     if (isset($wgLogActionsHandlers[$fulltype])) {
         $handler = $wgLogActionsHandlers[$fulltype];
     } elseif (isset($wgLogActionsHandlers[$wildcard])) {
         $handler = $wgLogActionsHandlers[$wildcard];
     }
     if ($handler !== '' && is_string($handler) && class_exists($handler)) {
         return new $handler($entry);
     }
     return new LegacyLogFormatter($entry);
 }
Ejemplo n.º 5
0
 public function logIt(LogEntry $entry)
 {
     $type = $entry->getType();
     $message = $entry->getMessage();
     $userID = $entry->getUserID();
     $db = Database::getInstance();
     if (!$db->isConnected()) {
         return false;
     }
     $message = $db->escapeString($message);
     $results = $db->insertData('systemLog', 'message, type, userID', '\'' . $message . '\', \'' . $type . '\', \'' . $userID . '\'');
     if (!$results) {
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Handles POST requests from the options admin page
  */
 public function post_options()
 {
     $option_items = array();
     $timezones = DateTimeZone::listIdentifiers();
     $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones)));
     $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => ''));
     $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Info'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.')));
     $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(HabariDateTime::date_create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(HabariDateTime::date_create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(HabariDateTime::date_create()->time))));
     $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(HabariLocale::list_all(), HabariLocale::list_all())), 'helptext' => _t('International language code')), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server')));
     $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!')));
     /*$option_items[_t('Presentation')] = array(
     		'encoding' => array(
     			'label' => _t('Encoding'),
     			'type' => 'select',
     			'selectarray' => array(
     				'UTF-8' => 'UTF-8'
     				),
     			'helptext' => '',
     			),
     		);*/
     $option_items = Plugins::filter('admin_option_items', $option_items);
     $form = new FormUI('Admin Options');
     $tab_index = 3;
     foreach ($option_items as $name => $option_fields) {
         $fieldset = $form->append('wrapper', Utils::slugify(_u($name)), $name);
         $fieldset->class = 'container settings';
         $fieldset->append('static', $name, '<h2>' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>');
         foreach ($option_fields as $option_name => $option) {
             $field = $fieldset->append($option['type'], $option_name, $option_name, $option['label']);
             $field->template = 'optionscontrol_' . $option['type'];
             $field->class = 'item clear';
             if ($option['type'] == 'select' && isset($option['selectarray'])) {
                 $field->options = $option['selectarray'];
             }
             $field->tabindex = $tab_index;
             $tab_index++;
             if (isset($option['helptext'])) {
                 $field->helptext = $option['helptext'];
             } else {
                 $field->helptext = '';
             }
         }
     }
     /* @todo: filter for additional options from plugins
      * We could either use existing config forms and simply extract
      * the form controls, or we could create something different
      */
     $submit = $form->append('submit', 'apply', _t('Apply'), 'admincontrol_submit');
     $submit->tabindex = $tab_index;
     $form->on_success(array($this, 'form_options_success'));
     $this->theme->form = $form->get();
     $this->theme->option_names = array_keys($option_items);
     $this->theme->display('options');
 }
Ejemplo n.º 7
0
 public function read($input)
 {
     $xfer = 0;
     $fname = null;
     $ftype = 0;
     $fid = 0;
     $xfer += $input->readStructBegin($fname);
     while (true) {
         $xfer += $input->readFieldBegin($fname, $ftype, $fid);
         if ($ftype == TType::STOP) {
             break;
         }
         switch ($fid) {
             case 1:
                 if ($ftype == TType::LST) {
                     $this->messages = array();
                     $_size7 = 0;
                     $_etype10 = 0;
                     $xfer += $input->readListBegin($_etype10, $_size7);
                     for ($_i11 = 0; $_i11 < $_size7; ++$_i11) {
                         $elem12 = null;
                         $elem12 = new LogEntry();
                         $xfer += $elem12->read($input);
                         $this->messages[] = $elem12;
                     }
                     $xfer += $input->readListEnd();
                 } else {
                     $xfer += $input->skip($ftype);
                 }
                 break;
             default:
                 $xfer += $input->skip($ftype);
                 break;
         }
         $xfer += $input->readFieldEnd();
     }
     $xfer += $input->readStructEnd();
     return $xfer;
 }
Ejemplo n.º 8
0
 public function __construct($vals = null)
 {
     if (!isset(self::$_TSPEC)) {
         self::$_TSPEC = array(1 => array('var' => 'category', 'type' => TType::STRING), 2 => array('var' => 'message', 'type' => TType::STRING));
     }
     if (is_array($vals)) {
         if (isset($vals['category'])) {
             $this->category = $vals['category'];
         }
         if (isset($vals['message'])) {
             $this->message = $vals['message'];
         }
     }
 }
Ejemplo n.º 9
0
 public function __construct()
 {
     parent::__construct();
     // Let's register the options page form so we can use it with ajax
     $self = $this;
     FormUI::register('admin_options', function ($form, $name, $extra_data) use($self) {
         $option_items = array();
         $timezones = \DateTimeZone::listIdentifiers();
         $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones)));
         $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => ''));
         $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Email'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.')));
         $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(DateTime::create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(DateTime::create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(DateTime::create()->time))));
         $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(Locale::list_all(), Locale::list_all())), 'helptext' => Config::exists('locale') ? _t('International language code : This value is set in your config.php file, and cannot be changed here.') : _t('International language code'), 'disabled' => Config::exists('locale'), 'value' => Config::get('locale', Options::get('locale', 'en-us'))), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server')));
         $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!')));
         $option_items = Plugins::filter('admin_option_items', $option_items);
         $tab_index = 3;
         foreach ($option_items as $name => $option_fields) {
             /** @var FormControlFieldset $fieldset  */
             $fieldset = $form->append(FormControlWrapper::create(Utils::slugify(_u($name)))->set_properties(array('class' => 'container main settings')));
             $fieldset->append(FormControlStatic::create($name)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>'));
             $fieldset->set_wrap_each('<div>%s</div>');
             foreach ($option_fields as $option_name => $option) {
                 /** @var FormControlLabel $label */
                 $label = $fieldset->append(FormControlLabel::create('label_for_' . $option_name, null)->set_label($option['label']));
                 /** @var FormControl $field */
                 $field = $label->append($option['type'], $option_name, $option_name);
                 $label->set_for($field);
                 if (isset($option['value'])) {
                     $field->set_value($option['value']);
                 }
                 if (isset($option['disabled']) && $option['disabled'] == true) {
                     $field->set_properties(array('disabled' => 'disabled'));
                 }
                 if ($option['type'] == 'select' && isset($option['selectarray'])) {
                     $field->set_options($option['selectarray']);
                 }
                 $field->tabindex = $tab_index;
                 $tab_index++;
                 if (isset($option['helptext'])) {
                     $field->set_helptext($option['helptext']);
                 }
             }
         }
         $buttons = $form->append(new FormControlWrapper('buttons', null, array('class' => 'container')));
         $buttons->append(FormControlSubmit::create('apply', null, array('tabindex' => $tab_index))->set_caption(_t('Apply')));
         $form->on_success(array($self, 'form_options_success'));
         $form = Plugins::filter('admin_options_form', $form);
     });
 }
Ejemplo n.º 10
0
 public function php()
 {
     parent::checkAuthentification();
     parent::checkIfAdmin();
     $entries = LogEntry::find('log', 'php');
     if ($entries == NULL) {
         $entries = array();
     } else {
         if ($entries instanceof LogEntry) {
             $entries = array($entries);
         }
     }
     usort($entries, array('LogEntry', 'compare'));
     $smarty = new Template();
     $smarty->assign('entries', $entries);
     $smarty->assign('title', System::getLanguage()->_('Log'));
     $smarty->assign('heading', System::getLanguage()->_('PHPEntries'));
     $smarty->assign('showPHPEntries', true);
     $smarty->display('log/log.tpl');
 }
Ejemplo n.º 11
0
function deleteMember()
{
    $member = new Member(array("id" => isset($_POST["memberId"]) ? (int) $_POST["memberId"] : ""));
    LogEntry::deleteAllForMember($member->getValue("id"));
    $member->delete();
    displaySuccess();
}
Ejemplo n.º 12
0
function clearLog()
{
    $id = isset($_POST["memberId"]) ? (int) $_POST["memberId"] : "";
    LogEntry::deleteAllForMember($id);
    displaySuccess();
}
Ejemplo n.º 13
0
    /**
     * Returns a LogEntry or EventLog array based on supplied parameters.
     * By default,fetch as many entries as pagination allows and order them in a descending fashion based on timestamp.
     *
     * @todo Cache query results.
     * @param array $paramarry An associated array of parameters, or a querystring
     * @return array An array of LogEntry objects, or a single LogEntry object, depending on request
     */
    public static function get($paramarray = array())
    {
        $params = array();
        $fns = array('get_results', 'get_row', 'get_value');
        $select = '';
        // Put incoming parameters into the local scope
        $paramarray = Utils::get_params($paramarray);
        $select_fields = LogEntry::default_fields();
        if (!isset($paramarray['return_data'])) {
            unset($select_fields['data']);
        }
        foreach ($select_fields as $field => $value) {
            $select .= '' == $select ? "{log}.{$field}" : ", {log}.{$field}";
        }
        // Default parameters.
        $orderby = 'ORDER BY timestamp DESC, id DESC';
        $limit = Options::get('pagination');
        // Get any full-query parameters
        $possible = array('orderby', 'fetch_fn', 'count', 'month_cts', 'nolimit', 'index', 'limit', 'offset');
        foreach ($possible as $varname) {
            if (isset($paramarray[$varname])) {
                ${$varname} = $paramarray[$varname];
            }
        }
        foreach ($paramarray as $key => $value) {
            if ('orderby' == $key) {
                $orderby = ' ORDER BY ' . $value;
                continue;
            }
        }
        // Transact on possible multiple sets of where information that is to be OR'ed
        if (isset($paramarray['where']) && is_array($paramarray['where'])) {
            $wheresets = $paramarray['where'];
        } else {
            $wheresets = array(array());
        }
        $wheres = array();
        $join = '';
        if (isset($paramarray['where']) && is_string($paramarray['where'])) {
            $wheres[] = $paramarray['where'];
        } else {
            foreach ($wheresets as $paramset) {
                // Safety mechanism to prevent empty queries
                $where = array('1=1');
                $paramset = array_merge((array) $paramarray, (array) $paramset);
                if (isset($paramset['id']) && is_numeric($paramset['id'])) {
                    $where[] = "id= ?";
                    $params[] = $paramset['id'];
                }
                if (isset($paramset['user_id'])) {
                    $where[] = "user_id= ?";
                    $params[] = $paramset['user_id'];
                }
                if (isset($paramset['severity']) && 'any' != LogEntry::severity_name($paramset['severity'])) {
                    $where[] = "severity_id= ?";
                    $params[] = LogEntry::severity($paramset['severity']);
                }
                if (isset($paramset['type_id'])) {
                    if (is_array($paramset['type_id'])) {
                        $types = array_filter($paramset['type_id'], 'is_numeric');
                        if (count($types)) {
                            $where[] = 'type_id IN (' . implode(',', $types) . ')';
                        }
                    } else {
                        $where[] = 'type_id = ?';
                        $params[] = $paramset['type_id'];
                    }
                }
                if (isset($paramset['module'])) {
                    if (!is_array($paramset['module'])) {
                        $paramset['module'] = array($paramset['module']);
                    }
                    $where[] = 'type_id IN ( SELECT DISTINCT id FROM {log_types} WHERE module IN ( ' . implode(', ', array_fill(0, count($paramset['module']), '?')) . ' ) )';
                    $params = array_merge($params, $paramset['module']);
                }
                if (isset($paramset['type'])) {
                    if (!is_array($paramset['type'])) {
                        $paramset['type'] = array($paramset['type']);
                    }
                    $where[] = 'type_id IN ( SELECT DISTINCT id FROM {log_types} WHERE type IN ( ' . implode(', ', array_fill(0, count($paramset['type']), '?')) . ' ) )';
                    $params = array_merge($params, $paramset['type']);
                }
                if (isset($paramset['ip'])) {
                    $where[] = 'ip = ?';
                    $params[] = $paramset['ip'];
                }
                /* do searching */
                if (isset($paramset['criteria'])) {
                    preg_match_all('/(?<=")(\\w[^"]*)(?=")|([:\\w]+)/u', $paramset['criteria'], $matches);
                    foreach ($matches[0] as $word) {
                        if (preg_match('%^id:(\\d+)$%i', $word, $special_crit)) {
                            $where[] .= '(id = ?)';
                            $params[] = $special_crit[1];
                        } else {
                            $where[] .= "( LOWER( message ) LIKE ? )";
                            $params[] = '%' . MultiByte::strtolower($word) . '%';
                        }
                    }
                }
                /**
                 * Build the pubdate
                 * If we've got the day, then get the date.
                 * If we've got the month, but no date, get the month.
                 * If we've only got the year, get the whole year.
                 *
                 * @todo Ensure that we've actually got all the needed parts when we query on them
                 */
                if (isset($paramset['day'])) {
                    $where[] = 'timestamp BETWEEN ? AND ?';
                    $start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']);
                    $start_date = HabariDateTime::date_create($start_date);
                    $params[] = $start_date->sql;
                    $params[] = $start_date->modify('+1 day')->sql;
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], $paramset['day'], $paramset['year'] ) );
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'], $paramset['day'], $paramset['year'] ) );
                } elseif (isset($paramset['month'])) {
                    $where[] = 'timestamp BETWEEN ? AND ?';
                    $start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1);
                    $start_date = HabariDateTime::date_create($start_date);
                    $params[] = $start_date->sql;
                    $params[] = $start_date->modify('+1 month')->sql;
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], 1, $paramset['year'] ) );
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'] + 1, 0, $paramset['year'] ) );
                } elseif (isset($paramset['year'])) {
                    $where[] = 'timestamp BETWEEN ? AND ?';
                    $start_date = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1);
                    $start_date = HabariDateTime::date_create($start_date);
                    $params[] = $start_date->sql;
                    $params[] = $start_date->modify('+1 year')->sql;
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, 1, 1, $paramset['year'] ) );
                    //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, -1, 1, 1, $paramset['year'] + 1 ) );
                }
                $wheres[] = ' (' . implode(' AND ', $where) . ') ';
            }
        }
        if (isset($index) && is_numeric($index)) {
            $offset = (intval($index) - 1) * intval($limit);
        }
        if (isset($fetch_fn)) {
            if (!in_array($fetch_fn, $fns)) {
                $fetch_fn = $fns[0];
            }
        } else {
            $fetch_fn = $fns[0];
        }
        if (isset($count)) {
            $select = "COUNT({$count})";
            $fetch_fn = 'get_value';
            $orderby = '';
        }
        if (isset($limit)) {
            $limit = " LIMIT {$limit}";
            if (isset($offset)) {
                $limit .= " OFFSET {$offset}";
            }
        }
        // If the month counts are requested, replace the select clause
        if (isset($paramset['month_cts'])) {
            // @todo shouldn't this hand back to habari to convert to DateTime so it reflects the right timezone?
            $select = 'MONTH(FROM_UNIXTIME(timestamp)) AS month, YEAR(FROM_UNIXTIME(timestamp)) AS year, COUNT(*) AS ct';
            $groupby = 'year, month';
            $orderby = ' ORDER BY year, month';
        }
        if (isset($nolimit) || isset($month_cts)) {
            $limit = '';
        }
        $query = '
			SELECT ' . $select . '
			FROM {log} ' . $join;
        if (count($wheres) > 0) {
            $query .= ' WHERE ' . implode(" \nOR\n ", $wheres);
        }
        $query .= !isset($groupby) || $groupby == '' ? '' : ' GROUP BY ' . $groupby;
        $query .= $orderby . $limit;
        // Utils::debug( $paramarray, $fetch_fn, $query, $params );
        DB::set_fetch_mode(PDO::FETCH_CLASS);
        DB::set_fetch_class('LogEntry');
        $results = DB::$fetch_fn($query, $params, 'LogEntry');
        // If the fetch callback function is not get_results,
        // return an EventLog ArrayObject filled with the results as LogEntry objects.
        if ('get_results' != $fetch_fn) {
            return $results;
        } elseif (is_array($results)) {
            $c = __CLASS__;
            $return_value = new $c($results);
            $return_value->get_param_cache = $paramarray;
            return $return_value;
        }
    }
Ejemplo n.º 14
0
 /** 
  * Returns a list of log entries
  */
 public static function getList($keywords, $type, $limit)
 {
     $db = Loader::db();
     if ($keywords != '') {
         $kw = 'and logText like ' . $db->quote('%' . $keywords . '%');
     }
     if ($type != false) {
         $v = array($type);
         $r = $db->Execute('select logID from Logs where logType = ? ' . $kw . ' order by timestamp desc limit ' . $limit, $v);
     } else {
         $r = $db->Execute('select logID from Logs where 1=1 ' . $kw . ' order by timestamp desc limit ' . $limit);
     }
     $entries = array();
     while ($row = $r->FetchRow()) {
         $entries[] = LogEntry::getByID($row['logID']);
     }
     return $entries;
 }
Ejemplo n.º 15
0
 /**
  * @covers Phossa\Logger\LogEntry::setContext
  */
 public function testSetContext()
 {
     $this->object->setContext('wow', 'wow2');
     $this->assertEquals('wow2', $this->object->getContext('wow'));
     $this->assertEquals(null, $this->object->getContext('notfind'));
 }
Ejemplo n.º 16
0
 private function logTimestamp(LogEntry $entry)
 {
     global $wgLang;
     $time = $wgLang->timeanddate(wfTimestamp(TS_MW, $entry->getTimestamp()), true);
     return htmlspecialchars($time);
 }
Ejemplo n.º 17
0
	/**
	 * Insert this LogEntry data into the database
	 */
	public function insert()
	{
		if ( isset( $this->fields['severity'] ) ) {
			$this->severity_id = LogEntry::severity( $this->fields['severity'] );
			unset( $this->fields['severity'] );
		}
		if ( isset( $this->fields['module'] ) && isset( $this->fields['type'] ) ) {
			$this->type_id = LogEntry::type( $this->fields['module'], $this->fields['type'] );
			unset( $this->fields['module'] );
			unset( $this->fields['type'] );
		}
		
		// if we're set to only log entries greater than a sertain level, make sure we're that level or higher
		if ( $this->fields['severity_id'] < Options::get( 'log_min_severity' ) ) {
			return;
		}
		
		// make sure data is a string and can be stored. lots of times it's convenient to hand in an array of data values
		if ( is_array( $this->fields['data'] ) || is_object( $this->fields['data'] ) ) {
			$this->fields['data'] = serialize( $this->fields['data'] );
		}

		Plugins::filter( 'insert_logentry', $this );
		parent::insertRecord( DB::table( 'log' ) );
		
		$this->id = DB::last_insert_id();
		
	}
Ejemplo n.º 18
0
 public function deleteBox($barcode)
 {
     $this->connection->query("begin;");
     $query = "\n\t\tSELECT COUNT(a_barcode)\n\t\tFROM assets\n\t\tWHERE a_box = {$barcode};";
     $this->connection->query($query);
     $row = $this->connection->fetch_row();
     if ($row[0] != 0) {
         echo "Cannot delete an Assest Type that is currently being used by assets<br><br>";
     } else {
         $query = "DELETE FROM boxes WHERE b_barcode = {$barcode};";
         $this->connection->query($query);
         //log away
         $user = new User();
         $logEntry = new LogEntry($this->connection);
         $logEntry->setBarcode($barcode);
         $logEntry->setPerson($user->get_Username());
         $logEntry->setType("Box Deleted");
         $logEntry->insert();
     }
     $this->connection->query("commit;");
 }
Ejemplo n.º 19
0
 *
 */
if (!isset($APP)) {
    die;
}
$default_controller = $APP['controller_path'] . '/subject_controller.php';
$constraint = NULL;
$id = NULL;
if (isset($_GET['constraint'])) {
    $constraint = trim($_GET['constraint']);
}
if (isset($_GET['id'])) {
    $id = (int) trim($_GET['id']);
}
$post_data = 'action: "view_subject"';
$suspicious_address = $APP['ana']->get_ip();
$log_message = 'Unauthorized access from Google Account: ' . $APP['user']['email'] . ' at IP address: ' . $suspicious_address;
$log_entry = new LogEntry($log_message);
$log_entry->save();
?>

<div class="col-xs-12" id="main_view">
	<h2>You are not authorized to use this software.</h2>
	<p> Your Google account is: <?php 
echo $APP['user']['email'];
?>
</p>
	<p>This unauthorized use has been logged.</p>
</div>

Ejemplo n.º 20
0
 private function fetch_log_modules_types()
 {
     $module_list = LogEntry::list_logentry_types();
     $modules = $types = array('any' => 'Any');
     foreach ($module_list as $module_name => $type_array) {
         // Utils::slugify() gives us a safe key to use - this is what will be handed to the filter after a POST as well
         $modules[Utils::slugify($module_name)] = $module_name;
         foreach ($type_array as $type_name => $type_value) {
             $types[Utils::slugify($type_name)] = $type_name;
         }
     }
     return array('modules' => $modules, 'types' => $types);
 }
Ejemplo n.º 21
0
 /**
  * Returns a LogEntry or EventLog array based on supplied parameters.
  * By default,fetch as many entries as pagination allows and order them in a descending fashion based on timestamp.
  *
  * @todo Cache query results.
  * @param array $paramarray An associated array of parameters, or a querystring
  * The following keys are supported:
  * - id => an entry id or array of post ids
  * - user_id => id of the logged in user for which to return entries
  * - severity => severity level for which to return entries
  * - type_id => the numeric id or array of ids for the type of entries for which which to return entries
  * - module => a name or array of names of modules for which to return entries
  * - type => a single type name or array of type names for which to return entries
  * - ip => the IP number for which to return entries
  * - criteria => a literal search string to match entry message content or a special search
  * - day => a day of entry creation, ignored if month and year are not specified
  * - month => a month of entry creation, ignored if year isn't specified
  * - year => a year of entry creation
  * - orderby => how to order the returned entries
  * - fetch_fn => the function used to fetch data, one of 'get_results', 'get_row', 'get_value'
  * - count => return the number of entries that would be returned by this request
  * - month_cts => return the number of entries created in each month
  * - nolimit => do not implicitly set limit
  * - limit => the maximum number of entries to return, implicitly set for many queries
  * - index => 
  * - offset => amount by which to offset returned entries, used in conjunction with limit
  * - where => manipulate the generated WHERE clause
  * - return_data => set to return the data associated with the entry
  * 
  * @return array An array of LogEntry objects, or a single LogEntry object, depending on request
  */
 public static function get($paramarray = array())
 {
     $params = array();
     $fns = array('get_results', 'get_row', 'get_value');
     $select_ary = array();
     $select_distinct = array();
     // Put incoming parameters into the local scope
     $paramarray = Utils::get_params($paramarray);
     if ($paramarray instanceof \ArrayIterator) {
         $paramarray = $paramarray->getArrayCopy();
     }
     $select_fields = LogEntry::default_fields();
     if (!isset($paramarray['return_data'])) {
         unset($select_fields['data']);
     }
     foreach ($select_fields as $field => $value) {
         if (preg_match('/(?:(?P<table>[\\w\\{\\}]+)\\.)?(?P<field>\\w+)(?:(?:\\s+as\\s+)(?P<alias>\\w+))?/i', $field, $fielddata)) {
             if (empty($fielddata['table'])) {
                 $fielddata['table'] = '{log}';
             }
             if (empty($fielddata['alias'])) {
                 $fielddata['alias'] = $fielddata['field'];
             }
         }
         $select_ary[$fielddata['alias']] = "{$fielddata['table']}.{$fielddata['field']} AS {$fielddata['alias']}";
         $select_distinct[$fielddata['alias']] = "{$fielddata['table']}.{$fielddata['field']}";
     }
     // Transact on possible multiple sets of where information that is to be OR'ed
     if (isset($paramarray['where']) && is_array($paramarray['where'])) {
         $wheresets = $paramarray['where'];
     } else {
         $wheresets = array(array());
     }
     $query = Query::create('{log}');
     $query->select($select_ary);
     if (isset($paramarray['where']) && is_string($paramarray['where'])) {
         $query->where()->add($paramarray['where']);
     }
     foreach ($wheresets as $paramset) {
         $where = new QueryWhere();
         $paramset = array_merge((array) $paramarray, (array) $paramset);
         if (isset($paramset['id'])) {
             $where->in('{log}.id', $paramset['id'], 'log_id', 'intval');
         }
         if (isset($paramset['user_id'])) {
             $where->in('{log}.user_id', $paramset['user_id'], 'log_user_id', 'intval');
         }
         if (isset($paramset['severity']) && 'any' != LogEntry::severity_name($paramset['severity'])) {
             $where->in('{log}.severity_id', $paramset['severity'], 'log_severity_id', function ($a) {
                 return LogEntry::severity($a);
             });
         }
         if (isset($paramset['type_id'])) {
             $where->in('{log}.type_id', $paramset['type_id'], 'log_type_id', 'intval');
         }
         if (isset($paramset['module'])) {
             $paramset['module'] = Utils::single_array($paramset['module']);
             $qry = Query::create('{log_types}');
             $qry->select('{log_types}.id')->distinct();
             $qry->where()->in('{log_types}.module', $paramset['module'], 'log_subquery_module');
             $where->in('{log}.type_id', $qry, 'log_module');
         }
         if (isset($paramset['type'])) {
             $paramset['type'] = Utils::single_array($paramset['type']);
             $qry = Query::create('{log_types}');
             $qry->select('{log_types}.id')->distinct();
             $qry->where()->in('{log_types}.type', $paramset['type'], 'log_subquery_type');
             $where->in('{log}.type_id', $qry, 'log_type');
         }
         if (isset($paramset['ip'])) {
             $where->in('{log}.ip', $paramset['ip']);
         }
         /* do searching */
         if (isset($paramset['criteria'])) {
             // this regex matches any unicode letters (\p{L}) or numbers (\p{N}) inside a set of quotes (but strips the quotes) OR not in a set of quotes
             preg_match_all('/(?<=")(\\w[^"]*)(?=")|([:\\w]+)/u', $paramset['criteria'], $matches);
             foreach ($matches[0] as $word) {
                 if (preg_match('%^id:(\\d+)$%i', $word, $special_crit)) {
                     $where->in('{log}.id', $special_crit[1], 'log_special_criteria');
                 } else {
                     $crit_placeholder = $query->new_param_name('criteria');
                     $where->add("( LOWER( {log}.message ) LIKE :{$crit_placeholder}", array($crit_placeholder => '%' . MultiByte::strtolower($word) . '%'));
                 }
             }
         }
         /**
          * Build the pubdate
          * If we've got the day, then get the date.
          * If we've got the month, but no date, get the month.
          * If we've only got the year, get the whole year.
          *
          * @todo Ensure that we've actually got all the needed parts when we query on them
          */
         if (isset($paramset['day']) && isset($paramset['month']) && isset($paramset['year'])) {
             $start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']);
             $start_date = DateTime::create($start_date);
             $where->add('timestamp BETWEEN :start_date AND :end_date', array('start_date' => $start_date->sql, 'end_date' => $start_date->modify('+1 day -1 second')->sql));
         } elseif (isset($paramset['month']) && isset($paramset['year'])) {
             $start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1);
             $start_date = DateTime::create($start_date);
             $where->add('timestamp BETWEEN :start_date AND :end_date', array('start_date' => $start_date->sql, 'end_date' => $start_date->modify('+1 month -1 second')->sql));
         } elseif (isset($paramset['year'])) {
             $start_date = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1);
             $start_date = DateTime::create($start_date);
             $where->add('timestamp BETWEEN :start_date AND :end_date', array('start_date' => $start_date->sql, 'end_date' => $start_date->modify('+1 year -1 second')->sql));
         }
         // Concatenate the WHERE clauses
         $query->where()->add($where);
     }
     // Default parameters.
     $orderby = 'timestamp DESC, id DESC';
     //		$limit = Options::get( 'pagination' );
     // Get any full-query parameters
     $paramarray = new SuperGlobal($paramarray);
     $extract = $paramarray->filter_keys('orderby', 'fetch_fn', 'count', 'month_cts', 'nolimit', 'index', 'limit', 'offset');
     foreach ($extract as $key => $value) {
         ${$key} = $value;
     }
     if (isset($index) && is_numeric($index)) {
         $offset = (intval($index) - 1) * intval($limit);
     }
     if (isset($fetch_fn)) {
         if (!in_array($fetch_fn, $fns)) {
             $fetch_fn = $fns[0];
         }
     } else {
         $fetch_fn = $fns[0];
     }
     if (isset($count)) {
         $query->set_select("COUNT({$count})");
         $fetch_fn = isset($paramarray['fetch_fn']) ? $fetch_fn : 'get_value';
         $orderby = null;
         $groupby = null;
         $having = null;
     }
     // If the month counts are requested, replace the select clause
     if (isset($paramset['month_cts'])) {
         // @todo shouldn't this hand back to habari to convert to DateTime so it reflects the right timezone?
         $query->set_select('MONTH(FROM_UNIXTIME(timestamp)) AS month, YEAR(FROM_UNIXTIME(timestamp)) AS year, COUNT(*) AS ct');
         $groupby = 'year, month';
         if (!isset($paramarray['orderby'])) {
             $orderby = 'year, month';
         }
     }
     if (isset($nolimit) || isset($month_cts)) {
         $limit = null;
     }
     // Define the LIMIT, OFFSET, ORDER BY, GROUP BY if they exist
     if (isset($limit)) {
         $query->limit($limit);
     }
     if (isset($offset)) {
         $query->offset($offset);
     }
     if (isset($orderby)) {
         $query->orderby($orderby);
     }
     if (isset($groupby)) {
         $query->groupby($groupby);
     }
     /*
     if(isset($paramarray['type'])) {
     	print_r($query->params());
     	print_r($query->get());die();
     }
     */
     /* All SQL parts are constructed, on to real business! */
     DB::set_fetch_mode(\PDO::FETCH_CLASS);
     DB::set_fetch_class('LogEntry');
     $results = DB::$fetch_fn($query->get(), $query->params(), 'LogEntry');
     // If the fetch callback function is not get_results,
     // return an EventLog ArrayObject filled with the results as LogEntry objects.
     if ('get_results' != $fetch_fn) {
         return $results;
     } elseif (is_array($results)) {
         $c = __CLASS__;
         $return_value = new $c($results);
         $return_value->get_param_cache = $paramarray;
         return $return_value;
     }
 }
Ejemplo n.º 22
0
 /**
  * Get raw entries with a selected set of values to grab.
  */
 public function rawLogEntriesTable()
 {
     $title = 'Raw log entries';
     $fields = Config::get('marauder.rawLogEntries');
     // all of the users log entries:
     $get = ['log_entries.id', 'structures.time_zone', 'log_entries.time', 'devices.name'];
     $query = LogEntry::leftJoin('devices', 'devices.id', '=', 'log_entries.device_id')->leftJoin('structures', 'structures.id', '=', 'devices.structure_id')->where('structures.user_id', Auth::user()->id)->take(Config::get('marauder.logTableLimit'))->orderBy('time', 'DESC')->orderBy('devices.id', 'ASC');
     // ignore stuff from the query:
     $ignore = ['id', 'time_zone'];
     foreach ($fields as $field) {
         $query->withLogValue($field);
         $get[] = $field . '.value as ' . $field;
     }
     $result = $query->get($get);
     if ($result->count() > 0) {
         $result = $result->toArray();
     }
     foreach ($result as $key => $entry) {
         foreach ($entry as $name => $value) {
             if ($name == 'time') {
                 // time zone correction!
                 $value = new Carbon($value, 'UTC');
                 $timezone = strlen($result[$key]['time_zone']) > 0 ? $result[$key]['time_zone'] : 'Europe/Amsterdam';
                 $value->setTimezone($timezone);
             }
             $result[$key][$name] = Format::format($name, $value);
         }
     }
     return View::make('raw.table', compact('result', 'ignore', 'title'));
 }
Ejemplo n.º 23
0
 /**
  * Assign values needed to display the logs page to the theme based on handlervars and parameters.
  *
  */
 private function fetch_logs($params = NULL)
 {
     $locals = array('do_delete' => false, 'log_ids' => null, 'nonce' => '', 'timestamp' => '', 'PasswordDigest' => '', 'change' => '', 'limit' => 20, 'offset' => 0, 'user' => 0, 'date' => 'any', 'module' => '0', 'type' => '0', 'severity' => 'any', 'address' => '0', 'search' => '', 'do_search' => false, 'index' => 1);
     foreach ($locals as $varname => $default) {
         ${$varname} = isset($this->handler_vars[$varname]) ? $this->handler_vars[$varname] : $default;
         $this->theme->{$varname} = ${$varname};
     }
     if ($do_delete && isset($log_ids)) {
         $okay = true;
         if (empty($nonce) || empty($timestamp) || empty($PasswordDigest)) {
             $okay = false;
         }
         $wsse = Utils::WSSE($nonce, $timestamp);
         if ($PasswordDigest != $wsse['digest']) {
             $okay = false;
         }
         if ($okay) {
             foreach ($log_ids as $id) {
                 $ids[] = array('id' => $id);
             }
             $to_delete = EventLog::get(array('nolimit' => 1));
             $count = 0;
             foreach ($to_delete as $log) {
                 $log->delete();
                 $count++;
             }
             Session::notice(_t('Deleted %d logs', array($count)));
         }
         Utils::redirect();
     }
     $this->theme->severities = LogEntry::list_severities();
     $any = array('0' => 'Any');
     $modulelist = LogEntry::list_logentry_types();
     $modules = array();
     $types = array();
     $addresses = $any;
     $ips = DB::get_column('SELECT DISTINCT(ip) FROM {log}');
     foreach ($ips as $ip) {
         $addresses[$ip] = long2ip($ip);
     }
     $this->theme->addresses = $addresses;
     foreach ($modulelist as $modulename => $typearray) {
         $modules['0,' . implode(',', $typearray)] = $modulename;
         foreach ($typearray as $typename => $typevalue) {
             if (!isset($types[$typename])) {
                 $types[$typename] = '0';
             }
             $types[$typename] .= ',' . $typevalue;
         }
     }
     $types = array_flip($types);
     $this->theme->types = array_merge($any, $types);
     $this->theme->modules = array_merge($any, $modules);
     // set up the users
     $users_temp = DB::get_results('SELECT DISTINCT username, user_id FROM {users} JOIN {log} ON {users}.id = {log}.user_id ORDER BY username ASC');
     array_unshift($users_temp, new QueryRecord(array('username' => 'All', 'user_id' => 0)));
     foreach ($users_temp as $user_temp) {
         $users[$user_temp->user_id] = $user_temp->username;
     }
     $this->theme->users = $users;
     // set up dates.
     $dates = DB::get_column('SELECT timestamp FROM {log} ORDER BY timestamp DESC');
     $dates = array_map(create_function('$date', 'return HabariDateTime::date_create( $date )->get(\'Y-m\');'), $dates);
     array_unshift($dates, 'Any');
     $dates = array_combine($dates, $dates);
     $this->theme->dates = $dates;
     // prepare the WSSE tokens
     $this->theme->wsse = Utils::WSSE();
     $arguments = array('severity' => LogEntry::severity($severity), 'limit' => $limit, 'offset' => $offset);
     // deduce type_id from module and type
     $r_type = explode(',', substr($type, 2));
     $r_module = explode(',', substr($module, 2));
     if ($type != '0' && $module != '0') {
         $arguments['type_id'] = array_intersect($r_type, $r_module);
     } elseif ($type == '0') {
         $arguments['type_id'] = $r_module;
     } elseif ($module == '0') {
         $arguments['type_id'] = $r_type;
     }
     if ('0' != $address) {
         $arguments['ip'] = $address;
     }
     if ('any' != strtolower($date)) {
         list($arguments['year'], $arguments['month']) = explode('-', $date);
     }
     if ('' != $search) {
         $arguments['criteria'] = $search;
     }
     if ('0' != $user) {
         $arguments['user_id'] = $user;
     }
     if (is_array($params)) {
         $arguments = array_merge($arguments, $params);
     }
     $this->theme->logs = EventLog::get($arguments);
     $monthcts = EventLog::get(array_merge($arguments, array('month_cts' => true)));
     foreach ($monthcts as $month) {
         if (isset($years[$month->year])) {
             $years[$month->year][] = $month;
         } else {
             $years[$month->year] = array($month);
         }
     }
     if (isset($years)) {
         $this->theme->years = $years;
     } else {
         $this->theme->years = array();
     }
 }
Ejemplo n.º 24
0
 public static function find($column = '*', $value = NULL, array $options = array())
 {
     $query = 'SELECT * FROM log';
     $params = array();
     if ($column != '*' && strlen($column) > 0 && $value != NULL) {
         $query .= ' WHERE ' . Database::makeTableOrColumnName($column) . ' = :value';
         $params[':value'] = $value;
     }
     if (isset($options['orderby']) && isset($options['sort'])) {
         $query .= ' ORDER BY ' . Database::makeTableOrColumnName($options['orderby']) . ' ' . strtoupper($options['sort']);
     }
     if (isset($options['limit'])) {
         $query .= ' LIMIT ' . $options['limit'];
     }
     $sql = System::getDatabase()->prepare($query);
     $sql->execute($params);
     if ($sql->rowCount() == 0) {
         return NULL;
     } else {
         if ($sql->rowCount() == 1) {
             $row = $sql->fetch();
             $entry = new LogEntry();
             $entry->assign($row);
             return $entry;
         } else {
             $list = array();
             while ($row = $sql->fetch()) {
                 $entry = new LogEntry();
                 $entry->assign($row);
                 $list[] = $entry;
             }
             return $list;
         }
     }
 }
Ejemplo n.º 25
0
 public function UpdateStatistics()
 {
     global $database, $cphp_config;
     if (!empty($cphp_config->debugmode) || $this->sLastStatisticsUpdate < time() - 60 * 5) {
         /* Update subscriber count */
         if ($result = $database->CachedQuery("SELECT COUNT(*) FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId))) {
             $this->uSubscriberCount = $result->data[0]["COUNT(*)"];
         }
         /* Update total monthly donations */
         try {
             $sSubscriptions = Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId));
             $sTotalDonations = 0;
             foreach ($sSubscriptions as $sSubscription) {
                 $sTotalDonations += Currency::Convert("usd", $sSubscription->sCurrency, $sSubscription->sAmount);
             }
             $this->uMonthlyTotal = $sTotalDonations;
         } catch (NotFoundException $e) {
             $this->uMonthlyTotal = 0;
         }
         /* Update donation rate */
         try {
             $sDonationsAsked = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_ASKED));
             $have_data = true;
         } catch (NotFoundException $e) {
             /* We don't have any data to work from yet. */
             $sDonationsAsked = array();
             $have_data = false;
         }
         if ($have_data) {
             try {
                 $sDonationsMade = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_MADE));
                 $this->uDonationRate = count($sDonationsMade) / count($sDonationsAsked) * 100;
                 $this->uHaveData = true;
             } catch (NotFoundException $e) {
                 $sDonationsMade = array();
                 $this->uDonationRate = 0;
                 $this->uHaveData = false;
             }
         } else {
             $sDonationsMade = array();
             $this->uDonationRate = 100;
             $this->uHaveData = false;
         }
         /* Update projected monthly donations */
         $this->uMonthlyProjection = $this->uMonthlyTotal * ($this->uDonationRate / 100);
         /* Update past-month subscription count */
         if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::SUBSCRIPTION_CONFIRMED), 0)) {
             $this->uPastMonthSubscriptions = $result->data[0]["COUNT(*)"];
         }
         /* Update past-month unsubscription count */
         if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::UNSUBSCRIPTION), 0)) {
             $this->uPastMonthUnsubscriptions = $result->data[0]["COUNT(*)"];
         }
         /* Update past month donation count */
         $this->uPastMonthDonations = count($sDonationsMade);
         /* Update past month non-donation count */
         $this->uPastMonthNonDonations = count($sDonationsAsked) - count($sDonationsMade);
         $this->uLastStatisticsUpdate = time();
         $this->InsertIntoDatabase();
     }
 }
Ejemplo n.º 26
0
 public function deleteAsset($barcode)
 {
     $this->connection->query("begin;");
     //log this sad event
     $user = new User();
     $logEntry = new LogEntry($this->connection);
     $logEntry->setBarcode($barcode);
     $logEntry->setPerson($user->get_Username());
     $logEntry->setType("Asset Deleted");
     $logEntry->insert();
     $query = "DELETE FROM assets WHERE a_barcode = '{$barcode}'";
     $this->connection->query($query);
     $this->connection->query("commit;");
 }
Ejemplo n.º 27
0
/*
 * ReDonate is more free software. It is licensed under the WTFPL, which
 * allows you to do pretty much anything with it, without having to
 * ask permission. Commercial use is allowed, and no attribution is
 * required. We do politely request that you share your modifications
 * to benefit other developers, but you are under no enforced
 * obligation to do so :)
 * 
 * Please read the accompanying LICENSE document for the full WTFPL
 * licensing text.
 */
if (!isset($_APP)) {
    die("Unauthorized.");
}
if (!empty($_POST['submit'])) {
    $sSubscription->uIsActive = false;
    $sSubscription->InsertIntoDatabase();
    $sLogEntry = new LogEntry(0);
    $sLogEntry->uType = LogEntry::UNSUBSCRIPTION;
    $sLogEntry->uIp = $_SERVER['REMOTE_ADDR'];
    $sLogEntry->uData = json_encode(array("email" => $sSubscription->sEmailAddress));
    $sLogEntry->uCampaignId = $sSubscription->sCampaign->sId;
    $sLogEntry->uDate = time();
    $sLogEntry->uSessionId = session_id();
    $sLogEntry->InsertIntoDatabase();
    flash_notice("We've unsubscribed you.");
    redirect("/manage/{$sSubscription->sEmailAddress}/{$sSubscription->sSettingsKey}");
}
$sPageTitle = "Change pledge amount";
$sPageContents = NewTemplater::Render("subscription/unsubscribe", $locale->strings, array("email" => $sSubscription->sEmailAddress, "key" => $sSubscription->sSettingsKey, "name" => $sSubscription->sCampaign->sName));
Ejemplo n.º 28
0
<?php

require_once "common.inc.php";
require_once "config.php";
require_once "Member.class.php";
require_once "LogEntry.class.php";
$memberId = isset($_GET["memberId"]) ? (int) $_GET["memberId"] : 0;
if (!($member = Member::getMember($memberId))) {
    displayPageHeader("Error");
    echo "<div>Member not found.</div>";
    displayPageFooter();
    exit;
}
$logEntries = LogEntry::getLogEntries($memberId);
displayPageHeader("View member: " . $member->getValueEncoded("firstName") . " " . $member->getValueEncoded("lastName"));
?>
    <dl style="width: 30em;">
      <dt>Username</dt>
      <dd><?php 
echo $member->getValueEncoded("username");
?>
</dd>
      <dt>First name</dt>
      <dd><?php 
echo $member->getValueEncoded("firstName");
?>
</dd>
      <dt>Last name</dt>
      <dd><?php 
echo $member->getValueEncoded("lastName");
?>
Ejemplo n.º 29
0
 /**
  * Limit the number of log entries returned
  * - limit => the maximum number of posts to return, implicitly set for many queries
  * - nolimit => do not implicitly set limit
  */
 public function test_get_logs_with_limit()
 {
     for ($i = 1; $i <= 5; $i++) {
         $entry = new LogEntry(array('user_id' => $this->user->id, 'type' => 'default', 'severity' => 'err', 'module' => 'habari', 'message' => 'Event message from test_logs_with_limit' . $i));
         $entry->insert();
     }
     $count_entries = EventLog::get(array('count' => 1, 'limit' => 2, 'user_id' => $this->user->id));
     $this->assert_equal($count_entries, 5, "LIMIT with a COUNT is pointless - COUNTing anything should return a single value.");
     $entries = EventLog::get(array('limit' => 2, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 2);
     $count_entries = EventLog::get(array('count' => 1, 'nolimit' => 1, 'user_id' => $this->user->id));
     $this->assert_true($count_entries > 2);
     $entries = EventLog::get(array('nolimit' => 1, 'user_id' => $this->user->id));
     $this->assert_true(count($entries) > 2);
     // OFFSET based on page number (and limit)
     $entries = EventLog::get(array('limit' => 2, 'index' => 2, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 2);
     $entries = EventLog::get(array('limit' => 2, 'index' => 3, 'user_id' => $this->user->id));
     $this->assert_equal(count($entries), 1);
 }
Ejemplo n.º 30
0
 */
if (!isset($APP)) {
    die;
}
$default_controller = $APP['controller_path'] . '/subject_controller.php';
$constraint = NULL;
$id = NULL;
if (isset($_GET['constraint'])) {
    $constraint = trim($_GET['constraint']);
}
if (isset($_GET['id'])) {
    $id = (int) trim($_GET['id']);
}
$post_data = 'action: "view_subject"';
?>

<div class="col-xs-12" id="main_view">
	<H2>Most Recent Log Entries</h2>

	<div id="log_list">
    	<?php 
$recent_log = new LogEntry();
$output = $recent_log->print_last_logs(10);
echo $output;
?>
    
    </div>


</div>