Debian Codegraph @

hs20/server/www/terms.php

raw
1 <?php
2
3 require('config.php');
4
5 function print_header()
6 {
7 echo "<html>\n";
8 echo "<head><title>HS 2.0 Terms and Conditions</title></head>\n";
9 echo "<body>\n";
10 }
11
12 $db = new PDO($osu_db);
13 if (!$db) {
14 die($sqliteerror);
15 }
16
17 if (!isset($_GET["addr"])) {
18 die("Missing addr parameter");
19 }
20 $addr = $_GET["addr"];
21
22 $accept = isset($_GET["accept"]) && $_GET["accept"] == "yes";
23
24 $res = $db->prepare("SELECT identity FROM pending_tc WHERE mac_addr=?");
25 $res->execute(array($addr));
26 $row = $res->fetch();
27 if (!$row) {
28 die("No pending session for the specified MAC address");
29 }
30 $identity = $row[0];
31
32 if (!$accept) {
33 print_header();
34
35 echo "<p>Accept the following terms and conditions by clicking here: <a href=\"terms.php?addr=$addr&accept=yes\">Accept</a></p>\n<hr>\n";
36 readfile($t_c_file);
37 } else {
38 $res = $db->prepare("UPDATE users SET t_c_timestamp=? WHERE identity=?");
39 if (!$res->execute(array($t_c_timestamp, $identity))) {
40 die("Failed to update user account.");
41 }
42
43 $res = $db->prepare("DELETE FROM pending_tc WHERE mac_addr=?");
44 $res->execute(array($addr));
45
46 $fp = fsockopen($hostapd_ctrl);
47 if (!$fp) {
48 die("Could not connect to hostapd(AS)");
49 }
50
51 fwrite($fp, "DAC_REQUEST coa $addr t_c_clear");
52 fclose($fp);
53
54 $waiting = true;
55 $ack = false;
56 for ($i = 1; $i <= 10; $i++) {
57 $res = $db->prepare("SELECT waiting_coa_ack,coa_ack_received FROM current_sessions WHERE mac_addr=?");
58 $res->execute(array($addr));
59 $row = $res->fetch();
60 if (!$row) {
61 die("No current session for the specified MAC address");
62 }
63 if (strlen($row[0]) > 0)
64 $waiting = $row[0] == 1;
65 if (strlen($row[1]) > 0)
66 $ack = $row[1] == 1;
67 $res->closeCursor();
68 if (!$waiting)
69 break;
70 sleep(1);
71 }
72 if ($ack) {
73 header('X-WFA-Hotspot20-Filtering: removed');
74 print_header();
75 echo "<p>Terms and conditions were accepted.</p>\n";
76
77 echo "<P>Filtering disabled.</P>\n";
78 } else {
79 print_header();
80 echo "<P>Failed to disable filtering.</P>\n";
81 }
82 }
83
84 ?>
85
86 </body>
87 </html>