Current Path :
/
home
/
develito
/
www
/
plugins
/
system
/
bfnetwork
/
bfnetwork
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//home/develito/www/plugins/system/bfnetwork/bfnetwork/bfActivitylog.php
<?php /** * @author Phil Taylor <phil@phil-taylor.com> * @copyright Copyright (C) 2011, 2012, 2013, 2014, 2015 Blue Flame IT Ltd. All rights reserved. * @license Commercial License - Not to be distributed! * @link https://manage.myjoomla.com * @source https://github.com/PhilETaylor/bfnetwork * */ require_once 'bfPreferences.php'; class bfActivitylog { protected static $instance; private $db; private $table_create = 'CREATE TABLE IF NOT EXISTS `bf_activitylog` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `who` varchar(255) DEFAULT NULL, `who_id` int(11) DEFAULT NULL, `what` varchar(255) DEFAULT NULL, `when` datetime DEFAULT NULL, `where` varchar(255) DEFAULT NULL, `where_id` int(11) DEFAULT NULL, `ip` varchar(20) DEFAULT NULL, `useragent` varchar(255) DEFAULT NULL, `meta` text, `action` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `who` (`who`), KEY `who_id` (`who_id`), KEY `when` (`when`) ) DEFAULT CHARSET=utf8'; private $table_insert = 'INSERT INTO `bf_activitylog` (`id`, `who`, `who_id`, `what`, `when`, `where`, `where_id`, `ip`, `useragent`, `meta`,`action`) VALUES (NULL, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", %s, "%s")'; private $prefs; /** * bfActivitylog constructor. */ public function __construct() { $preferences = new bfPreferences(); $this->prefs = $preferences->getPreferences(); $this->db = JFactory::getDBO(); $this->ensureTableCreated(); } public function ensureTableCreated() { $this->db->setQuery($this->table_create); if (method_exists($this->db, 'query')) { $this->db->query(); } else { $this->db->execute(); } } public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new bfActivitylog; } return self::$instance; } /** * If we get here we are "inside" the Joomla Application API and so all Joomla functions available * * @param string $who * @param int $who_id * @param string $what * @param string $where * @param int $where_id * @param null $ip * @param null $userAgent * * * @since version */ public function log($who = 'not me!', $who_id = 0, $what = 'dunno', $where = 'er?', $where_id = 0, $ip = NULL, $userAgent = NULL, $meta = '{}', $action = '', $alertName = '') { $when = JFactory::getDate()->format('Y-m-d H:i:s', TRUE); if (NULL == $ip) { $ip = str_replace('::ffff:', '', (@getenv('HTTP_X_FORWARDED_FOR') ? @getenv('HTTP_X_FORWARDED_FOR') : @$_SERVER['REMOTE_ADDR'])); } if ('system' == $ip) { $ip = ''; } $sql = sprintf($this->table_insert, $who, $who_id, $what, $when, $where, $where_id, $ip, NULL, $this->db->quote($meta), $action ); $this->db->setQuery($sql); if (method_exists($this->db, 'execute')) { $this->db->execute(); } else { $this->db->query(); } if (property_exists($this->prefs, $alertName) && $this->prefs->$alertName == 1) { $this->sendLogAlert($who, $who_id, $what, $when, $where, $where_id, $ip, $userAgent, $meta, $action, $alertName); } } public function sendLogAlert($who = 'not me!', $who_id = 0, $what = 'dunno', $when, $where = 'er?', $where_id = 0, $ip = NULL, $userAgent = NULL, $meta = '{}', $action = '', $alertName = '') { $host_id = $this->getHostID(); if (!$host_id) return; $postdata = http_build_query( array( 'HOST_ID' => $host_id, 'who' => $who, 'who_id' => $who_id, 'what' => $what, 'what' => $what, 'when' => $when, 'where' => $where, 'where_id' => $where_id, 'ip' => $ip, 'userAgent' => $userAgent, 'meta' => $meta, 'action' => $action, 'alert_name' => $alertName ) ); $opts = array('http' => array( 'content' => $postdata, 'method' => 'POST', 'user_agent' => JURI::base(), 'max_redirects' => 1, 'header' => 'Content-type: application/x-www-form-urlencoded', 'proxy' => (getenv('APPLICATION_ENV') == 'local' ? 'tcp://127.0.0.1:8888' : ''), 'timeout' => 5, //so we don't destroy live sites if the service is offline ) ); if (getenv('APPLICATION_ENV') == 'local') { return @file_get_contents('https://local-manage.myjoomla.com/api/log', FALSE, stream_context_create($opts)); } else { // Using @ so we don't destroy live sites if the service is offline return @file_get_contents('https://manage.myjoomla.com/api/log', FALSE, stream_context_create($opts)); } } public function getHostID() { $files = array( str_replace('/administrator', '', JPATH_BASE . '/plugins/system/bfnetwork/HOST_ID'), //Joomla 1.5 gulp str_replace('/administrator', '', JPATH_BASE . '/plugins/system/bfnetwork/bfnetwork/HOST_ID')//Joomla 2+ ); foreach ($files as $file) { if (file_exists($file)) { return file_get_contents($file); } } } }