From a2b765486d71ae1d003a928f2d66b39735e8136c Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 28 Dec 2014 12:14:03 +0000 Subject: [PATCH] move new classes to comply with PSR1/2 style guides, still a lot todo here... --- src/etc/inc/captiveportal.inc | 18 +++++++-------- src/etc/inc/voucher.inc | 4 ++-- .../CaptivePortal}/ARP.php | 23 +++++++++++-------- .../CaptivePortal}/CPClient.php | 14 ++++++----- .../CaptivePortal}/DB.php | 4 ++-- .../CaptivePortal}/Rules.php | 4 ++-- .../app/models/{ => OPNsense}/Core/Config.php | 4 ++-- .../app/models/{ => OPNsense}/Core/Shell.php | 2 +- .../models/{ => OPNsense}/Core/Singleton.php | 2 +- src/opnsense/mvc/script/test.php | 7 +++++- src/www/services_captiveportal_zones.php | 2 +- src/www/status_captiveportal.php | 2 +- .../widgets/captive_portal_status.widget.php | 2 +- 13 files changed, 49 insertions(+), 39 deletions(-) rename src/opnsense/mvc/app/models/{Captiveportal => OPNsense/CaptivePortal}/ARP.php (91%) rename src/opnsense/mvc/app/models/{Captiveportal => OPNsense/CaptivePortal}/CPClient.php (99%) rename src/opnsense/mvc/app/models/{Captiveportal => OPNsense/CaptivePortal}/DB.php (99%) rename src/opnsense/mvc/app/models/{Captiveportal => OPNsense/CaptivePortal}/Rules.php (99%) rename src/opnsense/mvc/app/models/{ => OPNsense}/Core/Config.php (98%) rename src/opnsense/mvc/app/models/{ => OPNsense}/Core/Shell.php (99%) rename src/opnsense/mvc/app/models/{ => OPNsense}/Core/Singleton.php (99%) diff --git a/src/etc/inc/captiveportal.inc b/src/etc/inc/captiveportal.inc index 651e48434..8c13abf6e 100644 --- a/src/etc/inc/captiveportal.inc +++ b/src/etc/inc/captiveportal.inc @@ -54,14 +54,14 @@ require_once("script/load_phalcon.php"); // TODO : restructure code / gui, for now we try to maintain gui compatibility by not breaking the old callbacks // function captiveportal_passthrumac_configure_entry($macent) { - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->update(); return "" ; } function captiveportal_passthrumac_delete_entry($macent) { - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->update(); return "" ; @@ -72,7 +72,7 @@ function captiveportal_passthrumac_configure($lock = false) { } function captiveportal_allowedip_configure_entry($ipent, $ishostname = false) { - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->update(); return "" ; @@ -86,7 +86,7 @@ function captiveportal_allowedip_configure() { function captiveportal_disconnect_client($sessionid, $term_cause = 1, $logoutReason = "LOGOUT") { global $cpzone; - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->disconnect($cpzone,$sessionid); } @@ -96,7 +96,7 @@ function captiveportal_remove_entries($remove) { if (!is_array($remove) || empty($remove)) return; - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->disconnect($cpzone,$remove); } @@ -120,7 +120,7 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut if (is_null($radiusctx)) $radiusctx = 'first'; - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $sessionid = $cpc->portal_allow($cpzone,$clientip,$clientmac,$username,$password,$bw_up,$bw_down,$radiusctx,$session_timeout,$idle_timeout,$session_terminate_time,$interim_interval); if (isset($config['captiveportal'][$cpzone]['radacct_enable']) && !empty($radiusservers[$radiusctx])) { @@ -199,7 +199,7 @@ function captiveportal_init_rules($reinit = false) { // if ( $reinit ) { - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpc->reconfigure(); unset($cpc); } @@ -651,7 +651,7 @@ function captiveportal_prune_old() { if (empty($cpzone)) return; - $cpc = new Captiveportal\CPClient(); + $cpc = new OPNsense\CaptivePortal\CPClient(); $cpcfg = $config['captiveportal'][$cpzone]; if ( !isset($cpcfg['radacct_enable'])) { @@ -841,7 +841,7 @@ function captiveportal_radius_stop_all() { $radiusservers = captiveportal_get_radius_servers(); if (!empty($radiusservers)) { - $cpdb = new Captiveportal\DB($cpzone); + $cpdb = new OPNsense\Captiveportal\DB($cpzone); $clients = $cpdb->listClients(array()); diff --git a/src/etc/inc/voucher.inc b/src/etc/inc/voucher.inc index e08f140f6..af629694d 100644 --- a/src/etc/inc/voucher.inc +++ b/src/etc/inc/voucher.inc @@ -218,8 +218,8 @@ EOF; function voucher_expire($voucher_received) { global $g, $config, $cpzone; - $cpdb = new Captiveportal\DB($cpzone); - $cpc = new Captiveportal\CPClient(); + $cpdb = new OPNsense\CaptivePortal\DB($cpzone); + $cpc = new OPNsense\CaptivePortal\CPClient(); // XMLRPC Call over to the master Voucher node if(!empty($config['voucher'][$cpzone]['vouchersyncdbip'])) { diff --git a/src/opnsense/mvc/app/models/Captiveportal/ARP.php b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/ARP.php similarity index 91% rename from src/opnsense/mvc/app/models/Captiveportal/ARP.php rename to src/opnsense/mvc/app/models/OPNsense/CaptivePortal/ARP.php index 70b9ea388..6b3a97721 100644 --- a/src/opnsense/mvc/app/models/Captiveportal/ARP.php +++ b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/ARP.php @@ -30,12 +30,12 @@ function: provides access to the systems ARP table */ +namespace OPNsense\CaptivePortal; +use \OPNsense\Core; -namespace Captiveportal; - - -class ARP { +class ARP +{ /** * pointer to shell object @@ -46,9 +46,9 @@ class ARP { /** * construct new ARP table handlers */ - function __construct() + public function __construct() { - $this->shell = new \Core\Shell(); + $this->shell = new Core\Shell(); } /** @@ -56,10 +56,13 @@ class ARP { * @param $ipaddress hosts ipaddress * @param $mac hosts physical address */ - function setStatic($ipaddress,$mac){ + public function setStatic($ipaddress, $mac) + { // validate input, only set static entries for valid addresses - if (preg_match('/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/', trim($mac))){ - if ( filter_var($ipaddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4|FILTER_FLAG_IPV6) ){ + if (preg_match('/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/', trim($mac))) + { + if ( filter_var($ipaddress , FILTER_VALIDATE_IP, FILTER_FLAG_IPV4|FILTER_FLAG_IPV6) ) + { $this->shell->exec("/usr/sbin/arp -s ".trim($ipaddress)." ".trim($mac)); } } @@ -106,4 +109,4 @@ class ARP { } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/opnsense/mvc/app/models/Captiveportal/CPClient.php b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CPClient.php similarity index 99% rename from src/opnsense/mvc/app/models/Captiveportal/CPClient.php rename to src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CPClient.php index 07bc8ce9b..efe4124eb 100644 --- a/src/opnsense/mvc/app/models/Captiveportal/CPClient.php +++ b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CPClient.php @@ -32,12 +32,14 @@ */ -namespace Captiveportal; +namespace OPNsense\CaptivePortal; + +use \OPNsense\Core; /** * Class CPClient * // TODO: CARP interfaces are probably not handled correctly - * @package Captiveportal + * @package CaptivePortal */ class CPClient { @@ -50,7 +52,7 @@ class CPClient { /** * ipfw rule object - * @var \Captiveportal\Rules + * @var \CaptivePortal\Rules */ private $rules = null; @@ -227,9 +229,9 @@ class CPClient { // Request handle to configuration $this->config = \Core\Config::getInstance(); // generate new ruleset - $this->rules = new \Captiveportal\Rules(); + $this->rules = new Rules(); // keep a link to the shell object - $this->shell = new \Core\Shell(); + $this->shell = new Core\Shell(); } /** @@ -581,7 +583,7 @@ class CPClient { */ function flush($zone=null){ if ( $zone == null ) { - $shell = new \Core\Shell(); + $shell = new Core\Shell(); $shell->exec("/sbin/ipfw -f table all flush"); } else{ diff --git a/src/opnsense/mvc/app/models/Captiveportal/DB.php b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/DB.php similarity index 99% rename from src/opnsense/mvc/app/models/Captiveportal/DB.php rename to src/opnsense/mvc/app/models/OPNsense/CaptivePortal/DB.php index 260dcfa7b..df663e119 100644 --- a/src/opnsense/mvc/app/models/Captiveportal/DB.php +++ b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/DB.php @@ -31,11 +31,11 @@ */ -namespace Captiveportal; +namespace OPNsense\CaptivePortal; /** * Class DB, handles captive portal zone's adminstration - * @package Captiveportal + * @package CaptivePortal */ class DB { diff --git a/src/opnsense/mvc/app/models/Captiveportal/Rules.php b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/Rules.php similarity index 99% rename from src/opnsense/mvc/app/models/Captiveportal/Rules.php rename to src/opnsense/mvc/app/models/OPNsense/CaptivePortal/Rules.php index 154ca8b52..bcb72d03e 100644 --- a/src/opnsense/mvc/app/models/Captiveportal/Rules.php +++ b/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/Rules.php @@ -31,12 +31,12 @@ */ -namespace Captiveportal; +namespace OPNsense\CaptivePortal; /** * Class Rules - * @package Captiveportal + * @package CaptivePortal */ class Rules { diff --git a/src/opnsense/mvc/app/models/Core/Config.php b/src/opnsense/mvc/app/models/OPNsense/Core/Config.php similarity index 98% rename from src/opnsense/mvc/app/models/Core/Config.php rename to src/opnsense/mvc/app/models/OPNsense/Core/Config.php index ca32ae411..32653ea13 100644 --- a/src/opnsense/mvc/app/models/Core/Config.php +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Config.php @@ -32,7 +32,7 @@ */ -namespace Core; +namespace OPNsense\Core; /** * Class ConfigException @@ -44,7 +44,7 @@ class ConfigException extends \Exception { } * Class Config * @package Core */ -class Config extends \Core\Singleton { +class Config extends Singleton { /** * config file location ( path + name ) diff --git a/src/opnsense/mvc/app/models/Core/Shell.php b/src/opnsense/mvc/app/models/OPNsense/Core/Shell.php similarity index 99% rename from src/opnsense/mvc/app/models/Core/Shell.php rename to src/opnsense/mvc/app/models/OPNsense/Core/Shell.php index 329c846a6..f840e200f 100644 --- a/src/opnsense/mvc/app/models/Core/Shell.php +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Shell.php @@ -31,7 +31,7 @@ */ -namespace Core; +namespace OPNsense\Core; class Shell diff --git a/src/opnsense/mvc/app/models/Core/Singleton.php b/src/opnsense/mvc/app/models/OPNsense/Core/Singleton.php similarity index 99% rename from src/opnsense/mvc/app/models/Core/Singleton.php rename to src/opnsense/mvc/app/models/OPNsense/Core/Singleton.php index 6c3a53bad..3698aa40f 100644 --- a/src/opnsense/mvc/app/models/Core/Singleton.php +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Singleton.php @@ -31,7 +31,7 @@ */ -namespace Core; +namespace OPNsense\Core; /** diff --git a/src/opnsense/mvc/script/test.php b/src/opnsense/mvc/script/test.php index 0e6f13b08..651a325a1 100644 --- a/src/opnsense/mvc/script/test.php +++ b/src/opnsense/mvc/script/test.php @@ -2,9 +2,14 @@ require_once("script/load_phalcon.php"); $cpc = new Captiveportal\CPClient(); + +$acc_list = $cpc->list_accounting(); + +print_r($acc_list); + //$cpc->portal_allow("test","10.211.55.101","00:1C:42:49:B7:B2","Fritsx"); -$cpc->disconnect("test",array("5489714eba263","gdsajhgadsjhg")); +//$cpc->disconnect("test",array("5489714eba263","gdsajhgadsjhg")); //$cpc->reconfigure(); //$cpc->refresh_allowed_mac(); diff --git a/src/www/services_captiveportal_zones.php b/src/www/services_captiveportal_zones.php index 1522fa66e..6f0321550 100644 --- a/src/www/services_captiveportal_zones.php +++ b/src/www/services_captiveportal_zones.php @@ -94,7 +94,7 @@ $main_buttons = array( countClients() ; ?> diff --git a/src/www/status_captiveportal.php b/src/www/status_captiveportal.php index 4f8f2cdeb..b15db4bcf 100644 --- a/src/www/status_captiveportal.php +++ b/src/www/status_captiveportal.php @@ -80,7 +80,7 @@ function clientcmp($a, $b) { } if (!empty($cpzone)) { - $cpdb_handle = new Captiveportal\DB($cpzone); + $cpdb_handle = new OPNsense\CaptivePortal\DB($cpzone); $order = ""; if ($_GET['order']) { diff --git a/src/www/widgets/widgets/captive_portal_status.widget.php b/src/www/widgets/widgets/captive_portal_status.widget.php index 26b6661ac..16ac75437 100644 --- a/src/www/widgets/widgets/captive_portal_status.widget.php +++ b/src/www/widgets/widgets/captive_portal_status.widget.php @@ -63,7 +63,7 @@ $a_cp =& $config['captiveportal']; $cpdb_all = array(); foreach ($a_cp as $cpzone => $cp) { - $cpdb_handle = new Captiveportal\DB($cpzone); + $cpdb_handle = new OPNsense\CaptivePortal\DB($cpzone); $order = ""; if ($_GET['order']) {