Example #1
0
function wifidog_register_perform()
{
    session_start();
    $page = CurrentPageName();
    $tpl = new templates();
    $autocreate_confirmed = 0;
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("Starting wifidog_register_perform()");
    }
    $wifidog_build_uri = wifidog_build_uri();
    $uriext = $wifidog_build_uri[0];
    $HiddenFields = $wifidog_build_uri[1];
    $sock = new wifidog_settings($_SESSION["WIFIDOG_RULES"]);
    $ENABLED_SMTP = intval($sock->GET_INFO("ENABLED_SMTP"));
    $wifidog_templates = new wifidog_templates($_SESSION["WIFIDOG_RULES"]);
    $ENABLED_REDIRECT_LOGIN = intval($sock->GET_INFO("ENABLED_REDIRECT_LOGIN"));
    $email = trim(strtolower($_POST["email"]));
    $q = new mysql_hotspot();
    $password2 = trim($_POST["password2"]);
    $password = trim($_POST["password"]);
    $passphrase = trim(strtolower($_POST["passphrase"]));
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("{$email}: Ask a passphrase: {$wifidog_templates->REGISTER_GENERIC_PASSWORD}");
    }
    if ($wifidog_templates->REGISTER_GENERIC_PASSWORD == 1) {
        if ($passphrase != trim(strtolower($wifidog_templates->REGISTER_GENERIC_PASSTXT))) {
            return wifidog_register($wifidog_templates->char($wifidog_templates->REGISTER_GENERIC_PASSERR));
        }
    }
    if ($password2 != $password) {
        return wifidog_register("{password_mismatch}");
    }
    if ($ENABLED_SMTP == 1) {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return wifidog_register("{error_email_invalid}");
        }
        $tr = explode("@", $email);
        $domain = $tr[1];
        if (!checkdnsrr($domain, 'MX')) {
            return wifidog_register("&laquo;{$domain}&raquo;<br>{error_domain_email_invalid}");
        }
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid,autocreate FROM hotspot_members WHERE `uid`='{$email}'"));
    if ($ENABLED_REDIRECT_LOGIN == 1) {
        if (intval($ligne["autocreate"]) == 1) {
            if ($ligne["uid"] != null) {
                $q->QUERY_SQL("DELETE FROM hotspot_members WHERE `uid`='{$email}'");
                $ligne["uid"] = null;
            }
        }
    }
    if ($ligne["uid"] != null) {
        if ($ENABLED_SMTP == 1) {
            $link = "<br><strong><a href=\"{$page}?wifidog-recover=yes&{$uriext}\">{lost_password}</a></strong>";
        }
        return wifidog_register($tpl->_ENGINE_parse_body("{this_account_already_exists}<br>{$link}"));
    }
    wifidog_logs("Ruleid: {$_SESSION["WIFIDOG_RULES"]}");
    $MAC = $_REQUEST["mac"];
    $REGISTER_MAX_TIME = intval($sock->GET_INFO("REGISTER_MAX_TIME"));
    $ArticaSplashHotSpotEndTime = intval($sock->GET_INFO("ArticaSplashHotSpotEndTime"));
    if ($REGISTER_MAX_TIME == 0) {
        $REGISTER_MAX_TIME = 5;
    }
    wifidog_logs("Ruleid: REGISTER_MAX_TIME:{$REGISTER_MAX_TIME}");
    wifidog_logs("Ruleid: ArticaSplashHotSpotEndTime:{$ArticaSplashHotSpotEndTime}");
    $password = md5($password);
    $creationtime = time();
    $autocreate_maxttl = $ArticaSplashHotSpotEndTime;
    $sessionkey = md5($password . $creationtime . $email);
    $gateway_addr = $_REQUEST["gw_address"];
    $gw_port = $_REQUEST["gw_port"];
    $gw_id = $_REQUEST["gw_id"];
    $ARP = $_REQUEST["mac"];
    $url = $_REQUEST["url"];
    $token = $_REQUEST["token"];
    if ($token == null) {
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("no token retrive", __FUNCTION__, __LINE__);
        }
        $token = generateToken($ARP);
        if ($token == null) {
            $token = md5(uniqid(rand(), 1));
            if ($GLOBALS["HOTSPOT_DEBUG"]) {
                wifidog_logs("Generate a temporary token {$token}", __FUNCTION__, __LINE__);
            }
        }
    }
    if ($ENABLED_SMTP == 0) {
        $autocreate_confirmed = 1;
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("Create new member {$email},{$password},TTL:{$ArticaSplashHotSpotEndTime}", __FUNCTION__, __LINE__);
    }
    $sql = "INSERT IGNORE INTO hotspot_members \n\t(uid,username,token,ruleid,ttl,sessiontime,password,enabled,creationtime,autocreate,autocreate_confirmed,autocreate_maxttl,sessionkey,MAC) VALUES\n\t('{$email}','{$email}','{$token}','{$_SESSION["WIFIDOG_RULES"]}','{$ArticaSplashHotSpotEndTime}','','{$password}',1,'{$creationtime}',1,'{$autocreate_confirmed}',{$autocreate_maxttl},'{$sessionkey}','{$MAC}')";
    $q->QUERY_SQL($sql);
    wifidog_logs("[{$ARP}]:[{$GLOBALS["CONNECTED_IP"]}]: {$email}: Create New member with a token {$token}", __FUNCTION__, __LINE__);
    if (!$q->ok) {
        events(0, "MySQL error: {$q->mysql_error} (Line: " . __LINE__ . ")");
        wifidog_logs("{$q->mysql_error}");
        wifidog_logs("{$sql}");
        return wifidog_register($q->mysql_error);
    }
    if ($ENABLED_SMTP == 0) {
        $array["SERVER_NAME"] = $_SERVER["SERVER_NAME"];
        $array["redirecturi"] = $url;
        $array["LOGIN"] = $email;
        $array["redirecturi"] = $_REQUEST["url"];
        $array["REMOTE_ADDR"] = $_REQUEST["ip"];
        $array["token"] = $token;
        $array["HOST"] = $_REQUEST["ip"];
        $array["ruleid"] = $_SESSION["WIFIDOG_RULES"];
        UnLock($array);
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
        $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
        $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
        $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
        header("Location: {$redirecturi}");
        return;
    }
    $proto = "http";
    $myHostname = $_SERVER["HTTP_HOST"];
    $page = CurrentPageName();
    if (isset($_SERVER["HTTPS"])) {
        $proto = "https";
    }
    $URL_REDIRECT = "{$proto}://{$myHostname}/{$page}?wifidog-confirm={$sessionkey}";
    $smtp_sender = $sock->GET_INFO("smtp_sender");
    include_once dirname(__FILE__) . "/ressources/externals/mime/mime.inc";
    $message = new Mail_mime("\r\n");
    $text = "<p style=font-size:18px>{$wifidog_templates->REGISTER_MESSAGE}</p>\n\t<p>\t\n\t<hr>\n\t\t<center>\n\t\t\t<a href=\"{$URL_REDIRECT}\" style='font-size:22px;text-decoration:underline'>{$URL_REDIRECT}</a>\n\t\t</center>\n\t</p>";
    $message->setFrom($smtp_sender);
    $message->addTo($email);
    $message->setSubject($wifidog_templates->REGISTER_SUBJECT);
    $message->setTXTBody(strip_tags($text));
    $message->setHTMLBody($text);
    $finalbody = $message->getMessage();
    $webauth_msmtp = new webauth_msmtp($smtp_sender, $finalbody, $email);
    if (!$webauth_msmtp->Send()) {
        events(0, "SMTP Error[method 1]: {$webauth_msmtp->logs}", $webauth_msmtp->logs);
        $content[] = "Method 1:\n{$webauth_msmtp->logs}\n";
        $smtp = new smtp();
        if ($sock->GET_INFO("smtp_auth_user") != null) {
            $params["auth"] = true;
            $params["user"] = $sock->GET_INFO("smtp_auth_user");
            $params["pass"] = $sock->GET_INFO("smtp_auth_passwd");
        }
        $params["host"] = $sock->GET_INFO("smtp_server_name");
        $params["port"] = $sock->GET_INFO("smtp_server_port");
        if (!$smtp->connect($params)) {
            $content[] = "Method2 Error:{$smtp->error_number} {$smtp->error_text}";
            events(0, "SMTP Error[method 2 - Connect]: {$params["host"]} {$smtp->error_number} {$smtp->error_text}", @implode("\n", $content));
            return wifidog_register("{$email}: {error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
        }
        if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $email, "body" => $finalbody, "headers" => null))) {
            events(0, "SMTP Error[method 2 - Send]: {$smtp->error_number} {$smtp->error_text}", null);
            $smtp->quit();
            return wifidog_register("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
        }
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("From: {$smtp_sender} to {$email} {$wifidog_templates->REGISTER_SUBJECT} success");
        }
        $smtp->quit();
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Token: {$token} -> UnLock(..");
    }
    $array["LOGIN"] = $email;
    $array["ARP"] = $_REQUEST["mac"];
    $array["token"] = $token;
    $array["redirecturi"] = $_REQUEST["url"];
    $array["REMOTE_ADDR"] = $_REQUEST["ip"];
    $array["REGISTER"] = true;
    if (!UnLock($array)) {
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("wifidog_auth/" . __FUNCTION__ . "::failed_to_create_session");
        }
        return wifidog_register("{error} {failed_to_create_session}");
    }
    wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
    $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
    $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
    $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
    wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
    header("Location: {$redirecturi}");
}
Example #2
0
function wifidog_register_perform()
{
    session_start();
    $page = CurrentPageName();
    $tpl = new templates();
    $autocreate_confirmed = 0;
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("Starting wifidog_register_perform()");
    }
    $wifidog_build_uri = wifidog_build_uri();
    $uriext = $wifidog_build_uri[0];
    $HiddenFields = $wifidog_build_uri[1];
    $sock = new wifidog_settings($_SESSION["WIFIDOG_RULES"]);
    $ENABLED_SMTP = intval($sock->GET_INFO("ENABLED_SMTP"));
    $wifidog_templates = new wifidog_templates($_SESSION["WIFIDOG_RULES"]);
    $ENABLED_REDIRECT_LOGIN = intval($sock->GET_INFO("ENABLED_REDIRECT_LOGIN"));
    $email = trim(strtolower($_POST["email"]));
    $q = new mysql_squid_builder();
    $password2 = trim($_POST["password2"]);
    $password = trim($_POST["password"]);
    if ($password2 != $password) {
        return wifidog_register("{password_mismatch}");
    }
    if ($ENABLED_SMTP == 1) {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return wifidog_register("{error_email_invalid}");
        }
        $tr = explode("@", $email);
        $domain = $tr[1];
        if (!checkdnsrr($domain, 'MX')) {
            return wifidog_register("&laquo;{$domain}&raquo;<br>{error_domain_email_invalid}");
        }
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid,autocreate FROM hotspot_members WHERE `uid`='{$email}'"));
    if ($ENABLED_REDIRECT_LOGIN == 1) {
        if (intval($ligne["autocreate"]) == 1) {
            if ($ligne["uid"] != null) {
                $q->QUERY_SQL("DELETE FROM hotspot_members WHERE `uid`='{$email}'");
                $ligne["uid"] = null;
            }
        }
    }
    if ($ligne["uid"] != null) {
        if ($ENABLED_SMTP == 1) {
            $link = "<br><strong><a href=\"{$page}?wifidog-recover=yes&{$uriext}\">{lost_password}</a></strong>";
        }
        return wifidog_register($tpl->_ENGINE_parse_body("{this_account_already_exists}<hr>{$link}"));
    }
    wifidog_logs("Ruleid: {$_SESSION["WIFIDOG_RULES"]}");
    $MAC = $_REQUEST["mac"];
    $REGISTER_MAX_TIME = intval($sock->GET_INFO("REGISTER_MAX_TIME"));
    $ArticaSplashHotSpotEndTime = intval($sock->GET_INFO("ArticaSplashHotSpotEndTime"));
    if ($REGISTER_MAX_TIME == 0) {
        $REGISTER_MAX_TIME = 5;
    }
    wifidog_logs("Ruleid: REGISTER_MAX_TIME:{$REGISTER_MAX_TIME}");
    wifidog_logs("Ruleid: ArticaSplashHotSpotEndTime:{$ArticaSplashHotSpotEndTime}");
    $password = md5($password);
    $creationtime = time();
    $autocreate_maxttl = $ArticaSplashHotSpotEndTime;
    $sessionkey = md5($password . $creationtime . $email);
    $gateway_addr = $_REQUEST["gw_address"];
    $gw_port = $_REQUEST["gw_port"];
    $gw_id = $_REQUEST["gw_id"];
    $ARP = $_REQUEST["mac"];
    $url = $_REQUEST["url"];
    $token = $_REQUEST["token"];
    if ($ENABLED_SMTP == 0) {
        $autocreate_confirmed = 1;
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("Create new member {$email},{$password},TTL:{$ArticaSplashHotSpotEndTime} in line:" . __LINE__);
    }
    $sql = "INSERT IGNORE INTO hotspot_members \n\t(uid,username,token,ruleid,ttl,sessiontime,password,enabled,creationtime,autocreate,autocreate_confirmed,autocreate_maxttl,sessionkey,MAC) VALUES\n\t('{$email}','{$email}','{$token}','{$_SESSION["WIFIDOG_RULES"]}','{$ArticaSplashHotSpotEndTime}','','{$password}',1,'{$creationtime}',1,'{$autocreate_confirmed}',{$autocreate_maxttl},'{$sessionkey}','{$MAC}')";
    $q->QUERY_SQL($sql);
    wifidog_logs("{$email}: Create New member with a token {$token}");
    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}");
        wifidog_logs("{$sql}");
        return wifidog_register($q->mysql_error);
    }
    if ($ENABLED_SMTP == 0) {
        $array["SERVER_NAME"] = $_SERVER["SERVER_NAME"];
        $array["redirecturi"] = $url;
        $array["LOGIN"] = $email;
        $array["redirecturi"] = $_REQUEST["url"];
        $array["REMOTE_ADDR"] = $_REQUEST["ip"];
        $array["token"] = $token;
        $array["HOST"] = $_REQUEST["ip"];
        $array["ruleid"] = $_SESSION["WIFIDOG_RULES"];
        UnLock($array);
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
        $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
        $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
        $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
        header("Location: {$redirecturi}");
        return;
    }
    $proto = "http";
    $myHostname = $_SERVER["HTTP_HOST"];
    $page = CurrentPageName();
    if (isset($_SERVER["HTTPS"])) {
        $proto = "https";
    }
    $URL_REDIRECT = "{$proto}://{$myHostname}/{$page}?wifidog-confirm={$sessionkey}";
    $smtp_sender = $sock->GET_INFO("smtp_sender");
    $smtp_senderTR = explode("@", $smtp_sender);
    $instance = $smtp_senderTR[1];
    $random_hash = md5(date('r', time()));
    $boundary = "{$random_hash}/{$instance}";
    $body[] = "Return-Path: <{$smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$smtp_sender}";
    $body[] = "Subject: {$wifidog_templates->REGISTER_SUBJECT}";
    $body[] = "To: {$email}";
    $body[] = "Auto-Submitted: auto-replied";
    $body[] = "MIME-Version: 1.0";
    $body[] = "Content-Type: multipart/mixed;";
    $body[] = "\tboundary=\"{$boundary}\"";
    $body[] = "Content-Transfer-Encoding: 8bit";
    $body[] = "Message-Id: <{$random_hash}@{$instance}>";
    $body[] = "--{$boundary}";
    $body[] = "Content-Description: Notification";
    $body[] = "Content-Type: text/plain; charset=us-ascii";
    $body[] = "";
    $body[] = $wifidog_templates->REGISTER_MESSAGE;
    $body[] = $URL_REDIRECT;
    $body[] = "";
    $body[] = "";
    $body[] = "--{$boundary}";
    $finalbody = @implode("\r\n", $body);
    $webauth_msmtp = new webauth_msmtp($smtp_sender, $finalbody, $email);
    if (!$webauth_msmtp->Send()) {
        $smtp = new smtp();
        if ($sock->GET_INFO("smtp_auth_user") != null) {
            $params["auth"] = true;
            $params["user"] = $sock->GET_INFO("smtp_auth_user");
            $params["pass"] = $sock->GET_INFO("smtp_auth_passwd");
        }
        $params["host"] = $sock->GET_INFO("smtp_server_name");
        $params["port"] = $sock->GET_INFO("smtp_server_port");
        if (!$smtp->connect($params)) {
            return wifidog_register("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
        }
        if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $email, "body" => $finalbody, "headers" => null))) {
            $smtp->quit();
            return wifidog_register("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
        }
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("From: {$smtp_sender} to {$email} {$wifidog_templates->REGISTER_SUBJECT} success");
        }
        $smtp->quit();
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Token: {$token} -> UnLock(..");
    }
    $array["LOGIN"] = $email;
    $array["ARP"] = $_REQUEST["mac"];
    $array["token"] = $token;
    $array["redirecturi"] = $_REQUEST["url"];
    $array["REMOTE_ADDR"] = $_REQUEST["ip"];
    $array["REGISTER"] = true;
    if (!UnLock($array)) {
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("wifidog_auth/" . __FUNCTION__ . "::failed_to_create_session");
        }
        return wifidog_register("{error} {failed_to_create_session}");
    }
    wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
    $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
    $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
    $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
    wifidog_logs("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
    header("Location: {$redirecturi}");
}
Example #3
0
function tests_smtp()
{
    //ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);
    header("content-type: application/x-javascript");
    $sock = new sockets();
    $sock = new wifidog_settings($_GET["ruleid"]);
    $wifidog_templates = new wifidog_templates($_GET["ruleid"]);
    $ArticaSplashHotSpotEndTime = $sock->GET_INFO("ArticaSplashHotSpotEndTime");
    $proto = "http";
    $myHostname = $_SERVER["HTTP_HOST"];
    $page = CurrentPageName();
    if (isset($_SERVER["HTTPS"])) {
        $proto = "https";
    }
    $URL_REDIRECT = "{$proto}://{$myHostname}/{$page}?wifidog-confirm=NONE";
    $tpl = new templates();
    $smtp_sender = $sock->GET_INFO("smtp_sender");
    $smtp_senderTR = explode("@", $smtp_sender);
    $instance = $smtp_senderTR[1];
    $random_hash = md5(date('r', time()));
    $body[] = "Return-Path: <{$smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$smtp_sender}";
    $body[] = "Subject: {$wifidog_templates->REGISTER_SUBJECT}";
    $body[] = "To: {$smtp_sender}";
    $body[] = "";
    $body[] = "";
    $body[] = $wifidog_templates->REGISTER_MESSAGE;
    $body[] = $URL_REDIRECT;
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    $webauth_msmtp = new webauth_msmtp($smtp_sender, $finalbody, $smtp_sender, $_GET["ruleid"]);
    if ($webauth_msmtp->Send()) {
        echo "alert('" . $tpl->javascript_parse_text("{$wifidog_templates->REGISTER_SUBJECT}\nTo {$smtp_sender}: {success}") . "');";
        return;
    }
    $smtp = new smtp();
    if ($sock->GET_INFO("smtp_auth_user") != null) {
        $params["auth"] = true;
        $params["user"] = $sock->GET_INFO("smtp_auth_user");
        $params["pass"] = $sock->GET_INFO("smtp_auth_passwd");
    }
    $params["host"] = $sock->GET_INFO("smtp_server_name");
    $params["port"] = $sock->GET_INFO("smtp_server_port");
    if (!$smtp->connect($params)) {
        echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}") . "');";
        return;
    }
    if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $smtp_sender, "body" => $finalbody, "headers" => null))) {
        $smtp->quit();
        echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}") . "');";
        return;
    }
    echo "alert('" . $tpl->javascript_parse_text("{$wifidog_templates->REGISTER_SUBJECT}\nTo {$smtp_sender}: {success}") . "');";
    $smtp->quit();
}
Example #4
0
function tests_smtp()
{
    //ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);
    include_once dirname(__FILE__) . "/ressources/externals/mime/mime.inc";
    header("content-type: application/x-javascript");
    $sock = new sockets();
    $sock = new wifidog_settings($_GET["ruleid"]);
    $wifidog_templates = new wifidog_templates($_GET["ruleid"]);
    $ArticaSplashHotSpotEndTime = $sock->GET_INFO("ArticaSplashHotSpotEndTime");
    $proto = "http";
    $myHostname = $_SERVER["HTTP_HOST"];
    $page = CurrentPageName();
    if (isset($_SERVER["HTTPS"])) {
        $proto = "https";
    }
    $URL_REDIRECT = "{$proto}://{$myHostname}/{$page}?wifidog-confirm=NONE";
    $tpl = new templates();
    $smtp_sender = $sock->GET_INFO("smtp_sender");
    if ($GLOBALS["VERBOSE"]) {
        echo "new Mail_mime....<br>\n";
    }
    include_once dirname(__FILE__) . "/ressources/externals/mime/mime.inc";
    $message = new Mail_mime("\r\n");
    $text = "<p style=font-size:18px>{$wifidog_templates->REGISTER_MESSAGE}</p><p>\n\t<hr><center><a href=\"{$URL_REDIRECT}\" style='font-size:22px;text-decoration:underline'>{$URL_REDIRECT}</a></center></p>";
    $message->setFrom($smtp_sender);
    $message->addTo($smtp_sender);
    $message->setSubject($wifidog_templates->REGISTER_SUBJECT);
    $message->setTXTBody(strip_tags($text));
    // for plain-text
    $message->setHTMLBody($text);
    $finalbody = $message->getMessage();
    if ($GLOBALS["VERBOSE"]) {
        echo $finalbody . "<hr>\n";
    }
    $webauth_msmtp = new webauth_msmtp($smtp_sender, $finalbody, $smtp_sender, $_GET["ruleid"]);
    if ($webauth_msmtp->Send()) {
        echo "alert('Rule: {$_GET["ruleid"]} {$smtp_sender} " . $tpl->javascript_parse_text("{$wifidog_templates->REGISTER_SUBJECT}\nTo {$smtp_sender}: {success}") . "');";
        return;
    } else {
        echo "alert('Rule: {$_GET["ruleid"]} {$smtp_sender} Method 1 " . $tpl->javascript_parse_text($webauth_msmtp->logs) . "');";
    }
    $smtp = new smtp();
    if ($sock->GET_INFO("smtp_auth_user") != null) {
        $params["auth"] = true;
        $params["user"] = $sock->GET_INFO("smtp_auth_user");
        $params["pass"] = $sock->GET_INFO("smtp_auth_passwd");
    }
    $params["host"] = $sock->GET_INFO("smtp_server_name");
    $params["port"] = $sock->GET_INFO("smtp_server_port");
    if (!$smtp->connect($params)) {
        echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}") . "');";
        return;
    }
    if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $smtp_sender, "body" => $finalbody, "headers" => null))) {
        $smtp->quit();
        echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}") . "');";
        return;
    }
    echo "alert('" . $tpl->javascript_parse_text("{$wifidog_templates->REGISTER_SUBJECT}\nTo {$smtp_sender}: {success}") . "');";
    $smtp->quit();
}