preparations for assign-multiple-ips-to-an-admin in Api, not in webinterface yet
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -95,7 +95,7 @@ CREATE TABLE `panel_admins` (
|
|||||||
`name` varchar(255) NOT NULL default '',
|
`name` varchar(255) NOT NULL default '',
|
||||||
`email` varchar(255) NOT NULL default '',
|
`email` varchar(255) NOT NULL default '',
|
||||||
`def_language` varchar(255) NOT NULL default '',
|
`def_language` varchar(255) NOT NULL default '',
|
||||||
`ip` tinyint(4) NOT NULL default '-1',
|
`ip` varchar(500) NOT NULL default '-1',
|
||||||
`customers` int(15) NOT NULL default '0',
|
`customers` int(15) NOT NULL default '0',
|
||||||
`customers_used` int(15) NOT NULL default '0',
|
`customers_used` int(15) NOT NULL default '0',
|
||||||
`customers_see_all` tinyint(1) NOT NULL default '0',
|
`customers_see_all` tinyint(1) NOT NULL default '0',
|
||||||
|
|||||||
@@ -51,4 +51,18 @@ if (isFroxlorVersion('0.10.0')) {
|
|||||||
showUpdateStep("Adding new default-ssl-ip setting");
|
showUpdateStep("Adding new default-ssl-ip setting");
|
||||||
Settings::AddNew('system.defaultsslip', '');
|
Settings::AddNew('system.defaultsslip', '');
|
||||||
lastStepStatus(0);
|
lastStepStatus(0);
|
||||||
|
|
||||||
|
showUpdateStep("Altering admin ip's field to allow multiple ip addresses");
|
||||||
|
// get all admins for updating the new field
|
||||||
|
$sel_stmt = Database::prepare("SELECT adminid, ip FROM `panel_admins`");
|
||||||
|
Database::pexecute($sel_stmt);
|
||||||
|
$all_admins = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
Database::query("ALTER TABLE `panel_admins` MODIFY `ip` varchar(500) NOT NULL default '-1';");
|
||||||
|
$upd_stmt = Database::prepare("UPDATE `panel_admins` SET `ip` = :ip WHERE `adminid` = :adminid");
|
||||||
|
foreach ($all_admins as $adm) {
|
||||||
|
if ($admin['ip'] != -1) {
|
||||||
|
Database::pexecute($upd_stmt, array('ip' => json_encode($adm['ip']), 'adminid' => $adm['adminid']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastStepStatus(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
$tickets_see_all = $this->getParam('tickets_see_all', true, 0);
|
$tickets_see_all = $this->getParam('tickets_see_all', true, 0);
|
||||||
$caneditphpsettings = $this->getParam('caneditphpsettings', true, 0);
|
$caneditphpsettings = $this->getParam('caneditphpsettings', true, 0);
|
||||||
$change_serversettings = $this->getParam('change_serversettings', true, 0);
|
$change_serversettings = $this->getParam('change_serversettings', true, 0);
|
||||||
$ipaddress = intval_ressource($this->getParam('ipaddress', true, - 1));
|
$ipaddress = $this->getParam('ipaddress', true, -1);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
$name = validate($name, 'name', '', '', array(), true);
|
$name = validate($name, 'name', '', '', array(), true);
|
||||||
@@ -244,7 +244,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
'tickets' => $tickets,
|
'tickets' => $tickets,
|
||||||
'tickets_see_all' => $tickets_see_all,
|
'tickets_see_all' => $tickets_see_all,
|
||||||
'mysqls' => $mysqls,
|
'mysqls' => $mysqls,
|
||||||
'ip' => $ipaddress,
|
'ip' => empty($ipaddress) ? "" : (is_array($ipaddress) && $ipaddress > 0 ? json_encode($ipaddress) : -1),
|
||||||
'theme' => $_theme,
|
'theme' => $_theme,
|
||||||
'custom_notes' => $custom_notes,
|
'custom_notes' => $custom_notes,
|
||||||
'custom_notes_show' => $custom_notes_show
|
'custom_notes_show' => $custom_notes_show
|
||||||
@@ -354,7 +354,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
$change_serversettings = $result['change_serversettings'];
|
$change_serversettings = $result['change_serversettings'];
|
||||||
$diskspace = $result['diskspace'];
|
$diskspace = $result['diskspace'];
|
||||||
$traffic = $result['traffic'];
|
$traffic = $result['traffic'];
|
||||||
$ipaddress = $result['ip'];
|
$ipaddress = ($result['ip'] != -1 ? json_decode($result['ip'], true) : -1);
|
||||||
} else {
|
} else {
|
||||||
$deactivated = $this->getParam('deactivated', true, $result['deactivated']);
|
$deactivated = $this->getParam('deactivated', true, $result['deactivated']);
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
$tickets_see_all = $this->getParam('tickets_see_all', true, $result['tickets_see_all']);
|
$tickets_see_all = $this->getParam('tickets_see_all', true, $result['tickets_see_all']);
|
||||||
$caneditphpsettings = $this->getParam('caneditphpsettings', true, $result['caneditphpsettings']);
|
$caneditphpsettings = $this->getParam('caneditphpsettings', true, $result['caneditphpsettings']);
|
||||||
$change_serversettings = $this->getParam('change_serversettings', true, $result['change_serversettings']);
|
$change_serversettings = $this->getParam('change_serversettings', true, $result['change_serversettings']);
|
||||||
$ipaddress = intval_ressource($this->getParam('ipaddress', true, $result['ip']));
|
$ipaddress = $this->getParam('ipaddress', true, ($result['ip'] != -1 ? json_decode($result['ip'], true) : -1));
|
||||||
|
|
||||||
$diskspace = $diskspace * 1024;
|
$diskspace = $diskspace * 1024;
|
||||||
$traffic = $traffic * 1024 * 1024;
|
$traffic = $traffic * 1024 * 1024;
|
||||||
@@ -512,7 +512,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
'tickets' => $tickets,
|
'tickets' => $tickets,
|
||||||
'tickets_see_all' => $tickets_see_all,
|
'tickets_see_all' => $tickets_see_all,
|
||||||
'mysqls' => $mysqls,
|
'mysqls' => $mysqls,
|
||||||
'ip' => $ipaddress,
|
'ip' => empty($ipaddress) ? "" : (is_array($ipaddress) && $ipaddress > 0 ? json_encode($ipaddress) : -1),
|
||||||
'deactivated' => $deactivated,
|
'deactivated' => $deactivated,
|
||||||
'custom_notes' => $custom_notes,
|
'custom_notes' => $custom_notes,
|
||||||
'custom_notes_show' => $custom_notes_show,
|
'custom_notes_show' => $custom_notes_show,
|
||||||
|
|||||||
@@ -27,10 +27,14 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
*/
|
*/
|
||||||
public function list()
|
public function list()
|
||||||
{
|
{
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
|
||||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] list ips and ports");
|
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] list ips and ports");
|
||||||
|
$ip_where = "";
|
||||||
|
if (!empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != -1) {
|
||||||
|
$ip_where = "WHERE `id` IN (".implode(", ", json_decode($this->getUserDetail('ip'), true)).")";
|
||||||
|
}
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
|
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` " . $ip_where . " ORDER BY `ip` ASC, `port` ASC
|
||||||
");
|
");
|
||||||
Database::pexecute($result_stmt, null, true, true);
|
Database::pexecute($result_stmt, null, true, true);
|
||||||
$result = array();
|
$result = array();
|
||||||
@@ -50,16 +54,21 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* ip-port-id
|
* ip-port-id
|
||||||
*
|
*
|
||||||
* @access admin
|
* @access admin
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get()
|
public function get()
|
||||||
{
|
{
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
|
||||||
$id = $this->getParam('id');
|
$id = $this->getParam('id');
|
||||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] get ip and port #" . $id);
|
if (!empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != -1) {
|
||||||
|
$allowed_ips = json_decode($this->getUserDetail('ip'), true);
|
||||||
|
if (!in_array($id, $allowed_ips)) {
|
||||||
|
throw new Exception("You cannot access this resource", 405);
|
||||||
|
}
|
||||||
|
}
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :id
|
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :id
|
||||||
");
|
");
|
||||||
@@ -67,6 +76,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
'id' => $id
|
'id' => $id
|
||||||
), true, true);
|
), true, true);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] get ip " . $result['ip'] . " " . $result['port']);
|
||||||
return $this->response(200, "successfull", $result);
|
return $this->response(200, "successfull", $result);
|
||||||
}
|
}
|
||||||
throw new Exception("IP/port with id #" . $id . " could not be found", 404);
|
throw new Exception("IP/port with id #" . $id . " could not be found", 404);
|
||||||
@@ -204,7 +214,12 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
$ip = '[' . $ip . ']';
|
$ip = '[' . $ip . ']';
|
||||||
}
|
}
|
||||||
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added IP/port '" . $ip . ":" . $port . "'");
|
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added IP/port '" . $ip . ":" . $port . "'");
|
||||||
return $this->response(200, "successfull", $ins_data);
|
// get ip for return-array
|
||||||
|
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
|
||||||
|
'id' => $ins_data['id']
|
||||||
|
))->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
return $this->response(200, "successfull", $result);
|
||||||
}
|
}
|
||||||
throw new Exception("Not allowed to execute given command.", 403);
|
throw new Exception("Not allowed to execute given command.", 403);
|
||||||
}
|
}
|
||||||
@@ -220,7 +235,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
*/
|
*/
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
|
||||||
$id = $this->getParam('id');
|
$id = $this->getParam('id');
|
||||||
|
|
||||||
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
|
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
|
||||||
@@ -368,7 +383,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* ip-port-id
|
* ip-port-id
|
||||||
*
|
*
|
||||||
* @access admin
|
* @access admin
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return array
|
* @return array
|
||||||
@@ -411,17 +426,17 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
|||||||
if ($result['ip'] != '') {
|
if ($result['ip'] != '') {
|
||||||
|
|
||||||
$del_stmt = Database::prepare("
|
$del_stmt = Database::prepare("
|
||||||
DELETE FROM `" . TABLE_PANEL_IPSANDPORTS . "`
|
DELETE FROM `" . TABLE_PANEL_IPSANDPORTS . "`
|
||||||
WHERE `id` = :id
|
WHERE `id` = :id
|
||||||
");
|
");
|
||||||
Database::pexecute($del_stmt, array(
|
Database::pexecute($del_stmt, array(
|
||||||
'id' => $id
|
'id' => $id
|
||||||
));
|
));
|
||||||
|
|
||||||
// also, remove connections to domains (multi-stack)
|
// also, remove connections to domains (multi-stack)
|
||||||
$del_stmt = Database::prepare("
|
$del_stmt = Database::prepare("
|
||||||
DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_ipandports` = :id
|
DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_ipandports` = :id
|
||||||
");
|
");
|
||||||
Database::pexecute($del_stmt, array(
|
Database::pexecute($del_stmt, array(
|
||||||
'id' => $id
|
'id' => $id
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user