]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Servers: Make ability to rehash selected servers
authorValerie Pond <redacted>
Mon, 16 Jan 2023 05:25:43 +0000 (05:25 +0000)
committerValerie Pond <redacted>
Mon, 16 Jan 2023 05:25:43 +0000 (05:25 +0000)
servers/index.php

index 0a02a6ad5fc52f60d906ce2ea7b87b325b4bfb04..dfe8a4ab8f8235cdbc4158f1b655d2a2f6317672 100644 (file)
@@ -2,24 +2,95 @@
 require_once "../common.php";
 require_once UPATH . "/header.php";
 
-if (!empty($_POST)) {
-       do_log($_POST);
-}
+$rehash_errors = [];
+$rehash_warnings = [];
+$rehash_success = [];
+
+if (!empty($_POST) && do_log($_POST))
+       if (isset($_POST['rehash']))
+               foreach ($_POST['serverch'] as $servID)
+                       if ($response = $rpc->server()->rehash($servID)) 
+                       {
+                               $serb = $rpc->server()->get($servID);
+                               do_log($servID, $response);
+                               if ($response->success || (!isset($response->success) != false && $response == true))
+                               {
+                                       $rehash_success[] = $serb->name;
+                                       foreach($response->log as $log)
+                                       {
+                                               do_log($log->level);
+                                               if ($log->level == "warn")
+                                                       $rehash_warnings[$log->log_source][] = $log->msg;
+                                       }
+                               }
+                               else if (isset($response->success) && !$response->success)
+                               {
+                                       foreach ($response->log as $log)
+                                       {
+                                               if ($log->level == "error")
+                                                       $rehash_errors[$log->log_source][] = $log->msg;
+                                       }
+                               }                
+                       }
+
 
 /* Get the server list */
 $servers = $rpc->server()->getAll();
 ?>
 <h4>Servers Overview</h4>
+<?php
+       if (isset($_POST['rehash']))
+       {
+               if (!empty($rehash_success))
+                       do_log($rehash_success);
+                       $servlist_bullet = "<ol>";
+                       
+                       foreach($rehash_success as $serv)
+                       {
+                               $servlist_bullet .= "<li>$serv</li>";
+                       }
+                       $servlist_bullet .= "</ol>";
+                       $servlist_err_bullet = "";
+                       foreach($rehash_errors as $serv => $err)
+                       {
+                               $servlist_err_bullet .= "<h6>$serv</h6><ol>";
+                               foreach($err as $er)
+                                       $servlist_err_bullet .= "<li>$er</li>";
+                               echo "</ol>";
+                       }
+                       $servlist_warn_bullet = "";
+                       foreach($rehash_warnings as $server => $warning)
+                       {
+                               $servlist_warn_bullet .= "<h6>$serv</h6><ol>";
+                               foreach($warning as $w)
+                                       $servlist_warn_bullet .= "<li>$w</li>";
+                               $servlist_warn_bullet .= "</ol>";
+                       }
+                       if (!empty($rehash_success))
+                               Message::Success(
+                                       "The following server(s) were successfully rehashed:",
+                                       $servlist_bullet
+                               );
+                       if (!empty($rehash_warnings))
+                               Message::Info(
+                                       "The following warning(s) were encountered:",
+                                       $servlist_warn_bullet
+                               );
+                       if (!empty($rehash_errors))
+                               Message::Fail(
+                                       "The following error(s) were encountered and the server(s) failed to rehash:",
+                                       $servlist_err_bullet
+                               );
+       }
+       if (isset($_POST['sf_name']) && strlen($_POST['sf_name']))
+               Message::Info("Listing servers which match name: \"" . $_POST['sf_name'] . "\"");
 
+       ?>
 Click on a server name to view more information.
 
 <div id="Servers">
        
-       <?php
-       if (isset($_POST['sf_name']) && strlen($_POST['sf_name']))
-               Message::Info("Listing servers which match name: \"" . $_POST['sf_name'] . "\"");
-
-       ?>
+       
        <table class="container-xxl table table-sm table-responsive caption-top table-striped">
        <thead>
                <th scope="col"><h5>Filter:</h5></th>
@@ -27,7 +98,7 @@ Click on a server name to view more information.
                <th scope="col" colspan="2">Name<input name="sf_name" type="text" class="form-control short-form-control">
                <th scope="col"> <input class="btn btn-primary btn-sm" type="submit" value="Search"></th></form>
        </thead></table>
-
+       <form action="index.php" method="post"><button type="submit" class="btn btn-info" name="rehash">Rehash Selected</div><br>
        <table class="container-xxl table table-sm table-responsive caption-top table-striped">
        <thead class="table-primary">
                <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_server(this)" /></th>
@@ -39,7 +110,6 @@ Click on a server name to view more information.
        </thead>
        
        <tbody>
-       <form method="post">
        <?php
 
                foreach($servers as $server)
@@ -54,7 +124,7 @@ Click on a server name to view more information.
 
 
                        echo "<tr>";
-                       echo "<th scope=\"row\"><input type=\"checkbox\" value='" . base64_encode($server->id)."' name=\"serverch[]\"></th>";
+                       echo "<th scope=\"row\"><input type=\"checkbox\" value='$server->id' name=\"serverch[]\"></th>";
                        echo "<td><a href=\"details.php?server=".$server->id."\">$server->name</a></td>";
                        echo "<td>".$server->server->num_users."</td>";
                        
@@ -68,6 +138,7 @@ Click on a server name to view more information.
                        echo "<td>".$server->server->boot_time."</td>";
                }
        ?>
+       </form>
        </tbody></table>
 </div>