Skip to content

Commit

Permalink
adjust Request-class methods to be more flexible
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
  • Loading branch information
d00p committed Dec 30, 2022
1 parent 983d929 commit f2485ec
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 57 deletions.
2 changes: 1 addition & 1 deletion admin_admins.php
Expand Up @@ -39,7 +39,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if (($page == 'admins' || $page == 'overview') && $userinfo['change_serversettings'] == '1') {
if ($action == '') {
Expand Down
4 changes: 2 additions & 2 deletions admin_configfiles.php
Expand Up @@ -41,8 +41,8 @@
}

// get distro from URL param
$distribution = Request::get('distribution');
$reselect = Request::get('reselect', 0);
$distribution = Request::any('distribution');
$reselect = Request::any('reselect', 0);

// check for possible setting
if (empty($distribution)) {
Expand Down
2 changes: 1 addition & 1 deletion admin_cronjobs.php
Expand Up @@ -34,7 +34,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'cronjobs' || $page == 'overview') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion admin_customers.php
Expand Up @@ -42,7 +42,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if (($page == 'customers' || $page == 'overview') && $userinfo['customers'] != '0') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion admin_domains.php
Expand Up @@ -47,7 +47,7 @@
use Froxlor\Validate\Validate;
use Froxlor\CurrentUser;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'domains' || $page == 'overview') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion admin_index.php
Expand Up @@ -40,7 +40,7 @@
use Froxlor\Validate\Validate;
use Froxlor\Language;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($action == 'logout') {
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "logged out");
Expand Down
2 changes: 1 addition & 1 deletion admin_ipsandports.php
Expand Up @@ -36,7 +36,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'ipsandports' || $page == 'overview') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion admin_message.php
Expand Up @@ -33,7 +33,7 @@
use Froxlor\UI\Response;
use Froxlor\User;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

