diff --git a/resources/classes/event/handler/syslog.php b/resources/classes/event/handler/syslog.php new file mode 100644 index 0000000000..ab5b98e67c --- /dev/null +++ b/resources/classes/event/handler/syslog.php @@ -0,0 +1,36 @@ +include_once('virtual.php'); + +class Syslog extends Event_Handler{ + + protected $ident; + protected $option; + protected $facility; + protected $priority; + function __construct($ident='fusionpbx', $option=(LOG_PID | LOG_PERROR), $facility=LOG_LOCAL0, $priority=LOG_INFO){ + $this->ident = $ident; + $this->option = $option; + $this->facility = $facility; + $this->priority = $priority; + + if ($_SESSION['event']['syslog']['enable'] <> 0){ + openlog($ident, $option, $facility); + } + } + + function __destruct(){ + if ($_SESSION['event']['syslog']['enable'] <> 0){ + closelog(); + } + } + + public function log_event($event_type, $params){ + if ($_SESSION['event']['syslog']['enable'] <> 0){ + $log = '' ; + foreach ($params as $k => $v) { + $log .= "[$k]=[$v] "; + } + + syslog($priority, $log); + } + } +} diff --git a/resources/classes/event/handler/virtual.php b/resources/classes/event/handler/virtual.php new file mode 100644 index 0000000000..58e121259d --- /dev/null +++ b/resources/classes/event/handler/virtual.php @@ -0,0 +1,4 @@ +abstract class Event_Handler{ + // Force Extending class to define this method + abstract public function log_event($event_type, $params); +} diff --git a/resources/classes/events.php b/resources/classes/events.php new file mode 100644 index 0000000000..87658a6f95 --- /dev/null +++ b/resources/classes/events.php @@ -0,0 +1,48 @@ +add_event_function('myfunction') it could be a static method as well + * $e->execute_event(ADD, $params) event type, params is an associative array + */ +include "root.php"; + +define ("MODULE_LOAD", 1); // when loading a FS module with FS +define ("MODULE_UNLOAD", 2); +define ("RELOADXML", 3); // when reloading xml +define ("ADD", 4); // when adding something +define ("EDIT", 5); // when editing something +define ("DEL", 6); // when deleting something +define ("LOGIN", 7); // when login +define ("LOGOUT", 8); // when logout + +if (!class_exists('database')) { + class Events{ + private $handler = array(); + private $event = array(); + + public function __construct(){ + } + // declare log file and file pointer as private properties + + public function add_event_function($event_type, $event_function){ + $event[$event_type][] = $event_function; + } + + public function execute_event($event_type, $params=null){ + foreach ($this->event[$event_type] as $event_function){ + call_user_func($event_function, $params); + + // Lets log + foreach ($this->handler as $handler){ + $handler->log_event($event_type, $params); + } + } + } + } +} + + +?>