function wifidog_confirm($error = null) { $sessionkey = null; session_start(); if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("Starting wifidog_confirm({$error})", __FUNCTION__, __LINE__); } $t = time(); $page = CurrentPageName(); $tpl = new templates(); if ($GLOBALS["CONNECTED_IP"] == null) { if (isset($_SERVER["REMOTE_ADDR"])) { $IPADDR = $_SERVER["REMOTE_ADDR"]; } if (isset($_SERVER["HTTP_X_REAL_IP"])) { $IPADDR = $_SERVER["HTTP_X_REAL_IP"]; } if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $IPADDR = $_SERVER["HTTP_X_FORWARDED_FOR"]; } if (isset($_GET["forceip"])) { $IPADDR = $_GET["forceip"]; } if ($GLOBALS["CONNECTED_IP"] == null) { $GLOBALS["CONNECTED_IP"] = $IPADDR; } } $sessionkey = $_REQUEST["wifidog-confirm"]; wifidog_logs("wifidog_confirm:: Starting Confirm with key `{$sessionkey}`"); if ($sessionkey == null) { if (isset($_REQUEST["sessionkey"])) { $sessionkey = $_REQUEST["sessionkey"]; } } else { $_REQUEST["sessionkey"] = $sessionkey; } $q = new mysql_hotspot(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid,ruleid,autocreate,MAC,token FROM hotspot_members WHERE `sessionkey`='{$sessionkey}'")); if (!$q->ok) { wifidog_logs("FATAL: {$q->mysql_error}"); events(0, "[{$GLOBALS["CONNECTED_IP"]}]: Error while confirm {$q->mysql_error}", null); echo BuildFullPage(null, $q->mysql_error); return; } wifidog_logs("Starting key `{$sessionkey}` from \"hotspot_members\" is member `{$ligne["uid"]}`"); if ($ligne["uid"] == null) { $url = null; // A voir , ipaddr sinon... events(0, "[{$GLOBALS["CONNECTED_IP"]}]: {$sessionkey}: User did not exists, cancel confirmation", null); if (isset($_SESSION["HOTSPOT_REDIRECT_URL"])) { $url = $_SESSION["HOTSPOT_REDIRECT_URL"]; } if ($url == null) { $sock = new wifidog_settings($_SESSION["WIFIDOG_RULES"]); $LANDING_PAGE = trim($sock->GET_INFO("LANDING_PAGE")); if ($LANDING_PAGE != null) { $url = $LANDING_PAGE; } } if ($url == null) { $url = "http://articatech.net"; } $this_account_didnot_exists = $tpl->_ENGINE_parse_body("{this_account_didnot_exists}"); $text_form = "\n\t\t<form>\n\t\t\t<center>\n\t\t\t\t<img src='hotspot.php?imgload=wait_verybig_mini_red.gif'>\n\t\t\t</center>\n\t\t</form>"; echo BuildFullPage($text_form, "{$error}", "<META http-equiv=\"refresh\" content=\"3; URL={$url}\">"); return; echo BuildFullPage(null, $this_account_didnot_exists); return; } $email = mysql_escape_string2($ligne["uid"]); if ($_REQUEST["url"] == null) { $_REQUEST["url"] = $_SESSION["HOTSPOT_REDIRECT_URL"]; } if (preg_match("#msftncsi\\.com#", $_REQUEST["url"])) { $_REQUEST["url"] = null; } if ($LANDING_PAGE != null) { if (!preg_match("#^http:#", $LANDING_PAGE)) { $LANDING_PAGE = "http://{$LANDING_PAGE}"; } $parse = parse_url($LANDING_PAGE); $host = $parse["host"]; $url = $LANDING_PAGE; } unset($_SESSION["HOTSPOT_AUTO_REGISTER"]); $url = wifidog_redirect_uri(); $parse = parse_url($url); $host = $parse["host"]; $autocreate = intval($ligne["autocreate"]); $token = $ligne["token"]; $MAC = $ligne["MAC"]; $wifidog_templates = new wifidog_templates($ligne["ruleid"]); $ArticaSplashHotSpotRedirectText = $wifidog_templates->ArticaSplashHotSpotRedirectText; $ruleid = $ligne["ruleid"]; $sock = new wifidog_settings($ligne["ruleid"]); $REGISTER_MAX_TIME = intval($sock->GET_INFO("REGISTER_MAX_TIME")); $ArticaSplashHotSpotCacheAuth = intval($sock->GET_INFO("ArticaSplashHotSpotCacheAuth")); $ENABLED_REDIRECT_LOGIN = intval($sock->GET_INFO("ENABLED_REDIRECT_LOGIN")); $LANDING_PAGE = trim($sock->GET_INFO("LANDING_PAGE")); if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("{$ligne["uid"]}: Ruleid..........: {$ligne["ruleid"]}", __FUNCTION__, __LINE__); wifidog_logs("{$ligne["uid"]}: Requested url...: {$_REQUEST["url"]}", __FUNCTION__, __LINE__); wifidog_logs("{$ligne["uid"]}: Redirect url....: {$url}", __FUNCTION__, __LINE__); wifidog_logs("{$ligne["uid"]}: ENABLED_REDIRECT_LOGIN: {$ENABLED_REDIRECT_LOGIN}", __FUNCTION__, __LINE__); wifidog_logs("{$ligne["uid"]}: token/sessionkey: {$token}", __FUNCTION__, __LINE__); wifidog_logs("{$ligne["uid"]}: Re-Authenticate.: {$ArticaSplashHotSpotCacheAuth}mn", __FUNCTION__, __LINE__); } $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT `md5` as `sessionkey` FROM hotspot_sessions WHERE `md5`='{$token}'")); if (!$q->ok) { events(0, "FATAL: {$q->mysql_error}", null); wifidog_logs("FATAL: {$q->mysql_error}"); } $sessionkey = $ligne2["sessionkey"]; if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("[{$MAC}]: {$ligne["uid"]}: sessionkey = `{$sessionkey}` from Token:{$token}", __FUNCTION__, __LINE__); } if ($sessionkey == null) { if ($autocreate == 1) { if ($ENABLED_REDIRECT_LOGIN == 1) { events(2, "[{$MAC}]:[{$GLOBALS["CONNECTED_IP"]}]: {$ligne["uid"]}: Auto-created by email, remove user by {$sessionkey} in database", null); wifidog_logs("{$ligne["uid"]}: Auto-created by email, remove user by {$sessionkey} in database"); $q->QUERY_SQL("DELETE FROM hotspot_members WHERE `sessionkey`='{$sessionkey}'"); } } events(0, "[{$MAC}]: {$ligne["uid"]}: Session expired", null); $error = $tpl->_ENGINE_parse_body("{session_expired}"); $text_form = "\n\t\t<p>{$ArticaSplashHotSpotRedirectText}: <a href=\"{$url}\">{$host}</a></p>\n\t\t<form><center><img src='hotspot.php?imgload=wait_verybig_mini_red.gif'></center></form>"; echo BuildFullPage($text_form, "{$error}", "<META http-equiv=\"refresh\" content=\"0; URL={$url}\">"); return; } wifidog_logs("Next authentication will be in {$ArticaSplashHotSpotCacheAuth}mn"); if ($ArticaSplashHotSpotCacheAuth > 0) { $NextCheck = strtotime("+{$ArticaSplashHotSpotCacheAuth} minutes"); $NextCheck_results = $NextCheck - time(); $NextCheck_results_minutes = $NextCheck_results / 60; wifidog_logs("[{$MAC}]: {$email}: session key: `{$sessionkey}` Re-Authenticate at: {$NextCheck}s calculate {$NextCheck_results}s/{$NextCheck_results_minutes}Mn from " . time()); events(2, "[{$MAC}]:[{$GLOBALS["CONNECTED_IP"]}]: {$email}: session key: `{$sessionkey}` Rule:{$ruleid} Re-Authenticate at: {$NextCheck}s", null); $q->QUERY_SQL("UPDATE hotspot_sessions SET nextcheck='{$NextCheck}' WHERE `md5`='{$sessionkey}'"); if (!$q->ok) { events(0, "[{$MAC}]: {$email}: {$q->mysql_error}"); wifidog_logs("MySQL error {$q->mysql_error}"); } } $sql = "UPDATE hotspot_members SET \n\t\tautocreate_confirmed=1, \n\t\tautocreate=1, \n\t\tautocreate_maxttl='{$REGISTER_MAX_TIME}', \n\t\tcreationtime='" . time() . "', sessionkey='{$sessionkey}' WHERE uid='{$email}'"; $q->QUERY_SQL($sql); if (!$q->ok) { events(0, "[{$MAC}]:[{$GLOBALS["CONNECTED_IP"]}]: {$email}: Unable to confirm Rule:{$ruleid} MySQL Error {$q->mysql_error}", null); wifidog_logs("{$q->mysql_error}"); echo BuildFullPage(null, $q->mysql_error); die; } events(2, "[{$MAC}]: {$email}:[{$GLOBALS["CONNECTED_IP"]}]: [Confirmed]: Rule:{$ruleid} Success update session {$sessionkey}", null); $sock = new wifidog_settings($_SESSION["WIFIDOG_RULES"]); $ttl = $sock->GET_INFO("ArticaSplashHotSpotEndTime"); $ENABLED_META_LOGIN = intval($sock->GET_INFO("ENABLED_META_LOGIN")); $LANDING_PAGE = trim($sock->GET_INFO("LANDING_PAGE")); if ($LANDING_PAGE != null) { $url = $LANDING_PAGE; } if (!preg_match("#^http:#", $url)) { $url = "http://{$url}"; } if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("{$ligne["uid"]}: LANDING_PAGE.: {$LANDING_PAGE}"); } if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("{$ligne["uid"]}: Redirect to {$url} host:{$host}"); } if ($ENABLED_META_LOGIN == 1) { $sql = "CREATE TABLE IF NOT EXISTS `squidlogs`.`hotspot_members_meta` ( `uid` VARCHAR( 128 ) NOT NULL , `creationtime` INT UNSIGNED NOT NULL, PRIMARY KEY ( `uid` ) , INDEX ( `creationtime`) ) ENGINE = MYISAM;"; $q->QUERY_SQL($sql); $sql = "INSERT IGNORE INTO `hotspot_members_meta` (uid,creationtime) VALUES ('{$email}','" . time() . "')"; $q->QUERY_SQL($sql); } $text_form = "\n\t\n\t<form>\n\t<p>{$wifidog_templates->REGISTER_MESSAGE_SUCCESS}</p>\n\t<p>{$ArticaSplashHotSpotRedirectText}: <a href=\"{$url}\">{$host}</a></p>\t\t\t\n\t<center>\n\t\t<img src='hotspot.php?imgload=wait_verybig_mini_red.gif'>\n\t</center>\n\t\n\t</form>"; if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("Redirect Client {$_SESSION["HOTSPOT_REDIRECT_MAC"]} to {$url}", __FUNCTION__, __LINE__); } echo BuildFullPage($text_form, null, "<META http-equiv=\"refresh\" content=\"5; URL={$url}\">"); }
function wifidog_confirm($error = null) { $sessionkey = null; session_start(); if ($GLOBALS["HOTSPOT_DEBUG"]) { ToSyslog("Starting wifidog_password({$error})"); } $t = time(); $page = CurrentPageName(); $tpl = new templates(); $sessionkey = $_REQUEST["wifidog-confirm"]; if ($sessionkey == null) { if (isset($_REQUEST["sessionkey"])) { $sessionkey = $_REQUEST["sessionkey"]; } } else { $_REQUEST["sessionkey"] = $sessionkey; } $q = new mysql_squid_builder(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid FROM hotspot_members WHERE `sessionkey`='{$sessionkey}'")); if ($ligne["uid"] == null) { echo BuildFullPage(null, "{this_account_didnot_exists}"); return; } $email = $ligne["uid"]; if ($_REQUEST["url"] == null) { $_REQUEST["url"] = $_SESSION["HOTSPOT_REDIRECT_URL"]; } unset($_SESSION["HOTSPOT_AUTO_REGISTER"]); $ArticaHotSpotSMTP = SMTP_SETTINGS(); if ($sessionkey == null) { $sessionkey = md5(time() . $email); } $sql = "UPDATE hotspot_members\n\tSET autocreate_confirmed=1,\n\tautocreate=1,\n\tautocreate_maxttl='{$ArticaHotSpotSMTP["REGISTER_MAX_TIME"]}',\n\tcreationtime='" . time() . "',\n\tsessionkey='{$sessionkey}'\n\tWHERE uid='{$email}'"; $q->QUERY_SQL($sql); if (!$q->ok) { if (strpos(" {$q->mysql_error}", "Unknown column") > 0) { if ($GLOBALS["HOTSPOT_DEBUG"]) { ToSyslog("check_hotspot_tables in line:" . __LINE__); } $q->check_hotspot_tables(); if (!$q->ok) { if ($GLOBALS["HOTSPOT_DEBUG"]) { ToSyslog("{$q->mysql_error} in line:" . __LINE__); } } $q->QUERY_SQL($sql); } } if (!$q->ok) { ToSyslog("{$q->mysql_error}"); echo BuildFullPage(null, $q->mysql_error); die; } $REGISTER_MESSAGE_SUCCESS = $ArticaHotSpotSMTP["REGISTER_MESSAGE_SUCCESS"]; $tpl = new templates(); $sock = new sockets(); $text_redirecting = $tpl->_ENGINE_parse_body("{please_wait_redirecting_to}:"); $url = wifidog_redirect_uri(); $parse = parse_url($url); $host = $parse["host"]; $ArticaHotSpotSMTP = SMTP_SETTINGS(); $btsize = $ArticaHotSpotSMTP["SKIN_BUTTON_SIZE"]; $fontsize = $ArticaHotSpotSMTP["SKIN_FONT_SIZE"]; $text_form = "\n\t<div style='width:98%' class=form>\n\t<center>\n\t<div style='font-size:{$fontsize}'><center>{$REGISTER_MESSAGE_SUCCESS}<br>{$text_redirecting}: <a href=\"{$url}\">{$host}</a></center></div>\n\t<img src='img/wait_verybig_mini_red.gif'></center></div>"; if ($GLOBALS["HOTSPOT_DEBUG"]) { ToSyslog("Redirect Client {$_SESSION["HOTSPOT_REDIRECT_MAC"]} to {$url}"); } echo BuildFullPage($text_form, null, "<META http-equiv=\"refresh\" content=\"5; URL={$url}\">"); }
function wifidog_confirm($error = null) { $sessionkey = null; session_start(); if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("Starting wifidog_password({$error})"); } $t = time(); $page = CurrentPageName(); $tpl = new templates(); $sessionkey = $_REQUEST["wifidog-confirm"]; wifidog_logs("Starting Confirm with key `{$sessionkey}`"); if ($sessionkey == null) { if (isset($_REQUEST["sessionkey"])) { $sessionkey = $_REQUEST["sessionkey"]; } } else { $_REQUEST["sessionkey"] = $sessionkey; } $q = new mysql_squid_builder(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid,ruleid,autocreate,token FROM hotspot_members WHERE `sessionkey`='{$sessionkey}'")); if (!$q->ok) { wifidog_logs("FATAL: {$q->mysql_error}"); echo BuildFullPage(null, $q->mysql_error); return; } wifidog_logs("Starting key `{$sessionkey}` is member `{$ligne["uid"]}`"); if ($ligne["uid"] == null) { $this_account_didnot_exists = $tpl->_ENGINE_parse_body("{this_account_didnot_exists}"); echo BuildFullPage(null, $this_account_didnot_exists); return; } $email = mysql_escape_string2($ligne["uid"]); if ($_REQUEST["url"] == null) { $_REQUEST["url"] = $_SESSION["HOTSPOT_REDIRECT_URL"]; } unset($_SESSION["HOTSPOT_AUTO_REGISTER"]); $url = wifidog_redirect_uri(); $parse = parse_url($url); $host = $parse["host"]; $autocreate = intval($ligne["autocreate"]); $token = $ligne["token"]; $wifidog_templates = new wifidog_templates($ligne["ruleid"]); $ArticaSplashHotSpotRedirectText = $wifidog_templates->ArticaSplashHotSpotRedirectText; $sock = new wifidog_settings($ligne["ruleid"]); $REGISTER_MAX_TIME = intval($sock->GET_INFO("REGISTER_MAX_TIME")); $ArticaSplashHotSpotCacheAuth = intval($sock->GET_INFO("REGISTER_MAX_TIME")); $ENABLED_REDIRECT_LOGIN = intval($sock->GET_INFO("ENABLED_REDIRECT_LOGIN")); $LANDING_PAGE = trim($sock->GET_INFO("LANDING_PAGE")); if ($LANDING_PAGE != null) { $url = $LANDING_PAGE; } wifidog_logs("{$ligne["uid"]}: Ruleid..........: {$ligne["ruleid"]}"); wifidog_logs("{$ligne["uid"]}: Requested url...: {$_REQUEST["url"]}"); wifidog_logs("{$ligne["uid"]}: Redirect url....: {$url}"); wifidog_logs("{$ligne["uid"]}: ENABLED_REDIRECT_LOGIN: {$ENABLED_REDIRECT_LOGIN}"); wifidog_logs("{$ligne["uid"]}: token...........: {$token}"); wifidog_logs("{$ligne["uid"]}: Re-Authenticate.: {$ArticaSplashHotSpotCacheAuth}mn"); $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT md5 FROM hotspot_sessions WHERE `md5`='{$token}'")); if (!$q->ok) { wifidog_logs("FATAL: {$q->mysql_error}"); } wifidog_logs("{$ligne["uid"]}: sessionkey {$ligne2["md5"]}"); if ($ligne2["md5"] == null) { if ($autocreate == 1) { if ($ENABLED_REDIRECT_LOGIN == 1) { wifidog_logs("{$ligne["uid"]}: Auto-created by email, remove user by {$sessionkey} in database"); $q->QUERY_SQL("DELETE FROM hotspot_members WHERE `sessionkey`='{$sessionkey}'"); proxydb(); } } $error = $tpl->_ENGINE_parse_body("{session_expired}"); $text_form = "\n\t\t<p>{$ArticaSplashHotSpotRedirectText}: <a href=\"{$url}\">{$host}</a></p>\n\t\t<form>\n\t\t\n\t\t<center>\n\t\t\t<img src='img/wait_verybig_mini_red.gif'>\n\t\t</center>\n\t\t</form>"; echo BuildFullPage($text_form, "{$error}", "<META http-equiv=\"refresh\" content=\"3; URL={$url}\">"); return; } wifidog_logs("Re-Authenticate each: {$ArticaSplashHotSpotCacheAuth}mn"); if ($ArticaSplashHotSpotCacheAuth > 0) { $NextCheck = strtotime("+{$ArticaSplashHotSpotCacheAuth} minutes", time()); wifidog_logs("Re-Authenticate at: {$NextCheck}s"); $q->QUERY_SQL("UPDATE hotspot_sessions SET `ttl`='{$ArticaSplashHotSpotCacheAuth}', nextcheck='{$NextCheck}' WHERE `md5`='{$sessionkey}'"); } if ($sessionkey == null) { $sessionkey = md5(time() . $email); } $sql = "UPDATE hotspot_members\n\tSET autocreate_confirmed=1,\n\tautocreate=1,\n\tautocreate_maxttl='{$REGISTER_MAX_TIME}',\n\tcreationtime='" . time() . "',\n\tsessionkey='{$sessionkey}'\n\tWHERE uid='{$email}'"; $q->QUERY_SQL($sql); if (!$q->ok) { if (strpos(" {$q->mysql_error}", "Unknown column") > 0) { if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("check_hotspot_tables in line:" . __LINE__); } $q->check_hotspot_tables(); if (!$q->ok) { if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("{$q->mysql_error} in line:" . __LINE__); } } $q->QUERY_SQL($sql); } } if (!$q->ok) { wifidog_logs("{$q->mysql_error}"); echo BuildFullPage(null, $q->mysql_error); die; } $sock = new wifidog_settings($_SESSION["WIFIDOG_RULES"]); $ttl = $sock->GET_INFO("ArticaSplashHotSpotEndTime"); $ENABLED_META_LOGIN = intval($sock->GET_INFO("ENABLED_META_LOGIN")); $LANDING_PAGE = trim($sock->GET_INFO("LANDING_PAGE")); if ($LANDING_PAGE != null) { $url = $LANDING_PAGE; } if ($ENABLED_META_LOGIN == 1) { $sql = "CREATE TABLE IF NOT EXISTS `squidlogs`.`hotspot_members_meta` ( `uid` VARCHAR( 128 ) NOT NULL , `creationtime` INT UNSIGNED NOT NULL, PRIMARY KEY ( `uid` ) , INDEX ( `creationtime`) ) ENGINE = MYISAM;"; $q->QUERY_SQL($sql); $sql = "INSERT IGNORE INTO `hotspot_members_meta` (uid,creationtime) VALUES ('{$email}','" . time() . "')"; $q->QUERY_SQL($sql); } $text_form = "\n\t<p>{$wifidog_templates->REGISTER_MESSAGE_SUCCESS}</p>\n\t<p>{$ArticaSplashHotSpotRedirectText}: <a href=\"{$url}\">{$host}</a></p>\n\t<form>\n\t<center>\n\t\t<img src='img/wait_verybig_mini_red.gif'>\n\t</center>\n\t\n\t</form>"; if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("Redirect Client {$_SESSION["HOTSPOT_REDIRECT_MAC"]} to {$url}"); } echo BuildFullPage($text_form, null, "<META http-equiv=\"refresh\" content=\"5; URL={$url}\">"); }