ok_login, ko_login, loggato, ok_logout, auth_stato, ko_logout, ko_pagina ok_login -> presente nella prima pagina dopo un login OK ko_login -> tutte le volte che si entra con credenziali sbagliate loggato -> stato successivo ad ok_login, indica l' utente loggato ok_logout -> nella pagina successiva all' azione di logout ko_logout -> logout fallito ko_pagina -> errore di accesso ad una pagina "protetta" sloggato -> quando un utente non e' autenticato TEMPLATE {auth_txt_stato} //Visualizza il messaggio in base allo stato corrente {auth_txt_auto} //Visualizza il messaggio in maniera intelligente in base a dove si trova ??? da fare WRAPPER Esempio di default, che prova ad autenticarsi con i wrapper indi e poi con jetbox. $CONF["auth_wrapper_funct"] = "AUTO"; INDI -> Autenticazione via file di testo nel formato: staff e' il nome utente ! $UTENTI[staff][nome] = "Test User"; $UTENTI[staff][password] = "staff"; $UTENTI[staff][email] = "staff@tnx.it"; JETBOX Tramite la tabella webuser, con isActive impostato ad 1 DATABASE Impostando $CONF["auth_wrapper_funct"] = "auth_wrapper_database"; Generica e configurazile tramite i seguenti parametri $CONF["auth_wrapper_table"] = "webuser"; $CONF["auth_wrapper_utente"] = "login"; //nome + cognome $CONF["auth_wrapper_password"]= "user_password"; //nome + cognome $CONF["auth_wrapper_nome"] = "firstname"; //nome + cognome $CONF["auth_wrapper_cognome"] = "lastname"; //nome + cognome $CONF["auth_wrapper_email"] = "email"; //nome + cognome oppure con una funzione personalizzata es: $CONF["auth_wrapper_funct"] = "indi_login"; function indi_login($username,$password) { global $DATI; $res = db_qr("SELECT * from premio_utenti WHERE email = '$username' and md5(md5(lcase(password)))='$password'"); //$res = db_qr("SELECT * from mtp_utenti WHERE email = '$username' and md5(lcase(password))='$password' AND verificato='1'"); if(is_array($res)) { //print "aaa"; $DATI["auth_utente"] = $res["email"]; $DATI["auth_nome"] = $res["nome"]; //setto auth_nome if($res[lastname] != "") $DATI["auth_nome"] .= " ".$AUTH["cognome"]; if(trim($DATI["auth_nome"]) == "") $DATI["auth_nome"] = $DATI["auth_utente"]; $DATI["auth_email"] = $res["email"]; return $res; } else return FALSE; } */ //################################################### //############### CONFIGURAZIONE ################### //################################################### //AGGIUNTA UTENTE WEB DI DEFAULT (solo in loale) if(stristr($_SERVER['REMOTE_ADDR'],"192.168.0")) { $UTENTI['staff']['nome'] = "Test User"; $UTENTI['staff']['password'] = "staff123"; $UTENTI['staff']['email'] = "staff@tnx.it"; } //AVVIO SEMPRE SESSIONE QUANDO MI AUTENTICO IL MODULO //TEMPLATE NON_CAMBIARE $CONF["auth"] = "NO"; //SI / NO $CONF["auth_stato"] = "sloggato"; //stato di autenticazione (no_login, ko_login, ok_login, ok_pagina, ko_pagina) $CONF["auth_ko_login_sleep_time"] = 3; //tempo di attesa secondi se accesso sbagliato $CONF["auth_utente"] = ""; //Username $CONF["auth_nome"] = ""; //nome + cognome $CONF["auth_email"] = ""; //indirizzo e-mail $CONF['auth_persistent'] = "NO"; $CONF['auth_pagina_login_redirect'] = "NO"; //fatto per intercultura non cambiare (cecca) $CONF['auth_md5_salt'] = NULL; //eventualmente usato per la generazione dell' md5 //TEMPLATE pagine di redirezione DA_CAMBIARE queste sono quelle di default //$CONF["auth_pagina_home"] = "AUTO"; //pagina di home riservata ???? controllare anche redirect e capperucci se cambio $CONF["auth_pagina_login"] = "auth_login"; $CONF["auth_pagina_logout"] = "auth_login"; $CONF["auth_pagina_reg"] = ""; //specificare una pagina $CONF["auth_pagina_psw"] = ""; //specificare una pagina per il recupero della password $CONF["auth_pagina_errore"] = "auth_login"; //pagina a cui si accede quando si richiede una pagina protetta if($CONF["indi_subversion"] < 4) { //TEMPLATE TESTI BASE //testo che di solito va' vicino alla form di login $CONF["xxx"]["auth_txt_form"] = 'Insert {auth_txt_utente} and {auth_txt_password} to enter in {auth_txt_nomearea}.
'; $CONF["ita"]["auth_txt_form"] = 'Inserisci {auth_txt_utente} e {auth_txt_password} per accedere all\' {auth_txt_nomearea}.
'; //template per il LOGOUT //TESTI DA CAMBAIRE CHE COSTRUISCONO {auth_txt_auto} $CONF["xxx"]["auth_txt_nomearea"] = "reserved area"; $CONF["ita"]["auth_txt_nomearea"] = "area riservata"; $CONF["xxx"]["auth_txt_ko_login"] = "

