5 * Copyright (C) 2014 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
27 $mlang_umgmt = array( 'nu_psubj' => array( 'it' => 'Brisk: credenziali di accesso.',
28 'en' => 'Brisk: credentials.'),
29 'nu_ptext' => array( 'it' =>
30 'Ciao, sono l\' amministratore del sito di Brisk.
32 La verifica del tuo indirizzo di posta elettronica e del tuo nickname è andata a buon fine, per accedere al sito
33 d\'ora in poi potrai utilizzare l\' utente \'%s\' e la password \'%s\'.
35 Benvenuto e buone partite, mop.',
36 'en' => 'EN ptext [%s] [%s]'),
37 'nu_phtml' => array( 'it' => 'Ciao, sono l\' amministratore del sito di Brisk.<br><br>
38 La verifica del tuo indirizzo di posta elettronica e del tuo nickname è andata a buon fine, per accedere al sito d\'ora in poi potrai usare l\' utente \'%s\' e la password \'%s\'.<br>
39 Benvenuto e buone partite, mop.<br>',
40 'en' => 'EN phtml [%s] [%s]')
44 ini_set("max_execution_time", "240");
46 require_once($G_base."Obj/brisk.phh");
47 require_once($G_base."Obj/user.phh");
48 require_once($G_base."Obj/auth.phh");
49 require_once($G_base."Obj/mail.phh");
50 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
51 require_once($G_base."briskin5/Obj/briskin5.phh");
52 require_once($G_base."briskin5/Obj/placing.phh");
53 require_once($G_base."spush/brisk-spush.phh");
54 require_once($G_base."index_wr.php");
58 GLOBAL $G_alarm_passwd, $sess, $_POST, $_SERVER;
62 $ip = $_SERVER["REMOTE_ADDR"];
64 $private = md5($G_alarm_passwd.$ip.$sess);
65 $cmd = array ("cmd" => "userauth", "sess" => $sess, "private" => $private, "the_end" => "true");
66 $cmd_ser = cmd_serialize($cmd);
67 $cmd_len = mb_strlen($cmd_ser, "ASCII");
70 if (($socket = stream_socket_client("unix://".USOCK_PATH."2")) == FALSE)
73 if (($rwr = fwrite($socket, $cmd_ser, $cmd_len)) == FALSE
78 if (($buf = fread($socket, 4096)) == FALSE)
80 $res = cmd_deserialize($buf);
82 if (!isset($res['val']) || $res['val'] != 200)
97 GLOBAL $G_dbpfx, $G_lang, $G_alarm_passwd, $G_domain, $G_webbase;
98 GLOBAL $mlang_umgmt, $mlang_indwr, $f_mailusers, $sess, $_POST, $_SERVER;
103 if (check_auth() == FALSE) {
104 echo "Authentication failed";
108 if (isset($_GET['do']) && $_GET['do'] == 'newuser') {
109 if (isset($_POST['f_accept'])) {
112 else if (isset($_POST['f_delete'])) {
119 if ($action == "accept") {
120 foreach($_POST as $key => $value) {
121 if (substr($key, 0, 9) != "f_newuser")
124 $id = (int)substr($key, 9);
128 // check existence of username or email
132 if (($bdb = BriskDB::create()) == FALSE)
135 // retrieve list added users
137 SELECT usr.*, guar.login AS guar_login
139 JOIN %susers AS guar ON guar.code = usr.guar_code
140 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
141 AND usr.disa_reas = %d AND usr.code = %d;",
143 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
144 USER_DIS_REA_NU_ADDED, $id);
145 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
146 log_crit("stat-day: select from tournaments failed");
149 $usr_n = pg_numrows($usr_pg);
151 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
156 $usr_obj = pg_fetch_object($usr_pg, 0);
158 $bdb->transaction('BEGIN');
162 if (($bdb->user_update_flag_ty($usr_obj->code,
163 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_ADDED,
164 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_MAILED)) == FALSE) {
169 if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
170 fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
173 $hash = md5($curtime . $G_alarm_passwd . $usr_obj->login . $usr_obj->email);
175 $confirm_page = sprintf("http://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
176 $G_domain, $G_webbase, $mail_code, $hash);
177 $subj = $mlang_indwr['nu_msubj'][$G_lang];
178 $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang],
179 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
180 $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang],
181 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
183 $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
184 $curtime, $subj, $body_txt, $body_htm, $hash);
186 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
188 fprintf(STDERR, "ERROR: mail send FAILED\n");
192 if ($mail_item->store($bdb) == FALSE) {
194 fprintf(STDERR, "ERROR: store mail FAILED\n");
197 $status .= sprintf("status change for %s: SUCCESS<br>", $usr_obj->login);
198 $bdb->transaction('COMMIT');
202 $status .= sprintf("Error occurred during accept action<br>");
204 $bdb->transaction('ROLLBACK');
211 if (($bdb = BriskDB::create()) == FALSE) {
212 log_crit("stat-day: database connection failed");
216 // retrieve list added users
218 SELECT usr.*, guar.login AS guar_login
220 JOIN %susers AS guar ON guar.code = usr.guar_code
221 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
222 AND usr.disa_reas = %d;",
224 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
225 USER_DIS_REA_NU_ADDED);
226 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
227 log_crit("stat-day: select from tournaments failed");
230 $usr_n = pg_numrows($usr_pg);
232 for ($i = 0 ; $i < $usr_n ; $i++) {
233 $usr_obj = pg_fetch_object($usr_pg, $i);
235 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" CHECKED></td><td>%s</td><td></td></tr>\n",
236 $usr_obj->code, eschtml($usr_obj->login), eschtml($usr_obj->guar_login));
241 <h2> New imported users management.</h2>
242 <?php if ($status != "") { echo "$status"; } ?>
243 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
249 <input type="submit" name="f_accept" value="Newuser Accept">
250 <input type="submit" name="f_delete" value="Newuser Delete">
257 printf("Some error occurred during newuser visualization\n");
260 else { // if ($_GET['do'] ...
261 if (isset($_POST['f_accept'])) {
264 else if (isset($_POST['f_delete'])) {
271 if ($action == "accept") {
272 if (($bdb = BriskDB::create()) == FALSE) {
273 log_crit("stat-day: database connection failed");
277 foreach($_POST as $key => $value) {
278 if (substr($key, 0, 9) != "f_newuser")
281 $id = (int)substr($key, 9);
286 // retrieve list of active tournaments
288 SELECT usr.*, guar.login AS guar_login
290 JOIN %susers AS guar ON guar.code = usr.guar_code
291 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
292 AND usr.disa_reas = %d AND usr.code = %d;",
294 USER_FLAG_TY_ALL, USER_FLAG_TY_DISABLE,
295 USER_DIS_REA_NU_TOBECHK, $id);
296 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
297 log_crit("stat-day: select from tournaments failed");
300 $usr_obj = pg_fetch_object($usr_pg, 0);
302 printf("KEY: %s: %s %s<br>\n", $id, $value, $usr_obj->login);
304 $passwd = passwd_gen();
306 if (($bdb->user_update_passwd($usr_obj->code, $passwd)) == FALSE) {
311 if (($bdb->user_update_flag_ty($usr_obj->code,
312 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_TOBECHK,
313 USER_FLAG_TY_NORM, USER_DIS_REA_NONE)) == FALSE) {
318 $bdb->user_update_login_time($usr_obj->code, 0);
321 $subj = $mlang_umgmt['nu_psubj'][$G_lang];
322 $body_txt = sprintf($mlang_umgmt['nu_ptext'][$G_lang],
323 $usr_obj->login, $passwd);
324 $body_htm = sprintf($mlang_umgmt['nu_phtml'][$G_lang],
325 $usr_obj->login, $passwd);
327 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
329 fprintf(STDERR, "ERROR: mail send FAILED\n");
337 if (($bdb = BriskDB::create()) == FALSE) {
338 log_crit("stat-day: database connection failed");
342 // retrieve list of active tournaments
344 SELECT usr.*, guar.login AS guar_login
346 JOIN %susers AS guar ON guar.code = usr.guar_code
347 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
348 AND usr.disa_reas = %d;",
350 USER_FLAG_TY_ALL, USER_FLAG_TY_DISABLE,
351 USER_DIS_REA_NU_TOBECHK);
352 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
353 log_crit("stat-day: select from tournaments failed");
357 $usr_n = pg_numrows($usr_pg);
359 for ($i = 0 ; $i < $usr_n ; $i++) {
360 $usr_obj = pg_fetch_object($usr_pg, $i);
362 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" CHECKED></td><td>%s</td><td></td></tr>\n",
363 $usr_obj->code, eschtml($usr_obj->login), eschtml($usr_obj->guar_login));
368 <h2> E-mail verified user management.</h2>
369 <?php if ($status != "") { echo "$status"; } ?>
370 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
376 <input type="submit" name="f_accept" value="Accept">
377 <input type="submit" name="f_delete" value="Delete">
383 } // else of if ($action ...
384 } // else of if ($do ...