Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions resources/lib/UnityHTTPD.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,6 @@ public static function errorHandler(int $severity, string $message, string $file
return false;
}

public static function getPostData(string $key): string
{
if (!array_key_exists($key, $_POST)) {
self::badRequest("\$_POST has no array key '$key'");
}
return $_POST[$key];
}

/* returns null if not found and not $die_if_not_found */
public static function getQueryParameter(string $key, bool $die_if_not_found = true): ?string
{
if (!array_key_exists($key, $_GET)) {
if ($die_if_not_found) {
self::badRequest("\$_GET has no array key '$key'");
} else {
return null;
}
}
return $_GET[$key];
}

public static function getUploadedFileContents(
string $filename,
bool $do_delete_tmpfile_after_read = true,
Expand Down Expand Up @@ -382,8 +361,7 @@ public static function deleteMessage(UnityHTTPDMessageLevel $level, string $titl

public static function validatePostCSRFToken(): void
{
$token = self::getPostData("csrf_token");
if (!CSRFToken::validate($token)) {
if (!CSRFToken::validate($_POST["csrf_token"])) {
$errorid = uniqid();
self::errorLog("csrf failed to validate", "", errorid: $errorid);
self::messageError(
Expand Down
3 changes: 1 addition & 2 deletions webroot/admin/ajax/get_group_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
UnityHTTPD::forbidden("not an admin", "You are not an admin.");
}

$gid = UnityHTTPD::getQueryParameter("gid");
$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK);
$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
$members = $group->getGroupMembersAttributes(["gecos", "mail"]);
$requests = $group->getRequests();

Expand Down
3 changes: 1 addition & 2 deletions webroot/admin/ajax/get_page_contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
UnityHTTPD::forbidden("not an admin", "You are not an admin.");
}

$pageid = UnityHTTPD::getQueryParameter("pageid");
$page = $SQL->getPage($pageid);
$page = $SQL->getPage($_GET["pageid"]);
header('Content-Type: application/json; charset=utf-8');
echo jsonEncode(["content" => $page["content"]]);
11 changes: 3 additions & 8 deletions webroot/admin/pi-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
UnityHTTPD::forbidden("not an admin", "You are not an admin.");
}

$getUserFromPost = function () {
global $LDAP, $SQL, $MAILER, $WEBHOOK;
return new UnityUser(UnityHTTPD::getPostData("uid"), $LDAP, $SQL, $MAILER, $WEBHOOK);
};

if ($_SERVER["REQUEST_METHOD"] == "POST") {
UnityHTTPD::validatePostCSRFToken();
switch ($_POST["form_type"]) {
case "req":
$form_user = $getUserFromPost();
$form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
if ($_POST["action"] == "Approve") {
$group = $form_user->getPIGroup();
$group->approveGroup();
Expand All @@ -31,7 +26,7 @@
}
break;
case "reqChild":
$form_user = $getUserFromPost();
$form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
$parent_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $WEBHOOK);
if ($_POST["action"] == "Approve") {
$parent_group->approveUser($form_user);
Expand All @@ -40,7 +35,7 @@
}
break;
case "remUserChild":
$form_user = $getUserFromPost();
$form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
$parent = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $WEBHOOK);
$parent->removeUser($form_user);
break;
Expand Down
4 changes: 2 additions & 2 deletions webroot/api/content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

require_once __DIR__ . "/../../../resources/autoload.php";

$CHAR_WRAP = digits2int(UnityHTTPD::getQueryParameter("line_wrap", false) ?? "80");
$content_name = UnityHTTPD::getQueryParameter("content_name");
$CHAR_WRAP = digits2int($_GET["line_wrap"] ?? "80");
$content_name = $_GET["content_name"];
echo $SQL->getPage($content_name)["content"];
2 changes: 1 addition & 1 deletion webroot/js/ajax/ssh_generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$private = EC::createKey('Ed25519');
$public = $private->getPublicKey();
$public_str = $public->toString('OpenSSH');
if (UnityHTTPD::getQueryParameter("type", false) == "ppk") {
if (($_GET["type"] ?? null) == "ppk") {
$private_str = $private->toString('PuTTY');
} else {
$private_str = $private->toString('OpenSSH');
Expand Down
2 changes: 1 addition & 1 deletion webroot/js/ajax/ssh_validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
use UnityWebPortal\lib\UnityHTTPD;

header('Content-Type: application/json; charset=utf-8');
echo jsonEncode(["is_valid" => testValidSSHKey(UnityHTTPD::getPostData("key"))]);
echo jsonEncode(["is_valid" => testValidSSHKey($_POST["key"])]);
12 changes: 6 additions & 6 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

if ($_SERVER['REQUEST_METHOD'] == "POST") {
UnityHTTPD::validatePostCSRFToken();
switch (UnityHTTPD::getPostData("form_type")) {
switch ($_POST["form_type"]) {
case "addKey":
$keys = array();
switch (UnityHTTPD::getPostData("add_type")) {
switch ($_POST["add_type"]) {
case "paste":
array_push($keys, UnityHTTPD::getPostData("key"));
array_push($keys, $_POST["key"]);
break;
case "import":
try {
Expand All @@ -28,10 +28,10 @@
array_push($keys, $key);
break;
case "generate":
array_push($keys, UnityHTTPD::getPostData("gen_key"));
array_push($keys, $_POST["gen_key"]);
break;
case "github":
$githubUsername = UnityHTTPD::getPostData("gh_user");
$githubUsername = $_POST["gh_user"];
$githubKeys = $GITHUB->getSshPublicKeys($githubUsername);
$keys = array_merge($keys, $githubKeys);
break;
Expand All @@ -53,7 +53,7 @@
break;
case "delKey":
$keys = $USER->getSSHKeys();
$index = digits2int(UnityHTTPD::getPostData("delIndex"));
$index = digits2int($_POST["delIndex"]);
if ($index >= count($keys)) {
break;
}
Expand Down
6 changes: 3 additions & 3 deletions webroot/panel/ajax/delete_message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use UnityWebPortal\lib\UnityHTTPD;
use UnityWebPortal\lib\UnityHTTPDMessageLevel;

$level_str = base64_decode(UnityHTTPD::getPostData("level"));
$level_str = base64_decode($_POST["level"]);
$level = UnityHTTPDMessageLevel::from($level_str);
$title = base64_decode(UnityHTTPD::getPostData("title"));
$body = base64_decode(UnityHTTPD::getPostData("body"));
$title = base64_decode($_POST["title"]);
$body = base64_decode($_POST["body"]);
UnityHTTPD::deleteMessage($level, $title, $body);
3 changes: 1 addition & 2 deletions webroot/panel/ajax/get_group_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use UnityWebPortal\lib\UnityHTTPD;


$gid = UnityHTTPD::getQueryParameter("gid");
$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK);
$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
if (!$group->memberUIDExists($USER->uid)) {
UnityHTTPD::forbidden("not a group member", "You are not a member of this group.");
}
Expand Down
2 changes: 1 addition & 1 deletion webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$getPIGroupFromPost = function () {
global $LDAP, $SQL, $MAILER, $WEBHOOK;
$gid_or_mail = UnityHTTPD::getPostData("pi");
$gid_or_mail = $_POST["pi"];
if (substr($gid_or_mail, 0, 3) !== "pi_" && str_contains($gid_or_mail, "@")) {
try {
$gid_or_mail = UnityGroup::ownerMail2GID($gid_or_mail);
Expand Down
2 changes: 1 addition & 1 deletion webroot/panel/modal/pi_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use UnityWebPortal\lib\UnityHTTPD;

$search_query = UnityHTTPD::getQueryParameter("search");
$search_query = $_GET["search"];
if (empty($search_query)) {
echo "<span>No Results</span>";
UnityHTTPD::die();
Expand Down
8 changes: 2 additions & 6 deletions webroot/panel/pi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@
UnityHTTPD::forbidden("not a PI", "You are not a PI.");
}

$getUserFromPost = function () {
global $LDAP, $SQL, $MAILER, $WEBHOOK;
return new UnityUser(UnityHTTPD::getPostData("uid"), $LDAP, $SQL, $MAILER, $WEBHOOK);
};

if ($_SERVER["REQUEST_METHOD"] == "POST") {
UnityHTTPD::validatePostCSRFToken();
switch ($_POST["form_type"]) {
case "userReq":
$form_user = $getUserFromPost();
$form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
if ($_POST["action"] == "Approve") {
$group->approveUser($form_user);
} elseif ($_POST["action"] == "Deny") {
$group->denyUser($form_user);
}
break;
case "remUser":
$form_user = $getUserFromPost();
$form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
// remove user button clicked
$group->removeUser($form_user);

Expand Down