Control Web Panel

Developers => New Modules => Topic started by: Administrator on May 23, 2014, 09:20:00 AM

Title: How to Build a new module for CentOS Web Panel (CWP)
Post by: Administrator on May 23, 2014, 09:20:00 AM
How to Build a new module for CentOS Web Panel (CWP)??

It’s very easy to build new module for CentOS-WebPanel

Let’s create file named: test2.php
Code: [Select]
<?php

$cpu_info 
shell_exec("cat /proc/cpuinfo");
echo 
"This is example module<br>";
echo 
"You can edit this file and make new modules based on this file<br>";
echo 
"Examples and functions are on our website: centos-webpanel.com<br>";
echo 
"<h3>CPU INFO</h3>";
echo 
"<pre>".$cpu_info."</pre>";

?>


to open this file in CentOS-WebPanel upload it to modules folder and use this link path:

Code: [Select]
http://SERVER_IP:2030/index.php?module=FILE_NAME
eg. http://123.123.123.123:2030/index.php?module=test2

How to add this module to CentOS-WebPanel menu?
It’s easy, go to include folder and make new file named 3rdparty.php ,in this file you add links one per line.
eg.

/usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php
Code: [Select]
<li><a href="index.php?module=test2"><span class="icon16 icomoon-icon-arrow-right-3"></span>Test2 Module</a></li>
<li><a href="index.php?module=test3"><span class="icon16 icomoon-icon-arrow-right-3"></span>Test3 Module</a></li>

All useful modules will be added in CWP installation or additional module installation panel.

Admin panel modules location
/usr/local/cwpsrv/htdocs/resources/admin/modules

Client panel modules location
/usr/local/cwpsrv/htdocs/resources/client/modules

Example module developed by the 3rdParty
https://github.com/boxbillinggit/cwp_modules/blob/master/php_phalcon.php
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: haminhgiap on June 08, 2014, 04:23:48 AM
Something wrong in CWP ver 0.9.1, where my file 3rdparty.php will be place?
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: Administrator on June 08, 2014, 07:32:15 PM
you will need to use direct link for now as we will add this in 0.9.2 soon.
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: erm3nda on August 18, 2014, 01:26:44 PM
you will need to use direct link for now as we will add this in 0.9.2 soon.

For root/admin user put here /usr/local/cwpsrv/htdocs/resources/admin/modules
For users put here /usr/local/cwpsrv/htdocs/resources/client/modules

Regards.
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: cyberxwolf on May 13, 2015, 06:47:25 PM
Simple solution to adding custom built menu's to CWP 0.9.8.6 without needing to use the developer menu

Step #1 - Build your module, and add it to module directory for the admin panel.

ifconfig.php:
Code: [Select]
<?php
if(!isset($include_path)){
    echo(
"invalid access");
}else{
    
$ifconfig shell_exec("ifconfig");
    echo(
"<h3>IFCONFIG</h3><pre>".$ifconfig."</pre>");
}
?>

save your module into the admin modules directory.
/usr/local/cwpsrv/htdocs/resources/admin/modules/ifconfig.php

Step #2 - create a file named 3rdparty.php in /usr/local/cwpsrv/htdocs/resources/admin/include

The default way this file works is meant to let users add modules to the submenu Developer Menu.

The file expects modules to be added as list items like the following:
Code: [Select]
<li><a href="index.php?module=ifconfig"><span class="icon16 icomoon-icon-arrow-right-3"></span>Network Interface</a></li>
However with some minor changes we can create our own menu to use instead of the Developer Menu.

3rdparty.php:
Code: [Select]
<?php
/* File: /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php */
?>

</ul></li> <!-- This line closes the opened submenu tag and menu item for the Developer menu -->

<li class="custom-menu"> <!-- this class "custom-menu" was added so you can remove the Developer Menu easily if you want -->
    <a class="hasUl" href="#"><span class="icon16 icomoon-icon-hammer"></span>MY CUSTOM MENU<span class="hasDrop icon16 icomoon-icon-arrow-down-2"></span></a>
    <ul class="sub">
        <li><a href="index.php?module=ifconfig"><span class="icon16 icomoon-icon-arrow-right-3"></span>Network Interface</a></li>
    </ul>
</li>

<li style="display:none;"><ul> <!-- This line opens a new menu item and submenu that's hidden because CWP will add closing ul and li tags to the end of this file -->
<?php
/* End 3rdparty.php */
?>

Now we have added a new menu with the title "MY CUSTOM MENU" and have added the ifconfig module we built to it.

If you want to add more menus then you simply create another menu block in 3rdparty.php like so:
3rdparty.php:
Code: [Select]
<?php
/* File: /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php */
?>

</ul></li> <!-- This line closes the opened submenu tag and menu item for the Developer menu -->

<li class="custom-menu"> <!-- this class "custom-menu" was added so you can remove the Developer Menu easily if you want -->
    <a class="hasUl" href="#"><span class="icon16 icomoon-icon-hammer"></span>MY CUSTOM MENU<span class="hasDrop icon16 icomoon-icon-arrow-down-2"></span></a>
    <ul class="sub">
        <li><a href="index.php?module=ifconfig"><span class="icon16 icomoon-icon-arrow-right-3"></span>Network Interface</a></li>
    </ul>
</li>

