Skip to content

Commit b48ec2f

Browse files
author
Jacob Clark
committed
Revert to 9cdc127
1 parent 7becc33 commit b48ec2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2266
-0
lines changed

LICENCE

+375
Large diffs are not rendered by default.

README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [Raspcontrol](http://raspcontrol.com)
2+
3+
Raspcontrol has been drastically improved since the inital release, we now have improved security, standalone deployment and many new awesome features!
4+
5+
### Getting Started Guide
6+
##### Typical Requirements:
7+
8+
Raspcontrol is intended to be used with the PHP 5.4 inbuilt web server.
9+
10+
If your distribution does not support PHP 5.4 then you will need to build it from source or use a HTTP server such as Apache to access Raspcontrol.
11+
12+
13+
***
14+
15+
## How to setup:
16+
17+
### Getting the source
18+
19+
#### .zip Download
20+
21+
You can download this as a _.zip_ from the GitHub Repository via the following link:
22+
23+
https://github.com/Bioshox/Raspcontrol/zipball/master
24+
25+
#### Git Clone
26+
27+
If you have Git installed you can clone the repo
28+
29+
git clone https://github.com/Bioshox/Raspcontrol.git
30+
31+
### Getting it running
32+
33+
Raspcontrol is developed to be deployed with PHP 5.4, although it is possible to deploy it with any other HTTP server too.
34+
35+
#### Deploying with PHP 5.4
36+
37+
Navigate to the location you downloaded Raspcontrol to, from that location we need to give ./start.sh Read/Write/Execute Permissions
38+
39+
sudo chmod 0777 ./start.sh
40+
41+
Now we can deploy the server by running the command from the same location
42+
43+
sudo ./start.sh
44+
45+
You can now access Raspcontrol from _localhost_ directly on your Pi, or the Internal IP from a different computer on your LAN and externally if you're using Port Forwarding. (Raspcontrol binds to the IP 0.0.0.0:80 by default)
46+
47+
__This will work with PHP 5.4 ONLY__ you can check your PHP version by running the command
48+
49+
php -v
50+
51+
#### With Apache
52+
53+
__Running Raspcontrol under Apache is considered insecure and not recomended.__
54+
55+
Add www-data on Apache to the SUDOERS file
56+
57+
sudo VISUDO
58+
59+
On the last line add the following
60+
61+
www-data ALL=(ALL) NOPASSWD: ALL
62+
63+
__Raspcontrol is not designed for production use, adding www-data to a SUDOERS file is dangerous and is not a permanent solution.__
64+
65+
If you're accessing Apaches web avaliable directory on your Raspberry Pi (using startx) you can navigate to localhost/raspcontrol, if you're accessing it from another computer on your Network you will need to navigate to http://your.internal.ip/raspcontrol.
66+
67+
### Setting up your account
68+
69+
Now you will be promted to setup a new account, this will create the initial user to login to the system.
70+
71+
***
72+
73+
### Thanks!
74+
75+
Please feel free to contribute to this development!
76+
77+
[raspcontrol.com](http://raspcontrol.com)
78+
79+
Hosting proudly supplied by [Fusion Strike](http://fusionstrike.com)

app/_lib/API/PiControl.php

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php session_start();
2+
3+
// PiControl API
4+
5+
$handle = file_get_contents("/etc/raspcontrol/database.aptmnt");
6+
$db = json_decode($handle);
7+
$username = $db->{'user'};
8+
$password = $db->{'password'};
9+
10+
if($_GET['username'] == $username && $_GET['password'] == $password){
11+
12+
$_SESSION['username'] = $username; ?>
13+
14+
15+
16+
<?php
17+
if($_GET['action'] == 'reboot'){
18+
system('sudo reboot');
19+
}
20+
21+
if($_GET['action'] == 'stats'){
22+
$uptime = shell_exec("cat /proc/uptime");
23+
$uptime = explode(" ", $uptime);
24+
$seconds = $uptime[0];
25+
$y = floor($seconds / 60/60/24/365);
26+
$d = floor($seconds/60/60/24) % 365;
27+
$h = floor(($seconds / 3600) % 24);
28+
$m = floor(($seconds / 60) % 60);
29+
$s = $seconds % 60;
30+
31+
$string = '';
32+
33+
if($y > 0)
34+
{
35+
$yw = $y > 1 ? ' years ' : ' year ';
36+
$string .= $y . $yw;
37+
}
38+
39+
if($d > 0)
40+
{
41+
$dw = $d > 1 ? ' days ' : ' day ';
42+
$string .= $d . $dw;
43+
}
44+
45+
if($h > 0)
46+
{
47+
$hw = $h > 1 ? ' hours ' : ' hour ';
48+
$string .= $h . $hw;
49+
}
50+
51+
if($m > 0)
52+
{
53+
$mw = $m > 1 ? ' minutes ' : ' minute ';
54+
$string .= $m . $mw;
55+
}
56+
57+
if($s > 0)
58+
{
59+
$sw = $s > 1 ? ' seconds ' : ' second ';
60+
$string .= $s . $sw;
61+
}
62+
63+
$uptime = "Uptime:\n" . preg_replace('/\s+/',' ',$string);
64+
$getLoad = sys_getloadavg();
65+
66+
$rawCPUSpeed = shell_exec('cat /proc/cpuinfo | grep BogoMIPS');
67+
$cpuSpeed = str_replace("BogoMIPS : ", "", "$rawCPUSpeed");
68+
$cpu = "CPU Load:\n1 min: " . $getLoad[0] . "\n" . "5 mins: " . $getLoad[1] . "\n" . "15 mins: " . $getLoad[2] . "\n" . "CPU Speed: " . $cpuSpeed . " MHz";
69+
70+
exec('free -mo', $out);
71+
preg_match_all('/\s+([0-9]+)/', $out[1], $matches);
72+
list($total, $used, $free, $shared, $buffers, $cached) = $matches[1];
73+
$percentage = round(($used - $buffers - $cached) / $total * 100);
74+
$ram = "RAM: " . $percentage . "%" . "\n" . "Free: " . ($free + $buffers + $cached) . " MB" . "\n" . "Used: " . ($used - $buffers - $cached) . " MB" . "\n" . "Total: " . $total . " MB";
75+
exec('free -mo', $out);
76+
preg_match_all('/\s+([0-9]+)/', $out[2], $matches);
77+
list($total, $used, $free) = $matches[1];
78+
79+
$percentage = round($used / $total * 100);
80+
$swap = "Swap: " . $percentage . "%" . "\n" . "Free: " . $free . " MB" . "\n" . "Used: " . $used . " MB" . "\n" . "Total: " . $total . " MB";
81+
82+
$bytes = disk_free_space(".");
83+
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
84+
$base = 1024;
85+
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
86+
$free = sprintf('%1.2f' , $bytes / pow($base,$class));
87+
88+
89+
90+
$bytes = disk_total_space(".");
91+
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
92+
$base = 1024;
93+
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
94+
$total = sprintf('%1.2f' , $bytes / pow($base,$class));
95+
96+
97+
98+
$used = $total - $free;
99+
$percentage = round($used / $total * 100);
100+
101+
$hdd = "SD Card: " . $percentage . "%" . "\n" . "Free: " . $free . "GB" . "\n" . "Used: " . $used . "GB" . "\n" . "Total: " . $total . "GB";
102+
103+
104+
$netType = shell_exec("sudo ifconfig");
105+
$netTypeRaw = explode(" ", $netType);
106+
$netTypeFormatted = str_replace("encap:", "", $netTypeRaw);
107+
108+
109+
$dataThroughput = exec("sudo ifconfig eth0 | grep RX\ bytes", $out);
110+
$dataThroughput = str_ireplace("RX bytes:", "", $dataThroughput);
111+
$dataThroughput = str_ireplace("TX bytes:", "", $dataThroughput);
112+
$dataThroughput = trim($dataThroughput);
113+
$dataThroughput = explode(" ", $dataThroughput);
114+
115+
116+
117+
$rxRaw = $dataThroughput[0] / 1024 / 1024;
118+
$txRaw = $dataThroughput[4] / 1024 / 1024;
119+
$rx = round($rxRaw, 2)." ";
120+
$tx = round($txRaw, 2);
121+
$totalRxTx = $rx + $tx;
122+
123+
$network = "Ethernet:\n" . "Received: " . $rx . "MB" . "\n" . "Sent: " . $tx . "MB" . "\n" . "Total: " . $totalRxTx . "MB";
124+
125+
$whoUsersType = shell_exec("sudo users");
126+
$whoUsersFormatted = str_replace(" ", "\n", $whoUsersType);
127+
128+
$users = "Active Users:" . "\n" . $whoUsersFormatted;
129+
Print $uptime . "\n\n" . $cpu . "\n\n" . $ram . "\n\n" . $swap . "\n\n" . $hdd . "\n\n" . $network. "\n\n" . $users;
130+
131+
}
132+
133+
if($_GET['action'] == 'status'){
134+
Print "Good";
135+
}
136+
137+
//Print "Auth Good";
138+
}else{
139+
Print "Auth Bad";
140+
$wrong = 1;
141+
142+
}
143+
144+

app/_lib/classes/_cpu.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
class cpuLoad {
3+
function getCpuLoad(){
4+
5+
$getLoad = sys_getloadavg();
6+
7+
$rawCPUSpeed = shell_exec('cat /proc/cpuinfo | grep BogoMIPS');
8+
$cpuSpeed = str_replace("BogoMIPS : ", "", "$rawCPUSpeed");
9+
10+
if ($getLoad[0] > 1) {
11+
$warning = "<img src=\"_lib/images/warning.png\" height=\"18\" />";
12+
} else {
13+
$warning = "<img src=\"_lib/images/ok.png\" height=\"18\" />";
14+
}
15+
?>
16+
17+
<div class="cpuIcon">
18+
<img src='_lib/images/cpu.png' align='middle'>
19+
</div>
20+
21+
<div class="cpuTitle">
22+
CPU
23+
</div>
24+
25+
<div class="cpuWarning">
26+
<?php echo $warning ?>
27+
</div>
28+
29+
<div class="cpuText">
30+
Loads: 1 Min: <strong> <?php echo $getLoad[0]; ?> </strong> &middot
31+
5 Mins: <strong><?php echo $getLoad[1]; ?> </strong> &middot
32+
15 Mins: <strong><?php echo $getLoad[2]; ?> </strong> <br/><br/> CPU is running at <strong><?php echo $cpuSpeed; ?> MHz</strong>
33+
</div>
34+
<?php
35+
}
36+
}

app/_lib/classes/_hdd.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
class hddPercentage {
3+
function freeStorage(){
4+
exec('df -hT | grep -vE "tmpfs|rootfs|Filesystem"', $drivesarray);
5+
?>
6+
<div class="sdIcon">
7+
<img src="_lib/images/sd.png" align="middle">
8+
</div>
9+
10+
<div class="sdTitle">
11+
Storage
12+
</div>
13+
14+
<br/><br/><br/><br/><br/>
15+
<?php
16+
17+
for ($drive=0; $drive<count($drivesarray); $drive++)
18+
{
19+
$drivesarray[$drive] = preg_replace('!\s+!', ' ', $drivesarray[$drive]);
20+
preg_match_all('/\S+/', $drivesarray[$drive], $drivedetails);
21+
list($fs, $type, $size, $used, $available, $percentage, $mounted) = $drivedetails[0];
22+
23+
if(rtrim($percentage, '%') > '80'){
24+
$warning = "<img src=\"_lib/images/warning.png\" height=\"18\" />";
25+
$bar = "barAmber";
26+
} else {
27+
$warning = "<img src=\"_lib/images/ok.png\" height=\"18\" />";
28+
$bar = "barGreen";
29+
}
30+
?>
31+
32+
33+
<div class="sdName">
34+
<?php echo $mounted?>
35+
</div>
36+
37+
<div class="sdWarning">
38+
<?php echo $warning ?>
39+
</div>
40+
41+
<div class="sdText">
42+
<div class="graph">
43+
<strong class="<?php echo $bar; ?>" style="width:<?php echo $percentage ?>;"><?php echo $percentage ?></strong>
44+
</div>
45+
46+
<div class="clear"></div>
47+
48+
<br/>
49+
50+
Total: <strong><?php echo $size ?>B</strong> &middot
51+
Free: <strong><?php echo $available ?>B</strong> &middot
52+
Format: <strong><?php echo $type ?>B</strong>
53+
</div>
54+
55+
<div class="clear"></div>
56+
57+
58+
59+
60+
61+
<?php
62+
}
63+
}
64+
}

app/_lib/classes/_login.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php session_start();
2+
if(isset($_POST['login'])){
3+
$handle = file_get_contents("/etc/raspcontrol/database.aptmnt");
4+
$db = json_decode($handle);
5+
$username = $db->{'user'};
6+
$password = $db->{'password'};
7+
$_POST['homepath'] = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - strlen(strrchr($_SERVER['SCRIPT_FILENAME'], "/")));
8+
9+
if($_POST['username'] == $username && $_POST['password'] == $password){
10+
11+
$_SESSION['username'] = $username; ?>
12+
13+
<script type="text/javascript">
14+
<!--
15+
window.location = "main.php"
16+
//-->
17+
</script>
18+
19+
<?php
20+
21+
}else{
22+
23+
$wrong = 1;
24+
25+
}
26+
27+
}

app/_lib/classes/_logout.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
session_start();
3+
session_unset();
4+
session_destroy();
5+
header('location: ../../index.php');

0 commit comments

Comments
 (0)