Example #1
0
 function init()
 {
     if (Statistics::$browscap_enabled) {
         $browscap = new Browscap();
         $this->hitdata = $browscap->getBrowser(null, true);
     }
 }
Example #2
0
/**
 * Get information about the user browser.
 * @return array
 */
function vendorBasicBrowscapGetBrowser()
{
    if (ini_get('browscap')) {
        return get_browser();
    }
    $bc = new Browscap(APPPATH . 'data/cache');
    return $bc->getBrowser();
}
Example #3
0
 /**
  * Create an instance of the MailViewLog class.
  * 
  * This takes the primary key as a parameter and builds the object around the
  * returned row. If the parameter is null, not specified or the row does not
  * exist then a blank template MailViewLog object is returned.
  *
  * @param int $id
  * @return MailViewLog object
  */
 public function __construct($id = null)
 {
     if (!is_null($id)) {
         $sql = 'select * from mail_view_log where id=' . $id;
         if (!($result = Database::singleton()->query_fetch($sql))) {
             return false;
         }
         $this->setId($result['id']);
         $this->setUser($result['user']);
         $this->setSendOut($result['mso_id']);
         $this->setTimestamp($result['timestamp']);
         $browscap = new Browscap('/tmp');
         $this->setBrowser($browscap->getBrowser($result['browser']));
     }
 }
