add_dhcp.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/qauth.php");
  3. if (isset($_GET["ip"]) and isset($_GET["mac"])) {
  4. $ip = $_GET["ip"];
  5. $mac = mac_dotted(trim($_GET["mac"]));
  6. if (isset($_GET["host"])) {
  7. $dhcp_hostname = trim($_GET["host"]);
  8. }
  9. $faction = $_GET["action"] * 1;
  10. if ($faction === 1) {
  11. $action = 'add';
  12. }
  13. if ($faction === 0) {
  14. $action = 'del';
  15. }
  16. if (! isset($action)) {
  17. $action = 'add';
  18. }
  19. LOG_VERBOSE($db_link, "external dhcp request for $ip [$mac] $action");
  20. if (checkValidIp($ip) and is_our_network($db_link, $ip)) {
  21. $log_dhcp = 1;
  22. $ip_aton = ip2long($ip);
  23. //check hotspot
  24. $hotspot_user = is_hotspot($db_link,$ip);
  25. if ($hotspot_user) {
  26. LOG_DEBUG($db_link,"Hotspot user found!");
  27. $log_dhcp_hotspot = get_option($db_link,44);
  28. if (!isset($log_dhcp_hotspot)) { $log_dhcp_hotspot = 0; }
  29. $log_dhcp = !$log_dhcp_hotspot;
  30. }
  31. if ($faction ===0 and get_count_records($db_link, 'User_auth', "ip_int=" . $ip_aton . " and enabled=1")===0) {
  32. LOG_VERBOSE($db_link, "dhcp action delete for unknown ip: $ip. Skip add record.");
  33. } else {
  34. $aid = resurrection_auth($db_link, $ip, $mac, $action, $dhcp_hostname);
  35. if ($log_dhcp) {
  36. $dhcp_log[auth_id] = $aid;
  37. $dhcp_log[ip] = $ip;
  38. $dhcp_log[ip_int] = $ip_aton;
  39. $dhcp_log[mac] = $mac;
  40. $dhcp_log[action] = $action;
  41. insert_record($db_link, "dhcp_log", $dhcp_log);
  42. }
  43. }
  44. } else {
  45. LOG_ERROR($db_link, "$ip - wrong network!");
  46. }
  47. }
  48. unset($_GET);
  49. ?>