Skip to content

Commit f493217

Browse files
committed
add init file for workers
1 parent 98bf4b7 commit f493217

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +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";
11-
use UnityWebPortal\lib\UnityGroup;
8+
include __DIR__ . "/init.php";
129

1310
$today = time();
1411
$accounts = $LDAP->getAllPIGroups($SQL, $MAILER, $REDIS, $WEBHOOK);

workers/init.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
use UnityWebPortal\lib\UnityConfig;
12+
use UnityWebPortal\lib\UnityLDAP;
13+
use UnityWebPortal\lib\UnityMailer;
14+
use UnityWebPortal\lib\UnitySQL;
15+
use UnityWebPortal\lib\UnityHTTPD;
16+
use UnityWebPortal\lib\UnitySSO;
17+
use UnityWebPortal\lib\UnityUser;
18+
use UnityWebPortal\lib\UnityRedis;
19+
use UnityWebPortal\lib\UnityWebhook;
20+
use PHPOpenLDAPer\LDAPEntry;
21+
22+
// UnityHTTPD::die() makes no output by default
23+
// builtin die() makes a return code of 0, we want nonzero
24+
function _die($msg)
25+
{
26+
print $msg;
27+
exit(1);
28+
}

workers/remove-users-from-group.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +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";
6-
use UnityWebPortal\lib\UnityUser;
7-
use UnityWebPortal\lib\UnityGroup;
8-
9-
// builtin die() makes a return code of 0, we want nonzero
10-
function _die($msg)
11-
{
12-
print $msg;
13-
exit(1);
14-
}
3+
include __DIR__ . "/init.php";
154

165
if (sizeof($argv) != 3 or in_array($argv, ["-h", "--help"])) {
176
die("Usage: $argv[0] group_name filename_of_users_to_remove\n");

workers/update-ldap-cache.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +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";
6-
7-
use UnityWebPortal\lib\UnityConfig;
8-
use UnityWebPortal\lib\UnityLDAP;
9-
use UnityWebPortal\lib\UnityMailer;
10-
use UnityWebPortal\lib\UnitySQL;
11-
use UnityWebPortal\lib\UnityHTTPD;
12-
use UnityWebPortal\lib\UnitySSO;
13-
use UnityWebPortal\lib\UnityUser;
14-
use UnityWebPortal\lib\UnityRedis;
15-
use UnityWebPortal\lib\UnityWebhook;
16-
use PHPOpenLDAPer\LDAPEntry;
3+
include __DIR__ . "/init.php";
174

185
$options = getopt("fuh", ["help"]);
196
if (array_key_exists("h", $options) or array_key_exists("help", $options)) {

0 commit comments

Comments
 (0)