Example #4
0
 private function updateBrowscapFile()
 {
     ini_set("memory_limit", "2G");
     require_once dirname(__FILE__) . '/../../../wsp/class/utils/Browscap.class.php';
     $cacheDir = SITE_DIRECTORY . '/wsp/includes/browscap/';
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     unlink($cacheDir . "cache.php");
     unlink($cacheDir . "browscap.ini");
     $browscap = new Browscap($cacheDir);
     $browscap->doAutoUpdate = true;
     $browser = $browscap->getBrowser();
     unset($_SESSION['user_browscap_version']);
     unset($_SESSION['browser_info']);
     global $browscapIni;
     unset($browscapIni);
     if (is_dir($cacheDir . "cache.php")) {
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Create a new BrowserInfo object for the given user agent string.
  *
  * Instances may not be created directly, use the static newFromUA method instead
  * @param $userAgent string
  */
 protected function parseUserAgent($userAgent)
 {
     $browscapCacheDir = $this->context->getConf()->storage->cacheDir . '/phpbrowscap';
     if (!is_dir($browscapCacheDir)) {
         if (!mkdir($browscapCacheDir, 755)) {
             throw new SwarmException("Cache directory must be writable.");
         }
     }
     /**
      * A Browscap object looks like this (simplified version of the actual object)
      * @source https://github.com/GaretJax/phpbrowscap/wiki/QuickStart
      *
      * stdClass Object (
      *     [Platform] => MacOSX
      *     [Browser] => Safari
      *     [Version] => 3.1
      *     [MajorVer] => 3
      *     [MinorVer] => 1
      * )
      */
     $browscapInstance = new Browscap($browscapCacheDir);
     // Default cache is 5 days...
     $browscapInstance->updateInterval = 3600;
     // 1 hour
     $browscapData = $browscapInstance->getBrowser($userAgent);
     $this->rawUserAgent = $userAgent;
     $this->browscapData = $browscapData;
     return $this;
 }
Example #6
0
<?php

date_default_timezone_set('America/Los_Angeles');
$feature = array('label' => 'Browser', 'emitter' => function () {
    require_once LIB_DIR . '/browscap/Browscap.php';
    $bc = new Browscap(TMP_DIR . '/browscap');
    $browser = $bc->getBrowser();
    return $browser->Parent;
});
 public function view()
 {
     $this->addStylesheetToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.stats.css', 'screen', 102);
     $this->addStylesheetToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.drawer.css', 'screen', 103);
     $this->addScriptToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.drawer.js', 103);
     $this->addScriptToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.jquery.ui.js', 104);
     $this->addStylesheetToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.jquery.daterangepicker.css', 'screen', 105);
     $this->addScriptToHead(URL . '/extensions/elasticsearch/assets/elasticsearch.jquery.daterangepicker.js', 106);
     parent::view(FALSE);
     // Get URL parameters, set defaults
     /*-----------------------------------------------------------------------*/
     $sort = (object) $_GET['sort'];
     $filter = (object) $_GET['filter'];
     $pagination = (object) $_GET['pagination'];
     if (!isset($sort->column)) {
         $sort->column = 'date';
     }
     if (!isset($sort->direction)) {
         $sort->direction = 'desc';
     }
     if (!isset($filter->keywords) || empty($filter->keywords)) {
         $filter->keywords = NULL;
     }
     if (!isset($filter->date_from) || empty($filter->date_from)) {
         $filter->date_from = date('Y-m-d', strtotime('last month'));
     }
     if (!isset($filter->date_to) || empty($filter->date_to)) {
         $filter->date_to = date('Y-m-d', strtotime('today'));
     }
     if (!isset($filter->results['value']) || !is_numeric($filter->results['value'])) {
         $filter->results = NULL;
     }
     if (!isset($filter->depth['value']) || !is_numeric($filter->depth['value'])) {
         $filter->depth = NULL;
     }
     if (!isset($filter->session_id) || empty($filter->session_id)) {
         $filter->session_id = NULL;
     }
     if (!isset($filter->user_agent) || empty($filter->user_agent)) {
         $filter->user_agent = NULL;
     }
     if (!isset($filter->ip) || empty($filter->ip)) {
         $filter->ip = NULL;
     }
     if (is_array($filter->results)) {
         $filter->results = implode('', $filter->results);
     }
     if (is_array($filter->depth)) {
         $filter->depth = implode('', $filter->depth);
     }
     $output_mode = $_GET['output'];
     if (!isset($output_mode)) {
         $output_mode = 'table';
     }
     // Build pagination and fetch rows
     /*-----------------------------------------------------------------------*/
     $pagination->{'per-page'} = (int) Symphony::Configuration()->get('pagination_maximum_rows', 'symphony');
     $pagination->{'current-page'} = @(int) $pagination->{'current-page'} > 1 ? (int) $pagination->{'current-page'} : 1;
     // get the logs!
     $rows = ElasticSearchLogs::getSessions($sort->column, $sort->direction, $pagination->{'current-page'}, $pagination->{'per-page'}, $filter);
     // total number of unique query terms
     $pagination->{'total-entries'} = ElasticSearchLogs::getTotalSessions($filter);
     $pagination->start = max(1, ($pagination->{'current-page'} - 1) * $pagination->{'per-page'});
     $pagination->end = $pagination->start == 1 ? $pagination->{'per-page'} : $pagination->start + count($rows);
     $pagination->{'total-pages'} = ceil($pagination->{'total-entries'} / $pagination->{'per-page'});
     // cache amended filters for use elsewhere
     $this->sort = $sort;
     $this->filter = $filter;
     $this->pagination = $pagination;
     // Set up page meta data
     /*-----------------------------------------------------------------------*/
     $this->setPageType('table');
     $this->setTitle(__('Symphony') . ' &ndash; ' . __('ElasticSearch') . ' &ndash; ' . __('Session Logs'));
     $this->insertDrawer(Widget::Drawer('elasticsearch', __('Filter Sessions'), $this->__buildDrawerHTML($filter), 'opened'), 'horizontal');
     $this->appendSubheading(__('Session Logs'), Widget::Anchor(__('Export CSV'), $this->__buildURL(NULL, array('output' => 'csv')), NULL, 'button'));
     $tableHead = array();
     $tableBody = array();
     // append table headings
     $tableHead[] = $this->__buildColumnHeader(__('Date'), 'date', 'desc');
     $tableHead[] = array(__('Query'), 'keywords');
     $tableHead[] = $this->__buildColumnHeader(__('Results'), 'results', 'desc');
     $tableHead[] = $this->__buildColumnHeader(__('Depth'), 'depth', 'desc');
     $tableHead[] = array(__('Session ID'));
     $tableHead[] = array(__('IP Address'));
     $tableHead[] = array(__('Browser'));
     if (!is_array($rows) or empty($rows)) {
         $tableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead)))));
     } else {
         $browscap = new Browscap(CACHE);
         $alt = FALSE;
         foreach ($rows as $row) {
             if (!empty($row['user_agent'])) {
                 $browser = $browscap->getBrowser($row['user_agent']);
                 $browser_string = sprintf('%s %s (%s)', $browser->Browser, $browser->MajorVer, $browser->Platform);
             } else {
                 $browser_string = '';
             }
             $searches = ElasticSearchLogs::getSessionSearches($row['session_id']);
             foreach ($searches as $i => $search) {
                 $r = array();
                 //$r[] = Widget::TableData('', NULL, NULL, 3);
                 $r[] = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($search['date'])), 'date');
                 $keywords = $search['keywords'];
                 $keywords_class = '';
                 if ($keywords == '') {
                     $keywords = __('None');
                     $keywords_class = 'inactive';
                 }
                 $r[] = Widget::TableData(stripslashes($keywords), $keywords_class . ' keywords');
                 $r[] = Widget::TableData($search['results'], 'results');
                 $r[] = Widget::TableData($search['page'], 'depth');
                 if ($i == 0) {
                     $r[] = Widget::TableData($row['session_id'], 'inactive');
                     $r[] = Widget::TableData(empty($row['ip']) ? __('None') : $row['ip'], 'inactive');
                     $r[] = Widget::TableData(empty($browser_string) ? __('None') : '<span title="' . $row['user_agent'] . '">' . $browser_string . '</span>', 'inactive');
                 } else {
                     $r[] = Widget::TableData('', NULL, NULL, 3);
                 }
                 $tableBody[] = Widget::TableRow($r, 'search ' . ($alt ? 'alt' : '') . ($i == count($searches) - 1 ? ' last' : ''));
             }
             $alt = !$alt;
         }
     }
     if ($output_mode == 'csv') {
         $file_path = sprintf('%s/search-index.session-log.%d.csv', TMP, time());
         $csv = fopen($file_path, 'w');
         $columns = array();
         foreach ($tableHead as $i => $heading) {
             $element = reset($heading);
             if ($element instanceof XMLElement) {
                 $columns[] = reset($heading)->getValue();
             } else {
                 $columns[] = (string) $element;
             }
         }
         $columns[] = 'Session ID';
         $columns[] = 'User Agent';
         $columns[] = 'IP';
         fputcsv($csv, $columns, ',', '"');
         $meta = array();
         foreach ($tableBody as $tr) {
             $cells = $tr->getChildren();
             if (preg_match("/session-meta/", $tr->getAttribute('class'))) {
                 $meta = array();
                 foreach ($cells as $i => $td) {
                     switch ($i) {
                         case 0:
                             $meta['session_id'] = $td->getValue();
                             break;
                         case 1:
                             $meta['user_agent'] = $td->getValue();
                             break;
                         case 2:
                             $meta['ip'] = $td->getValue();
                             break;
                     }
                 }
             } else {
                 $data = array();
                 foreach ($cells as $td) {
                     $data[] = $td->getValue();
                 }
                 $data[] = $meta['session_id'];
                 $data[] = $meta['user_agent'];
                 $data[] = $meta['ip'];
                 fputcsv($csv, $data, ',', '"');
             }
         }
         fclose($csv);
         header('Content-type: application/csv');
         header('Content-Disposition: attachment; filename="' . end(explode('/', $file_path)) . '"');
         readfile($file_path);
         unlink($file_path);
         exit;
     }
     $table = Widget::Table(Widget::TableHead($tableHead), NULL, Widget::TableBody($tableBody), 'sessions');
     $this->Form->appendChild($table);
     $this->Form->appendChild(new XMLElement('div', NULL, array('class' => 'actions')));
     // build pagination
     if ($pagination->{'total-pages'} > 1) {
         $this->Form->appendChild($this->__buildPagination($pagination));
     }
 }
