$value) { $fcontents = str_replace($key,$value,$fcontents); } return ($fcontents); } function langcheck(&$lang,$arrl = NULL) { GLOBAL $_SERVER; GLOBAL $G_main_langs; /* se non specificato assegna il default */ if ($arrl == NULL) $arrl = $G_main_langs; /* cerca il valore della var $lang nell'array */ $ct = count($arrl); for ($i = 0 ; $i < $ct ; $i++) { if ($lang == $arrl[$i]) { if ($i == 0) return(""); else return ("_".$lang); } } if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $langs = array(); // break up string into pieces (languages and q factors) preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); if (count($lang_parse[1])) { // create a list like "en" => 0.8 $langs = array_combine($lang_parse[1], $lang_parse[4]); // set default to 1 for any without q factor foreach ($langs as $lang => $val) { if ($val === '') $langs[$lang] = 1; } // sort list based on value arsort($langs, SORT_NUMERIC); foreach ($langs as $lang_cur => $val) { for ($i = 0 ; $i < $ct ; $i++) { if (strpos($lang_cur, $arrl[$i]) === 0) { if ($i == 0) return(""); /* caso default */ else return ("_".$arrl[$i]); } } } } } $lang = ""; return (""); } function dexcape($s) { $from = array ( '"' ); $to = array ( '"' ); // return (str_replace($from, $to, $s)); return (htmlentities($s, ENT_QUOTES)); } function xcape($s) { $from = array ( '\\', '\'' ); $to = array ( '\\\\', '\\\''); return (str_replace($from, $to, $s)); } function main() { GLOBAL $SSL_CLIENT_CERT, $SSL_CLIENT_S_DN_CN, $i_action, $i_email, $i_user, $i_pass_private, $lang; $notify = ""; $lng = langcheck($lang, array("it", "en")); $nazio = 'next '; $nazio .= 'next'; $ret = crgt_certgate($SSL_CLIENT_CERT, TRUE); if ($ret != CRGT_TRUE) { echo "ACCESSO NEGATO".$ret; exit(); } // Verify preview existence of the user into the db $pg = pg_connect("dbname=".BRDB_NAME." host=127.0.0.1 user=".BRDB_USER." password='".BRDB_PWD."'"); if ($pg == FALSE) { // FIXME: show error page echo "No conn
\n"; exit; } if ($SSL_CLIENT_S_DN_CN != "") { $cf_hash = bin2hex(mhash(MHASH_MD5, ereg_replace("/.*", "", $SSL_CLIENT_S_DN_CN))); } else $cf_hash = ""; $que = sprintf("SELECT * FROM %s WHERE %s='%s';", BRDB_SELFAUTH, "cf_hash", $cf_hash); $rec = pg_query($pg, $que); if (pg_num_rows($rec) > 0) { $row = pg_fetch_object($rec); if ($row->lock == 0) $new_action = "modify"; else $new_action = "show"; } else { $new_action = "insert"; } if ($new_action != "show") { if ($i_action == "insert" && $cf_hash != "") { $que = sprintf("INSERT INTO %s VALUES ( '%s', '%s', '%s', '%s', %d );", BRDB_SELFAUTH, xcape($cf_hash), xcape($i_email), xcape($i_user), xcape($i_pass_private), 0); $notify_arr = array( 'it' => 'L\'inserimento dei dati è andato a buon fine.', 'en' => 'Data inserted correctly.' ); $notify = $notify_arr[$lang]; } else if ($i_action == "modify" && $cf_hash != "") { if ($i_pass_private == "") { $que = sprintf("UPDATE %s SET \"email\"='%s',\"user\"='%s' where \"cf_hash\"='%s';", BRDB_SELFAUTH, xcape($i_email), xcape($i_user), xcape($cf_hash)); $notify_arr = array( 'it' => 'La modifica dei dati è andata a buon fine, la password non è stata aggiornata.', 'en' => 'Data updated correctly, password not changed.' ); $notify = $notify_arr[$lang]; } else { $que = sprintf("UPDATE %s SET \"email\"='%s',\"user\"='%s',\"password\"='%s' where \"cf_hash\"='%s';", BRDB_SELFAUTH, xcape($i_email), xcape($i_user), xcape($i_pass_private), xcape($cf_hash)); $notify = ""; $notify_arr = array( 'it' => 'La modifica dei dati è andata a buon fine, la password è stata aggiornata.', 'en' => 'Data and password updated correctly.' ); $notify = $notify_arr[$lang]; } } if (($res = pg_query($pg, $que)) == FALSE) { $notify_arr = array( 'it' => 'E\' occorso un qualche errore durante il processamento dei dati; se la cosa persiste contattare l\'amministratore.\n', 'en' => 'Some error has occurred during data processing; if the problem persists contact the administrator.\n' ); $notify = $notify_arr[$lang]; } $que = sprintf("SELECT * FROM %s WHERE %s='%s';", BRDB_SELFAUTH, "cf_hash", xcape($cf_hash)); $rec = pg_query($pg, $que); if (pg_num_rows($rec) > 0) { $row = pg_fetch_object($rec); if ($row->lock == 0) $new_action = "modify"; else $new_action = "show"; } else { $new_action = "insert"; } } $i_action = $new_action; $tmpl_page = ' #PAGE_TITLE#

