]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-checkup.php
2 require_once UPATH
. "/inc/connection.php" ;
5 * Does a complete checkup of the network.
9 const SCORE_PERFECT
= 0 ;
10 const SCORE_NOT_BAD
= 1 ;
11 const SCORE_COULD_BE_BETTER
= 10 ;
12 const SCORE_NEEDS_ATTENTION
= 25 ;
13 const SCORE_VERY_BAD
= 50 ;
15 public $num_of_problems = [
30 public $serverlist = [];
35 function __construct ()
39 $this- > serverlist
= $rpc- > server ()-> getAll ();
40 $this- > chanmode_check ();
41 $this- > usermode_check ();
42 $this- > module_check ();
43 $this- > server_check ();
47 public function total ()
50 foreach ( $this- > num_of_problems
as $problem )
55 public function equivalate ()
57 $total = $this- > total ();
58 if ( $total == self
:: SCORE_PERFECT
)
60 elseif ( $total < self
:: SCORE_COULD_BE_BETTER
)
62 elseif ( $total < self
:: SCORE_NEEDS_ATTENTION
)
63 return "Could Be Better" ;
64 elseif ( $total < self
:: SCORE_VERY_BAD
)
65 return "Needs Attention" ;
66 else return "Very Poor" ;
68 public function badgestyle ()
70 $total = $this- > total ();
71 if ( $total == self
:: SCORE_PERFECT
)
73 elseif ( $total < self
:: SCORE_COULD_BE_BETTER
)
75 elseif ( $total < self
:: SCORE_NEEDS_ATTENTION
)
77 elseif ( $total < self
:: SCORE_VERY_BAD
)
84 * Checks channel modes of servers against other servers
87 function chanmode_check () : void
89 foreach ( $this- > serverlist
as $s ) // cycle through each server
91 /* hmm if it's not unreal, skip it too */
92 if (! isset ( $s- > server
-> features
-> software
) || ! strstr ( $s- > server
-> features
-> software
, "UnrealIRCd" ))
94 /* make a single string from the array of groups */
96 foreach ( $s- > server
-> features
-> chanmodes
as $set )
97 for ( $i = 0 ; isset ( $set [ $i ]); $i ++
)
98 strcat ( $ourchmodes , $set [ $i ]);
100 /* take a look at every other server... yep, we do this for every server */
101 foreach ( $this- > serverlist
as $serv )
103 /* except for ourselves lol */
104 if ( $serv- > id
== $s- > id
)
107 /* hmm if it's not unreal, skip it too */
108 if (! isset ( $serv- > server
-> features
-> software
) || ! strstr ( $serv- > server
-> features
-> software
, "UnrealIRCd" ))
111 /* make a single string from the array of groups but for them this time */
113 foreach ( $serv- > server
-> features
-> chanmodes
as $set )
114 for ( $i = 0 ; isset ( $set [ $i ]); $i ++
)
115 strcat ( $theirchmodes , $set [ $i ]);
117 /* check ours against theirs */
118 for ( $i = 0 ; isset ( $ourchmodes [ $i ]) && $m = $ourchmodes [ $i ]; $i ++
)
120 /* if we have a mode that they don't have */
121 if (! strstr ( $theirchmodes , $m ))
123 ++
$this- > num_of_problems
[ 'chanmodes' ];
124 $this- > problems
[ 'chanmodes' ][] = "Channel mode <code> $m </code> is present on <code> $s- >name</code> but missing on <code> $serv- >name</code>" ;
132 * Checks user modes of servers against other servers
135 function usermode_check () : void
137 foreach ( $this- > serverlist
as $s )
139 /* hmm if it's not unreal, skip it too */
140 if (! isset ( $s- > server
-> features
-> software
) || ! strstr ( $s- > server
-> features
-> software
, "UnrealIRCd" ))
142 /* make a single string from the array of groups */
143 $ourumodes = $s- > server
-> features
-> usermodes
;
145 /* take a look at every other server... yep, we do this for every server */
146 foreach ( $this- > serverlist
as $serv )
148 /* except for ourselves lol */
149 if ( $serv- > id
== $s- > id
)
152 /* hmm if it's not unreal, skip it too */
153 if (! isset ( $serv- > server
-> features
-> software
) || ! strstr ( $serv- > server
-> features
-> software
, "UnrealIRCd" ))
156 $theirumodes = $serv- > server
-> features
-> usermodes
;
158 /* check ours against theirs */
159 for ( $i = 0 ; isset ( $ourumodes [ $i ]) && $m = $ourumodes [ $i ]; $i ++
)
161 /* if we have a mode that they don't have */
162 if (! strstr ( $theirumodes , $m ))
164 ++
$this- > num_of_problems
[ 'usermodes' ];
165 $this- > problems
[ 'usermodes' ][] = "User mode <code> $m </code> is present on <code> $s- >name</code> but missing on <code> $serv- >name</code>" ;
173 * Checks modules of servers against other servers
176 function module_check () : void
179 foreach ( $this- > serverlist
as $s )
181 /* hmm if it's not unreal, skip it too */
182 if (! isset ( $s- > server
-> features
-> software
) || ! strstr ( $s- > server
-> features
-> software
, "UnrealIRCd" ))
184 $ourmods = sort_mods ( json_decode ( json_encode (@ $rpc- > server ()-> module_list ( $s- > id
)-> list ), true ));
186 // doesn't support that yet
190 foreach ( $this- > serverlist
as $serv )
192 /* except for ourselves lol */
193 if ( $serv- > id
== $s- > id
)
196 /* hmm if it's not unreal, skip it too */
197 if (! isset ( $serv- > server
-> features
-> software
) || ! strstr ( $serv- > server
-> features
-> software
, "UnrealIRCd" ))
200 $theirmods = sort_mods ( json_decode ( json_encode (@ $rpc- > server ()-> module_list ( $serv- > id
)-> list ), true ));
202 // doesn't support that yet
203 if ( empty ( $theirmods ))
205 // we only check if theirs doesn't match ours
206 foreach ( $theirmods as $name => $version )
208 if (! isset ( $ourmods [ $name ])) // we don't have that module
210 ++
$this- > num_of_problems
[ 'modules' ];
211 $this- > problems
[ 'modules' ][] = "Module <code> $name </code> exists on <code> $serv- >name</code> but not <code> $s- >name</code>" ;
213 else if (( int ) $version > ( int ) $ourmods [ $name ])
215 ++
$this- > num_of_problems
[ 'modules' ];
216 $this- > problems
[ 'modules' ][] = "Module <code> $name </code> on <code> $serv- >name</code> is newer than on <code> $s- >name</code>" ;
223 function server_check () : void
226 foreach ( $this- > serverlist
as $s )
228 /* hmm if it's not unreal, skip it too */
229 if (! isset ( $s- > server
-> features
-> software
) || ! strstr ( $s- > server
-> features
-> software
, "UnrealIRCd" ))
232 $ours = ( int ) $s- > server
-> features
-> protocol
;
233 foreach ( $this- > serverlist
as $serv )
235 if (! isset ( $serv- > server
-> features
-> software
) || ! strstr ( $serv- > server
-> features
-> software
, "UnrealIRCd" ))
238 $theirs = ( int ) $serv- > server
-> features
-> protocol
;
242 ++
$this- > num_of_problems
[ 'servers' ];
243 $this- > problems
[ 'servers' ][] = "Protocol mismatch: <code> $serv- >name</code> using protocol <code> $theirs </code> but <code> $s- >name</code> using protocol <code> $ours </code>. <a href= \" https://www.unrealircd.org/docs/Upgrading \" >Click for upgrade documentation.</a>" ;
248 $tok = explode ( '-' , $s- > server
-> features
-> software
);
249 if (( int ) $tok [ 1 ] < 6 )
251 ++
$this- > num_of_problems
[ 'servers' ];
252 $this- > problems
[ 'servers' ][] = "EOL: <code> $s- >name</code> (" . $s- > server
-> features
-> software
. ") is running old unsupported software which is no longer receiving security updates. <a href= \" https://www.unrealircd.org/docs/Upgrading \" >Click here for upgrade documentation.</a>" ;
256 /* Print a widget easy! */
257 function __toString ()
260 <a style="width:fit-content" id="health_banner" class="card alert text-dark alert-' .(! $this- > total () ? "success" : "danger" ). '" role="alert" href="' . get_config ( "base_url" ). 'tools/checkup.php">
261 <i class="fa-solid fa-heart-pulse fa-2x" style="position:absolute;top:10px;left:10px"></i>
262 <h4 class="alert-heading mt-0 mb-0" style="padding-left:40px;">Network Health </h4><span style="position:relative;top:5px;" class="ml-3 badge badge-' . $this- > badgestyle (). '">' . $this- > equivalate (). '</span>
263 <p class="ml-4 mt-2 mb-0">Found <b>' . $this- > total (). '</b> problems in total.</p>
267 public function toTable ( Array $array )
269 echo "<table class= \" table table-striped \" > \n " ;
270 foreach ( $array as $key => $value )
272 echo " \t <tr><td> $value </td></tr> \n " ;
278 function sort_mods ( $mods )
283 foreach ( $mods as $mod )
284 $list [ $mod [ "name" ]] = $mod [ "version" ];
289 function checkup_widget ()