Skip to content

Commit 5c25c32

Browse files
authored
Merge branch 'main' into main
2 parents d9284c8 + 4fd7295 commit 5c25c32

File tree

8 files changed

+89
-5
lines changed

8 files changed

+89
-5
lines changed

config/branding/config.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ admin = "[email protected]"
5252
admin_name = "Unity Admins"
5353
5454
sender_name = "Unity Sender"
55+
pi_approve = "[email protected]"
56+
pi_approve_name = "Unity PI Approval"
5557

5658
[page] ; which sql objects to use for the content on these pages
5759
home = "home"

resources/init.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
$BRANDING["mail"]["support"],
6767
$BRANDING["mail"]["support_name"],
6868
$BRANDING["mail"]["admin"],
69-
$BRANDING["mail"]["admin_name"]
69+
$BRANDING["mail"]["admin_name"],
70+
$BRANDING["mail"]["pi_approve"],
71+
$BRANDING["mail"]["pi_approve_name"]
7072
);
7173

7274
//

resources/lib/UnityGroup.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ public function requestGroup($send_mail = true)
9393
"email" => $this->getOwner()->getMail()
9494
)
9595
);
96+
97+
$this->MAILER->sendMail(
98+
"pi_approve",
99+
"group_request_admin",
100+
array(
101+
"user" => $this->getOwner()->getUID(),
102+
"org" => $this->getOwner()->getOrg(),
103+
"name" => $this->getOwner()->getFullname(),
104+
"email" => $this->getOwner()->getMail()
105+
)
106+
);
96107
}
97108
}
98109

resources/lib/UnityMailer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class UnityMailer extends PHPMailer
1919
private $MSG_SUPPORT_NAME;
2020
private $MSG_ADMIN_EMAIL;
2121
private $MSG_ADMIN_NAME;
22+
private $MSG_PI_APPROVAL_EMAIL;
23+
private $MSG_PI_APPROVAL_NAME;
2224

2325
public function __construct(
2426
$template_dir,
@@ -34,7 +36,9 @@ public function __construct(
3436
$msg_support_email,
3537
$msg_support_name,
3638
$msg_admin_email,
37-
$msg_admin_name
39+
$msg_admin_name,
40+
$msg_pi_approval_email,
41+
$msg_pi_approval_name
3842
) {
3943
parent::__construct();
4044
$this->isSMTP();
@@ -87,6 +91,8 @@ public function __construct(
8791
$this->MSG_SUPPORT_NAME = $msg_support_name;
8892
$this->MSG_ADMIN_EMAIL = $msg_admin_email;
8993
$this->MSG_ADMIN_NAME = $msg_admin_name;
94+
$this->MSG_PI_APPROVAL_EMAIL = $msg_pi_approval_email;
95+
$this->MSG_PI_APPROVAL_NAME = $msg_pi_approval_name;
9096
}
9197

9298
public function sendMail($recipients, $template = null, $data = null)
@@ -105,6 +111,8 @@ public function sendMail($recipients, $template = null, $data = null)
105111

106112
if ($recipients == "admin") {
107113
$this->addBCC($this->MSG_ADMIN_EMAIL, $this->MSG_ADMIN_NAME);
114+
} elseif ($recipients == "pi_approve") {
115+
$this->addBCC($this->MSG_PI_APPROVAL_EMAIL, $this->MSG_PI_APPROVAL_NAME);
108116
} else {
109117
if (is_array($recipients)) {
110118
foreach ($recipients as $addr) {

resources/lib/UnitySite.php

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

33
namespace UnityWebPortal\lib;
44

5+
use phpseclib3\Crypt\PublicKeyLoader;
6+
57
class UnitySite
68
{
79
public static function redirect($destination)
@@ -50,4 +52,14 @@ public static function getConfig($conf_path)
5052
$arr = parse_ini_file($conf_path, true);
5153
return $arr;
5254
}
55+
56+
public static function testValidSSHKey($key_str)
57+
{
58+
try {
59+
PublicKeyLoader::load($key_str);
60+
return true;
61+
} catch (\Exception $e) {
62+
return false;
63+
}
64+
}
5365
}

webroot/js/ajax/ssh_validate.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
require "../../../resources/autoload.php";
4+
5+
use phpseclib3\Crypt\PublicKeyLoader;
6+
7+
try {
8+
PublicKeyLoader::load($_POST['key'], $password = false);
9+
echo "true";
10+
} catch (Exception $e) {
11+
echo "false";
12+
}

webroot/panel/account.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@
66

77
require_once $LOC_HEADER;
88

9+
$invalid_ssh_dialogue = "<script type='text/javascript'>
10+
alert('Invalid SSH key. Please verify your public key file is valid.');
11+
</script>";
12+
913
if ($_SERVER['REQUEST_METHOD'] == "POST") {
1014
switch ($_POST["form_type"]) {
1115
case "addKey":
1216
$added_keys = array();
1317

1418
switch ($_POST["add_type"]) {
1519
case "paste":
16-
array_push($added_keys, $_POST["key"]);
20+
$key = $_POST["key"];
21+
if (UnitySite::testValidSSHKey($key)) {
22+
array_push($added_keys, $key);
23+
} else {
24+
echo $invalid_ssh_dialogue;
25+
}
1726
break;
1827
case "import":
19-
array_push($added_keys, file_get_contents($_FILES['keyfile']['tmp_name']));
28+
$keyfile = $_FILES["keyfile"]["tmp_name"];
29+
$key = file_get_contents($keyfile);
30+
if (UnitySite::testValidSSHKey($key)) {
31+
array_push($added_keys, $key);
32+
} else {
33+
echo $invalid_ssh_dialogue;
34+
}
2035
break;
2136
case "generate":
2237
array_push($added_keys, $_POST["gen_key"]);

webroot/panel/modal/new_key.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<div id="key_paste">
3333
<textarea placeholder="ssh-rsa AAARs1..." form="newKeyform" name="key"></textarea>
3434

35-
<input type="submit" value="Add Key">
35+
<input type="submit" value="Add Key" id="add-key">
3636
</div>
3737

3838
<div style="display: none;" id="key_import">
@@ -90,4 +90,26 @@
9090
}
9191
});
9292
});
93+
94+
$("textarea[name=key]").on("input", function() {
95+
var key = $(this).val();
96+
$.ajax({
97+
url: "<?php echo $CONFIG["site"]["prefix"]; ?>/js/ajax/ssh_validate.php",
98+
type: "POST",
99+
data: {
100+
key: key
101+
},
102+
success: function(result) {
103+
const res = result.replace(key, "");
104+
if (res == "true") {
105+
$("input[id=add-key]").prop("disabled", false);
106+
$("textarea[name=key]").css("box-shadow", "none");
107+
} else {
108+
$("input[id=add-key]").prop("disabled", true);
109+
$("textarea[name=key]").css("box-shadow", "0 0 0 0.3rem rgba(220, 53, 69, 0.25)");
110+
}
111+
}
112+
});
113+
});
114+
93115
</script>

0 commit comments

Comments
 (0)