Skip to content

Commit

Permalink
As generated by AppGini 6.0.
Browse files Browse the repository at this point in the history
admin/incFunctions.php: add `getUserData()` and `setUserData()` to get/set user-specific data stored into `membership_users.data`
Add admin/pageSQL.php to allow admin to easily query the database (and store queries for later reference).
UI/UX enhancements for members list page under admin area.
Fix stored XSS in `invoice_items_autofill.php`
  • Loading branch information
Ahmad Gneady committed Jul 3, 2021
1 parent 41dda75 commit 478e5a5
Show file tree
Hide file tree
Showing 37 changed files with 775 additions and 172 deletions.
26 changes: 26 additions & 0 deletions app/admin/ajax-saved-sql.php
@@ -0,0 +1,26 @@
<?php
/*
Manage stored SQL queries for admin user.
Parameters:
queries: (optional) a json string [{name, query}, ..]) to store.
Response:
stored queries (as a json string).
queries are stored in the membership_users.data field for the current user, under the key 'storedQueries'
*/

$currDir = dirname(__FILE__);
require("{$currDir}/incCommon.php");

if(!csrf_token(true)) {
@header('HTTP/1.0 403 Access Denied');
die();
}

// store queries if provided
if(isset($_REQUEST['queries'])) {
$queries = $_REQUEST['queries'];
setUserData('storedQueries', $queries);
}

echo getUserData('storedQueries');
34 changes: 34 additions & 0 deletions app/admin/ajax-sql.php
@@ -0,0 +1,34 @@
<?php
$currDir = dirname(__FILE__);
require("{$currDir}/incCommon.php");

if(!csrf_token(true)) {
@header('HTTP/1.0 403 Access Denied');
die();
}

$sql = trim($_REQUEST['sql']);
if(!preg_match('/^SELECT\s+.*?\s+FROM\s+\S+/i', $sql)) {
@header('HTTP/1.0 404 Not Found');
die("Invalid query");
}

// force a limit of 1000 in case no limit specified
if(!preg_match('/\s+limit\s+\d+(\s*,\s*\d+)?/i', $sql))
$sql .= ' LIMIT 1000';

$resp = ['titles' => [], 'data' => [], 'error' => ''];
$eo = ['silentErrors' => true];

$res = sql($sql, $eo);
if(!$res)
$resp['error'] = $eo['error'];
else while($row = db_fetch_assoc($res)) {
if(!count($resp['titles']))
$resp['titles'] = array_keys($row);

$resp['data'][] = array_map('htmlspecialchars', array_values($row));
}

@header('Content-type: application/json');
echo json_encode($resp, JSON_PARTIAL_OUTPUT_ON_ERROR);
2 changes: 1 addition & 1 deletion app/admin/getUsers.php
@@ -1,5 +1,5 @@
<?php
// This script and data application were generated by AppGini 5.97
// This script and data application were generated by AppGini 6.0
// Download AppGini for free from https://bigprof.com/appgini/download/

