Skip to content

Commit a15701d

Browse files
committed
setup init.php for workers
1 parent 98bf4b7 commit a15701d

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

workers/clear-audit-log.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env php
22
<?php
3-
$_SERVER["HTTP_HOST"] = "worker"; // see deployment/overrides/worker
4-
5-
require_once __DIR__ . "/../resources/autoload.php";
3+
include __DIR__ . "/init.php";
64

75
// Days to keep
86
$days = 30;

workers/group_user_request_owner_reminder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
Removes the request after 34 days have passed.
66
*/
77

8-
$_SERVER["HTTP_HOST"] = "worker"; // see deployment/overrides/worker
9-
10-
require_once __DIR__ . "/../resources/autoload.php";
8+
include __DIR__ . "/init.php";
119
use UnityWebPortal\lib\UnityGroup;
1210

1311
$today = time();

workers/init.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
if (!array_key_exists("HTTP_HOST", $_SERVER)) {
3+
$_SERVER["HTTP_HOST"] = "worker"; // see deployment/overrides/worker
4+
}
5+
if (!array_key_exists("REMOTE_ADDR", $_SERVER)) {
6+
$_SERVER["REMOTE_ADDR"] = "127.0.0.1"; // needed for audit log
7+
}
8+
9+
require_once __DIR__ . "/../resources/autoload.php";
10+
11+
// UnityHTTPD::die() makes no output by default
12+
// builtin die() makes a return code of 0, we may want nonzero
13+
function _die(string $msg, int $exit_code)
14+
{
15+
print $msg;
16+
exit($exit_code);
17+
}

workers/remove-users-from-group.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
#!/usr/bin/env php
22
<?php
3-
$_SERVER["HTTP_HOST"] = "worker"; // see deployment/overrides/worker
4-
5-
require_once __DIR__ . "/../resources/autoload.php";
3+
include __DIR__ . "/init.php";
64
use UnityWebPortal\lib\UnityUser;
75
use UnityWebPortal\lib\UnityGroup;
86

9-
// builtin die() makes a return code of 0, we want nonzero
10-
function _die($msg)
11-
{
12-
print $msg;
13-
exit(1);
14-
}
15-
167
if (sizeof($argv) != 3 or in_array($argv, ["-h", "--help"])) {
17-
die("Usage: $argv[0] group_name filename_of_users_to_remove\n");
8+
_die("Usage: $argv[0] group_name filename_of_users_to_remove\n", 0);
189
}
1910

2011
$gid = $argv[1];
2112
$filename = $argv[2];
2213
$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
2314
if (!$group->exists()) {
24-
_die("No such group '$gid'\n");
15+
_die("No such group '$gid'\n", 1);
2516
}
26-
($handle = fopen($filename, "r")) or _die("Can't open '$filename'\n");
17+
($handle = fopen($filename, "r")) or _die("Can't open '$filename'\n", 1);
2718
while (($line = fgets($handle)) !== false) {
2819
$uid = trim($line);
2920
$user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);

workers/update-ldap-cache.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env php
22
<?php
3-
$_SERVER["HTTP_HOST"] = "worker"; // see deployment/overrides/worker
4-
5-
require_once __DIR__ . "/../resources/autoload.php";
3+
include __DIR__ . "/init.php";
64

75
use UnityWebPortal\lib\UnityConfig;
86
use UnityWebPortal\lib\UnityLDAP;
@@ -17,11 +15,13 @@
1715

1816
$options = getopt("fuh", ["help"]);
1917
if (array_key_exists("h", $options) or array_key_exists("help", $options)) {
20-
echo "arguments:
18+
_die(
19+
"arguments:
2120
f: flush cache and then update
2221
u: update cache even if already initialized
23-
h --help: display this message\n";
24-
die();
22+
h --help: display this message\n",
23+
0,
24+
);
2525
}
2626
if (array_key_exists("f", $options)) {
2727
echo "flushing cache...\n";

0 commit comments

Comments
 (0)