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.<br><br>Per accedere al sito d\'ora in poi potrai usare l\' utente \'%s\' e la password \'%s\'.<br><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)
100 border-collapse: collapse;
105 border: 1px solid black;
111 GLOBAL $s_style, $G_dbpfx, $G_lang, $G_alarm_passwd, $G_domain, $G_webbase;
112 GLOBAL $mlang_umgmt, $mlang_indwr, $f_mailusers, $sess, $_POST, $_SERVER;
118 if (check_auth() == FALSE) {
119 echo "Authentication failed";
124 if (isset($_GET['f_nocheck'])) {
128 if (isset($_GET['do']) && $_GET['do'] == 'newuser') {
129 if (isset($_POST['f_accept'])) {
132 else if (isset($_POST['f_delete'])) {
139 if ($action == "accept") {
140 foreach($_POST as $key => $value) {
141 if (substr($key, 0, 9) != "f_newuser")
144 $id = (int)substr($key, 9);
148 // check existence of username or email
152 if (($bdb = BriskDB::create()) == FALSE)
155 // retrieve list added users
157 SELECT usr.*, guar.login AS guar_login
159 JOIN %susers AS guar ON guar.code = usr.guar_code
160 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
161 AND usr.disa_reas = %d AND usr.code = %d;",
163 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
164 USER_DIS_REA_NU_ADDED, $id);
165 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
166 log_crit("stat-day: select from tournaments failed");
169 $usr_n = pg_numrows($usr_pg);
171 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
176 $usr_obj = pg_fetch_object($usr_pg, 0);
178 $bdb->transaction('BEGIN');
182 if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
183 TRUE, USER_DIS_REA_NU_ADDED,
184 TRUE, USER_DIS_REA_NU_MAILED)) == FALSE) {
189 if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
190 fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
193 $hash = md5($curtime . $G_alarm_passwd . $usr_obj->login . $usr_obj->email);
195 $confirm_page = sprintf("http://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
196 $G_domain, $G_webbase, $mail_code, $hash);
197 $subj = $mlang_indwr['nu_msubj'][$G_lang];
198 if (($usr_obj->type & USER_FLAG_TY_APPR) == USER_FLAG_TY_APPR) {
199 $body_txt = sprintf($mlang_indwr['ap_mtext'][$G_lang],
200 $cli_name, $confirm_page);
201 $body_htm = sprintf($mlang_indwr['ap_mhtml'][$G_lang],
202 $cli_name, $confirm_page);
205 $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang],
206 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
207 $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang],
208 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
211 $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
212 $curtime, $subj, $body_txt, $body_htm, $hash);
214 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
216 fprintf(STDERR, "ERROR: mail send FAILED\n");
220 if ($mail_item->store($bdb) == FALSE) {
222 fprintf(STDERR, "ERROR: store mail FAILED\n");
225 $status .= sprintf("status change for %s: SUCCESS<br>", $usr_obj->login);
226 $bdb->transaction('COMMIT');
230 $status .= sprintf("Error occurred during accept action<br>");
232 $bdb->transaction('ROLLBACK');
239 if (($bdb = BriskDB::create()) == FALSE) {
240 log_crit("stat-day: database connection failed");
244 // retrieve list added users
246 SELECT usr.*, guar.login AS guar_login
248 JOIN %susers AS guar ON guar.code = usr.guar_code
249 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
250 AND usr.disa_reas = %d
251 ORDER BY usr.lintm;",
253 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
254 USER_DIS_REA_NU_ADDED);
255 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
256 log_crit("stat-day: select from tournaments failed");
259 $usr_n = pg_numrows($usr_pg);
260 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
261 for ($i = 0 ; $i < $usr_n ; $i++) {
262 $usr_obj = pg_fetch_object($usr_pg, $i);
264 $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",
265 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
266 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
273 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
274 <title>Brisk: new imported users management.</title>
275 <?php echo "$s_style"; ?>
278 <h2> New imported users management.</h2>
279 <?php if ($status != "") { echo "$status"; } ?>
280 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
281 <table class="the_tab">
286 <input type="submit" name="f_accept" value="Newuser Accept">
287 <input type="submit" name="f_delete" value="Newuser Delete">
294 printf("Some error occurred during newuser visualization\n");
298 if (isset($_GET['do']) && $_GET['do'] == 'mailed') {
299 if (isset($_POST['f_resend'])) {
302 else if (isset($_POST['f_delete'])) {
309 if ($action == "resend") {
310 foreach($_POST as $key => $value) {
311 if (substr($key, 0, 9) != "f_newuser")
314 $id = (int)substr($key, 9);
320 if (($bdb = BriskDB::create()) == FALSE) {
324 // retrieve list added users
326 SELECT mail.*, usr.email AS email
328 JOIN %smails AS mail ON mail.ucode = usr.code
329 WHERE mail.ucode = %d AND mail.type = %d",
330 $G_dbpfx, $G_dbpfx, $id, MAIL_TYP_CHECK);
331 if (($mai_pg = pg_query($bdb->dbconn->db(), $mai_sql)) == FALSE) {
332 log_crit("retrieve mail failed");
336 $mai_n = pg_numrows($mai_pg);
338 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
342 $mai_obj = pg_fetch_object($mai_pg, 0);
343 $mail = MailDBItem::MailDBItemFromRecord($mai_obj);
345 if (brisk_mail($mai_obj->email, $mail->subj, $mail->body_txt, $mail->body_htm) == FALSE) {
347 $status .= sprintf("Send mail filed for user id %d<br>\n", $id);
353 $status .= sprintf("Error occurred during resend action<br>");
360 if (($bdb = BriskDB::create()) == FALSE) {
361 log_crit("stat-day: database connection failed");
365 // retrieve list added users
367 SELECT usr.*, guar.login AS guar_login
369 JOIN %susers AS guar ON guar.code = usr.guar_code
370 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
371 AND usr.disa_reas = %d
372 ORDER BY usr.lintm;",
374 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
375 USER_DIS_REA_NU_MAILED);
376 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
377 log_crit("stat-day: select from tournaments failed");
380 $usr_n = pg_numrows($usr_pg);
381 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
382 for ($i = 0 ; $i < $usr_n ; $i++) {
383 $usr_obj = pg_fetch_object($usr_pg, $i);
385 $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",
386 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
387 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
392 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
393 <title>Brisk: new mailed users management.</title>
394 <?php echo "$s_style"; ?>
397 <h2> New mailed users management.</h2>
398 <?php if ($status != "") { echo "$status"; } ?>
399 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
400 <table class="the_tab">
405 <input type="submit" name="f_resend" value="Mailed Resend">
406 <input type="submit" name="f_delete" value="Mailed Delete">
413 printf("Some error occurred during newuser visualization\n");
416 else { // if ($_GET['do'] ...
417 if (isset($_POST['f_accept'])) {
420 else if (isset($_POST['f_delete'])) {
427 if ($action == "accept") {
428 if (($bdb = BriskDB::create()) == FALSE) {
429 log_crit("stat-day: database connection failed");
433 foreach($_POST as $key => $value) {
434 if (substr($key, 0, 9) != "f_newuser")
437 $id = (int)substr($key, 9);
442 // retrieve list of active tournaments
444 SELECT usr.*, guar.login AS guar_login
446 JOIN %susers AS guar ON guar.code = usr.guar_code
447 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
448 AND usr.disa_reas = %d AND usr.code = %d;",
450 USER_FLAG_TY_ALL & ~USER_FLAG_TY_APPR, USER_FLAG_TY_DISABLE,
451 USER_DIS_REA_NU_TOBECHK, $id);
452 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
453 log_crit("stat-day: select from tournaments failed");
456 $usr_obj = pg_fetch_object($usr_pg, 0);
458 printf("KEY: %s: %s %s<br>\n", $id, $value, $usr_obj->login);
460 $passwd = passwd_gen();
462 if (($bdb->user_update_passwd($usr_obj->code, $passwd)) == FALSE) {
467 if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
468 TRUE, USER_DIS_REA_NU_TOBECHK,
469 FALSE, USER_DIS_REA_NONE)) == FALSE) {
474 $bdb->user_update_login_time($usr_obj->code, 0);
477 $subj = $mlang_umgmt['nu_psubj'][$G_lang];
478 $body_txt = sprintf($mlang_umgmt['nu_ptext'][$G_lang],
479 $usr_obj->login, $passwd);
480 $body_htm = sprintf($mlang_umgmt['nu_phtml'][$G_lang],
481 $usr_obj->login, $passwd);
483 log_step(sprintf("[%s], [%s], [%s], [%s]\n", $usr_obj->email, $subj, $body_txt, $body_htm));
486 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
488 fprintf(STDERR, "ERROR: mail send FAILED\n");
496 if (($bdb = BriskDB::create()) == FALSE) {
497 log_crit("stat-day: database connection failed");
501 // retrieve list of active tournaments
503 SELECT usr.*, guar.login AS guar_login
505 JOIN %susers AS guar ON guar.code = usr.guar_code
506 WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) )
507 AND usr.disa_reas = %d
508 ORDER BY usr.lintm;",
510 USER_FLAG_TY_ALL & ~USER_FLAG_TY_APPR, USER_FLAG_TY_DISABLE,
511 USER_DIS_REA_NU_TOBECHK);
512 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
513 log_crit("stat-day: select from tournaments failed");
517 $usr_n = pg_numrows($usr_pg);
518 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Apprendice</th><th>Date</th></tr>";
519 for ($i = 0 ; $i < $usr_n ; $i++) {
520 $usr_obj = pg_fetch_object($usr_pg, $i);
522 $tab_lines .= sprintf("<tr><td><input name=\"f_newuser%d\" type=\"checkbox\" %s></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
523 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
524 eschtml($usr_obj->login), eschtml($usr_obj->guar_login),
525 ($usr_obj->type & USER_FLAG_TY_APPR ? "Yes" : "No"),
531 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
532 <title>Brisk: email verified user management.</title>
533 <?php echo "$s_style"; ?>
536 <h2> E-mail verified user management.</h2>
537 <?php if ($status != "") { echo "$status"; } ?>
538 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
539 <table class="the_tab">
544 <input type="submit" name="f_accept" value="Accept">
545 <input type="submit" name="f_delete" value="Delete">
551 } // else of if ($action ...
552 } // else of if ($do ...