/*
Expand Down
39 changes: 39 additions & 0 deletions app/admin/incFunctions.php
Expand Up @@ -1088,7 +1088,9 @@ function update_membership_users() {
`comments` TEXT,
`pass_reset_key` VARCHAR(100),
`pass_reset_expiry` INT UNSIGNED,
`flags` TEXT,
`allowCSVImport` TINYINT NOT NULL DEFAULT '0',
`data` LONGTEXT,
PRIMARY KEY (`memberID`),
INDEX `groupID` (`groupID`)
) CHARSET " . mysql_charset,
Expand All @@ -1101,6 +1103,7 @@ function update_membership_users() {
sql("ALTER TABLE `{$tn}` ADD INDEX `groupID` (`groupID`)", $eo);
sql("ALTER TABLE `{$tn}` ADD COLUMN `flags` TEXT", $eo);
sql("ALTER TABLE `{$tn}` ADD COLUMN `allowCSVImport` TINYINT NOT NULL DEFAULT '0'", $eo);
sql("ALTER TABLE `{$tn}` ADD COLUMN `data` LONGTEXT", $eo);
}
########################################################################
function update_membership_userrecords() {
Expand Down Expand Up @@ -2440,3 +2443,39 @@ function assocArrFilter($arr, $func) {

return $filtered;
}
#########################################################
function setUserData($key, $value = null) {
$data = [];

$user = makeSafe(getMemberInfo()['username']);
if(!$user) return false;

$dataJson = sqlValue("SELECT `data` FROM `membership_users` WHERE `memberID`='$user'");
if($dataJson) {
$data = @json_decode($dataJson, true);
if(!$data) $data = [];
}

$data[$key] = $value;

return update(
'membership_users',
['data' => @json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR)],
['memberID' => $user]
);
}
#########################################################
function getUserData($key) {
$user = makeSafe(getMemberInfo()['username']);
if(!$user) return null;

$dataJson = sqlValue("SELECT `data` FROM `membership_users` WHERE `memberID`='$user'");
if(!$dataJson) return null;

$data = @json_decode($dataJson, true);
if(!$data) return null;

if(!isset($data[$key])) return null;

return $data[$key];
}
1 change: 1 addition & 0 deletions app/admin/incHeader.php
Expand Up @@ -208,6 +208,7 @@ function hideDialogs() {
<li><a href="pageBackupRestore.php"><i class="glyphicon menu-item-icon text-info glyphicon-tasks"></i> <?php echo $Translation['database backups']; ?></a></li>
<li><a href="pageUploadCSV.php"><i class="glyphicon menu-item-icon text-info glyphicon-upload"></i> <?php echo $Translation['import CSV']; ?></a></li>
<li><a href="pageQueryLogs.php"><i class="glyphicon menu-item-icon text-info glyphicon-book"></i> <?php echo $Translation['Query logs']; ?></a></li>
<li><a href="pageSQL.php"><i class="glyphicon menu-item-icon text-danger glyphicon-console"></i> <?php echo $Translation['Interactive SQL queries tool']; ?></a></li>
<li class="divider"></li>
<li><a href="https://forums.appgini.com" target="_blank"><i class="glyphicon menu-item-icon text-info glyphicon-new-window"></i> <?php echo $Translation['AppGini forum']; ?></a></li>
</ul>
Expand Down
14 changes: 6 additions & 8 deletions app/admin/pageDeleteMember.php
@@ -1,19 +1,17 @@
<?php
$currDir=dirname(__FILE__);
require("$currDir/incCommon.php");
require(__DIR__ . '/incCommon.php');

// validate input
$memberID=makeSafe(strtolower($_GET['memberID']));
$memberID = makeSafe(strtolower($_GET['memberID']));

if(!csrf_token(true)) die($Translation['csrf token expired or invalid']);

sql("delete from membership_users where lcase(memberID)='$memberID'", $eo);
sql("update membership_userrecords set memberID='' where lcase(memberID)='$memberID'", $eo);
$eo = ['silentErrors' => true];
sql("DELETE FROM `membership_users` WHERE LCASE(`memberID`)='$memberID'", $eo);
sql("UPDATE `membership_userrecords` SET `memberID`='' WHERE LCASE(`memberID`)='$memberID'", $eo);

if($_SERVER['HTTP_REFERER']) {
redirect($_SERVER['HTTP_REFERER'], TRUE);
} else {
redirect("admin/pageViewMembers.php");
redirect('admin/pageViewMembers.php');
}

?>
4 changes: 2 additions & 2 deletions app/admin/pageDeleteRecord.php
@@ -1,12 +1,12 @@
<?php
$currDir = dirname(__FILE__);
require("{$currDir}/incCommon.php");
require(__DIR__ . '/incCommon.php');

// validate input
$recID = intval($_GET['recID']);

if(!csrf_token(true)) die($Translation['csrf token expired or invalid']);

$eo = ['silentErrors' => true];
$res = sql("SELECT `tableName`, `pkValue` FROM `membership_userrecords` WHERE `recID`='{$recID}'", $eo);
if($row = db_fetch_row($res)) {
sql("DELETE FROM `membership_userrecords` WHERE `recID`='{$recID}'", $eo);
Expand Down

0 comments on commit 478e5a5

Please sign in to comment.