Atomic Posted October 11, 2016 Share Posted October 11, 2016 Is it possible to have the server status page show only the status of the server where a client has an account? Rather than a page with 30 servers. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 11, 2016 Share Posted October 11, 2016 you could use a hook, not a million miles from the previous network issues hook I gave you... <?php use Illuminate\Database\Capsule\Manager as Capsule; function server_status_hook($vars) { $client = Menu::context('client'); $myservers = Capsule::table('tblhosting') ->join('tblservers', 'tblservers.id', '=', 'tblhosting.server') ->select('tblservers.name') ->where('tblhosting.userid', $client->id) ->groupby('tblservers.name') ->lists('tblservers.name'); $encodedata = json_encode($myservers); $decodedata = json_decode($encodedata, true); return array("myservers" => $decodedata); } add_hook("ClientAreaPageServerStatus", 1, "server_status_hook"); ?> to make things slightly easier in the template, the hook is creating a one-dimensional array which allows us to use in_array in Smarty... you don't particularly need to do it, but it avoids the need to complicate the code required in the template. then in serverstatus.tpl... <tbody> {if $myservers|count gt 0} {foreach from=$servers key=num item=server} {if $server.name|in_array:$myservers} <tr> <td>{$server.name}</td> <td class="text-center" id="port80_{$num}"> <span class="fa fa-spinner fa-spin"></span> </td> <td class="text-center" id="port21_{$num}"> <span class="fa fa-spinner fa-spin"></span> </td> <td class="text-center" id="port110_{$num}"> <span class="fa fa-spinner fa-spin"></span> </td> <td class="text-center"><a href="{$server.phpinfourl}" target="_blank">{$LANG.serverstatusphpinfo}</a></td> <td class="text-center" id="load{$num}"> <span class="fa fa-spinner fa-spin"></span> </td> <td class="text-center" id="uptime{$num}"> <span class="fa fa-spinner fa-spin"></span> <script> jQuery(document).ready(function() { checkPort({$num}, 80); checkPort({$num}, 21); checkPort({$num}, 110); getStats({$num}); }); </script> </td> </tr> {/if} {/foreach} {else} <tr> <td class="text-center" colspan="7">{$LANG.serverstatusnoservers}</td> </tr> {/if} </tbody> tested with clients using just one server, but should work with multiple servers - i'm sure you'll let me know if it doesn't. - - - Updated - - - just to add that the above hook code was tested in v6... if using on v7, you'll likely need to change 'lists' to 'pluck'. 0 Quote Link to comment Share on other sites More sharing options...
Atomic Posted October 12, 2016 Author Share Posted October 12, 2016 Works flawlessly - thanks! 0 Quote Link to comment Share on other sites More sharing options...
Newton Posted March 22, 2021 Share Posted March 22, 2021 (edited) Hello @brian! and all, With the latest upgrade (well, a few months ago), that little script stopped working. Has anyone succeeded in fixing it or implementing another way to display only the relevant server to the client? Thanks! Edited March 22, 2021 by Newton 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 22, 2021 Share Posted March 22, 2021 9 hours ago, Newton said: Has anyone succeeded in fixing it or implementing another way to display only the relevant server to the client? lists got replaced by pluck soon after the original post - so replace one with the other in the code and it should work again. 0 Quote Link to comment Share on other sites More sharing options...
Newton Posted March 23, 2021 Share Posted March 23, 2021 Thank you @brian! indeed that fixed it. The code of serverstatus.tpl changed a bit so here it is if someone needs the latest version : <tbody>{if $myservers|count gt 0} {foreach from=$servers key=num item=server} {if $server.name|in_array:$myservers} <tr> <td>{$server.name}</td> <td class="text-center" id="port80_{$num}"> <div class="loader">{include file="$template/includes/loader.tpl" classes="spinner-sm"}</div> </td> <td class="text-center" id="port21_{$num}"> <div class="loader">{include file="$template/includes/loader.tpl" classes="spinner-sm"}</div> </td> <td class="text-center" id="port110_{$num}"> <div class="loader">{include file="$template/includes/loader.tpl" classes="spinner-sm"}</div> </td> <td class="text-center"> <a href="{$server.phpinfourl}" target="_blank">{$LANG.serverstatusphpinfo}</a> </td> <td class="text-center" id="load{$num}"> <div class="loader">{include file="$template/includes/loader.tpl" classes="spinner-sm"}</div> </td> <td class="text-center" id="uptime{$num}"> <div class="loader">{include file="$template/includes/loader.tpl" classes="spinner-sm"}</div> <script>function checkLsPort(num, port) { WHMCS.http.jqClient.post('serverstatus.php', 'ping=1&num=' + num + '&port=' + port, function(data) { var str = data; var res = str.replace("assets/img", "templates/lagom/assets/img/serverstatus"); res = res.replace("gif", "svg"); jQuery("#port" + port + "_" + num).html(res); }); } jQuery(document).ready(function() { checkLsPort({$num}, 80); checkLsPort({$num}, 21); checkLsPort({$num}, 110); getStats({$num}); });</script> </td> </tr> {/if} {/foreach} {else} <tr> <td colspan="7">{$LANG.serverstatusnoservers}</td> </tr> {/if} </tbody> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 23, 2021 Share Posted March 23, 2021 4 hours ago, Newton said: Thank you @brian! indeed that fixed it. good to hear. although I can't for the life of me remember why i'm not just removing inapplicable servers from the existing array before returning it to the template - if I had done that, then there would be little need to edit the template at all. 🙄 5 hours ago, Newton said: The code of serverstatus.tpl changed a bit so here it is if someone needs the latest version : are you using a custom third-party theme ? as neither Six or 21 looks like that. 0 Quote Link to comment Share on other sites More sharing options...
Newton Posted March 24, 2021 Share Posted March 24, 2021 16 hours ago, brian! said: good to hear. although I can't for the life of me remember why i'm not just removing inapplicable servers from the existing array before returning it to the template - if I had done that, then there would be little need to edit the template at all. 🙄 are you using a custom third-party theme ? as neither Six or 21 looks like that. Oh... you are right, this is lagom, not six/21. I thought it was the same but I guess not! 0 Quote Link to comment Share on other sites More sharing options...
Newton Posted September 21, 2022 Share Posted September 21, 2022 (edited) deleted Edited September 21, 2022 by Newton 0 Quote Link to comment Share on other sites More sharing options...
theozsnowman Posted February 16 Share Posted February 16 I tried this code and find it no longer works and spits an error from the hook BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::lists() in /home/USER/public_html/vendor/illuminate/support/Traits/ForwardsCalls.php:50 Stack trace: #0 /home/USER/public_html/vendor/illuminate/database/Query/Builder.php(3163): Illuminate\Database\Query\Builder::throwBadMethodCallException() #1 /home/USER/public_html/includes/hooks/myServersStatus.php(14): Illuminate\Database\Query\Builder->__call() #2 [internal function]: server_status_hook() #3 /home/USER/public_html/vendor/whmcs/whmcs-foundation/lib/Hook/Manager.php(0): call_user_func() #4 /home/USER/public_html/vendor/illuminate/support/Facades/Facade.php(261): WHMCS\Hook\Manager->run() #5 /home/USER/public_html/includes/functions.php(0): Illuminate\Support\Facades\Facade::__callStatic() #6 /home/USER/public_html/includes/clientareafunctions.php(0): run_hook() #7 /home/USER/public_html/serverstatus.php(0): outputClientArea() #8 {main anyone know a fix for this? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.