#TITLE#

#NAZIO#
#WELLCOME#
#NOTIFY#

#PASS#
'; $tmpl_page_tit = array ( 'it' => 'Brisk: auto-garanzia', 'en' => 'Brisk: self-guarantee' ); $tmpl_title = array ( 'it' => 'Procedura di auto-garanzia.', 'en' => 'Self-guarantee procedure.' ); $tmpl_hili = array ( 'it' => 'briscola chiamata in salsa ajax', 'en' => 'declaration briscola in ajax sauce' ); $tmpl_user_label = array ( 'it' => 'utente', 'en' => 'user' ); $tmpl_pass_confirm = array ('it' => 'conferma
password', 'en' => 'confirm
password' ); $tmpl_well_ins = array ( 'it' => 'Benvenuto e complimenti per essere arrivato/a fin qui.

Sei quasi alla fine della procedura di auto-garanzia: riempi i campi della maschera qui sotto e clicca "invia" per terminarla.

Ti ricordo che sul server non verrà memorizzato nessun dato sensibile che ti riguarda ma soltanto un codice univoco calcolata a partire dal tuo codice fiscale e dal quale è impossibile risalire al codice fiscale stesso.', 'en' => 'Wellcome and congratulation to be arrived here.

You are near the end of the self guarantee procedure: fill fields of the form below and click "send" to finish.

I remember you that on the server will not stored any sensible data about you but only a uniq code computed starting from your fiscal code and that from this uniq code is never possible traced back to your fiscal code.' ) ; $tmpl_well_mod = array ( 'it' => 'Ciao #USER_NAME#,

i tuoi dati non sono ancora stati processati e inseriti in Brisk; se vuoi modificarli aggiorna i campi qui di seguito.
Se lasci in bianco i campi per la password verrà mantenuta quella precedente.
', 'en' => 'Hi #USER_NAME#,

your data have not yet been processed and inserted into Brisk; if you want to change them update fields below.
If left blank passwords fields, will be mantained the previous version.
' ); $tmpl_well_def = array ( 'it' => 'Ciao #USER_NAME#,

i tuoi dati sono già stati processati e inseriti in Brisk; se vuoi modificarli segnalalo all\'amministratore attraverso il menù azioni del sito, provvederà a sospendere temporaneamente il tuo account e rendere di nuovo modificabili queste informazioni.
', 'en' => 'Hi #USER_NAME#,

your data has already been processed and inserted into Brisk; if you want to edit them you must contact the administrator using the actions menu item of the site, he will temporarily suspend your account and make this informations editable again.
' ); $pass_var_full = 'password: #PASS_CONFIRM_LABEL#: '; if ($i_action == "insert") { $tmpl_well = $tmpl_well_ins[$lang]; } else if ($i_action == "modify") { $well_vars = array( '#USER_NAME#' => $row->user ); $tmpl_well = stemplala( $tmpl_well_mod[$lang], $well_vars ); } else { $well_vars = array( '#USER_NAME#' => $row->user ); $tmpl_well = stemplala( $tmpl_well_def[$lang], $well_vars ); } if ($notify != "") $noti_var = sprintf("%s", $notify); else $noti_var = ""; if ($i_action != "show") { $email_var = sprintf("", ($i_action == "modify" ? dexcape($row->email) : "") ); } else { $email_var = sprintf("
%s
", $row->email); } if ($i_action != "show") { $user_var = sprintf("", ($i_action == "modify" ? dexcape($row->user) : "") ); } else { $user_var = sprintf("
%s
", $row->user); } if ($i_action != "show") { $submit_arr = array ( 'it' => 'invia', 'en' => 'send' ); $pass_arr = array ( '#SUBMIT_LABEL#' => $submit_arr[$lang], '#PASS_CONFIRM_LABEL#'=> $tmpl_pass_confirm[$lang] ); $pass_var = stemplala( $pass_var_full, $pass_arr ); } else $pass_var = ''; $page_vars = array( '#PAGE_TITLE#' => $tmpl_page_tit[$lang], '#HILI#' => $tmpl_hili[$lang], '#TITLE#' => $tmpl_title[$lang], '#NAZIO#' => $nazio, '#WELLCOME#' => $tmpl_well, '#NOTIFY#' => $noti_var, '#ACTION#' => $i_action, '#EMAIL#' => $email_var, '#USER_LABEL#' => $tmpl_user_label[$lang], '#USER#' => $user_var, '#PASS#' => $pass_var, '#LANG#' => $lang ); echo stemplala($tmpl_page, $page_vars); pg_close($pg); } main(); ?>