added getConfiguredScriptServers()
This commit is contained in:
parent
dc94c51cda
commit
cc3e8057d8
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
use \LAM\LIB\TWO_FACTOR\TwoFactorProviderService;
|
||||
use \LAM\REMOTE\RemoteServerConfiguration;
|
||||
/*
|
||||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
|
@ -1450,6 +1451,30 @@ class LAMConfig {
|
|||
return $this->scriptServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of configureed servers.
|
||||
*
|
||||
* @return RemoteServerConfiguration[] servers
|
||||
*/
|
||||
public function getConfiguredScriptServers() {
|
||||
$servers = array();
|
||||
if (empty($this->scriptServer)) {
|
||||
return $servers;
|
||||
}
|
||||
$serverChunks = explode(';', $this->scriptServer);
|
||||
foreach ($serverChunks as $serverChunk) {
|
||||
if (empty($serverChunk)) {
|
||||
continue;
|
||||
}
|
||||
$serverSettings = explode(':', $serverChunk);
|
||||
$serverName = $serverSettings[0];
|
||||
$serverLabel = isset($serverSettings[1]) ? $serverSettings[1] : null;
|
||||
$serverHomedirPrefix = isset($serverSettings[2]) ? $serverSettings[2] : null;
|
||||
$servers[] = new RemoteServerConfiguration($serverName, $serverLabel, $serverHomedirPrefix);
|
||||
}
|
||||
return $servers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the servers of the external script
|
||||
*
|
||||
|
@ -1470,21 +1495,25 @@ class LAMConfig {
|
|||
// Explode name and IP, if a name exists
|
||||
if (preg_match("/:/", $arr_value)) {
|
||||
$arr_value_explode = explode(":", $arr_value);
|
||||
$ip = $arr_value_explode[1];
|
||||
$servername = $arr_value_explode[0];
|
||||
$label = $arr_value_explode[1];
|
||||
$homedirPrefix = isset($arr_value_explode[2]) ? $arr_value_explode[2] : '';
|
||||
}
|
||||
else {
|
||||
$ip = $arr_value;
|
||||
$servername = "";
|
||||
$servername = $arr_value;
|
||||
$label = '';
|
||||
$homedirPrefix = '';
|
||||
}
|
||||
if (isset($ip) && is_string($ip) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $ip)) {
|
||||
// Check if the IP has a server name
|
||||
if (!empty($servername)) {
|
||||
$valid_ips[] = $servername.":".$ip;
|
||||
if (isset($servername) && is_string($servername) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $servername)) {
|
||||
$serverData = array($servername);
|
||||
if (!empty($label)) {
|
||||
$serverData[] = $label;
|
||||
}
|
||||
else {
|
||||
$valid_ips[] = $ip;
|
||||
if (!empty($homedirPrefix)) {
|
||||
$serverData[] = $homedirPrefix;
|
||||
}
|
||||
$serverChunk = implode(':', $serverData);
|
||||
$valid_ips[] = $serverChunk;
|
||||
}
|
||||
else {
|
||||
// wrong format
|
||||
|
@ -1492,7 +1521,7 @@ class LAMConfig {
|
|||
}
|
||||
}
|
||||
// Check that the array is not empty
|
||||
if ($array_string > 0) {
|
||||
if (!empty($array_string)) {
|
||||
$this->scriptServer = implode(";", $valid_ips);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -174,4 +174,63 @@ class Remote {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Server configuration.
|
||||
*
|
||||
* @author Roland Gruber
|
||||
*/
|
||||
class RemoteServerConfiguration {
|
||||
|
||||
private $server;
|
||||
private $label;
|
||||
private $homeDirPrefix;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $server server DNS name
|
||||
* @param string $label label for GUI
|
||||
* @param string $homeDirPrefix prefix for home directories
|
||||
*/
|
||||
public function __construct($server, $label, $homeDirPrefix) {
|
||||
$this->server = $server;
|
||||
$this->label = $label;
|
||||
if (empty($label)) {
|
||||
$this->label = $server;
|
||||
}
|
||||
$this->homeDirPrefix = $homeDirPrefix;
|
||||
if (empty($homeDirPrefix)) {
|
||||
$this->homeDirPrefix = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server's DNS name.
|
||||
*
|
||||
* @return string server name
|
||||
*/
|
||||
public function getServer() {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a descriptive label.
|
||||
*
|
||||
* @return string label
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix for user home directories.
|
||||
*
|
||||
* @return string prefix for user home directories
|
||||
*/
|
||||
public function getHomeDirPrefix() {
|
||||
return $this->homeDirPrefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -279,12 +279,34 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
|
|||
public function testscriptServers() {
|
||||
$this->assertFalse($this->lAMConfig->set_scriptServers(';;..'));
|
||||
$val = 'server;server';
|
||||
$this->lAMConfig->set_scriptServers($val);
|
||||
$this->assertTrue($this->lAMConfig->set_scriptServers($val));
|
||||
$this->assertEquals($val, $this->lAMConfig->get_scriptServers());
|
||||
$this->doSave();
|
||||
$this->assertEquals($val, $this->lAMConfig->get_scriptServers());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests LAMConfig->getConfiguredScriptServers().
|
||||
*/
|
||||
public function testGetConfiguredScriptServers() {
|
||||
$val = 'server1;server2:label2;server3:label3:/prefix';
|
||||
$this->assertTrue($this->lAMConfig->set_scriptServers($val));
|
||||
$servers = $this->lAMConfig->getConfiguredScriptServers();
|
||||
$this->assertEquals(3, sizeof($servers));
|
||||
$this->doSave();
|
||||
$servers = $this->lAMConfig->getConfiguredScriptServers();
|
||||
$this->assertEquals(3, sizeof($servers));
|
||||
$this->assertEquals('server1', $servers[0]->getServer());
|
||||
$this->assertEquals('server2', $servers[1]->getServer());
|
||||
$this->assertEquals('server3', $servers[2]->getServer());
|
||||
$this->assertEquals('server1', $servers[0]->getLabel());
|
||||
$this->assertEquals('label2', $servers[1]->getLabel());
|
||||
$this->assertEquals('label3', $servers[2]->getLabel());
|
||||
$this->assertEquals('', $servers[0]->getHomeDirPrefix());
|
||||
$this->assertEquals('', $servers[1]->getHomeDirPrefix());
|
||||
$this->assertEquals('/prefix', $servers[2]->getHomeDirPrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests LAMConfig->get_scriptRights() and LAMConfig->set_scriptRights()
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue