How to build a CWP Module

In this guide i am going to explain how to create a new module in CWP

The meny item under plugins are added in the file located at /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php it holds the actual text displayed under plugins.

In this guilde we are going to make a module for bandwidth statistics.

We need to add the following code to the 3rdparty.php file

After we have added the menu item its time to add the files needed to run the functions for getting the bandwidth statistics. In the code above it uses «?module=vnstat» as the plugin name/url.
You have to go to /usr/local/cwpsrv/htdocs/resources/admin/modules and add the file vnstat.php in that folder. The content i chose to use in that file are the following code.

                                                  
<noscript>
<li class="custom-menu"> <!-- this class "custom-menu" was added so you can remove the Developer Menu easily if you want -->
        <a href="index.php?module=vnstat"><span class="icon16 icomoon-icon-arrow-right-3"></span>Bandwidth Statistics</a>
</li>
</noscript>
<script type="text/javascript">
        $(document).ready(function() {
                var newButtons = ''
                +' <li>'
                +' <a href="?module=vnstat"><span aria-hidden="true" class="icon16 icomoon-icon-arrow-right-3"></span>Bandwidth Statistics</span></a>'
                +'</li>';
                $("ul#mn-15-sub").prepend(newButtons);
        });
</script>

That will add the Meny item under plugins. Now we need to create the functions to get the bandwidth statistics from the server. We are using vnstat for that. To install vnstat go to terminal and type

yum install vnstat

After that is installed open nano and the file vnstat.php

nano /usr/local/cwpsrv/htdocs/resources/admin/modules/vnstat.php

Add tthis content to the file

<?php
if ( !isset( $include_path ) )
{
    echo "invalid access";
    exit( );
}

$vnstat1 = shell_exec("vnstat");
$vnstat2 = shell_exec("vnstat -t");
$vnstat3 = shell_exec("vnstat -5");
$vnstat4 = shell_exec("vnstat -hg");
$vnstat5 = shell_exec("vnstat -h");
$vnstat6 = shell_exec("vnstat -d");
$vnstat7 = shell_exec("vnstat -m");
echo "<h2>Bandwidth Statistics</h2><pre>".$vnstat1."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth Top</h2><pre>".$vnstat2."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth 5-Minutes</h2><pre>".$vnstat3."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth Hourly Graph</h2><pre>".$vnstat4."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth Hourly</h2><pre>".$vnstat5."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth Daily</h2><pre>".$vnstat6."</pre>";
echo "<br><br>";
echo "<h2>Bandwidth Monthly</h2><pre>".$vnstat7."</pre>";
?>

Now open the CWP Admin and it will look something like this

That aall you have to do. Follo me to get more update and functions like this.

 

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *

Dette nettstedet bruker Akismet for å redusere spam. Lær om hvordan dine kommentar-data prosesseres.