<li>
    <a class="hasUl" href="#"><span class="icon16 icomoon-icon-hammer"></span>IM ANOTHER MENU<span class="hasDrop icon16 icomoon-icon-arrow-down-2"></span></a>
    <ul class="sub">
        <li><a href="index.php?module=ifconfig"><span class="icon16 icomoon-icon-arrow-right-3"></span>Network Interface</a></li>
    </ul>
</li>

<li style="display:none;"><ul> <!-- This line opens a new menu item and submenu that's hidden because CWP will add closing ul and li tags to the end of this file -->
<?php
/* End 3rdparty.php */
?>

And now there is a second new menu titled "IM ANOTHER MENU" now you can organize your modules better.
But I will write a proper module to handle menu modification to handle the menu from the UI.

If you would like to hide the Developer Menu because you aren't using it like me then you may hide it with a little jquery.
You can add this script to the end of the /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php
Code: [Select]
<script type='text/javascript'>$(document).ready(function(){$(".custom-menu").prev("LI").css("display","none");});</script>
That's all for now I hope you enjoyed this and can make use of it.
I have just begun to play with CentOS WebPanel but I have so many ideas of how to add some really cool stuff. it's just too bad a lot of the code is obfuscated because I would love to help build some of this stuff.
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: cyberxwolf on May 14, 2015, 04:49:02 AM
Here is another easier way to add new menus.

create /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php

Code: [Select]
<li>
<script type="text/javascript">
function add_custom_menu($icon_class,$menu_title,$sub_menu_items){
    $the_submenus = "";
    $.each($sub_menu_items,function(ind,itm){
    $the_submenus += "<li><a href='"+itm.link+"'><span class='icon16 icomoon-icon-arrow-right-3'></span>"+itm.link_title+"</a></li>";   
    });
    $(".mainnav > ul").append("<li><a href='#' onmousedown='javascript:return false;'><span class='icon16 "+$icon_class+"'></span>"+$menu_title+"<span class='hasDrop icon16 icomoon-icon-arrow-down-2'></span></a><ul class='sub'>"+$the_submenus+"</ul></li>");
}

//Add your menu items with the add_custom_menu function.

$(function(){
    add_custom_menu("icomoon-icon-hammer","MY NEW MENU 1",[{"link":"index.php?module=example","link_title":"TEST LINK 1"},{"link":"index.php?module=example","link_title":"TEST LINK 2"},{"link":"index.php?module=example","link_title":"TEST LINK 3"}]);
    add_custom_menu("icomoon-icon-hammer","MY NEW MENU 2",[{"link":"index.php?module=example","link_title":"TEST LINK 4"},{"link":"index.php?module=example","link_title":"TEST LINK 5"},{"link":"index.php?module=example","link_title":"TEST LINK 6"}]);

});
</script>
</li>
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: Multiman on October 24, 2015, 07:00:40 AM
Here is another easier way to add new menus.

create /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php

Code: [Select]
<li>
<script type="text/javascript">
function add_custom_menu($icon_class,$menu_title,$sub_menu_items){
    $the_submenus = "";
    $.each($sub_menu_items,function(ind,itm){
    $the_submenus += "<li><a href='"+itm.link+"'><span class='icon16 icomoon-icon-arrow-right-3'></span>"+itm.link_title+"</a></li>";   
    });
    $(".mainnav > ul").append("<li><a href='#' onmousedown='javascript:return false;'><span class='icon16 "+$icon_class+"'></span>"+$menu_title+"<span class='hasDrop icon16 icomoon-icon-arrow-down-2'></span></a><ul class='sub'>"+$the_submenus+"</ul></li>");
}

//Add your menu items with the add_custom_menu function.

$(function(){
    add_custom_menu("icomoon-icon-hammer","MY NEW MENU 1",[{"link":"index.php?module=example","link_title":"TEST LINK 1"},{"link":"index.php?module=example","link_title":"TEST LINK 2"},{"link":"index.php?module=example","link_title":"TEST LINK 3"}]);
    add_custom_menu("icomoon-icon-hammer","MY NEW MENU 2",[{"link":"index.php?module=example","link_title":"TEST LINK 4"},{"link":"index.php?module=example","link_title":"TEST LINK 5"},{"link":"index.php?module=example","link_title":"TEST LINK 6"}]);

});
</script>
</li>


Him very nice thanks bro.
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: pedromidiasf on December 11, 2015, 01:22:02 AM
Is there a way to process ajax requests (PHP side)?
How can i call my module without calling the entire index page?
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: daws on May 08, 2016, 10:02:09 AM
if have error for 3rdparty.php

use this

open menu.php and go down
when you see
Code: [Select]
?>

add this:
Code: [Select]
<div class="mainnav">
<ul>
<li><a href="#" class="hasUl drop"><span class="icon16 icomoon-icon-hammer-2"></span>My Addons<span class="hasDrop icon16 icomoon-icon-arrow-down-2"></span></a>
<ul class="sub" style="display: block;">
<li><a href="index.php?module=test2"><span class="icon16 icomoon-icon-arrow-right-3"></span>Test</a></li>
</ul></li></ul>
</div>

(http://s32.postimg.org/4z39ribnl/Untitled.jpg) (http://postimg.org/image/4z39ribnl/)
Title: Re: How to Build a new module for CentOS Web Panel (CWP)
Post by: kcyg17 on December 23, 2017, 10:38:09 PM
not working for now