summaryrefslogtreecommitdiff
path: root/routers/router.php
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-09-24 15:04:36 +0200
committerGuillaume Mazoyer <respawneral@gmail.com>2014-09-24 15:04:36 +0200
commita7d51630981d0bbf68bfa1fa059cd56d3fc634ce (patch)
tree8aa50945e1d82aa7e5202e516bd4300d3716eaf8 /routers/router.php
parent652b2723b3a2915acb65cd4af9ad775665ad8deb (diff)
Log format can be configured.
The format for each log can be configured with the configuration option defined by $config['logs']['format']. %D is for the time, %R is for the requester IP address, %H is for the host on which the command has been executed and %C is for the command. Warning! The configuration option to choose the logs file has been moved from $config['misc']['logs'] to $config['logs']['file'].
Diffstat (limited to 'routers/router.php')
-rw-r--r--routers/router.php24
1 files changed, 13 insertions, 11 deletions
diff --git a/routers/router.php b/routers/router.php
index 3d6bd07..26f93fd 100644
--- a/routers/router.php
+++ b/routers/router.php
@@ -29,21 +29,21 @@ require_once 'includes/utils.php';
require_once 'auth/authentication.php';
abstract class Router {
+ protected $global_config;
protected $config;
protected $id;
protected $requester;
- public function __construct($config, $id, $requester) {
+ public function __construct($global_config, $config, $id, $requester) {
+ $this->global_config = $global_config;
$this->config = $config;
$this->id = $id;
$this->requester = $requester;
}
private function sanitize_output($output) {
- global $config;
-
// No filters defined
- if (count($config['filters']) < 1) {
+ if (count($this->global_config['filters']) < 1) {
return preg_replace('/(?:\n|\r\n|\r)$/D', '', $output);
}
@@ -52,7 +52,7 @@ abstract class Router {
foreach (preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) {
$valid = true;
- foreach ($config['filters'] as $filter) {
+ foreach ($this->global_config['filters'] as $filter) {
// Line has been marked as invalid
// Or filtered based on the configuration
if (!$valid || (preg_match($filter, $line) === 1)) {
@@ -97,8 +97,10 @@ abstract class Router {
$data .= $this->format_output($selected, $output);
- log_to_file('[client: '.$this->requester.'] '.$this->config['host'].
- '> '.$selected);
+ $log = str_replace(array('%D', '%R', '%H', '%C'),
+ array(date('Y-m-d H:i:s'), $this->requester, $this->config['host'],
+ $selected), $this->global_config['logs']['format']);
+ log_to_file($log);
}
} catch (Exception $e) {
throw $e;
@@ -114,19 +116,19 @@ abstract class Router {
switch (strtolower($router_config['type'])) {
case 'bird':
- return new Bird($router_config, $id, $requester);
+ return new Bird($config, $router_config, $id, $requester);
case 'cisco':
case 'ios':
- return new Cisco($router_config, $id, $requester);
+ return new Cisco($config, $router_config, $id, $requester);
case 'juniper':
case 'junos':
- return new Juniper($router_config, $id, $requester);
+ return new Juniper($config, $router_config, $id, $requester);
case 'quagga':
case 'zebra':
- return new Quagga($router_config, $id, $requester);
+ return new Quagga($config, $router_config, $id, $requester);
default:
print 'Unknown router type "'.$router_config['type'].'"."';