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_base.phh");
51 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
52 require_once($G_base."briskin5/Obj/briskin5.phh");
53 require_once($G_base."briskin5/Obj/placing.phh");
54 require_once($G_base."spush/brisk-spush.phh");
55 require_once($G_base."index_wr.php");
59 GLOBAL $G_alarm_passwd, $sess, $_POST, $_SERVER;
63 $ip = $_SERVER["REMOTE_ADDR"];
65 $private = md5($G_alarm_passwd.$ip.$sess);
66 $cmd = array ("cmd" => "userauth", "sess" => $sess, "private" => $private, "the_end" => "true");
67 $cmd_ser = cmd_serialize($cmd);
68 $cmd_len = mb_strlen($cmd_ser, "ASCII");
71 if (($socket = stream_socket_client("unix://".USOCK_PATH."2")) == FALSE)
74 if (($rwr = fwrite($socket, $cmd_ser, $cmd_len)) == FALSE
79 if (($buf = fread($socket, 4096)) == FALSE)
81 $res = cmd_deserialize($buf);
83 if (!isset($res['val']) || $res['val'] != 200)
98 GLOBAL $G_dbpfx, $G_lang, $G_alarm_passwd, $G_domain, $G_webbase;
99 GLOBAL $mlang_umgmt, $mlang_indwr, $f_mailusers, $sess, $_POST, $_SERVER;
104 if (check_auth() == FALSE) {
105 echo "Authentication failed";
110 if (isset($_GET['f_nocheck'])) {
114 if (isset($_GET['do']) && $_GET['do'] == 'newuser') {
115 if (isset($_POST['f_accept'])) {
118 else if (isset($_POST['f_delete'])) {
125 if ($action == "accept") {
126 foreach($_POST as $key => $value) {
127 if (substr($key, 0, 9) != "f_newuser")
130 $id = (int)substr($key, 9);
134 // check existence of username or email
138 if (($bdb = BriskDB::create()) == FALSE)
141 // retrieve list added users
143 SELECT usr.*, guar.login AS guar_login
145 JOIN %susers AS guar ON guar.code = usr.guar_code
146 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
147 AND usr.disa_reas = %d AND usr.code = %d;",
149 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
150 USER_DIS_REA_NU_ADDED, $id);
151 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
152 log_crit("stat-day: select from tournaments failed");
155 $usr_n = pg_numrows($usr_pg);
157 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
162 $usr_obj = pg_fetch_object($usr_pg, 0);
164 $bdb->transaction('BEGIN');
168 if (($bdb->user_update_flag_ty($usr_obj->code,
169 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_ADDED,
170 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_MAILED)) == FALSE) {
175 if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
176 fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
179 $hash = md5($curtime . $G_alarm_passwd . $usr_obj->login . $usr_obj->email);
181 $confirm_page = sprintf("http://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
182 $G_domain, $G_webbase, $mail_code, $hash);
183 $subj = $mlang_indwr['nu_msubj'][$G_lang];
184 $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang],
185 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
186 $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang],
187 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
189 $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
190 $curtime, $subj, $body_txt, $body_htm, $hash);
192 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
194 fprintf(STDERR, "ERROR: mail send FAILED\n");
198 if ($mail_item->store($bdb) == FALSE) {
200 fprintf(STDERR, "ERROR: store mail FAILED\n");
203 $status .= sprintf("status change for %s: SUCCESS<br>", $usr_obj->login);
204 $bdb->transaction('COMMIT');
208 $status .= sprintf("Error occurred during accept action<br>");
210 $bdb->transaction('ROLLBACK');
217 if (($bdb = BriskDB::create()) == FALSE) {
218 log_crit("stat-day: database connection failed");
222 // retrieve list added users
224 SELECT usr.*, guar.login AS guar_login
226 JOIN %susers AS guar ON guar.code = usr.guar_code
227 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
228 AND usr.disa_reas = %d;",
230 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
231 USER_DIS_REA_NU_ADDED);
232 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
233 log_crit("stat-day: select from tournaments failed");
236 $usr_n = pg_numrows($usr_pg);
237 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
238 for ($i = 0 ; $i < $usr_n ; $i++) {
239 $usr_obj = pg_fetch_object($usr_pg, $i);
241 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
242 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
243 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
248 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
249 <title>Brisk: new imported users management.</title>
252 <h2> New imported users management.</h2>
253 <?php if ($status != "") { echo "$status"; } ?>
254 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
260 <input type="submit" name="f_accept" value="Newuser Accept">
261 <input type="submit" name="f_delete" value="Newuser Delete">
268 printf("Some error occurred during newuser visualization\n");
272 if (isset($_GET['do']) && $_GET['do'] == 'mailed') {
273 if (isset($_POST['f_resend'])) {
276 else if (isset($_POST['f_delete'])) {
283 if ($action == "resend") {
284 foreach($_POST as $key => $value) {
285 if (substr($key, 0, 9) != "f_newuser")
288 $id = (int)substr($key, 9);
294 if (($bdb = BriskDB::create()) == FALSE) {
298 // retrieve list added users
300 SELECT mail.*, usr.email AS email
302 JOIN %smails AS mail ON mail.ucode = usr.code
303 WHERE mail.ucode = %d AND mail.type = %d",
304 $G_dbpfx, $G_dbpfx, $id, MAIL_TYP_CHECK);
305 if (($mai_pg = pg_query($bdb->dbconn->db(), $mai_sql)) == FALSE) {
306 log_crit("retrieve mail failed");
310 $mai_n = pg_numrows($mai_pg);
312 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
316 $mai_obj = pg_fetch_object($mai_pg, 0);
317 $mail = MailDBItem::MailDBItemFromRecord($mai_obj);
319 if (brisk_mail($mai_obj->email, $mail->subj, $mail->body_txt, $mail->body_htm) == FALSE) {
321 $status .= sprintf("Send mail filed for user id %d<br>\n", $id);
327 $status .= sprintf("Error occurred during resend action<br>");
334 if (($bdb = BriskDB::create()) == FALSE) {
335 log_crit("stat-day: database connection failed");
339 // retrieve list added users
341 SELECT usr.*, guar.login AS guar_login
343 JOIN %susers AS guar ON guar.code = usr.guar_code
344 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
345 AND usr.disa_reas = %d;",
347 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
348 USER_DIS_REA_NU_MAILED);
349 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
350 log_crit("stat-day: select from tournaments failed");
353 $usr_n = pg_numrows($usr_pg);
354 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
355 for ($i = 0 ; $i < $usr_n ; $i++) {
356 $usr_obj = pg_fetch_object($usr_pg, $i);
358 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
359 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
360 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
365 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
366 <title>Brisk: new mailed users management.</title>
369 <h2> New mailed users management.</h2>
370 <?php if ($status != "") { echo "$status"; } ?>
371 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
377 <input type="submit" name="f_resend" value="Mailed Resend">
378 <input type="submit" name="f_delete" value="Mailed Delete">
385 printf("Some error occurred during newuser visualization\n");
388 else { // if ($_GET['do'] ...
389 if (isset($_POST['f_accept'])) {
392 else if (isset($_POST['f_delete'])) {
399 if ($action == "accept") {
400 if (($bdb = BriskDB::create()) == FALSE) {
401 log_crit("stat-day: database connection failed");
405 foreach($_POST as $key => $value) {
406 if (substr($key, 0, 9) != "f_newuser")
409 $id = (int)substr($key, 9);
414 // retrieve list of active tournaments
416 SELECT usr.*, guar.login AS guar_login
418 JOIN %susers AS guar ON guar.code = usr.guar_code
419 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
420 AND usr.disa_reas = %d AND usr.code = %d;",
422 USER_FLAG_TY_ALL, USER_FLAG_TY_DISABLE,
423 USER_DIS_REA_NU_TOBECHK, $id);
424 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
425 log_crit("stat-day: select from tournaments failed");
428 $usr_obj = pg_fetch_object($usr_pg, 0);
430 printf("KEY: %s: %s %s<br>\n", $id, $value, $usr_obj->login);
432 $passwd = passwd_gen();
434 if (($bdb->user_update_passwd($usr_obj->code, $passwd)) == FALSE) {
439 if (($bdb->user_update_flag_ty($usr_obj->code,
440 USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_TOBECHK,
441 USER_FLAG_TY_NORM, USER_DIS_REA_NONE)) == FALSE) {
446 $bdb->user_update_login_time($usr_obj->code, 0);
449 $subj = $mlang_umgmt['nu_psubj'][$G_lang];
450 $body_txt = sprintf($mlang_umgmt['nu_ptext'][$G_lang],
451 $usr_obj->login, $passwd);
452 $body_htm = sprintf($mlang_umgmt['nu_phtml'][$G_lang],
453 $usr_obj->login, $passwd);
455 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
457 fprintf(STDERR, "ERROR: mail send FAILED\n");
465 if (($bdb = BriskDB::create()) == FALSE) {
466 log_crit("stat-day: database connection failed");
470 // retrieve list of active tournaments
472 SELECT usr.*, guar.login AS guar_login
474 JOIN %susers AS guar ON guar.code = usr.guar_code
475 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
476 AND usr.disa_reas = %d;",
478 USER_FLAG_TY_ALL, USER_FLAG_TY_DISABLE,
479 USER_DIS_REA_NU_TOBECHK);
480 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
481 log_crit("stat-day: select from tournaments failed");
485 $usr_n = pg_numrows($usr_pg);
486 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
487 for ($i = 0 ; $i < $usr_n ; $i++) {
488 $usr_obj = pg_fetch_object($usr_pg, $i);
490 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
491 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
492 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
497 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
498 <title>Brisk: email verified user management.</title>
501 <h2> E-mail verified user management.</h2>
502 <?php if ($status != "") { echo "$status"; } ?>
503 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
509 <input type="submit" name="f_accept" value="Accept">
510 <input type="submit" name="f_delete" value="Delete">
516 } // else of if ($action ...
517 } // else of if ($do ...