$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 = ' ';
$nazio .= '';
$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 = '
ThreeGates Example |