-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
152 lines (135 loc) · 4.33 KB
/
index.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
<!doctype html>
<head>
<meta charset="UTF-8">
<title> Weather Database </title>
<meta http-equiv="refresh" content="300">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script>
</head>
<style type="text/css">
Canvas {
padding: 0;
margin: auto;
display: block;
}
</style>
<html>
<script>
//// UUID Generator from GitHub User Kaizhu256
//// https://gist.github.com/kaizhu256/4482069
function uuid () {
'use strict';
var exports = {};
exports.uuid4 = function () {
//// return uuid of form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
var uuid = '', ii;
for (ii = 0; ii < 32; ii += 1) {
switch (ii) {
case 8:
case 20:
uuid += '-';
uuid += (Math.random() * 16 | 0).toString(16);
break;
case 12:
uuid += '-';
uuid += '4';
break;
case 16:
uuid += '-';
uuid += (Math.random() * 4 | 8).toString(16);
break;
default:
uuid += (Math.random() * 16 | 0).toString(16);
}
}
return uuid;
};
//// output
document.getElementById('uuidResult').innerText = "Your UUID4: " + exports.uuid4();
};
</script>
<body>
<h1 align="center">Clemson Weather</h1>
<?php
// session_start(); //cant find this anywhere
// include_once "mysqlClass.inc.php"; //has the functions
$link = mysqli_connect('localhost', 'cpsc424_eecr', 'L33tD@t@b@s3PAsSWoord', 'cpsc4240');
if (mysqli_connect_errno()){
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//echo 'Connected successfully';
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
$row = mysqli_fetch_row($result);
//printf("Default database is %s.\n", $row[0]);
mysqli_free_result($result);
}
mysqli_select_db($link, "cpsc424_6jt3");
$result = mysqli_query($link, "SELECT * FROM weather_attrs ORDER BY timestamp DESC LIMIT 1");
$row = mysqli_fetch_row($result);
$timestamp = $row[0];
#echo $timestamp;
$temp = $row[1];
$pressure = $row[2];
$humidity = $row[3];
//decrypt
$key = 'thiskey';
// $result = mysqli_query("SELECT *, CAST(AES_DECRYPT(gps, 'thiskey') AS CHAR(50)) gps_decrypt FROM weather_attrs ORDER BY timestamp DESC LIMIT 1");
$gpsresult = mysqli_query($link, "SELECT timestamp, AES_DECRYPT(cryptgps, 'key') FROM weather_attrs ORDER BY timestamp DESC LIMIT 1");
$gpsrow = mysqli_fetch_row($gpsresult);
$newgps = $gpsrow[1];
?>
<ul>
<li>Timestamp (UTC): <?php echo $timestamp?></li>
<li>Temperature: <?php echo $temp?> °F</li>
<li>GPS Location: <?php echo $newgps?></li>
<li>Pressure: <?php echo $pressure?> in</li>
<li>Humidity: <?php echo $humidity?></li>
</ul>
<?php
mysqli_free_result($result);
//getting timestamp and temp to populate the graph
$result = mysqli_query($link, "SELECT `timestamp`, temperature FROM weather_attrs ORDER BY timestamp DESC LIMIT 7");
//$i=0;
while($row=mysqli_fetch_assoc($result)){
$array[] = $row;
// $ts[$i] = array($row['timestamp']);
// $temp[$i] = array($row['temperature']);
// $i++;
}
?>
<canvas id="myChart" width="700" height="500"></canvas>
<script>
//Chart.defaults.global.maintainAspectRatio = false;
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['<?php echo $array[6]['timestamp']?>',
'<?php echo $array[5]['timestamp']?>',
'<?php echo $array[4]['timestamp']?>',
'<?php echo $array[3]['timestamp']?>',
'<?php echo $array[2]['timestamp']?>',
'<?php echo $array[1]['timestamp']?>',
'<?php echo $array[0]['timestamp']?>'],
datasets: [{
label: 'Temperature',
data: ['<?php echo $array[6]['temperature']?>',
'<?php echo $array[5]['temperature']?>',
'<?php echo $array[4]['temperature']?>',
'<?php echo $array[3]['temperature']?>',
'<?php echo $array[2]['temperature']?>',
'<?php echo $array[1]['temperature']?>',
'<?php echo $array[0]['temperature']?>'],
backgroundColor: "rgba(153,255,51,0.4)"
}]
},
options: {
responsive: false
}
});
</script>
<h2>Client Identification</h2>
<h3 id="uuidResult">Your UUID4: </h3>
<button id="uuidGenerator" type="button" onclick="uuid()">Get a new client UUID</button>
</body>
</html>