From 869f61c23a5fdce1f8ebf1d3fe88506ca45782bc Mon Sep 17 00:00:00 2001 From: Jos Schellevis Date: Thu, 2 Apr 2015 16:39:32 +0200 Subject: [PATCH] Proxy server WIP --- .../OPNsense/Proxy/Api/ServiceController.php | 8 +- .../OPNsense/Proxy/Api/SettingsController.php | 45 ++-- .../OPNsense/Proxy/IndexController.php | 2 +- .../mvc/app/models/OPNsense/Proxy/General.xml | 21 -- .../OPNsense/Proxy/{General.php => Proxy.php} | 2 +- .../mvc/app/models/OPNsense/Proxy/Proxy.xml | 37 ++++ .../mvc/app/views/OPNsense/Proxy/index.volt | 195 +++++++++++++----- .../app/views/layout_partials/base_tabs.volt | 35 ++++ .../views/layout_partials/form_input_tr.volt | 11 +- .../layout_partials/sample_input_field.volt | 2 +- .../templates/OPNsense/Proxy/squid.conf | 22 +- src/opnsense/www/css/jquery.tokenize.css | 7 +- 12 files changed, 280 insertions(+), 107 deletions(-) delete mode 100644 src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml rename src/opnsense/mvc/app/models/OPNsense/Proxy/{General.php => Proxy.php} (97%) create mode 100644 src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml create mode 100644 src/opnsense/mvc/app/views/layout_partials/base_tabs.volt diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php index 6b95b9d3c..9295f9f5e 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php @@ -30,7 +30,7 @@ namespace OPNsense\Proxy\Api; use \OPNsense\Base\ApiControllerBase; use \OPNsense\Core\Backend; -use \OPNsense\Proxy\General; +use \OPNsense\Proxy\Proxy; /** * Class ServiceController @@ -101,13 +101,13 @@ class ServiceController extends ApiControllerBase // close session for long running action session_write_close(); - $mdlGeneral = new General(); + $mdlProxy = new Proxy(); $backend = new Backend(); $runStatus = $this->statusAction(); // stop squid when disabled - if ($runStatus['status'] == "running" && $mdlGeneral->enabled->__toString() == 0) { + if ($runStatus['status'] == "running" && $mdlProxy->general->enabled->__toString() == 0) { $this->stopAction(); } @@ -115,7 +115,7 @@ class ServiceController extends ApiControllerBase $backend->sendEvent("template reload OPNsense.Proxy"); // (res)start daemon - if ($mdlGeneral->enabled->__toString() == 1) { + if ($mdlProxy->general->enabled->__toString() == 1) { if ($runStatus['status'] == "running") { $backend->sendEvent("service reconfigure proxy"); } else { diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php index 87ef60250..e7c529382 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/SettingsController.php @@ -29,7 +29,7 @@ namespace OPNsense\Proxy\Api; use \OPNsense\Base\ApiControllerBase; -use \OPNsense\Proxy\General; +use \OPNsense\Proxy\Proxy; use \OPNsense\Core\Config; /** @@ -39,19 +39,40 @@ use \OPNsense\Core\Config; class SettingsController extends ApiControllerBase { /** - * retrieve general settings + * retrieve proxy settings * @return array */ public function getAction() { $result = array(); if ($this->request->isGet()) { - $mdlGeneral = new General(); + $mdlProxy = new Proxy(); - $selopt=array("lan"=>"LAN","wan"=>"WAN"); - $mdlGeneral->interfaces->setSelectOptions($selopt); + // Define array for selected interfaces + $selopt=Array(); - $result['general'] = $mdlGeneral->getNodes(); + // Get ConfigObject + $configObj = Config::getInstance()->object(); + // Iterate over all interfaces configuration + // TODO: replace for helper + foreach ( $configObj->interfaces->children() as $key => $value ) { + // Check if interface is enabled, if tag is treat as enabled. + if ( isset($value->enable) && ( $value->enable != '0' ) ) { + // Check if interface has static ip + if ($value->ipaddr != 'dhcp') { + + if ($value->descr == '') { + $description = strtoupper($key); // Use interface name as description if none is given + } else { + $description = $value->descr; + } + $selopt[$key] = (string)$description; // Add Interface to selectable options. + } + } + } + + $mdlProxy->forward->interfaces->setSelectOptions($selopt); + $result['proxy'] = $mdlProxy->getNodes(); } return $result; @@ -66,23 +87,23 @@ class SettingsController extends ApiControllerBase public function setAction() { $result = array("result"=>"failed"); - if ($this->request->hasPost("general")) { + if ($this->request->hasPost("proxy")) { // load model and update with provided data - $mdlGeneral = new General(); - $mdlGeneral->setNodes($this->request->getPost("general")); + $mdlProxy = new Proxy(); + $mdlProxy->setNodes($this->request->getPost("proxy")); // perform validation - $valMsgs = $mdlGeneral->performValidation(); + $valMsgs = $mdlProxy->performValidation(); foreach ($valMsgs as $field => $msg) { if (!array_key_exists("validations", $result)) { $result["validations"] = array(); } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); + $result["validations"]["proxy.".$msg->getField()] = $msg->getMessage(); } // serialize model to config if ($valMsgs->count() == 0) { - $mdlGeneral->serializeToConfig(); + $mdlProxy->serializeToConfig(); } } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/IndexController.php b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/IndexController.php index 1f08a03b9..fc2673ade 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/IndexController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/IndexController.php @@ -36,7 +36,7 @@ class IndexController extends \OPNsense\Base\IndexController { public function indexAction() { - $this->view->title = "Proxy"; + $this->view->title = "Proxy Server"; $this->view->pick('OPNsense/Proxy/index'); } } diff --git a/src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml b/src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml deleted file mode 100644 index fe06319ef..000000000 --- a/src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml +++ /dev/null @@ -1,21 +0,0 @@ - - //OPNsense/proxy/general - - (squid) proxy general settings - - - - 0 - Y - - - N - - - 3128 - 1 - 65535 - Y - - - diff --git a/src/opnsense/mvc/app/models/OPNsense/Proxy/General.php b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.php similarity index 97% rename from src/opnsense/mvc/app/models/OPNsense/Proxy/General.php rename to src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.php index d6b98ed8b..d1db6b7f2 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Proxy/General.php +++ b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.php @@ -30,6 +30,6 @@ namespace OPNsense\Proxy; use OPNsense\Base\BaseModel; -class General extends BaseModel +class Proxy extends BaseModel { } diff --git a/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml new file mode 100644 index 000000000..3ab7f1091 --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml @@ -0,0 +1,37 @@ + + //OPNsense/proxy + + (squid) proxy settings + + + + + 0 + Y + + + + + N + + + 3128 + 1 + 65535 + "Proxy port needs to be an integer value between 1 and 65535" + Y + + + 1 + Y + + + 0 + Y + + + N + + + + diff --git a/src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt b/src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt index 87988ee58..cb968117a 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt @@ -1,29 +1,64 @@ - -
-
-
- - - - - - - - {{ partial("layout_partials/form_input_tr", - ['id': 'general.enabled', - 'label':'enabled', - 'type':'checkbox', - 'help':'test' - ]) - }} - {{ partial("layout_partials/form_input_tr", - ['id': 'general.interfaces', - 'label':'interfaces', - 'type':'select_multiple' - ]) - }} - {{ partial("layout_partials/form_input_tr", - ['id': 'general.port', - 'label':'port', - 'type':'text' - ]) - }} + + - - - - -
-
-
-
+{{ partial("layout_partials/base_tabs", + ['tabs': { + ['proxy-general','General Proxy Settings', + {['id': 'proxy.general.enabled', + 'label':'Enable proxy', + 'type':'checkbox', + 'help':'Enable or disable the proxy service.' + ]} + ], + ['proxy-forward','Forward Proxy', + {['id': 'proxy.forward.interfaces', + 'label':'Proxy interfaces', + 'type':'select_multiple', + 'style':'tokenize', + 'help':'Select interface(s) the proxy will bind to.', + 'hint':'Type or select interface' + ], + ['id': 'proxy.forward.port', + 'label':'Proxy port', + 'type':'text', + 'help':'The port the proxy service will listen to.' + ], + ['id': 'proxy.forward.addACLforInterfaceSubnets', + 'label':'Allow interface subnets', + 'type':'checkbox', + 'help':'When enabled the subnets of the selected interfaces will be added to the allow access list.' + ], + ['id': 'proxy.forward.transparentProxyMode', + 'label':'Enable Transparent HTTP proxy', + 'type':'checkbox', + 'help':'Enable transparent proxe mode to forward all requests for destination port 80 to the proxy server without any additional configuration.' + ], + ['id': 'proxy.forward.alternateDNSservers', + 'label':'Use alternate DNS-servers', + 'type':'select_multiple', + 'style':'tokenize', + 'help':'Type IPs of alternative DNS servers you like to use.', + 'hint':'Type or select interface', + 'allownew':'true' + ]} + ] + }, + 'activetab':'proxy-general' + ]) +}} -
-
diff --git a/src/opnsense/mvc/app/views/layout_partials/base_tabs.volt b/src/opnsense/mvc/app/views/layout_partials/base_tabs.volt new file mode 100644 index 000000000..8acd4bbfd --- /dev/null +++ b/src/opnsense/mvc/app/views/layout_partials/base_tabs.volt @@ -0,0 +1,35 @@ + + +
+{% for tab in tabs|default([]) %} +
+
+ + + + + + + + + + + {% for field in tab[2]|default({})%} + {{ partial("layout_partials/form_input_tr",field)}} + {% endfor %} + + + + +
+ {{ lang._('toggle full help on/off') }} +
+
+
+ +{% endfor %} +
diff --git a/src/opnsense/mvc/app/views/layout_partials/form_input_tr.volt b/src/opnsense/mvc/app/views/layout_partials/form_input_tr.volt index 1c2dae4e7..f49a7a68c 100644 --- a/src/opnsense/mvc/app/views/layout_partials/form_input_tr.volt +++ b/src/opnsense/mvc/app/views/layout_partials/form_input_tr.volt @@ -1,8 +1,12 @@
- {{label}} - {% if help|default(false) %} {% endif %} + {% if help|default(false) %} + + {% elseif help|default(false) == false %} + + {% endif %} + {{label}}
@@ -11,11 +15,10 @@ {% elseif type == "checkbox" %} {% elseif type == "select_multiple" %} - + {% endif %} {% if help|default(false) %} -
{% endif %} diff --git a/src/opnsense/mvc/app/views/layout_partials/sample_input_field.volt b/src/opnsense/mvc/app/views/layout_partials/sample_input_field.volt index 517886231..690b8f7cd 100644 --- a/src/opnsense/mvc/app/views/layout_partials/sample_input_field.volt +++ b/src/opnsense/mvc/app/views/layout_partials/sample_input_field.volt @@ -1 +1 @@ - + diff --git a/src/opnsense/service/templates/OPNsense/Proxy/squid.conf b/src/opnsense/service/templates/OPNsense/Proxy/squid.conf index 58970517b..408ab7352 100644 --- a/src/opnsense/service/templates/OPNsense/Proxy/squid.conf +++ b/src/opnsense/service/templates/OPNsense/Proxy/squid.conf @@ -4,19 +4,21 @@ # setup listen configuration {% if helpers.exists('OPNsense.proxy.general.port') %} -{% for interface in OPNsense.proxy.general.interfaces.split(",") %} -{% for intf_key,intf_item in interfaces.iteritems() %} -{% if intf_key == interface and intf_item.ipaddr != 'dhcp' %} +{% for interface in OPNsense.proxy.general.interfaces.split(",") %} +{% for intf_key,intf_item in interfaces.iteritems() %} +{% if intf_key == interface and intf_item.ipaddr != 'dhcp' %} http_port {{intf_item.ipaddr}}:{{ OPNsense.proxy.general.port }} -{% endif %} -{% endfor %} +{% endif %} +{% endfor %} {# virtual ip's #} -{% for intf_key,intf_item in virtualip.iteritems() %} -{% if intf_item.interface == interface and intf_item.mode == 'ipalias' %} +{% if helpers.exists('virtualip') %} +{% for intf_key,intf_item in virtualip.iteritems() %} +{% if intf_item.interface == interface and intf_item.mode == 'ipalias' %} http_port {{intf_item.subnet}}:{{ OPNsense.proxy.general.port }} -{% endif %} -{% endfor %} -{% endfor %} +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} {% endif %} diff --git a/src/opnsense/www/css/jquery.tokenize.css b/src/opnsense/www/css/jquery.tokenize.css index 5c21bf86b..5068c449b 100755 --- a/src/opnsense/www/css/jquery.tokenize.css +++ b/src/opnsense/www/css/jquery.tokenize.css @@ -29,7 +29,9 @@ div.Tokenize ul.TokensContainer { cursor: text; padding: 0 5px 0 0; - height: 100px; + height:auto; + min-height:34px; + max-height: 170px; overflow-y: auto; background-color: white; } @@ -138,6 +140,9 @@ div.Tokenize ul.Dropdown border-radius: 0 0 6px 6px; z-index: 20; + + height: auto; + overflow-x: hidden; } div.Tokenize ul.Dropdown li