blob: acba23ef1ad7d2edcb4076f30a50840d50d42444 [file] [log] [blame]
Roshan Pius3a1667e2018-07-03 15:17:14 -07001<?php
2
3require('config.php');
4
Hai Shalom021b0b52019-04-10 11:17:58 -07005function 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
Roshan Pius3a1667e2018-07-03 15:17:14 -070012$db = new PDO($osu_db);
13if (!$db) {
14 die($sqliteerror);
15}
16
17if (!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();
27if (!$row) {
28 die("No pending session for the specified MAC address");
29}
30$identity = $row[0];
Roshan Pius3a1667e2018-07-03 15:17:14 -070031
32if (!$accept) {
Hai Shalom021b0b52019-04-10 11:17:58 -070033 print_header();
34
Roshan Pius3a1667e2018-07-03 15:17:14 -070035 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))) {
Hai Shalom021b0b52019-04-10 11:17:58 -070040 die("Failed to update user account.");
Roshan Pius3a1667e2018-07-03 15:17:14 -070041 }
42
Hai Shalom021b0b52019-04-10 11:17:58 -070043 $res = $db->prepare("DELETE FROM pending_tc WHERE mac_addr=?");
44 $res->execute(array($addr));
45
Roshan Pius3a1667e2018-07-03 15:17:14 -070046 $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 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -080063 if (strlen($row[0]) > 0)
64 $waiting = $row[0] == 1;
65 if (strlen($row[1]) > 0)
66 $ack = $row[1] == 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070067 $res->closeCursor();
68 if (!$waiting)
69 break;
70 sleep(1);
71 }
72 if ($ack) {
Hai Shalom021b0b52019-04-10 11:17:58 -070073 header('X-WFA-Hotspot20-Filtering: removed');
74 print_header();
75 echo "<p>Terms and conditions were accepted.</p>\n";
76
Roshan Pius3a1667e2018-07-03 15:17:14 -070077 echo "<P>Filtering disabled.</P>\n";
78 } else {
Hai Shalom021b0b52019-04-10 11:17:58 -070079 print_header();
Roshan Pius3a1667e2018-07-03 15:17:14 -070080 echo "<P>Failed to disable filtering.</P>\n";
81 }
82}
83
84?>
85
86</body>
87</html>