2023-02-25 20:17:06 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
use Mince\Whitelist;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../mince.php';
|
|
|
|
|
2023-08-17 00:23:55 +00:00
|
|
|
// rewrite this to use the database shit
|
|
|
|
|
2023-02-25 20:17:06 +00:00
|
|
|
echo 'Syncing server whitelists...' . PHP_EOL;
|
|
|
|
|
|
|
|
$rInfo = $remote->getInfo();
|
|
|
|
if(empty($rInfo->servers)) {
|
|
|
|
echo 'There are no active servers.' . PHP_EOL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo 'Fetching master list from database...' . PHP_EOL;
|
|
|
|
$myNames = (new Whitelist($db))->getNames();
|
|
|
|
|
|
|
|
foreach($rInfo->servers as $serverId) {
|
|
|
|
try {
|
|
|
|
echo "[{$serverId}] Fetching list on server..." . PHP_EOL;
|
|
|
|
$rWhitelist = $remote->getWhitelist($serverId);
|
|
|
|
$rNames = $rWhitelist->list ?? [];
|
|
|
|
|
|
|
|
echo "[{$serverId}] Filtering..." . PHP_EOL;
|
|
|
|
$addNames = array_values(array_udiff($myNames, $rNames, 'strcasecmp'));
|
|
|
|
$removeNames = array_values(array_udiff($rNames, $myNames, $addNames, 'strcasecmp'));
|
|
|
|
|
|
|
|
if(!empty($addNames)) {
|
|
|
|
echo "[{$serverId}] Adding names..." . PHP_EOL;
|
|
|
|
$addResult = $remote->addToWhitelist($serverId, $addNames);
|
|
|
|
foreach($addResult->results as $name => $result)
|
|
|
|
echo "[{$serverId}] [{$name}] {$result->message}" . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($removeNames)) {
|
|
|
|
echo "[{$serverId}] Removing names..." . PHP_EOL;
|
|
|
|
$removeResult = $remote->removeFromWhitelist($serverId, $removeNames);
|
|
|
|
foreach($removeResult->results as $name => $result)
|
|
|
|
echo "[{$serverId}] [{$name}] {$result->message}" . PHP_EOL;
|
|
|
|
}
|
|
|
|
} catch(RuntimeException $ex) {
|
|
|
|
var_dump((string)$ex);
|
|
|
|
echo PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|