diff --git a/devel/helloworld/+POST_DEINSTALL b/devel/helloworld/+POST_DEINSTALL new file mode 100644 index 000000000..e69de29bb diff --git a/devel/helloworld/+POST_INSTALL b/devel/helloworld/+POST_INSTALL new file mode 100644 index 000000000..92d649b8a --- /dev/null +++ b/devel/helloworld/+POST_INSTALL @@ -0,0 +1,4 @@ +echo "restarting configd..." +if /usr/local/etc/rc.d/configd status > /dev/null; then + /usr/local/etc/rc.d/configd restart +fi diff --git a/devel/helloworld/+PRE_DEINSTALL b/devel/helloworld/+PRE_DEINSTALL new file mode 100644 index 000000000..e69de29bb diff --git a/devel/helloworld/+PRE_INSTALL b/devel/helloworld/+PRE_INSTALL new file mode 100644 index 000000000..e69de29bb diff --git a/devel/helloworld/Makefile b/devel/helloworld/Makefile new file mode 100644 index 000000000..ee3cf0a37 --- /dev/null +++ b/devel/helloworld/Makefile @@ -0,0 +1,7 @@ +PLUGIN_NAME= helloworld +PLUGIN_VERSION= 1.0 +PLUGIN_COMMENT= A sample framework application +#PLUGIN_DEPENDS= +PLUGIN_MAINTAINER= adopnsense.org + +.include "../../Mk/plugins.mk" diff --git a/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/ServiceController.php b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/ServiceController.php new file mode 100644 index 000000000..8a63a5921 --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/ServiceController.php @@ -0,0 +1,71 @@ +request->isPost()) { + $backend = new Backend(); + $bckresult = trim($backend->configdRun("template reload OPNsense.HelloWorld")); + if ($bckresult == "OK") { + $status = "ok"; + } + } + return array("status" => $status); + } + + /** + * test HelloWorld + */ + public function testAction() + { + if ($this->request->isPost()) { + $backend = new Backend(); + $bckresult = json_decode(trim($backend->configdRun("helloworld test")), true); + if ($bckresult !== null) { + // only return valid json type responses + return $bckresult; + } + } + return array("message" => "unable to run config action"); + } +} diff --git a/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/SettingsController.php b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/SettingsController.php new file mode 100644 index 000000000..0e4ccf0c8 --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/Api/SettingsController.php @@ -0,0 +1,86 @@ +request->isGet()) { + $mdlHelloWorld = new HelloWorld(); + $result['helloworld'] = $mdlHelloWorld->getNodes(); + } + return $result; + } + + /** + * update HelloWorld settings + * @return array status + */ + public function setAction() + { + $result = array("result"=>"failed"); + if ($this->request->isPost()) { + // load model and update with provided data + $mdlHelloWorld = new HelloWorld(); + $mdlHelloWorld->setNodes($this->request->getPost("helloworld")); + + // perform validation + $valMsgs = $mdlHelloWorld->performValidation(); + foreach ($valMsgs as $field => $msg) { + if (!array_key_exists("validations", $result)) { + $result["validations"] = array(); + } + $result["validations"]["helloworld.".$msg->getField()] = $msg->getMessage(); + } + + // serialize model to config and save + if ($valMsgs->count() == 0) { + $mdlHelloWorld->serializeToConfig(); + Config::getInstance()->save(); + $result["result"] = "saved"; + } + } + return $result; + } +} diff --git a/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/IndexController.php b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/IndexController.php new file mode 100644 index 000000000..5fd186022 --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/IndexController.php @@ -0,0 +1,46 @@ +view->title = "Hello World"; + // pick the template to serve to our users. + $this->view->pick('OPNsense/HelloWorld/index'); + // fetch form data "general" in + $this->view->generalForm = $this->getForm("general"); + } +} diff --git a/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/forms/general.xml b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/forms/general.xml new file mode 100644 index 000000000..8dbba0716 --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/controllers/OPNsense/HelloWorld/forms/general.xml @@ -0,0 +1,30 @@ +
+ + helloworld.general.Enabled + + checkbox + Enable this feature + + + helloworld.general.SMTPHost + + text + + choose a valid IPv4/v6 address + + + helloworld.general.FromEmail + + text + + + helloworld.general.ToEmail + + text + + + helloworld.general.Description + + text + +
diff --git a/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/ACL/ACL.xml b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/ACL/ACL.xml new file mode 100644 index 000000000..db591695c --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/ACL/ACL.xml @@ -0,0 +1,11 @@ + + + + WebCfg - Users: Hello World! + Allow access to the Hello World! module + + ui/helloworld/* + api/helloworld/* + + + diff --git a/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/HelloWorld.php b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/HelloWorld.php new file mode 100644 index 000000000..dac06e53f --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/HelloWorld.php @@ -0,0 +1,35 @@ + + //OPNsense/helloworld + + the OPNsense "Hello World" application + + + + + + + 1 + Y + + + Y + + + sample@example.com + Y + + + Y + please specify a valid email address + + + Y + + + + diff --git a/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/Menu/Menu.xml b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/Menu/Menu.xml new file mode 100644 index 000000000..df3779025 --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/models/OPNsense/HelloWorld/Menu/Menu.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/devel/helloworld/src/opnsense/mvc/app/views/OPNsense/HelloWorld/index.volt b/devel/helloworld/src/opnsense/mvc/app/views/OPNsense/HelloWorld/index.volt new file mode 100644 index 000000000..0c1dd3bce --- /dev/null +++ b/devel/helloworld/src/opnsense/mvc/app/views/OPNsense/HelloWorld/index.volt @@ -0,0 +1,68 @@ +{# + +OPNsense® is Copyright © 2014 – 2015 by Deciso B.V. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +#} + + + + + +
+ {{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_GeneralSettings'])}} +
+ +
+ + +
diff --git a/devel/helloworld/src/opnsense/scripts/OPNsense/HelloWorld/testConnection.py b/devel/helloworld/src/opnsense/scripts/OPNsense/HelloWorld/testConnection.py new file mode 100755 index 000000000..836182013 --- /dev/null +++ b/devel/helloworld/src/opnsense/scripts/OPNsense/HelloWorld/testConnection.py @@ -0,0 +1,76 @@ +#!/usr/local/bin/python2.7 + +""" + Copyright (c) 2015 Ad Schellevis + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------------- + + perform some tests for the helloworld application +""" +import os +import socket +import smtplib +import json +from ConfigParser import ConfigParser + +# set default timeout to 2 seconds +socket.setdefaulttimeout(2) + +hello_world_config = '/usr/local/etc/helloworld/helloworld.conf' + +result = {} +if os.path.exists(hello_world_config): + cnf = ConfigParser() + cnf.read(hello_world_config) + if cnf.has_section('general'): + try: + smtpObj = smtplib.SMTP(cnf.get('general', 'SMTPHost')) + msg_header = "From: " + cnf.get('general', 'FromEmail') + "\n" + \ + "To: " + cnf.get('general', 'ToEmail') + "\n" + \ + "Subject: " + cnf.get('general', 'Subject') + "\n" + \ + "Test message!" + + smtpObj.sendmail(cnf.get('general', 'FromEmail'), [cnf.get('general', 'ToEmail')], msg_header) + smtpObj.quit() + result['message'] = 'test ok!' + except smtplib.SMTPException as error: + # unable to send mail + result['message'] = '%s'%error + except socket.error as error: + # connect error + if error.strerror is None: + # probably hit timeout + result['message'] = 'time out!' + else: + result['message'] = error.strerror + else: + # empty config + result['message'] = 'empty configuration' +else: + # no config + result['message'] = 'no configuration file found' + + +print (json.dumps(result)) diff --git a/devel/helloworld/src/opnsense/service/conf/actions.d/actions_helloworld.conf b/devel/helloworld/src/opnsense/service/conf/actions.d/actions_helloworld.conf new file mode 100644 index 000000000..c5c521793 --- /dev/null +++ b/devel/helloworld/src/opnsense/service/conf/actions.d/actions_helloworld.conf @@ -0,0 +1,5 @@ +[test] +command:/usr/local/opnsense/scripts/OPNsense/HelloWorld/testConnection.py +parameters: +type:script_output +message:hello world module test diff --git a/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+MANIFEST b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+MANIFEST new file mode 100644 index 000000000..21aacd705 --- /dev/null +++ b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+MANIFEST @@ -0,0 +1,8 @@ +name: opnsense-helloworld +version: 1.0 +origin: opnsense/hello-world +comment: framework sample application +desc: configuration templates for helloworld +maintainer: ad at opnsense.org +www: https://opnsense.org +prefix: / diff --git a/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+TARGETS b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+TARGETS new file mode 100644 index 000000000..e906ff952 --- /dev/null +++ b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/+TARGETS @@ -0,0 +1 @@ +helloworld.conf:/usr/local/etc/helloworld/helloworld.conf diff --git a/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/helloworld.conf b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/helloworld.conf new file mode 100644 index 000000000..0b22eba6d --- /dev/null +++ b/devel/helloworld/src/opnsense/service/templates/OPNsense/HelloWorld/helloworld.conf @@ -0,0 +1,9 @@ +{% if true or helpers.exists('OPNsense.helloworld.general') and OPNsense.helloworld.general.Enabled|default("0") == "1" %} +[general] +SMTPHost={{ OPNsense.helloworld.general.SMTPHost|default("") }} +FromEmail={{ OPNsense.helloworld.general.FromEmail|default("") }} +ToEmail={{ OPNsense.helloworld.general.ToEmail|default("") }} +Subject={{ OPNsense.helloworld.general.Description|default("") }} +{% endif %} + +