Jump to content

Server Status - Show only server belonging to client


Atomic

Recommended Posts

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. :idea:

 

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'. :idea:

Link to comment
Share on other sites

  • 4 years later...

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 by Newton
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated