Skip to content

Commit 01e7581

Browse files
committed
UnitySite not static
1 parent e466ba2 commit 01e7581

File tree

9 files changed

+18
-27
lines changed

9 files changed

+18
-27
lines changed

resources/init.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use UnityWebPortal\lib\UnityRedis;
1414
use UnityWebPortal\lib\UnityWebhook;
1515
use UnityWebPortal\lib\UnityGithub;
16+
use UnityWebPortal\lib\UnitySite;
1617

1718
//
1819
// Initialize Session
@@ -125,6 +126,8 @@
125126
}
126127
}
127128

129+
$SITE = new UnitySite();
130+
128131
//
129132
// Define vars
130133
//

resources/lib/UnitySite.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
class UnitySite
88
{
9-
public static function redirect($destination)
9+
public function redirect($destination)
1010
{
1111
if ($_SERVER["PHP_SELF"] != $destination) {
1212
header("Location: $destination");
1313
die("Redirect failed, click <a href='$destination'>here</a> to continue.");
1414
}
1515
}
1616

17-
public static function removeTrailingWhitespace($arr)
17+
public function removeTrailingWhitespace($arr)
1818
{
1919
$out = array();
2020
foreach ($arr as $str) {
@@ -25,7 +25,7 @@ public static function removeTrailingWhitespace($arr)
2525
return $out;
2626
}
2727

28-
public static function testValidSSHKey($key_str)
28+
public function testValidSSHKey($key_str)
2929
{
3030
// key loader still throws, these just mute warnings for phpunit
3131
// https://github.com/phpseclib/phpseclib/issues/2079

resources/templates/header.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<?php
2-
3-
use UnityWebPortal\lib\UnitySite;
4-
52
if (isset($SSO)) {
63
if (!$_SESSION["user_exists"]) {
7-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/new_account.php");
4+
$SITE->redirect($CONFIG["site"]["prefix"] . "/panel/new_account.php");
85
}
96
}
107

@@ -119,7 +116,7 @@
119116
if (isset($_SESSION["is_admin"]) && $_SESSION["is_admin"]) {
120117
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["form_name"]) && $_POST["form_name"] == "clearView") {
121118
unset($_SESSION["viewUser"]);
122-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php");
119+
$SITE->redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php");
123120
}
124121

125122
if (isset($_SESSION["viewUser"])) {
@@ -135,4 +132,4 @@
135132
echo "</div>";
136133
}
137134
}
138-
?>
135+
?>

webroot/admin/user-mgmt.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

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

5-
use UnityWebPortal\lib\UnitySite;
6-
75
if (!$USER->isAdmin()) {
86
throw new Exception("access denied");
97
}
@@ -12,7 +10,7 @@
1210
switch ($_POST["form_name"]) {
1311
case "viewAsUser":
1412
$_SESSION["viewUser"] = $_POST["uid"];
15-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel");
13+
$SITE->redirect($CONFIG["site"]["prefix"] . "/panel");
1614
break;
1715
}
1816
}

webroot/js/ajax/ssh_validate.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
require_once __DIR__ . "/../../../resources/lib/UnitySite.php";
4-
require_once __DIR__ . "/../../../vendor/autoload.php";
3+
require_once __DIR__ . "/../../../resources/autoload.php";
54

6-
echo UnityWebPortal\lib\UnitySite::testValidSSHKey($_POST["key"]) ? "true" : "false";
5+
echo $SITE->testValidSSHKey($_POST["key"]) ? "true" : "false";

webroot/panel/account.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

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

5-
use UnityWebPortal\lib\UnitySite;
6-
75
require_once $LOC_HEADER;
86

97
$invalid_ssh_dialogue = "<script type='text/javascript'>
@@ -18,7 +16,7 @@
1816
switch ($_POST["add_type"]) {
1917
case "paste":
2018
$key = $_POST["key"];
21-
if (UnitySite::testValidSSHKey($key)) {
19+
if ($SITE->testValidSSHKey($key)) {
2220
array_push($added_keys, $key);
2321
} else {
2422
echo $invalid_ssh_dialogue;
@@ -27,7 +25,7 @@
2725
case "import":
2826
$keyfile = $_FILES["keyfile"]["tmp_name"];
2927
$key = file_get_contents($keyfile);
30-
if (UnitySite::testValidSSHKey($key)) {
28+
if ($SITE->testValidSSHKey($key)) {
3129
array_push($added_keys, $key);
3230
} else {
3331
echo $invalid_ssh_dialogue;
@@ -40,15 +38,15 @@
4038
$gh_user = $_POST["gh_user"];
4139
$keys = $GITHUB->getSshPublicKeys($gh_user);
4240
foreach ($keys as $key) {
43-
if (UnitySite::testValidSSHKey($key)) {
41+
if ($SITE->testValidSSHKey($key)) {
4442
array_push($added_keys, $key);
4543
}
4644
}
4745
break;
4846
}
4947

5048
if (!empty($added_keys)) {
51-
$added_keys = UnitySite::removeTrailingWhitespace($added_keys);
49+
$added_keys = $SITE->removeTrailingWhitespace($added_keys);
5250
$totalKeys = array_merge($USER->getSSHKeys(), $added_keys);
5351
$USER->setSSHKeys($totalKeys, $OPERATOR);
5452
}

webroot/panel/index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
require "../../resources/autoload.php";
44

5-
use UnityWebPortal\lib\UnitySite;
6-
7-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/account.php");
5+
$SITE->redirect($CONFIG["site"]["prefix"] . "/panel/account.php");

webroot/panel/new_account.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

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

5-
use UnityWebPortal\lib\UnitySite;
65
use UnityWebPortal\lib\UnityGroup;
76

87
require_once $LOC_HEADER;
98

109
if ($USER->exists()) {
11-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/index.php"); // Redirect if account already exists
10+
$SITE->redirect($CONFIG["site"]["prefix"] . "/panel/index.php"); // Redirect if account already exists
1211
}
1312

1413
if ($_SERVER["REQUEST_METHOD"] == "POST") {

webroot/panel/pi.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once __DIR__ . "/../../resources/autoload.php";
44

55
use UnityWebPortal\lib\UnityUser;
6-
use UnityWebPortal\lib\UnitySite;
76

87
$group = $USER->getPIGroup();
98

0 commit comments

Comments
 (0)