fakeroot usage added to avoid root privileges requirements.
[threegates.git] / raw / root / var / www / index.php
1 <?php
2
3 function stemplala($fcontents,$arr)
4 {
5     foreach ($arr as $key => $value) {
6         $fcontents = str_replace($key,$value,$fcontents);
7     }
8     
9     return ($fcontents);
10 }
11
12 function langcheck(&$lang,$arrl = NULL)
13 {
14     GLOBAL $_SERVER;
15     GLOBAL $G_main_langs;
16     
17     /* se non specificato assegna il default */
18     if ($arrl == NULL)
19         $arrl = $G_main_langs;
20     
21     /* cerca il valore della var $lang nell'array */
22     $ct = count($arrl);
23     for ($i = 0 ; $i < $ct ; $i++) {
24         if ($lang == $arrl[$i]) {
25             if ($i == 0) 
26                 return("");
27             else
28                 return ("_".$lang);
29         }
30     }
31     
32     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
33         $langs = array();
34         
35         // break up string into pieces (languages and q factors)
36         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);
37         
38         if (count($lang_parse[1])) {
39             // create a list like "en" => 0.8
40             $langs = array_combine($lang_parse[1], $lang_parse[4]);
41             
42             // set default to 1 for any without q factor
43             foreach ($langs as $lang => $val) {
44                 if ($val === '') $langs[$lang] = 1;
45             }
46             
47             // sort list based on value 
48             arsort($langs, SORT_NUMERIC);
49             
50             foreach ($langs as $lang_cur => $val) {
51                 for ($i = 0 ; $i < $ct ; $i++) {
52                     if (strpos($lang_cur, $arrl[$i]) === 0) {
53                         if ($i == 0) 
54                             return(""); /* caso default */
55                         else
56                             return ("_".$arrl[$i]);
57                     }
58                 }
59             }
60         }
61     }
62     
63     $lang = "";
64     return ("");
65 }
66
67 function main()
68 {
69     GLOBAL $lang;
70
71     $lng = langcheck($lang, array("it", "en"));
72
73     $nazio  = '<a href="index.php?lang=it"><img style="position: relative;" border=0 alt="next" src="/img/it.gif"></a> ';    
74     $nazio .= '<a href="index.php?lang=en"><img style="position: relative;" border=0 alt="next" src="/img/uk.gif"></a>';
75
76     $tmpl_page = '<html>
77 <head>
78 <script type="text/javascript"><!--
79
80 function $(id) { return document.getElementById(id); }
81
82 function createXMLHttpRequest() {
83 try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
84 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
85 try { return new XMLHttpRequest();                   } catch(e) {}
86 alert("XMLHttpRequest not supported");
87 return null;
88 }
89
90 function safestatus(a)
91 {
92     try{
93         return (a.status);
94     } catch(b)
95         { return (-1); }
96 }
97
98 function xhr_cb(xhr)
99 {
100     var ret;
101
102     // console.log(xhr_rd.readyState);
103
104     if (xhr.readyState == 4) {
105
106         try {
107             if ((ret = safestatus(xhr)) == 200) {
108               if (xhr.responseText == "CRGT_TRUE") {
109                 document.location.assign("onlycrs/index.php?lang=#LANG#");
110               }
111               else if (xhr.responseText == "CRGT_RETRY") {
112                 $(\'resp\').innerHTML = "#RESP_RETRY#";
113               }
114               else if (xhr.responseText == "CRGT_FALSE") {
115                 $(\'resp\').innerHTML = "#RESP_FALSE#";
116               }
117               else {
118                 ret = 300;
119               }
120             }
121         } catch(b) {
122         };
123         if (ret != 200) {
124           $(\'resp\').innerHTML = "#RESP_ERROR#";
125         }
126     }
127 };
128
129
130 window.onload = function() {
131   var xhr = createXMLHttpRequest();
132   var r;
133
134   xhr.open(\'GET\', \'onlycrs/gate.php\', true);
135   xhr.onreadystatechange = function() { xhr_cb(xhr); };
136   r = xhr.send(null);
137   
138   // alert("the end");
139
140
141 }
142
143
144 // -->
145 </script>
146 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
147 <link rel="stylesheet" type="text/css" href="threegates.css">
148 <link rel="stylesheet" type="text/css" href="room.css">
149 <title>#PAGE_TITLE#</title>
150 </head>
151
152 <body style="text-align: center;">
153 <div id="header" class="header">
154 <table width="100%" border="0" cols="3"><tr>
155 <td align="left"><div style="padding-left: 8px;"></div></td>
156 <td align="center"><div style="text-align: center;">
157     <h1>ThreeGates Example</h1>
158     </div></td>
159 <td align="right"><div style="padding-right: 8px;">
160 </div></td>
161 </td></table>
162 </div>
163 <br>
164 <h2>#TITLE#</h2>
165 <br>
166
167 <div style="text-align: justify; width: 800px; margin: auto; padding: 4px; display: block;">#NAZIO#<br></div>
168 <div style="margin: auto; /* border: 1px solid red; */ width: 700px;">
169 <div style="border: 1px solid #bbbbbb; padding: 8px; text-align: center; background-color: #eeeeee;" id="resp"><br><br><b>Attendere prego ...</b><br><br><br></div>
170 </div>
171 </body>
172 </html>';
173     
174     $tmpl_page_tit = array ( 'it' => 'Brisk: auto-garanzia',
175                              'en' => 'Brisk: self-guarantee' );
176     
177     $tmpl_title = array ( 'it' => 'Procedura di auto-garanzia.',
178                           'en' => 'Self-guarantee procedure.' );
179     
180     $tmpl_hili = array ( 'it' => 'briscola chiamata in salsa ajax',
181                          'en' => 'declaration briscola in ajax sauce' );
182     
183     $resp_retry = array ( 'it' => 'La <b>lista dei certificati di revoca (CRL)</b> indicata nel suo certificato non era tra quelle monitorate dal server; è stata aggiunta ed entro qualche minuto verrà processata.<br><br><b>Riprovi più tardi.</b>',
184                           'en' => 'The <b>certificate revocation list (CRL)</b> specified by your smartcard wasn\'t monitored by the server; it is added and will be processed within a few minutes.<br><br><b>Retry later.</b>' );
185
186     $resp_false = array ( 'it' => 'Spiacenti,<br><b>non siamo in possesso delle informazioni necessarie</b><br>alla verifica del suo certificato.<br><br>Se vuole segnalare il tipo di certificato che sta usando <a href=\'mailto:trustmaster@alternativeoutput.it\'><br><b>Contatti l\'amministratore</b></a>.',
187                           'en' => 'Sorry,<br><b>we haven\'t the required information</b><br>to verify your certificate.<br>If you want to report your certificate\'s type <a href=\'mailto:trustmaster@alternativeoutput.it\'><br><b>please contact the administrator</b></a>.' );
188
189     $resp_error = array ( 'it' => 'Spiacenti, <b>non siamo in possesso delle informazioni necessarie alla verifica del suo certificato</b> o <br><b>è occorso un errore sul server</b>.<br><br>Se vuole segnalare il tipo di certificato che sta usando <a href=\'mailto:trustmaster@alternativeoutput.it\'><br><b>Contatti l\'amministratore</b></a>.<br>',
190                           'en' => 'Sorry, <b>we haven\'t the information needed</b> to verify your certificate or<br> <b>an error occured on the server.<br><br>If you want to report your certificate\'s type <a href=\'mailto:trustmaster@alternativeoutput.it\'><br><b>please contact the administrator</b></a>.' );
191     
192     $page_vars = array(
193                        '#PAGE_TITLE#' => $tmpl_page_tit[$lang],
194                        '#HILI#'       => $tmpl_hili[$lang],
195                        '#TITLE#'      => $tmpl_title[$lang],
196                        '#LANG#'       => $lang,
197                        '#NAZIO#'      => $nazio,
198                        '#RESP_RETRY#' => $resp_retry[$lang],
199                        '#RESP_FALSE#' => $resp_false[$lang],
200                        '#RESP_ERROR#' => $resp_error[$lang]
201                        );
202     
203     
204     echo stemplala($tmpl_page, $page_vars);
205 }
206
207 main();
208
209 ?>