-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.php
More file actions
183 lines (154 loc) · 5.55 KB
/
led.php
File metadata and controls
183 lines (154 loc) · 5.55 KB
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
178
179
180
181
182
183
<?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 - Home</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' style = 'background-color:#bd0d00; color: #ffffff;'>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'>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>";
echo "<h3>This website is hosted on an Apache2 webserver running on the Raspberry Pi.<br></h3>";
}
?>
</div>
</div>
<!--GPIO LED CONTROLS-->
<div class = "row">
<!-- TURN ON/OFF RED LED -->
<div class = "col-lg-4">
<h3>Turn Red LED On</h3>
<form action "index.php" method = "GET">
<input class = "btn btn-danger" type = "submit" value = "Switch On" name = "red_on">
<input class = "btn btn-danger" type = "submit" value = "Switch Off" name = "red_off">
</form>
<?php
shell_exec("gpio -g mode 23 out");
if(isset($_GET["red_off"])){
shell_exec("gpio -g write 23 0");
}
else if(isset($_GET["red_on"])){
shell_exec("gpio -g write 23 1");
}
?>
</div>
<!-- TURN ON/OFF BLUE LED -->
<div class = "col-lg-4">
<h3>Turn Blue LED On</h3>
<form action "index.php" method = "GET">
<input class = "btn btn-primary" type = "submit" value = "Switch On" name = "blue_on">
<input class = "btn btn-primary" type = "submit" value = "Switch Off" name = "blue_off">
</form>
<?php
shell_exec("gpio -g mode 20 out");
if(isset($_GET["blue_off"])){
shell_exec("gpio -g write 20 0");
}
else if(isset($_GET["blue_on"])){
shell_exec("gpio -g write 20 1");
}
?>
</div>
<!-- TURN ON/OFF GREEN LED -->
<div class = "col-lg-4">
<h3>Turn Green LED On</h3>
<form action "index.php" method = "GET">
<input class = "btn btn-success" type = "submit" value = "Switch On" name = "green_on">
<input class = "btn btn-success" type = "submit" value = "Switch Off" name = "green_off">
</form>
<?php
shell_exec("gpio -g mode 25 out");
if(isset($_GET["green_off"])){
shell_exec("gpio -g write 25 0");
}
else if(isset($_GET["green_on"])){
shell_exec("gpio -g write 25 1");
}
?>
</div>
</div>
<!-- TURN ON/OFF MULTIPLE LEDs -->
<div class = "row">
<div class = "col-lg-12">
<h3>Turn Multple LEDs On / Off</h3>
<form action "index.php" method = "GET">
<input class = "btn btn-info" type = "submit" value = "Turn All LEDs On" name = "all_led_on">
<input class = "btn btn-info" type = "submit" value = "Turn All LEDs Off" name = "all_led_off">
</form>
<?php
shell_exec("gpio -g mode 23 out");
shell_exec("gpio -g mode 25 out");
shell_exec("gpio -g mode 20 out");
if(isset($_GET["all_led_on"])){
shell_exec("gpio -g write 23 1");
shell_exec("gpio -g write 25 1");
shell_exec("gpio -g write 20 1");
}
if(isset($_GET["all_led_off"])){
shell_exec("gpio -g write 23 0");
shell_exec("gpio -g write 25 0");
shell_exec("gpio -g write 20 0");
}
?>
</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>