$note_type = null;
$note_msg = null;
Expand Down
2 changes: 1 addition & 1 deletion admin_mysqlserver.php
Expand Up @@ -36,7 +36,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'mysqlserver' || $page == 'overview') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion admin_phpsettings.php
Expand Up @@ -37,7 +37,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'overview') {
if ($action == '') {
Expand Down
4 changes: 2 additions & 2 deletions admin_plans.php
Expand Up @@ -39,7 +39,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == '' || $page == 'overview') {
if ($action == '') {
Expand Down Expand Up @@ -263,7 +263,7 @@
}
}
} elseif ($action == 'jqGetPlanValues') {
$planid = (int)Request::get('planid', 0);
$planid = (int)Request::any('planid', 0);
try {
$json_result = HostingPlans::getLocal($userinfo, [
'id' => $planid
Expand Down
2 changes: 1 addition & 1 deletion admin_settings.php
Expand Up @@ -112,7 +112,7 @@
if ($_part == '' || $_part == 'all') {
UI::view('settings/index.html.twig', ['fields' => $fields]);
} else {
$em = Request::get('em', '');
$em = Request::any('em', '');
UI::view('settings/detailpart.html.twig', ['fields' => $fields, 'em' => $em]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin_templates.php
Expand Up @@ -39,9 +39,9 @@
use Froxlor\Validate\Validate;
use Froxlor\CurrentUser;

$id = (int)Request::get('id');
$subjectid = intval(Request::get('subjectid'));
$mailbodyid = intval(Request::get('mailbodyid'));
$id = (int)Request::any('id');
$subjectid = intval(Request::any('subjectid'));
$mailbodyid = intval(Request::any('mailbodyid'));

$available_templates = [
'createcustomer',
Expand Down
2 changes: 1 addition & 1 deletion admin_traffic.php
Expand Up @@ -31,7 +31,7 @@
use Froxlor\UI\Request;
use Froxlor\UI\Response;

$range = Request::get('range', 'currentmonth');
$range = Request::any('range', 'currentmonth');

if ($page == 'overview' || $page == 'customers') {
try {
Expand Down
2 changes: 1 addition & 1 deletion api_keys.php
Expand Up @@ -49,7 +49,7 @@
// and therefore does not need to require lib/init.php

$del_stmt = Database::prepare("DELETE FROM `" . TABLE_API_KEYS . "` WHERE id = :id");
$id = (int)Request::get('id');
$id = (int)Request::any('id');

// do the delete and then just show a success-message and the apikeys list again
if ($action == 'delete' && $id > 0) {
Expand Down
4 changes: 2 additions & 2 deletions customer_domains.php
Expand Up @@ -47,13 +47,13 @@
Response::redirectTo('customer_index.php');
}

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'overview' || $page == 'domains') {
if ($action == '') {
$log->logAction(FroxlorLogger::USR_ACTION, LOG_NOTICE, "viewed customer_domains::domains");

$parentdomain_id = (int)Request::get('pid', '0');
$parentdomain_id = (int)Request::any('pid', '0');

try {
$domain_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/customer/tablelisting.domains.php';
Expand Down
2 changes: 1 addition & 1 deletion customer_email.php
Expand Up @@ -47,7 +47,7 @@
Response::redirectTo('customer_index.php');
}

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'overview' || $page == 'emails') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion customer_extras.php
Expand Up @@ -46,7 +46,7 @@
Response::redirectTo('customer_index.php');
}

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'overview' || $page == 'htpasswds') {
// redirect if this customer sub-page is hidden via settings
Expand Down
2 changes: 1 addition & 1 deletion customer_ftp.php
Expand Up @@ -44,7 +44,7 @@
Response::redirectTo('customer_index.php');
}

$id = (int)Request::get('id', 0);
$id = (int)Request::any('id', 0);

if ($page == 'overview' || $page == 'accounts') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion customer_mysql.php
Expand Up @@ -50,7 +50,7 @@
$sql_root = Database::getSqlData();
Database::needRoot(false);

$id = (int)Request::get('id');
$id = (int)Request::any('id');

if ($page == 'overview' || $page == 'mysqls') {
if ($action == '') {
Expand Down
2 changes: 1 addition & 1 deletion customer_traffic.php
Expand Up @@ -37,7 +37,7 @@
Response::redirectTo('customer_index.php');
}

$range = Request::get('range', 'currentyear');
$range = Request::any('range', 'currentyear');

if ($page == 'current') {
$range = 'currentmonth';
Expand Down
2 changes: 1 addition & 1 deletion dns_editor.php
Expand Up @@ -40,7 +40,7 @@
// This file is being included in admin_domains and customer_domains
// and therefore does not need to require lib/init.php

$domain_id = (int)Request::get('domain_id');
$domain_id = (int)Request::any('domain_id');

$record = isset($_POST['dns_record']) ? trim($_POST['dns_record']) : null;
$type = isset($_POST['dns_type']) ? $_POST['dns_type'] : 'A';
Expand Down
2 changes: 1 addition & 1 deletion error_report.php
Expand Up @@ -37,7 +37,7 @@
// This file is being included in admin_domains and customer_domains
// and therefore does not need to require lib/init.php

$errid = Request::get('errorid');
$errid = Request::any('errorid');

if (!empty($errid)) {
// read error file
Expand Down
33 changes: 17 additions & 16 deletions lib/Froxlor/Ajax/Ajax.php
Expand Up @@ -53,8 +53,8 @@ class Ajax
*/
public function __construct()
{
$this->action = $_GET['action'] ?? $_POST['action'] ?? null;
$this->theme = $_GET['theme'] ?? 'Froxlor';
$this->action = Request::any('action');
$this->theme = Request::any('theme', 'Froxlor');

UI::sendHeaders();
UI::sendSslHeaders();
Expand Down Expand Up @@ -112,7 +112,8 @@ private function getNewsfeed()
$feed = "https://inside.froxlor.org/news/";

// Set custom feed if provided
if (isset($_GET['role']) && $_GET['role'] == "customer") {
$role = Request::get('role');
if ($role == "customer") {
$custom_feed = Settings::Get("customer.news_feed_url");
if (!empty(trim($custom_feed))) {
$feed = $custom_feed;
Expand Down Expand Up @@ -140,7 +141,7 @@ private function getNewsfeed()

if ($news === false) {
$err = [];
foreach(libxml_get_errors() as $error) {
foreach (libxml_get_errors() as $error) {
$err[] = $error->message;
}
return $this->errorResponse(
Expand Down Expand Up @@ -205,7 +206,7 @@ private function getUpdateCheck()
} catch (Exception $e) {
// don't display anything if just not allowed due to permissions
if ($e->getCode() != 403) {
Response::dynamicError($e->getMessage());
return $this->errorResponse($e->getMessage(), $e->getCode());
}
}
}
Expand All @@ -215,7 +216,7 @@ private function getUpdateCheck()
*/
private function searchGlobal()
{
$searchtext = Request::get('searchtext');
$searchtext = Request::any('searchtext');

$result = [];

Expand All @@ -236,27 +237,27 @@ private function searchGlobal()
private function updateTablelisting()
{
$columns = [];
foreach ((Request::get('columns') ?? []) as $value) {
foreach ((Request::any('columns') ?? []) as $value) {
$columns[] = $value;
}
if (!empty($columns)) {
Listing::storeColumnListingForUser([Request::get('listing') => $columns]);
Listing::storeColumnListingForUser([Request::any('listing') => $columns]);
return $this->jsonResponse($columns);
}
return $this->errorResponse('At least one column must be selected', 406);
}

private function resetTablelisting()
{
Listing::deleteColumnListingForUser([Request::get('listing') => []]);
Listing::deleteColumnListingForUser([Request::any('listing') => []]);
return $this->jsonResponse([]);
}

private function editApiKey()
{
$keyid = isset($_POST['id']) ? (int)$_POST['id'] : 0;
$allowed_from = isset($_POST['allowed_from']) ? $_POST['allowed_from'] : "";
$valid_until = isset($_POST['valid_until']) ? $_POST['valid_until'] : "";
$keyid = Request::post('id', 0);
$allowed_from = Request::post('allowed_from', "");
$valid_until = Request::post('valid_until', "");

if (empty($keyid)) {
return $this->errorResponse('Invalid call', 406);
Expand Down Expand Up @@ -318,9 +319,9 @@ private function editApiKey()
private function getConfigDetails()
{
if (isset($this->userinfo['adminsession']) && $this->userinfo['adminsession'] == 1 && $this->userinfo['change_serversettings'] == 1) {
$distribution = isset($_POST['distro']) ? $_POST['distro'] : "";
$section = isset($_POST['section']) ? $_POST['section'] : "";
$daemon = isset($_POST['daemon']) ? $_POST['daemon'] : "";
$distribution = Request::post('distro', "");
$section = Request::post('section', "");
$daemon = Request::post('daemon', "");

// validate distribution config-xml exists
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
Expand Down Expand Up @@ -375,7 +376,7 @@ private function getConfigJsonExport()
*/
private function loadLanguageString()
{
$langid = isset($_POST['langid']) ? $_POST['langid'] : "";
$langid = Request::post('langid', "");
if (preg_match('/^([a-zA-Z\.]+)$/', $langid)) {
return $this->jsonResponse(lng($langid));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Froxlor/Install/Install.php
Expand Up @@ -80,8 +80,8 @@ public function __construct(array $cliData = [])
$this->formfield = require dirname(__DIR__, 3) . '/lib/formfields/install/formfield.install.php';

// set actual step
$this->currentStep = $cliData['step'] ?? Request::get('step', 0);
$this->extendedView = $cliData['extended'] ?? Request::get('extended', 0);
$this->currentStep = $cliData['step'] ?? Request::any('step', 0);
$this->extendedView = $cliData['extended'] ?? Request::any('extended', 0);
$this->maxSteps = count($this->formfield['install']['sections']);

// set actual php version and extensions
Expand Down Expand Up @@ -114,7 +114,7 @@ public function __construct(array $cliData = [])
public function handle(): void
{
// handle form data
if (!is_null(Request::get('submit')) && $this->currentStep) {
if (!is_null(Request::any('submit')) && $this->currentStep) {
try {
$this->handleFormData($this->formfield['install']);
} catch (Exception $e) {
Expand Down Expand Up @@ -266,7 +266,7 @@ private function validateRequest(array $fields): array
{
$attributes = [];
foreach ($fields as $name => $field) {
$attributes[$name] = $this->validateAttribute(Request::get($name), $field);
$attributes[$name] = $this->validateAttribute(Request::any($name), $field);
if (isset($field['next_to'])) {
$attributes = array_merge($attributes, $this->validateRequest($field['next_to']));
}
Expand Down

0 comments on commit f2485ec

Please sign in to comment.