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