-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_commands.php
177 lines (157 loc) · 5.41 KB
/
linux_commands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
require "includes/db_connection.php";
session_start();
// This stops users jumping to page URL's without being logged in first
// An unregistered user should NOT be able to see this page's contents
// If a user does end up on this page without being logged on, they will be prompted to do so and then redirected to index.php
if(!isset($_SESSION['username'])) {
header('refresh:1;url=/mini_project/index.php');
die("Uh-oh! You cannot view these pages without registering or logging in first. This page will redirect.");
}
?>
<!DOCTYPE html>
<html lang = "en">
<head>
<title>Raspberry Pi Web Interface - Linux Commands</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--CSS-->
<link rel="stylesheet" href="css/style.css">
<!--Bootstrap-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!--jQuery 3.6.0-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class = "container-fluid">
<nav>
<!--Home tab always displayed, whether logged in or logged out-->
<a class='link-item' href ='index.php'>Home</a>
<?php
//Show register tab when session NOT set
if(!isset($_SESSION['username'])){
echo "<a class = 'link-item' href = 'register_screen.php'>Register</a>";
}
//Show login tab when session NOT set
if(!isset($_SESSION['username'])){
echo "<a class = 'link-item' href = 'login_screen.php'>Login</a>";
}
//Show LED tab when session HAS BEEN set
if(isset($_SESSION['username'])){
echo "<a class = 'link-item' href = 'led.php'>LED</a>";
}
//Show LINUX TERMINAL COMMANDS tab when session HAS BEEN set
if(isset($_SESSION['username'])){
echo "<a class = 'link-item' href = 'linux_commands.php' style = 'background-color:#bd0d00; color: #ffffff;'>Linux Terminal Commands</a>";
}
//Show logout tab when session HAS BEEN set
if(isset($_SESSION['username'])){
echo "<a class = 'link-item' href = 'includes/attempt_logout.php'>Logout</a>";
}
?>
</nav>
<div class="jumbotron text-center bg-danger">
<h1>Raspberry Pi Web Interface</h1>
<h2>CMP408 System Internals & Cybersecurity</h2>
<h3>Patrick Welsh</h3>
</div>
<div class = "row">
<div class = "col-lg-12">
<?php
///Display username below Jumbotron when session HAS BEEN set
// IE: when they have logged in
if(isset($_SESSION['username'])){
echo "<h3>Hello, {$_SESSION['username']}</h3><br>";
echo "<h3>This website is hosted on an Apache2 webserver running on the Raspberry Pi.<br>";
echo "This webpage includes Python scripts which contain stored Linux terminal commands inside a 'cmd' variable.<br>";
echo "PHP then executes that Python file on the webpage using 'exec_file'<br>";
echo "This allows us to see command data that can normally only be run from the Rasbian terminal, right here on a webpage.<h3>";
}
?>
</div>
</div>
<!-- Linux Commands Outputted to this HTML page via Python code being called via PHP shell_exec-->
<div class = "row">
<div class = "col-lg-4">
<h3>Temperature</h3>
<?php
$command = escapeshellcmd('python python_scripts/rpi_temp.py');
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>Uptime</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_uptime.py");
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>Hostname and Private IP Address</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_hostname.py");
$output = shell_exec($command);
echo $output;
?>
</div>
</div>
<div class = "row">
<div class = "col-lg-4">
<h3>Free Memory Available</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_free.py");
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>Raspberry Pi Version</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_version.py");
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>CPU Info</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_cpuinfo.py");
$output = shell_exec($command);
echo $output;
?>
</div>
</div>
<div class = "row">
<div class = "col-lg-4">
<h3>vcgencmd Voltage</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_volts.py");
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>vcgencmd CPU / GPU Memory Split</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_cpugpu.py");
$output = shell_exec($command);
echo $output;
?>
</div>
<div class = "col-lg-4">
<h3>vcgencmd CPU Clock Speed</h3>
<?php
$command = escapeshellcmd("python python_scripts/rpi_measure_clock.py");
$output = shell_exec($command);
echo $output;
?>
</div>
</div>
<footer>
<img src = "img/RPiLogo.png" style="height:200px; width:300px;">
<h6>Patrick Welsh | Email Me Here: <a href = "mailto: 1805531@uad.ac.uk">1805531@uad.ac.uk</h6>
</footer>
</div>
<body>
<html>