0, "usermodes" => 0, "modules" => 0, "servers" => 0, "other" => 0, ]; public $problems = [ "chanmodes" => [], "usermodes" => [], "modules" => [], "servers" => [], "other" => [], ]; public $serverlist = []; /** * Construct0r */ function __construct() { global $rpc; $this->serverlist = $rpc->server()->getAll(); $this->chanmode_check(); $this->usermode_check(); $this->module_check(); $this->server_check(); } public function total() { $count = 0; foreach ($this->num_of_problems as $problem) $count += $problem; return $count; } public function equivalate() { $total = $this->total(); if ($total == self::SCORE_PERFECT) return "Perfect"; elseif ($total < self::SCORE_COULD_BE_BETTER) return "Not Bad"; elseif ($total < self::SCORE_NEEDS_ATTENTION) return "Could Be Better"; elseif ($total < self::SCORE_VERY_BAD) return "Needs Attention"; else return "Very Poor"; } public function badgestyle() { $total = $this->total(); if ($total == self::SCORE_PERFECT) return "success"; elseif ($total < self::SCORE_COULD_BE_BETTER) return "info"; elseif ($total < self::SCORE_NEEDS_ATTENTION) return "warning"; elseif ($total < self::SCORE_VERY_BAD) return "danger"; else return "dark"; } /** * Checks channel modes of servers against other servers * @return void */ function chanmode_check() : void { foreach($this->serverlist as $s) // cycle through each server { /* hmm if it's not unreal, skip it too */ if (!strstr($s->server->features->software,"UnrealIRCd")) continue; /* make a single string from the array of groups */ $ourchmodes = ""; foreach ($s->server->features->chanmodes as $set) for ($i=0; isset($set[$i]); $i++) strcat($ourchmodes,$set[$i]); /* take a look at every other server... yep, we do this for every server */ foreach ($this->serverlist as $serv) { /* except for ourselves lol */ if ($serv->id == $s->id) continue; /* hmm if it's not unreal, skip it too */ if (!strstr($serv->server->features->software,"UnrealIRCd")) continue; /* make a single string from the array of groups but for them this time */ $theirchmodes = ""; foreach ($serv->server->features->chanmodes as $set) for ($i=0; isset($set[$i]); $i++) strcat($theirchmodes,$set[$i]); /* check ours against theirs */ for ($i=0; isset($ourchmodes[$i]) && $m = $ourchmodes[$i]; $i++) { /* if we have a mode that they don't have */ if (!strstr($theirchmodes, $m)) { ++$this->num_of_problems['chanmodes']; $this->problems['chanmodes'][] = "Channel mode $m is present on $s->name but missing on $serv->name"; } } } } } /** * Checks user modes of servers against other servers * @return void */ function usermode_check() : void { foreach($this->serverlist as $s) { /* hmm if it's not unreal, skip it too */ if (!strstr($s->server->features->software,"UnrealIRCd")) continue; /* make a single string from the array of groups */ $ourumodes = $s->server->features->usermodes; /* take a look at every other server... yep, we do this for every server */ foreach ($this->serverlist as $serv) { /* except for ourselves lol */ if ($serv->id == $s->id) continue; /* hmm if it's not unreal, skip it too */ if (!strstr($serv->server->features->software,"UnrealIRCd")) continue; $theirumodes = $serv->server->features->usermodes; /* check ours against theirs */ for ($i=0; isset($ourumodes[$i]) && $m = $ourumodes[$i]; $i++) { /* if we have a mode that they don't have */ if (!strstr($theirumodes, $m)) { ++$this->num_of_problems['usermodes']; $this->problems['usermodes'][] = "User mode $m is present on $s->name but missing on $serv->name"; } } } } } /** * Checks modules of servers against other servers * @return void */ function module_check() : void { global $rpc; foreach ($this->serverlist as $s) { /* hmm if it's not unreal, skip it too */ if (!strstr($s->server->features->software,"UnrealIRCd")) continue; $ourmods = sort_mods(json_decode(json_encode(@$rpc->server()->module_list($s->id)->list), true)); // doesn't support that yet if (empty($ourmods)) continue; foreach ($this->serverlist as $serv) { /* except for ourselves lol */ if ($serv->id == $s->id) continue; /* hmm if it's not unreal, skip it too */ if (!strstr($serv->server->features->software,"UnrealIRCd")) continue; $theirmods = sort_mods(json_decode(json_encode(@$rpc->server()->module_list($serv->id)->list), true)); // doesn't support that yet if (empty($theirmods)) continue; // we only check if theirs doesn't match ours foreach ($theirmods as $name => $version) { if (!isset($ourmods[$name])) // we don't have that module { ++$this->num_of_problems['modules']; $this->problems['modules'][] = "Module $name exists on $serv->name but not $s->name"; } else if ((int)$version > (int)$ourmods[$name]) { ++$this->num_of_problems['modules']; $this->problems['modules'][] = "Module $name on $serv->name is newer than on $s->name"; } } } } } function server_check() : void { global $rpc; foreach ($this->serverlist as $s) { /* hmm if it's not unreal, skip it too */ if (!strstr($s->server->features->software,"UnrealIRCd")) continue; // protocol checking $ours = (int)$s->server->features->protocol; foreach ($this->serverlist as $serv) { if (!strstr($serv->server->features->software,"UnrealIRCd")) continue; $theirs = (int)$serv->server->features->protocol; if ($ours < $theirs) { ++$this->num_of_problems['servers']; $this->problems['servers'][] = "Protocol mismatch: $serv->name using protocol $theirs but $s->name using protocol $ours. Click for upgrade documentation."; } } // EOL checking $tok = explode('-', $s->server->features->software); if ((int)$tok[1] < 6) { ++$this->num_of_problems['servers']; $this->problems['servers'][] = "EOL: $s->name (".$s->server->features->software.") is running old unsupported software which is no longer receiving security updates. Click here for upgrade documentation."; } } } /* Print a widget easy! */ function __toString() { return '

Network Health

'.$this->equivalate().'

Found '.$this->total().' problems in total.

'; } public function toTable(Array $array) { echo "\n"; foreach ($array as $key => $value) { echo "\t\n"; } echo "
$value
\n"; } } function sort_mods($mods) { $list = []; if (!$mods) return $list; foreach($mods as $mod) $list[$mod["name"]] = $mod["version"]; return $list; } function checkup_widget() { $ch = new CheckUp(); echo $ch; }