2010-01-27 08:54:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of the Froxlor project.
|
|
|
|
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
|
|
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the COPYING
|
|
|
|
* file that was distributed with this source code. You can also view the
|
|
|
|
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
|
|
|
*
|
|
|
|
* @copyright (c) the authors
|
|
|
|
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
|
|
|
* @author Froxlor team <team@froxlor.org> (2010-)
|
|
|
|
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
|
|
|
* @package Panel
|
2011-05-04 09:59:20 +00:00
|
|
|
*
|
2010-01-27 08:54:31 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-20 17:00:44 +00:00
|
|
|
const AREA = 'admin';
|
|
|
|
require __DIR__ . '/lib/init.php';
|
|
|
|
|
2022-02-28 08:21:04 +00:00
|
|
|
use Froxlor\Api\Commands\Admins;
|
2018-12-19 15:57:03 +00:00
|
|
|
use Froxlor\Database\Database;
|
|
|
|
use Froxlor\Settings;
|
2022-02-18 21:19:36 +00:00
|
|
|
use Froxlor\UI\Panel\UI;
|
2022-02-20 17:00:44 +00:00
|
|
|
use Froxlor\UI\Request;
|
2018-12-18 12:45:05 +00:00
|
|
|
|
2022-02-20 17:00:44 +00:00
|
|
|
$id = (int) Request::get('id');
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2018-12-22 07:15:31 +00:00
|
|
|
if ($page == 'admins' && $userinfo['change_serversettings'] == '1') {
|
2013-11-16 16:23:51 +00:00
|
|
|
|
|
|
|
if ($action == '') {
|
2018-12-26 14:51:26 +00:00
|
|
|
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_admins");
|
2022-02-20 17:00:44 +00:00
|
|
|
|
|
|
|
try {
|
2022-02-25 19:52:09 +00:00
|
|
|
$admin_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.admins.php';
|
|
|
|
$collection = (new \Froxlor\UI\Collection(\Froxlor\Api\Commands\Admins::class, $userinfo))
|
|
|
|
->withPagination($admin_list_data['admin_list']['columns']);
|
2019-11-10 17:35:32 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
|
|
|
}
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-02-25 19:41:06 +00:00
|
|
|
UI::twigBuffer('user/table.html.twig', [
|
2022-02-25 20:17:45 +00:00
|
|
|
'listing' => \Froxlor\UI\Listing::format($collection, $admin_list_data['admin_list']),
|
2022-02-25 19:41:06 +00:00
|
|
|
'actions_links' => [[
|
|
|
|
'href' => $linker->getLink(['section' => 'admins', 'page' => $page, 'action' => 'add']),
|
|
|
|
'label' => $lng['admin']['admin_add']
|
|
|
|
]]
|
|
|
|
]);
|
|
|
|
UI::twigOutputBuffer();
|
|
|
|
} elseif ($action == 'su') {
|
2013-11-16 16:23:51 +00:00
|
|
|
|
2018-02-23 10:57:29 +00:00
|
|
|
try {
|
2018-12-22 07:15:31 +00:00
|
|
|
$json_result = Admins::getLocal($userinfo, array(
|
2018-02-23 10:57:29 +00:00
|
|
|
'id' => $id
|
|
|
|
))->get();
|
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
2018-02-23 10:57:29 +00:00
|
|
|
}
|
|
|
|
$result = json_decode($json_result, true)['data'];
|
2010-01-27 08:54:31 +00:00
|
|
|
$destination_admin = $result['loginname'];
|
|
|
|
|
2018-12-22 07:15:31 +00:00
|
|
|
if ($destination_admin != '' && $result['adminid'] != $userinfo['userid']) {
|
2013-11-16 16:23:51 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT * FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid` = :userid
|
|
|
|
");
|
2018-12-19 15:57:03 +00:00
|
|
|
$result = Database::pexecute_first($result_stmt, array(
|
2018-12-22 07:15:31 +00:00
|
|
|
'userid' => $userinfo['userid']
|
2018-12-19 15:57:03 +00:00
|
|
|
));
|
2013-11-16 16:23:51 +00:00
|
|
|
|
2021-10-02 10:38:17 +00:00
|
|
|
$s = \Froxlor\Froxlor::genSessionId();
|
2013-11-16 16:23:51 +00:00
|
|
|
$ins_stmt = Database::prepare("
|
|
|
|
INSERT INTO `" . TABLE_PANEL_SESSIONS . "` SET
|
|
|
|
`hash` = :hash, `userid` = :userid, `ipaddress` = :ip,
|
|
|
|
`useragent` = :ua, `lastactivity` = :la,
|
|
|
|
`language` = :lang, `adminsession` = '1'
|
|
|
|
");
|
|
|
|
$ins_data = array(
|
|
|
|
'hash' => $s,
|
|
|
|
'userid' => $id,
|
|
|
|
'ip' => $result['ipaddress'],
|
|
|
|
'ua' => $result['useragent'],
|
|
|
|
'la' => time(),
|
|
|
|
'lang' => $result['language']
|
|
|
|
);
|
|
|
|
Database::pexecute($ins_stmt, $ins_data);
|
2018-12-26 14:51:26 +00:00
|
|
|
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_INFO, "switched adminuser and is now '" . $destination_admin . "'");
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo('admin_index.php', array(
|
2018-12-19 15:57:03 +00:00
|
|
|
's' => $s
|
|
|
|
));
|
2013-11-16 16:23:51 +00:00
|
|
|
} else {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo('index.php', array(
|
2018-12-19 15:57:03 +00:00
|
|
|
'action' => 'login'
|
|
|
|
));
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2018-12-19 15:57:03 +00:00
|
|
|
} elseif ($action == 'delete' && $id != 0) {
|
2018-02-23 10:57:29 +00:00
|
|
|
try {
|
2018-12-22 07:15:31 +00:00
|
|
|
$json_result = Admins::getLocal($userinfo, array(
|
2018-02-23 10:57:29 +00:00
|
|
|
'id' => $id
|
|
|
|
))->get();
|
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
2018-02-23 10:57:29 +00:00
|
|
|
}
|
|
|
|
$result = json_decode($json_result, true)['data'];
|
2013-11-16 16:23:51 +00:00
|
|
|
|
|
|
|
if ($result['loginname'] != '') {
|
2018-12-22 07:15:31 +00:00
|
|
|
if ($result['adminid'] == $userinfo['userid']) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::standard_error('youcantdeleteyourself');
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 15:57:03 +00:00
|
|
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
2019-01-16 09:59:32 +00:00
|
|
|
Admins::getLocal($userinfo, array(
|
2018-02-23 10:57:29 +00:00
|
|
|
'id' => $id
|
|
|
|
))->delete();
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-12-19 15:57:03 +00:00
|
|
|
'page' => $page,
|
|
|
|
's' => $s
|
|
|
|
));
|
2013-11-16 16:23:51 +00:00
|
|
|
} else {
|
2018-12-24 12:50:45 +00:00
|
|
|
\Froxlor\UI\HTML::askYesNo('admin_admin_reallydelete', $filename, array(
|
2018-12-19 15:57:03 +00:00
|
|
|
'id' => $id,
|
|
|
|
'page' => $page,
|
|
|
|
'action' => $action
|
|
|
|
), $result['loginname']);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-19 15:57:03 +00:00
|
|
|
} elseif ($action == 'add') {
|
2013-11-16 16:23:51 +00:00
|
|
|
|
2018-12-19 15:57:03 +00:00
|
|
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
2018-02-22 15:51:56 +00:00
|
|
|
try {
|
2018-12-22 07:15:31 +00:00
|
|
|
Admins::getLocal($userinfo, $_POST)->add();
|
2018-02-22 15:51:56 +00:00
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-12-19 15:57:03 +00:00
|
|
|
'page' => $page,
|
|
|
|
's' => $s
|
|
|
|
));
|
2013-11-16 16:23:51 +00:00
|
|
|
} else {
|
|
|
|
|
2022-02-18 21:19:36 +00:00
|
|
|
$ipaddress = [];
|
|
|
|
$ipaddress[-1] = $lng['admin']['allips'];
|
2013-11-16 16:23:51 +00:00
|
|
|
$ipsandports_stmt = Database::query("
|
2015-02-15 06:54:34 +00:00
|
|
|
SELECT `id`, `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip` ORDER BY `ip` ASC
|
2013-11-16 16:23:51 +00:00
|
|
|
");
|
|
|
|
while ($row = $ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2022-02-18 21:19:36 +00:00
|
|
|
$ipaddress[$row['id']] = $row['ip'];
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 15:57:03 +00:00
|
|
|
$admin_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/admin/formfield.admin_add.php';
|
2015-06-10 12:59:38 +00:00
|
|
|
|
2022-02-20 10:38:08 +00:00
|
|
|
UI::twigBuffer('user/form.html.twig', [
|
2022-02-21 16:42:04 +00:00
|
|
|
'formaction' => $linker->getLink(array('section' => 'admins')),
|
2022-02-18 21:19:36 +00:00
|
|
|
'formdata' => $admin_add_data['admin_add']
|
|
|
|
]);
|
2022-02-20 10:38:08 +00:00
|
|
|
UI::twigOutputBuffer();
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2018-12-19 15:57:03 +00:00
|
|
|
} elseif ($action == 'edit' && $id != 0) {
|
2018-02-23 10:57:29 +00:00
|
|
|
try {
|
2018-12-22 07:15:31 +00:00
|
|
|
$json_result = Admins::getLocal($userinfo, array(
|
2018-02-23 10:57:29 +00:00
|
|
|
'id' => $id
|
|
|
|
))->get();
|
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
2018-02-23 10:57:29 +00:00
|
|
|
}
|
|
|
|
$result = json_decode($json_result, true)['data'];
|
2013-11-16 16:23:51 +00:00
|
|
|
|
|
|
|
if ($result['loginname'] != '') {
|
|
|
|
|
2018-12-19 15:57:03 +00:00
|
|
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
2018-02-23 10:57:29 +00:00
|
|
|
try {
|
2018-12-22 07:15:31 +00:00
|
|
|
Admins::getLocal($userinfo, $_POST)->update();
|
2018-02-23 10:57:29 +00:00
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
2015-02-08 11:43:04 +00:00
|
|
|
}
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-12-19 15:57:03 +00:00
|
|
|
'page' => $page,
|
|
|
|
's' => $s
|
|
|
|
));
|
2013-11-16 16:23:51 +00:00
|
|
|
} else {
|
|
|
|
|
2013-12-15 10:47:23 +00:00
|
|
|
$dec_places = Settings::Get('panel.decimal_places');
|
|
|
|
$result['traffic'] = round($result['traffic'] / (1024 * 1024), $dec_places);
|
|
|
|
$result['diskspace'] = round($result['diskspace'] / 1024, $dec_places);
|
2010-01-27 08:54:31 +00:00
|
|
|
$result['email'] = $idna_convert->decode($result['email']);
|
|
|
|
|
2022-02-18 21:19:36 +00:00
|
|
|
$ipaddress = [];
|
|
|
|
$ipaddress[-1] = $lng['admin']['allips'];
|
2013-11-16 16:23:51 +00:00
|
|
|
$ipsandports_stmt = Database::query("
|
2022-02-18 21:19:36 +00:00
|
|
|
SELECT `id`, `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "` GROUP BY `ip` ORDER BY `ip` ASC
|
2013-11-16 16:23:51 +00:00
|
|
|
");
|
|
|
|
while ($row = $ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2022-02-18 21:19:36 +00:00
|
|
|
$ipaddress[$row['id']] = $row['ip'];
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:50:45 +00:00
|
|
|
$result = \Froxlor\PhpHelper::htmlentitiesArray($result);
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2018-12-19 15:57:03 +00:00
|
|
|
$admin_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/admin/formfield.admin_edit.php';
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2022-02-20 10:38:08 +00:00
|
|
|
UI::twigBuffer('user/form.html.twig', [
|
2022-02-21 16:42:04 +00:00
|
|
|
'formaction' => $linker->getLink(array('section' => 'admins', 'id' => $id)),
|
2022-02-18 21:19:36 +00:00
|
|
|
'formdata' => $admin_edit_data['admin_edit']
|
|
|
|
]);
|
2022-02-20 10:38:08 +00:00
|
|
|
UI::twigOutputBuffer();
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|