Example #8
0
$tpl = new Smarty();
$javascript = false;
$uniq = strtotime("now") . '-' . mt_rand(0, 100);
$output = '';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $client_ip = import_var('HTTP_X_FORWARDED_FOR', 'SE');
} else {
    $client_ip = import_var('REMOTE_ADDR', 'SE');
}
if ($client_ip == false) {
    die("Client IP not valid");
}
switch (_JAVASCRIPT) {
    default:
    case "auto":
        $bc = new Browscap();
        $current_browser = $bc->getBrowser();
        // Output the result
        if ($current_browser->JavaScript == 1) {
            $javascript = true;
        } else {
            $javascript = false;
        }
        break;
    case "on":
        $javascript = true;
        break;
    case "off":
        $javascript = false;
        break;
}
Example #9
0
 function get_browser()
 {
     $file = $this->include_path . '/browscap.php';
     if (is_file($file)) {
         require_once $file;
         $bc = new Browscap($this->include_path . '/browscap-cache');
         $this->browser = $bc->getBrowser();
     }
 }
Example #10
0
include_once '../../config.php';
$site = get_site(__DIR__);
include_once CONFIG_PATH . '/' . $site . PHP_EXT;
$Mac_ID = isset($_GET['id']) ? addslashes($_GET['id']) : '';
$fromUserName = isset($_GET['fromUserName']) ? addslashes($_GET['fromUserName']) : '';
if (!$Mac_ID) {
    header('Location: template/introduce.html');
    exit;
}
$sql = "select * from " . WEIXIN_TABLE . "\n        where `Mac_ID` = '{$Mac_ID}'\n        and `ticket` != ''";
$res = $mysql::query($sql, 'row');
if (is_array($res) && count($res) > 0) {
    include_once DEPS_PATH . '/weixin_success.php';
}
if ($res['ticket'] != 'authorized') {
    $bc = new Browscap();
    $client_type = $bc->get_type();
    if (!$fromUserName && $client_type != Browscap::MOBILE) {
        include_once WEIXIN_PATH . '/class/wechat.class.php';
        $options = array('token' => WECHAT_TOKEN, 'appid' => WECHAT_APP_ID, 'appsecret' => WECHAT_APP_SECRET);
        $weObj = new Wechat($options);
        $sql = "select `Mac_ID`, `scene_id`, `created_at`,\n                       `updated_at`, `ticket`\n                from " . WEIXIN_TABLE . "\n                where `Mac_ID` = '{$Mac_ID}'\n                and `ticket` != 'authorized'\n                limit 1";
        $result = $mysql::query($sql, 'all');
        $expire = 500;
        if (!is_array($result) || count($result) < 0) {
            $sql = "select `scene_id` from " . WEIXIN_TABLE . " order by id desc limit 1";
            $scene_id = $mysql::query($sql, '1');
            $scene_id = $scene_id % 9999 + 1;
            $qrcode = $weObj->getQRCode($scene_id, $type = 0, $expire);
            $ticket = $qrcode['ticket'];
            $sql = "insert into " . WEIXIN_TABLE . " (`Mac_ID`, `ticket`, `scene_id`,  `site`)\n                    values ('{$Mac_ID}', '{$ticket}', '{$scene_id}', '{$site}')";
Example #11
0
function insert_new_visitor($ip_address)
{
    global $mysqli;
    $visitor = array('ip_address' => $ip_address);
    //TODO: make optional
    require_once 'Browscap/Browscap.php';
    $bc = new Browscap('cache');
    foreach ($bc->getBrowser() as $key => $value) {
        //  filter out raw fields
        if (!strstr($key, 'browser_name')) {
            $visitor[$key] = $value;
        }
    }
    //TODO: convert database column names
    // $visitor = _camel_to_underscore($visitor);
    // TODO: best delimiter?
    $visitor['hash'] = md5(implode('', $visitor));
    $sql = "SELECT * FROM visitor WHERE visitor.hash = '" . $visitor['hash'] . "'";
    $id = _get_unique_row_id('visitor', $sql);
    if ($id == 0) {
        $sql = "INSERT INTO visitor(" . implode(', ', array_keys($visitor)) . ") VALUES('" . implode("', '", $visitor) . "')";
        $stmt = $mysqli->prepare($sql);
        $id = _execute_and_return_id('visitor', $stmt);
    }
    return $id;
}
Example #12
0
function get_browser_info($user_agent = null, $return_array = false)
{
    require_once dirname(__FILE__) . '/../class/utils/Browscap.class.php';
    $cacheDir = SITE_DIRECTORY . '/wsp/includes/browscap/';
    if (!is_dir($cacheDir)) {
        mkdir($cacheDir);
    }
    if (!is_file($cacheDir . "cache.php")) {
        ini_set("memory_limit", "2G");
    }
    $browscap = new Browscap($cacheDir);
    $browscap->doAutoUpdate = false;
    $browser = $browscap->getBrowser($user_agent);
    return get_object_vars($browser);
}
 public function contactView()
 {
     $EmailData = array();
     $EmailData['sender'] = isset($_POST['commentName']) ? $_POST['commentName'] : "Nelson A. Daza P.";
     $EmailData['message'] = isset($_POST['commentMessage']) ? $_POST['commentMessage'] : "Grandiosa app!!.";
     $EmailData['clientInfo'] = array('Browser' => '', 'Version' => '', 'Platform' => '', 'Win32' => '', 'Cookies' => '', 'JavaScript' => '', 'CssVersion' => '', 'isMobileDevice' => '');
     $bc = new Browscap(Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . "cache");
     $EmailData['clientInfo'] = array_intersect_key((array) $bc->getBrowser(), $EmailData['clientInfo']);
     $this->renderc('email/contact', $EmailData);
 }
Example #14
0
 /**
  * Give some info on browser
  * @param	string	$property [optional default ''] : Name of the property (case in-sensitive) to retrieve. '' for browser array instead as returend by browscap.
  * @return	mixed	Value of property or browser array that was returned by Browscap
  */
 public static function gb($property = '')
 {
     $property = strtolower($property);
     static $cached_browscap = null;
     // will either be cached array OR the object itself if it was loaded
     static $cached_js_detect = null;
     switch ($property) {
         // Properties that are not returned by Browscap
         //case 'Accept' : return explode(",", strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"])); break;	// useless since IE always return */*
         case 'languages':
             return isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? explode(",", strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"])) : array();
         case 'country':
             throw new exception('TODO : Not available yet');
         case 'javascript_detected':
             return isset($_SESSION['BF_' . BF::gc('project_id') . '_cached_js_detect']);
         case 'js_browser':
         case 'js_browser_version':
         case 'js_flash':
         case 'js_resolution':
             if (!isset($_SESSION['BF_' . BF::gc('project_id') . '_cached_js_detect'])) {
                 return null;
             }
             if (!isset($cached_js_detect)) {
                 $cached_js_detect = array_combine(array('js_browser', 'js_browser_version', 'js_flash', 'js_resolution'), explode('|', $_SESSION['BF_' . BF::gc('project_id') . '_cached_js_detect']));
             }
             return $cached_js_detect[$property];
             // Properties that are returned by Browscap
             // cached properties
         // Properties that are returned by Browscap
         // cached properties
         case 'browser':
         case 'version':
         case 'platform':
         case 'win32':
         case 'majorver':
         case 'wap':
         case 'ismobiledevice':
         case 'crawler':
             if ($cached_browscap) {
                 return is_array($cached_browscap) ? $cached_browscap[$property] : $cached_browscap->{$property};
             } elseif (isset($_SESSION['BF_' . BF::gc('project_id') . 'cached_browscap'])) {
                 $cached_browscap = array_combine(array('browser', 'version', 'platform', 'win32', 'majorver', 'wap', 'ismobiledevice', 'crawler'), explode('|', $_SESSION['BF_' . BF::gc('project_id') . '_cached_browscap']));
                 return $cached_browscap[$property];
             }
             // not cached properties
         // not cached properties
         default:
             if (!$cached_browscap || !is_object($cached_browscap)) {
                 if (!BF::gf('browscap')) {
                     throw new exception('Invalid config entry for browscap folder path');
                 }
                 BF::load_module('Browscap');
                 $previous_error_reporting = error_reporting();
                 error_reporting($previous_error_reporting ^ E_STRICT ^ E_NOTICE);
                 // shut off notices
                 $bc = new Browscap(gf('browscap')->path);
                 $cached_browscap = array_change_key_case($bc->getBrowser(null, true), CASE_LOWER);
                 error_reporting($previous_error_reporting);
                 if (!isset($_SESSION['BF_' . BF::gc('project_id') . '_cached_browscap'])) {
                     $_SESSION['BF_' . BF::gc('project_id') . '_cached_browscap'] = implode('|', array($cached_browscap['browser'], $cached_browscap['version'], $cached_browscap['platform'], $cached_browscap['win32'], $cached_browscap['majorver'], $cached_browscap['wap'], $cached_browscap['ismobiledevice'], $cached_browscap['crawler']));
                 }
             }
             if ($property) {
                 return $cached_browscap[$property];
             } else {
                 return $cached_browscap;
             }
     }
 }