www/web-proxy-sso: adapt to mutable thingy, fix update-only and typo

PR: https://github.com/opnsense/plugins/issues/43
This commit is contained in:
Franco Fichtner
2016-10-22 16:44:19 +02:00
parent fe6f1175dd
commit 1a14d86fe0
11 changed files with 33 additions and 77 deletions
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,6 @@
* 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.
*
*/
namespace OPNsense\SSOProxyAD\Api;
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,59 +24,28 @@
* 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.
*
*/
namespace OPNsense\SSOProxyAD\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\SSOProxyAD\SSOProxyAD;
use \OPNsense\Base\ApiMutableModelControllerBase;
use \OPNsense\Core\Config;
class SettingsController extends ApiControllerBase
class SettingsController extends ApiMutableModelControllerBase
{
/*
* retrieve SSO Proxy Active Directory general settings
* @return array general settings
static protected $internalModelClass = '\OPNsense\SSOProxyAD\SSOProxyAD';
static protected $internalModelName = 'ssoproxyad';
/**
* @return array plain model settings (non repeating items)
*/
public function getAction()
protected function getModelNodes()
{
// define list of configurable settings
$settingsNodes = array('general');
$result = array();
if ($this->request->isGet()) {
$mdlSSOProxyAD= new SSOProxyAD();
$result['ssoproxyad'] = $mdlSSOProxyAD->getNodes();
}
return $result;
}
/**
* update SSOProxyAD settings
* @return array status
*/
public function setAction()
{
$result = array("result"=>"failed");
if ($this->request->isPost()) {
// load model and update with provided data
$mdlSSOProxyAD= new SSOProxyAD();
$mdlSSOProxyAD->setNodes($this->request->getPost("ssoproxyad"));
// perform validation
$valMsgs = $mdlSSOProxyAD->performValidation();
foreach ($valMsgs as $field => $msg) {
if (!array_key_exists("validations", $result)) {
$result["validations"] = array();
}
$result["validations"]["general.".$msg->getField()] = $msg->getMessage();
}
// serialize model to config and save
if ($valMsgs->count() == 0) {
$mdlSSOProxyAD->serializeToConfig();
Config::getInstance()->save();
$result["result"] = "saved";
}
$mdlSSO = $this->getModel();
foreach ($settingsNodes as $key) {
$result[$key] = $mdlSSO->$key->getNodes();
}
return $result;
}
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,6 @@
* 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.
*
*/
namespace OPNsense\SSOProxyAD;
@@ -33,11 +32,8 @@ class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
// set page title, used by the standard template in layouts/default.volt.
$this->view->title = "SSO Proxy Active Directory";
// pick the template to serve to our users.
$this->view->title = gettext('SSO Proxy Active Directory');
$this->view->pick('OPNsense/SSOProxyAD/index');
$this->view->generalForm = $this->getForm("general");
}
}
@@ -22,7 +22,7 @@
</field>
<field>
<id>ssoproxyad.general.DomainUser</id>
<label>Active Directory Domin User</label>
<label>Active Directory Domain User</label>
<type>text</type>
</field>
<field>
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,6 @@
* 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.
*
*/
namespace OPNsense\Auth;
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,8 +24,8 @@
* 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.
*
*/
namespace OPNsense\SSOProxyAD;
use OPNsense\Base\BaseModel;
@@ -21,7 +21,7 @@
<DomainUser type="TextField">
<Required>Y</Required>
</DomainUser>
<DomainPassword type="UpdateOnly">
<DomainPassword type="UpdateOnlyTextField">
<Required>Y</Required>
</DomainPassword>
<UpdateCron type="ModelRelationField">
@@ -1,6 +1,5 @@
{#
Copyright (C) 2016 gitdevmod@github.com
Copyright (C) 2016 <gitdevmod@github.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -23,7 +22,6 @@ 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'])}}
@@ -2,8 +2,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,13 +25,13 @@
* 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.
*
*/
// Use legacy code to export certificates to the filesystem.
require_once("config.inc");
require_once("certs.inc");
require_once("legacy_bindings.inc");
use OPNsense\Core\Config;
global $config;
@@ -1,7 +1,7 @@
#!/usr/local/bin/python2.7
"""
Copyright (c) 2015 Ad Schellevis
Copyright (c) 2016 <gitdevmod@github.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -24,11 +24,8 @@
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 json
@@ -2,8 +2,7 @@
<?php
/**
* Copyright (C) 2016 gitdevmod@github.com
*
* Copyright (C) 2016 <gitdevmod@github.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,13 +25,13 @@
* 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.
*
*/
// Use legacy code to export certificates to the filesystem.
require_once("config.inc");
require_once("certs.inc");
require_once("legacy_bindings.inc");
use OPNsense\Core\Config;
global $config;