Error in {auth_txt_utente|piccolo} or {auth_txt_password|piccolo}

"; $CONF["ita"]["auth_txt_ko_login"] = "

{auth_txt_utente|pgrande} o {auth_txt_password} non corrette

"; $CONF["xxx"]["auth_txt_ok_login"] = "Welcome {auth_nome|pgrande}, login ok, {auth_txt_logout|grassetto|link({auth_link_logout})}"; $CONF["ita"]["auth_txt_ok_login"] = "Benvenuto {auth_nome|pgrande}, adesso sei autenticato, {auth_txt_logout|grassetto|link({auth_link_logout})}"; $CONF["xxx"]["auth_txt_ko_pagina"] = "Bad Login, please go to {auth_txt_login|glink({auth_pagina_login})} for login"; $CONF["ita"]["auth_txt_ko_pagina"] = "Accesso negato, vai alla pagina di {auth_txt_login|glink({auth_pagina_login})} per effettuare l' accesso"; //login logout $CONF["xxx"]["auth_txt_sloggato"] = "{auth_txt_login|pgrande|link({auth_link_login})}"; $CONF["ita"]["auth_txt_sloggato"] = "{auth_txt_login|pgrande|link({auth_link_login})}"; $CONF["xxx"]["auth_txt_loggato"] = "{auth_nome|pgrande|g} logged in, {auth_txt_logout|grassetto|link({auth_link_logout})}"; $CONF["ita"]["auth_txt_loggato"] = "{auth_nome|pgrande|g} sei autenticato, {auth_txt_logout|grassetto|link({auth_link_logout})}"; $CONF["xxx"]["auth_txt_sloggato_sito"] = "{auth_txt_login|pgrande|link({auth_link_login})}"; $CONF["ita"]["auth_txt_sloggato_sito"] = "{auth_txt_login|pgrande|link({auth_link_login})}"; $CONF["xxx"]["auth_txt_loggato_sito"] = "{auth_nome|pgrande|g} logged in, {auth_txt_nomearea|pgrande|link({auth_link_home})}"; $CONF["ita"]["auth_txt_loggato_sito"] = "{auth_nome|pgrande|g} sei autenticato, accedi all' {auth_txt_nomearea|pgrande|link({auth_link_home})}"; //ALTRI TESTI $CONF["xxx"]["auth_txt_formsubmit"] = "Enter"; $CONF["ita"]["auth_txt_formsubmit"] = "Entra"; $CONF["xxx"]["auth_txt_login"] = "Login"; $CONF["ita"]["auth_txt_login"] = "Login"; $CONF["xxx"]["auth_txt_reg"] = 'If you don\'t have an account you can request it at {auth_txt_reg2|glink({auth_pagina_reg})}'; $CONF["ita"]["auth_txt_reg"] = 'Se non sei registrato vai alla {auth_txt_reg2|glink({auth_pagina_reg})} per accedere.'; $CONF["xxx"]["auth_txt_psw"] = ' {auth_txt_recupera_password|glink({auth_pagina_psw})}'; $CONF["ita"]["auth_txt_psw"] = 'Se non ricordi la password {auth_txt_recupera_password|glink({auth_pagina_psw})}'; $CONF["xxx"]["auth_txt_reg2"] = 'registration page'; $CONF["ita"]["auth_txt_reg2"] = 'pagina di registrazione'; $CONF["xxx"]["auth_txt_utente"] = "username"; $CONF["ita"]["auth_txt_utente"] = "nome utente"; $CONF["xxx"]["auth_txt_password"] = "password"; $CONF["ita"]["auth_txt_password"] = "password"; $CONF["xxx"]["auth_txt_logout"] = "Logout"; $CONF["ita"]["auth_txt_logout"] = "Esci"; $CONF["xxx"]["auth_txt_home"] = "<<< Back to home"; $CONF["ita"]["auth_txt_home"] = "<<< Torna alla homepage"; $CONF["xxx"]["auth_txt_recupera_password"] = "retrieve password"; $CONF["ita"]["auth_txt_recupera_password"] = "recupera password"; $CONF["xxx"]["auth_txt_annulla"] = "Abort"; $CONF["ita"]["auth_txt_annulla"] = "Annulla"; } //################# WRAPPER FUNCT ################################## $CONF["auth_wrapper_funct"] = "AUTO"; // Se auto prova ad autenticarsi con indi e poi con jetbox $CONF["auth_wrapper_funct_force"] = false; //serve per richiamare la funzione anche se non vengono passati username e password con indi subv > 5 (vedi intercultura 2016) $CONF["auth_wrapper_funct_logout"] = "auth_logout"; // funzione logout // spostato in base.inc.php perchè controllato anche da admin_tnx $CONF["auth_wrapper_funct_plain_password"] = false;//invia a auth_wrapper_funct_logout la password in chiaro (invece di fare il doppio md5) //Opzioni auth_wrapper_database $CONF["auth_wrapper_table"] = "webuser"; $CONF["auth_wrapper_utente"] = "login"; //nome + cognome $CONF["auth_wrapper_password"]= "user_password"; //nome + cognome $CONF["auth_wrapper_nome"] = "firstname"; //nome + cognome $CONF["auth_wrapper_cognome"] = "lastname"; //nome + cognome $CONF["auth_wrapper_email"] = "email"; //nome + cognome //################# PAGINE AUTOMATICHE NON CAMBIARE #################### //Pagina AUTO di LOGIN if($CONF["indi_subversion"] < 4) { $MENU["auth_login"]["xxx"]["menu_txt"] = "login"; $MENU["auth_login"]["xxx"]["menu_pagina_vis"] = "NO"; //Pagina AUTO di LOGOUT $MENU["auth_logout"]["xxx"]["menu_txt"] = "logout"; $MENU["auth_logout"]["xxx"]["menu_pagina_vis"] = "NO"; //Pagina AUTO di HOME DOPO L' AMMINISTRAZIONE //$MENU["auth_home"]["xxx"]["menu_txt"] = "auth_home"; //$MENU["auth_home"]["xxx"]["menu_pagina_vis"] = "NO"; //$MENU["auth_home"]["xxx"]["protetta"] = "SI"; //Pagina di registrazione UTENTE $MENU["auth_reg"]["ita"]["menu_txt"] = "Area riservata"; $MENU["auth_reg"]["xxx"]["menu_pagina_vis"] = "NO"; $CONF["file:_files/auth.css"] = "COPY,VIS"; // O COPY $CONF["file:_pagine/auth_login.inc.php"] = "COPY"; // O COPY //$CONF["file:_pagine/auth_logout.inc.php"] = "COPY"; // O COPY //$CONF["file:_pagine/auth_reg.inc.php"] = "COPY"; // O COPY $CONF["file:_pagine/auth_password.inc.php"] = "COPY"; // O COPY //$CONF["file:_pagine/auth_home.inc.php"] = "SYNC"; // O COPY } /* ISTRUZIONI FACEBOOK LOGIN: - creare a con href=facebookLoginHref, il parametro redirectTo potrebbe essere la pagina di registrazione, comodo se l'utente non è ancora registrato - nella pagina redirectTo va inserito un if di questo tipo: if(!$AUTH && $data = facebookLoginData()){ //controllare se la mail in $data è registrata: //- se sì fare autologin //- se no mostrare form registrazione con campi precompilati } */ function facebookLoginHref($redirectTo = null){ //nella pagina redirectTo chiamare facebookLoginData //la versione oauth login manda l'header X-Frame-Options DENY quindi non può essere usato nei frame //in tal caso usare target=_blank e poi passare true a facebookLoginData (non funziona su edge) //tentativi con edge: //- window.opener nella pagina di destinazione => viene svuotato nel momento in cui si cambia dominio e poi non si avvalora più (rimane "vivo" sui domini *.tnx.it) //- apertura con window.open + window.onbeforeunload() => access denied (cors) //- apertura con window.open + window.closed => non funziona correttamente https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15030423/ //- apertura con window.open setInterval per controllare nuovawin.document.domain o nuovawin.title => funziona su ie non su edge global $DATI; if(!$DATI['facebookAppId']){ trigger_error("Manca facebookAppId"); return ""; } else{ //https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow if(!$redirectTo) $redirectTo = genera_link_agg(); $proxyPage = ""; if(!$_SESSION['facebookState']) $_SESSION['facebookState'] = mt_rand(); $to = "https://www.facebook.com/v4.0/dialog/oauth?scope=email&client_id=".$DATI['facebookAppId']."&redirect_uri=".rawurlencode($DATI['facebookProxyPage'])."&state=".$_SESSION['facebookState']; return $DATI['facebookProxyPage']."?to=".rawurlencode($to)."&from=".rawurlencode($redirectTo); } } function facebookLoginData($chiamatoDaPopupPerLoginInFrame = false){ global $DATI; if($_GET['code']){ if($_GET['state'] != $_SESSION['facebookState']) trigger_error("CSRF attack?"); else{ $facebookToken = json_decode(file_get_contents("https://graph.facebook.com/v4.0/oauth/access_token?client_id=".$DATI['facebookAppId']."&redirect_uri=".rawurlencode($DATI['facebookProxyPage'])."&client_secret=".$DATI['facebookAppSecret']."&code=".$_GET['code']), true); $_SESSION['facebookToken'] = $facebookToken['access_token']; indi_redirect_agg(null,null,array("code"=>null, 'state'=>null)); } } else if($chiamatoDaPopupPerLoginInFrame){ indiObCleanAll(); echo " "; die; } if($_SESSION['facebookToken']){ return json_decode(file_get_contents("https://graph.facebook.com/v4.0/me?fields=email,last_name,first_name&access_token=".$_SESSION['facebookToken']), true); } } function facebookLogout($revocaPermessi = false){//se non revoco i permessi alla prossima richiesta di login all'utente non verrà chiesta nessuna conferma if($_SESSION['facebookToken']){ if($revocaPermessi){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v4.0/me/permissions?access_token=".$_SESSION['facebookToken']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); $result = json_decode(curl_exec($ch), true); if($result['success'] != 1) trigger_error("Errore Facebook logout"); curl_close($ch); } unset($_SESSION['facebookToken']); } } //action di indi, e' la base del modulo, non serve altro function auth_pre_page_action() { global $DATI,$AUTH,$UTENTI,$DB,$MENU; //GESTIONE LOGIN SESSIONE / COOKIE / AUTENTICAZIONE (auth_login) //prende i dati di login dallo wrapper e torna qualche variabile globale if($DATI["auth_wrapper_funct"] == "AUTO") { //Autenticazione Indi if(is_array($UTENTI)) $AUTH = auth_login("auth_wrapper_indi"); //Autenticazione JETBOX - ATTENZIONE: cerca su db anche a login fallito da $UTENTI if($AUTH == FALSE and $DB["database"]) $AUTH = auth_login("auth_wrapper_jetbox");//JETBOX } else { //alternativa funzione personalizzata richiamata ad ogni pagina vista if($DATI["auth_wrapper_funct"]) $AUTH = auth_login($DATI["auth_wrapper_funct"]); } //GESTIONE REDIREZIONI //se sono autenticato //if($AUTH != FALSE or $_GET['auth_logout'] != "") indi_session_cache("NO"); //costruisco template vari if($MENU[$DATI["auth_pagina_logout"]]) $DATI["auth_link_logout"] = genera_link($DATI["auth_pagina_logout"],$DATI["lang"],"auth_logout=1"); if($MENU[$DATI["auth_pagina_login"]]) $DATI["auth_link_login"] = genera_link($DATI["auth_pagina_login"]); if($MENU[$DATI["auth_pagina_reg"]]) $DATI["auth_link_reg"] = genera_link($DATI["auth_pagina_reg"]); if($MENU[$DATI["auth_pagina_errore"]]) $DATI["auth_link_errore"] = genera_link($DATI["auth_pagina_errore"]); if($MENU[$DATI["auth_pagina_home"]]) $DATI["auth_link_home"] = genera_link($DATI["auth_pagina_home"],null,$DATI["agg_raw"]); if($MENU[$DATI["auth_pagina_login"]]) $DATI["auth_link_action"] = genera_link($DATI["auth_pagina_login"],$DATI["lang"],"auth_login=1"); //imposto stato if($_REQUEST["auth_stato"] == "ok_login" and $AUTH != FALSE) $DATI["auth_stato"] = "ok_login"; elseif($_REQUEST["auth_login"] == 1 and $AUTH == FALSE) {$DATI["auth_stato"] = "ko_login";} //elseif($_REQUEST["auth_login"] == 1 and $AUTH != FALSE) $DATI["auth_stato"] = "re_login"; //??? da fare elseif($_REQUEST["auth_login"] != 1 and $AUTH != FALSE) $DATI["auth_stato"] = "loggato"; elseif($_REQUEST["auth_stato"] == "logout" and $AUTH == FALSE) $DATI["auth_stato"] = "ok_logout"; elseif($_REQUEST["auth_stato"] == "logout" and $AUTH != FALSE and $_REQUEST["auth_login"] != 1) $DATI["auth_stato"] = "ko_logout"; elseif($_REQUEST["auth_stato"] == "err" and $AUTH == FALSE) $DATI["auth_stato"] = "ko_pagina"; //nel coso di accesso a pagina riservata //TEMPLATE after creazione $DATI["auth_txt_stato"] = "{auth_txt_$DATI[auth_stato]}"; if($AUTH != FALSE) $DATI["auth_txt_login_logout"] = $DATI['auth_txt_loggato']; elseif($MENU[$DATI["auth_pagina_login"]]) $DATI["auth_txt_login_logout"] = "".$DATI["auth_txt_login"].""; if($AUTH != FALSE) $DATI["auth_txt_login_logout_sito"] = $DATI['auth_txt_loggato_sito']; else $DATI["auth_txt_login_logout_sito"] = $DATI['auth_txt_sloggato_sito']; //debug //d($AUTH); d_info("Info","------------- MOD_AUTH","INDI"); d_info($DATI['auth'],"AUTH:auth","INDI"); d_info($DATI['auth_stato'],"AUTH:auth_stato","INDI"); if($DATI['auth'] == "SI") { d_info($DATI['auth_utente'],"AUTH:auth_utente","INDI"); d_info($DATI['auth_nome'],"AUTH:auth_nome","INDI"); d_info($DATI['auth_email'],"AUTH:auth_email","INDI"); } //ERRORE //redirezioni pagine in caso di accesso a pagina protetta o auth = 1 esplicito if ($AUTH == FALSE and ($DATI["protetta"] == "SI" or $_GET['auth'] == 1) && !$_GET['t']/* mod_pc su siti con home protetta (weddingwithaview) */) { indi_log("mod_auth: LOGIN redirect - Richesta pagina protetta con - auth=1"); //header("Location: $DATI[baseurl2]".indi_urlencode($_SERVER["REQUEST_URI"])); $_SESSION['auth_pagina_login_referer'] = $DATI["pagina"];//aggiunto carlo per legufe //caso redirect file ??? da gestire if($_GET[file] != "") $auth_r_file = "file=$_GET[file]"; //elenco parametri $auth_r_agg .= $auth_r_file; if ($DATI["auth_pagina_login_redirect"] == "SI") { if ( $DATI["auth_pagina_login"]() !== null ) { $url = $DATI["auth_pagina_login"](); $_SESSION[auth_pagina_login_redirect] = "1"; indi_redirect($url); } else { indi_redirect($DATI[auth_pagina_login]); } } else { //le variabili aggiuntive vengono ripassate se presenti // if($DATI['agg'] == "") $login_ref = indi_urlencode(genera_link_email(null,null, $DATI['agg']."&auth=&auth_stato=ok_login")); // else $login_ref = indi_urlencode($CONF["url_richiesto_httpd"]); $login_ref = indi_urlencode(indi_urlencode($DATI['redirects_genera_link'](null,null, $DATI['agg']."&auth=&auth_stato=ok_login"))); indi_redirect("$DATI[baseurl]$DATI[nome_programma]?p=$DATI[auth_pagina_errore]&l=$DATI[lang]&auth_stato=err&loginreferer=".$login_ref); /* vecchia versione senza con genera_link_email forzato e senza indi_redirect $login_ref = indi_urlencode(indi_urlencode(genera_link_email(null,null, $DATI['agg']."&auth=&auth_stato=ok_login"))); header("Location: $DATI[baseurl]$DATI[nome_programma]?p=$DATI[auth_pagina_errore]&l=$DATI[lang]&auth_stato=err&loginreferer=".$login_ref); session_write_close(); exit(); */ } } //AUTENTICAZIONE RIUSCITA elseif($AUTH != FALSE and $_REQUEST["auth_login"] == "1" ) { $GLOBALS['indi_redirectDumpHeaders'] = true; /* carlo 9/2/2017 situazione verificata oggi: - utente fa recupero password e riceve la mail con il link autologgante - amministratore cambia la password e gliela manda manualmente - utente clicca il clicca il link della mail di recupero - il link non logga perchè contiene i parametri non aggiornati - l'utente viene rimandato alla pagina di login e inserisce i dati giusti - la mod_auth rimanda al referer, che contiene i parametri di autologin, che non sono corretti e che quindi sloggano di nuovo l'utente */ if(trim($_REQUEST["loginreferer"]) && strpos($_REQUEST["loginreferer"], "auth_pass_md5") === false && strpos($_REQUEST["loginreferer"], "auth_pass") === false){ // if(trim($_REQUEST["loginreferer"])){ //die(html_entity_decode(indi_urldecode($_REQUEST['loginreferer']))); //print html_entity_decode(indi_urldecode($_REQUEST['loginreferer']); //login con referrer indi_log("mod_auth: LOGIN OK - auth_login=1 - redirect referrer -> (".html_entity_decode(indi_urldecode($_REQUEST['loginreferer'])).")"); indi_log("Headers al login: ".implode("|", headers_list())); // header("Location: ".html_entity_decode(indi_urldecode($_REQUEST['loginreferer']))); // session_write_close(); indi_redirect( html_entity_decode(indi_urldecode($_REQUEST['loginreferer'])), $DATI['auth_redirect_meta'] ? 'meta' : null ); } else if($DATI["auth_login_stay_on_page"]){ indi_log("mod_auth: LOGIN OK - auth_login=1 - auth_login_stay_on_page"); indi_log("Headers al login: ".implode("|", headers_list())); indi_redirect( genera_link_agg(null,null,["auth_login"=>null, "auth_email" =>null, "auth_user" =>null, "auth_pass"=>null, "auth_pass_md5"=>null]), $DATI['auth_redirect_meta'] ? 'meta' : null ); } else { //decido quali variabili ripassare nel login //task se presente if(trim($_REQUEST['auth_task']) != "") $task = "&auth_task=$_REQUEST[auth_task]"; //task se presente if(trim($_REQUEST['auth_return']) != "") $return = "&auth_return=$_REQUEST[auth_return]"; //auth memorizza if(trim($_REQUEST['am']) == 1) $am = "&am=1"; indi_log("mod_auth: LOGIN OK - auth_login=1 - redirect pagina -> (".$DATI["auth_pagina_home"].")"); indi_log("Headers al login: ".implode("|", headers_list())); //non cambiare indi_redirect_pagina( $DATI["auth_pagina_home"],$DATI["lang"],"auth_stato=ok_login$task$return$am", null, null, null, $DATI['auth_redirect_meta'] ? 'meta' : null ); } } //LOGOUT elseif($_REQUEST["auth_logout"]==1) { indi_log("mod_auth: LOGOUT - u:$username - funct: $DATI[auth_wrapper_funct_logout] - redirect: $DATI[auth_pagina_logout] - auth_logout=1"); //logout standard //auth_logout(); //logout if ($DATI["auth_wrapper_funct_logout"] != "") $DATI["auth_wrapper_funct_logout"](); //cancello cookie setcookie ("auth_cript2", "", time() - 3600, indi_cookie_path()); setcookie ("auth_user2", "", time() - 3600, indi_cookie_path()); unset($_COOKIE["auth_cript2"]); unset($_COOKIE["auth_user2"]); unset($_COOKIE["auth_user"]); unset($_COOKIE["auth_pass"]); $_SESSION['indicarr'] = array(); //cancello carrello if($DATI["auth_logout_stay_on_page"]){ indi_redirect(genera_link_agg(null,null,["auth_logout"=>null])); } else indi_redirect_pagina($DATI["auth_pagina_logout"],$DATI["lang"],"auth_stato=logout"); //exit(); } d_info($AUTH,"AUTH:\$AUTH"); } ############## FUNZIONI AUTH ################################ //wrapper autenticazione per jetbox //funzione di logout function auth_logout() { global $AUTH,$DATI; unset($AUTH); $DATI[auth] = "NO"; $DATI[auth_stato] = "sloggato"; $DATI["auth_utente"] = ""; //Username $DATI["auth_nome"] = ""; //nome + cognome $DATI["auth_email"] = ""; //indirizzo e-mail unset($_SESSION["auth_user"]); unset($_SESSION["auth_pass"]); unset($_SESSION["autenticato"]); unset($_SESSION["AUTH"]); unset($_SESSION["auth_cript"]); if($_COOKIE["auth_cript2"] != ""){ setcookie("auth_cript2", "", time() - 3600, indi_cookie_path()); } if($_COOKIE["auth_user2"] != ""){ setcookie("auth_user2", "", time() - 3600, indi_cookie_path()); } if(function_exists("auth_logout_post")) { auth_logout_post(); } } //generica personalizzabile function auth_wrapper_database($username,$password) { global $DATI; $res = db_qr("SELECT * from $DATI[auth_wrapper_table] WHERE $DATI[auth_wrapper_utente] = '$username' and md5(md5(lcase($DATI[auth_wrapper_password])))='$password'"); if(is_array($res)) { $DATI["auth_utente"] = $res[$DATI["auth_wrapper_utente"]]; $DATI["auth_nome"] = $res[$DATI["auth_wrapper_nome"]]; if($res[$DATI["auth_wrapper_cognome"]] != "") $DATI["auth_nome"] .= " ".$AUTH[$DATI["auth_wrapper_cognome"]]; $DATI["auth_email"] = $res[$DATI["auth_wrapper_email"]]; return $res; } else return FALSE; } function auth_wrapper_jetbox($username,$password) { global $DATI; $res = db_qr("SELECT * from $DATI[auth_wrapper_table] WHERE login = '$username' and md5(md5(lcase(user_password)))='$password' AND isActive='1'"); if(is_array($res)) { //print "aaa"; $DATI["auth_utente"] = $res["login"]; $DATI["auth_nome"] = $res[firstname]; //setto auth_nome if($res[lastname] != "") $DATI["auth_nome"] .= " ".$AUTH[lastname]; if(trim($DATI["auth_nome"]) == "") $DATI["auth_nome"] = $DATI["auth_utente"]; $DATI["auth_email"] = $res["email"]; return $res; } else return FALSE; } function auth_wrapper_indi($username,$password) { global $DATI,$UTENTI; reset($UTENTI); while(list($k, $v)=@each($UTENTI)) { if($k == $username and md5(md5(trim(strtolower($v["password"])))) == $password) { $DATI["auth_utente"] = $k; $DATI["auth_nome"] = $UTENTI[$k][nome]; $DATI["auth_email"] = $UTENTI[$k][email]; return $UTENTI[$k]; } } return FALSE; } //FUNZIONE PERSONALIZZATA DI AUTENTICAZIONE function auth_wrapper_personalizzata($username,$password) { } function auth_login($wrapper_funct) { global $DATI; $AUTH = FALSE; //se tento di riautenticarmi con credenziali diverse prima mi sloggo in automatico if($_REQUEST['auth_login'] == 1 and (($_REQUEST["auth_user"] != $_SESSION["auth_user"] or $_REQUEST["auth_cript"] != $_SESSION["auth_cript"]) and $_SESSION["auth_user"]) and $DATI["auth_wrapper_funct_logout"] != "") { $DATI["auth_wrapper_funct_logout"](); } //se le variabili sono in sessione o cookie o request le riprendo per effettuare il login if($_SESSION["auth_cript"] != "") { $password = $_SESSION["auth_cript"]; } elseif ($_COOKIE["auth_cript2"] != "" and $_REQUEST[auth_stato] != "logout") { $password = $_COOKIE["auth_cript2"]; } if(trim($_REQUEST["auth_pass"]) != ""){ $password = trim($password); if($DATI['auth_password_solo_minuscole']) $password = strtolower($_REQUEST["auth_pass"]); else $password = $_REQUEST["auth_pass"]; if(!$DATI['auth_wrapper_funct_plain_password']) $password = md5(md5(stripslashes($password))); } if(trim($_REQUEST["auth_pass_md5"]) != "") $password = $_REQUEST["auth_pass_md5"]; if($_SESSION["auth_user"] != "") { $username = $_SESSION["auth_user"]; } elseif ($_COOKIE["auth_user2"] != "" and $_REQUEST[auth_stato] != "logout") { $username = $_COOKIE["auth_user2"]; } if(trim($_REQUEST["auth_user"]) != "") $username = trim(strtolower($_REQUEST[auth_user])); //PASSO USERNAME E PASSOWORD ALLA FUNZIONE DI LOGIN /* CARLO 12/09/2013 dopo mia segnalazione 31/7/2013 volevo sostituire questo pezzo di codice ma con intercultura si crea troppo casino perchè la funzione di login viene usata qusi come una pre_page_action e andrebbe rivisto tutto e non ho tempo. */ //controllo sempre per campi nulli che non devono esistere if($DATI["auth_wrapper_funct"] == "AUTO" || $DATI["auth_wrapper_funct"] == "") { if(trim($password) != "" and trim($username) != "") { //RICHIAMO LA FUNZIONE DI AUTENTICAZIONE $AUTH = $wrapper_funct($username,$password); } else { $AUTH = FALSE; } } else { //se indi_subversion > 5 controllo login solo se presenti username e password, senno fallisce SEMPRE if($DATI['indi_subversion'] > 5 && !$DATI["auth_wrapper_funct_force"]) { if(trim($password) != "" and trim($username) != "") { $AUTH = $wrapper_funct($username,$password); } else { $AUTH = FALSE; } } else { $AUTH = $wrapper_funct($username,$password); } } //Imposto le variabili di sessione se il login ha avuto successo if(is_array($AUTH)) { //prima volta che accedo mi salvo i dati in sessione se non presenti if(!$_SESSION['auth_cript'] and !$_SESSION['auth_user'] and $password and $username) { $_SESSION["auth_cript"] = $password; $_SESSION["auth_user"] = $username; indi_log("mod_auth: LOGIN OK - ($username/$_REQUEST[auth_pass]) - funct:($wrapper_funct)"); //se metto l' autenticazione persistente //cancello carrello se c'e' //$_SESSION['indicarr'] = array(); } //Se c'e' l'opzione persistente salvo i dati in un cookie solo in fase di autenticazione auth_login == 1 if($_REQUEST['auth_login'] == 1 and ($DATI['auth_persistent'] == "SI" or ( $_REQUEST["am"] == 1 ))) { indi_log("mod_auth: LOGIN Persistent - am=1"); //risetto setcookie("auth_cript2", $_SESSION["auth_cript"], time()+365*2*24*60*60, indi_cookie_path()); setcookie("auth_user2", $_SESSION["auth_user"], time()+365*2*24*60*60, indi_cookie_path()); } $DATI["auth"] = "SI"; $DATI["auth_stato2"] = "auth"; } else { //LOGIN FALLITO //se il login fallisce e avevo specificato una user e uan password if((trim($password) != "" or trim($username) != "")) { sleep($DATI["auth_ko_login_sleep_time"]); //carlo 6/8/24 evito che il sito si rallenti se ho un cookie con una password vecchia (toglo anche da sessione): unset($_SESSION["auth_cript"]); unset($_SESSION["auth_user"]); setcookie ("auth_cript2", "", time() - 3600, indi_cookie_path()); setcookie ("auth_user2", "", time() - 3600, indi_cookie_path()); $e = "mod_auth: LOGIN ERR - ($username/$_REQUEST[auth_pass]) - ANTISPAM sleep: $DATI[auth_ko_login_sleep_time] sec, rimuovo dati in cookie / sessione"; if($DATI['dove_sono'] == 'loc') trigger_error($e); indi_log($e); } $DATI["auth"] = "NO"; $DATI["auth_stato2"] = "non_auth"; $AUTH = FALSE; } return $AUTH; } function auth_manual_login($username,$password,$return="") { } ?>