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.
25 foreach (array("HTTP_HOST", "DOCUMENT_ROOT") as $i) {
26 if (isset($_SERVER[$i])) {
31 foreach (array("pazz") as $i) {
32 if (isset($_POST[$i])) {
37 foreach (array("sess") as $i) {
38 if (isset($_COOKIE[$i])) {
43 foreach (array("sess") as $i) {
44 if (isset($_COOKIE[$i])) {
51 $mlang_umgmt = array( 'nu_psubj' => array( 'it' => 'Brisk: credenziali di accesso.',
52 'en' => 'Brisk: credentials.'),
53 'nu_ptext' => array( 'it' =>
54 'Ciao, sono l\' amministratore del sito di Brisk.
56 La verifica del tuo indirizzo di posta elettronica e del tuo nickname è andata a buon fine, per accedere al sito
57 d\'ora in poi potrai utilizzare l\' utente \'%s\' e la password \'%s\'.
59 Benvenuto e buone partite, mop.',
60 'en' => 'EN ptext [%s] [%s]'),
61 'nu_phtml' => array( 'it' => 'Ciao, sono l\' amministratore del sito di Brisk.<br><br>
62 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>
63 Benvenuto e buone partite, mop.<br>',
64 'en' => 'EN phtml [%s] [%s]')
68 ini_set("max_execution_time", "240");
70 require_once($G_base."Obj/brisk.phh");
71 require_once($G_base."Obj/user.phh");
72 require_once($G_base."Obj/auth.phh");
73 require_once($G_base."Obj/mail.phh");
74 require_once($G_base."Obj/dbase_base.phh");
75 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
76 require_once($G_base."briskin5/Obj/briskin5.phh");
77 require_once($G_base."briskin5/Obj/placing.phh");
78 require_once($G_base."spush/brisk-spush.phh");
79 require_once($G_base."index_wr.php");
83 GLOBAL $G_alarm_passwd, $sess, $_POST, $_SERVER;
87 if (array_key_exists("HTTP_X_REAL_IP", $_SERVER)) {
88 $ip = $_SERVER["HTTP_X_REAL_IP"];
91 $ip = $_SERVER["REMOTE_ADDR"];
94 $private = md5($G_alarm_passwd.$ip.$sess);
95 $cmd = array ("cmd" => "userauth", "sess" => $sess, "private" => $private, "the_end" => "true");
96 $cmd_ser = cmd_serialize($cmd);
97 $cmd_len = mb_strlen($cmd_ser, "ASCII");
100 if (($socket = stream_socket_client("unix://".USOCK_PATH."2")) == FALSE)
103 if (($rwr = fwrite($socket, $cmd_ser, $cmd_len)) == FALSE
108 if (($buf = fread($socket, 4096)) == FALSE)
110 $res = cmd_deserialize($buf);
112 if (!isset($res['val']) || $res['val'] != 200)
117 if ($socket != FALSE)
121 echo "STP: $stp<br>";
129 border-collapse: collapse;
134 border: 1px solid black;
140 GLOBAL $s_style, $G_dbpfx, $G_lang, $G_alarm_passwd, $G_proto, $G_domain, $G_webbase;
141 GLOBAL $mlang_umgmt, $mlang_indwr, $f_mailusers, $sess, $_POST, $_SERVER;
147 if (check_auth() == FALSE) {
148 echo "Authentication failed";
153 if (isset($_GET['f_nocheck'])) {
157 if (isset($_GET['do']) && $_GET['do'] == 'newuser') {
158 if (isset($_POST['f_accept'])) {
161 else if (isset($_POST['f_delete'])) {
168 if ($action == "accept") {
169 foreach($_POST as $key => $value) {
170 if (substr($key, 0, 9) != "f_newuser")
173 $id = (int)substr($key, 9);
177 // check existence of username or email
181 if (($bdb = BriskDB::create()) == FALSE)
184 // retrieve list added users
186 SELECT usr.*, guar.login AS guar_login
188 JOIN %susers AS guar ON guar.code = usr.guar_code
189 WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
190 AND usr.disa_reas = %d AND usr.code = %d;",
192 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
193 USER_DIS_REA_NU_ADDED, $id);
194 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
195 log_crit("stat-day: select from tournaments failed");
198 $usr_n = pg_numrows($usr_pg);
200 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
205 $usr_obj = pg_fetch_object($usr_pg, 0);
207 $bdb->transaction('BEGIN');
211 if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
212 TRUE, USER_DIS_REA_NU_ADDED,
213 TRUE, USER_DIS_REA_NU_MAILED)) == FALSE) {
218 if (($mail_code = $bdb->mail_reserve_code()) == FALSE) {
219 fprintf(STDERR, "ERROR: mail reserve code FAILED\n");
222 $hash = md5($curtime . $G_alarm_passwd . $usr_obj->login . $usr_obj->email);
224 $confirm_page = sprintf("%s://%s/%s/mailmgr.php?f_act=checkmail&f_code=%d&f_hash=%s",
225 $G_proto, $G_domain, $G_webbase, $mail_code, $hash);
226 $subj = $mlang_indwr['nu_msubj'][$G_lang];
227 if (($usr_obj->type & USER_FLAG_TY_APPR) == USER_FLAG_TY_APPR) {
228 $body_txt = sprintf($mlang_indwr['ap_mtext'][$G_lang],
229 $usr_obj->login, $confirm_page);
230 $body_htm = sprintf($mlang_indwr['ap_mhtml'][$G_lang],
231 $usr_obj->login, $confirm_page);
234 $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang],
235 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
236 $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang],
237 $usr_obj->guar_login, $usr_obj->login, $confirm_page);
240 $mail_item = new MailDBItem($mail_code, $usr_obj->code, MAIL_TYP_CHECK,
241 $curtime, $subj, $body_txt, $body_htm, $hash);
243 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
245 fprintf(STDERR, "ERROR: mail send FAILED\n");
249 if ($mail_item->store($bdb) == FALSE) {
251 fprintf(STDERR, "ERROR: store mail FAILED\n");
254 $status .= sprintf("status change for %s: SUCCESS<br>", $usr_obj->login);
255 $bdb->transaction('COMMIT');
259 $status .= sprintf("Error occurred during accept action<br>");
261 $bdb->transaction('ROLLBACK');
265 } // else if ($action == "accept") {
269 if (($bdb = BriskDB::create()) == FALSE) {
270 log_crit("stat-day: database connection failed");
274 // retrieve list added users
276 SELECT usr.*, guar.login AS guar_login
278 JOIN %susers AS guar ON guar.code = usr.guar_code
279 WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
280 AND usr.disa_reas = %d ORDER BY usr.lintm;",
282 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
283 USER_DIS_REA_NU_ADDED);
284 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
285 log_crit("stat-day: select from tournaments failed");
288 $usr_n = pg_numrows($usr_pg);
289 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
290 for ($i = 0 ; $i < $usr_n ; $i++) {
291 $usr_obj = pg_fetch_object($usr_pg, $i);
293 $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",
294 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
295 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
302 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
303 <title>Brisk: new imported users management.</title>
304 <?php echo "$s_style"; ?>
307 <h2> New imported users management.</h2>
308 <?php if ($status != "") { echo "$status"; } ?>
309 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
310 <table class="the_tab">
315 <input type="submit" name="f_accept" value="Newuser Accept">
316 <input type="submit" name="f_delete" value="Newuser Delete">
323 printf("Some error occurred during newuser visualization\n");
327 if (isset($_GET['do']) && $_GET['do'] == 'mailed') {
328 if (isset($_POST['f_resend'])) {
331 else if (isset($_POST['f_delete'])) {
338 if ($action == "resend") {
339 foreach($_POST as $key => $value) {
340 if (substr($key, 0, 9) != "f_newuser")
343 $id = (int)substr($key, 9);
349 if (($bdb = BriskDB::create()) == FALSE) {
353 // retrieve list added users
355 SELECT mail.*, usr.email AS email
357 JOIN %smails AS mail ON mail.ucode = usr.code
358 WHERE mail.ucode = %d AND mail.type = %d",
359 $G_dbpfx, $G_dbpfx, $id, MAIL_TYP_CHECK);
360 if (($mai_pg = pg_query($bdb->dbconn->db(), $mai_sql)) == FALSE) {
361 log_crit("retrieve mail failed");
365 $mai_n = pg_numrows($mai_pg);
367 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
371 $mai_obj = pg_fetch_object($mai_pg, 0);
372 $mail = MailDBItem::MailDBItemFromRecord($mai_obj);
374 if (brisk_mail($mai_obj->email, $mail->subj, $mail->body_txt, $mail->body_htm) == FALSE) {
376 $status .= sprintf("Send mail filed for user id %d<br>\n", $id);
382 $status .= sprintf("Error occurred during resend action<br>");
389 if (($bdb = BriskDB::create()) == FALSE) {
390 log_crit("stat-day: database connection failed");
394 // retrieve list added users
396 SELECT usr.*, guar.login AS guar_login
398 JOIN %susers AS guar ON guar.code = usr.guar_code
399 WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
400 AND usr.disa_reas = %d ORDER BY usr.lintm;",
402 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
403 USER_DIS_REA_NU_MAILED);
404 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
405 log_crit("stat-day: select from tournaments failed");
408 $usr_n = pg_numrows($usr_pg);
409 $tab_lines = "<tr><th></th><th>User</th><th>Guar</th><th>Date</th></tr>";
410 for ($i = 0 ; $i < $usr_n ; $i++) {
411 $usr_obj = pg_fetch_object($usr_pg, $i);
413 $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",
414 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
415 eschtml($usr_obj->login), eschtml($usr_obj->guar_login), $usr_obj->lintm);
420 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
421 <title>Brisk: new mailed users management.</title>
422 <?php echo "$s_style"; ?>
425 <h2> New mailed users management.</h2>
426 <?php if ($status != "") { echo "$status"; } ?>
427 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
428 <table class="the_tab">
433 <input type="submit" name="f_resend" value="Mailed Resend">
434 <input type="submit" name="f_delete" value="Mailed Delete">
441 printf("Some error occurred during newuser visualization\n");
444 else { // if ($_GET['do'] ...
445 if (isset($_POST['f_accept'])) {
448 else if (isset($_POST['f_delete'])) {
455 if ($action == "accept") {
456 if (($bdb = BriskDB::create()) == FALSE) {
457 log_crit("stat-day: database connection failed");
461 foreach($_POST as $key => $value) {
462 if (substr($key, 0, 9) != "f_newuser")
465 $id = (int)substr($key, 9);
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 AND usr.code = %d;",
478 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
479 USER_DIS_REA_NU_TOBECHK, $id);
480 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
481 log_crit("stat-day: select from tournaments failed");
484 $usr_obj = pg_fetch_object($usr_pg, 0);
486 printf("KEY: %s: %s %s<br>\n", $id, $value, $usr_obj->login);
488 $passwd = passwd_gen();
490 if (($bdb->user_update_passwd($usr_obj->code, $passwd)) == FALSE) {
495 if (($bdb->user_update_flag_ty($usr_obj->code, USER_FLAG_TY_DISABLE,
496 TRUE, USER_DIS_REA_NU_TOBECHK,
497 FALSE, USER_DIS_REA_NONE)) == FALSE) {
502 $bdb->user_update_login_time($usr_obj->code, 0);
505 $subj = $mlang_umgmt['nu_psubj'][$G_lang];
506 $body_txt = sprintf($mlang_umgmt['nu_ptext'][$G_lang],
507 $usr_obj->login, $passwd);
508 $body_htm = sprintf($mlang_umgmt['nu_phtml'][$G_lang],
509 $usr_obj->login, $passwd);
511 log_step(sprintf("[%s], [%s], [%s], [%s]\n", $usr_obj->email, $subj, $body_txt, $body_htm));
514 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
516 fprintf(STDERR, "ERROR: mail send FAILED\n");
524 else if ($action == "delete") {
525 foreach($_POST as $key => $value) {
526 if (substr($key, 0, 9) != "f_newuser")
529 $id = (int)substr($key, 9);
533 // check existence of username or email
537 if (($bdb = BriskDB::create()) == FALSE)
540 // retrieve list added users
542 SELECT usr.*, guar.login AS guar_login
544 JOIN %susers AS guar ON guar.code = usr.guar_code
545 WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
546 AND usr.disa_reas = %d AND usr.code = %d;",
548 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
549 USER_DIS_REA_NU_TOBECHK, $id);
552 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
553 log_crit("stat-day: select from tournaments failed");
556 $usr_n = pg_numrows($usr_pg);
558 $status .= sprintf("Inconsistency for code %d, returned %d records, skipped.<br>",
563 $usr_obj = pg_fetch_object($usr_pg, 0);
565 $bdb->transaction('BEGIN');
568 $del_sql = sprintf("DELETE FROM %susers WHERE code = %d;",
569 $G_dbpfx, $usr_obj->code);
571 if (($del_pg = pg_query($bdb->dbconn->db(), $del_sql)) == FALSE) {
572 log_crit("stat-day: select from tournaments failed");
576 // FIXME: add to index_wr.php strings
577 $subj = "Brisk: nickname rifiutato";
578 // the same for both cases:
579 // if (($usr_obj->type & USER_FLAG_TY_APPR) == USER_FLAG_TY_APPR) {
580 $body_txt = sprintf('Ciao, sono l\' amministratore del sito di Brisk.
582 Ti volevo segnalare che il nickname \'%s\' con cui ti volevi registrare
583 non ha superato la fase di verifica manuale; il motivo può essere
584 la sua illeggibilità per gli altri utenti o il contenuto poco ortodosso
585 o troppo aggressivo o ci sono troppe cifre consecutive o qualcosa del genere.
587 La procedura di registrazione va ripetuta.
589 Saluti e buone partite, mop.', $usr_obj->login);
591 $body_htm = sprintf('Ciao, sono l\' amministratore del sito di Brisk.<br><br>
592 Ti volevo segnalare che il nickname \'%s\' con cui ti volevi registrare
593 non ha superato la fase di verifica manuale; il motivo può essere
594 la sua illeggibilità per gli altri utenti o il contenuto poco ortodosso
595 o troppo aggressivo o ci sono troppe cifre consecutive o qualcosa del genere.<br><br>
596 La procedura di registrazione va ripetuta.<br><br>
597 Saluti e buone partite, mop.', $usr_obj->login);
600 /* $body_txt = sprintf($mlang_indwr['nu_mtext'][$G_lang], */
601 /* $usr_obj->guar_login, $usr_obj->login, $confirm_page); */
602 /* $body_htm = sprintf($mlang_indwr['nu_mhtml'][$G_lang], */
603 /* $usr_obj->guar_login, $usr_obj->login, $confirm_page); */
606 if (brisk_mail($usr_obj->email, $subj, $body_txt, $body_htm) == FALSE) {
608 fprintf(STDERR, "ERROR: mail send FAILED\n");
611 $status .= sprintf("user delete for %s: SUCCESS<br>", $usr_obj->login);
612 $bdb->transaction('COMMIT');
616 $status .= sprintf("Error occurred during accept action<br>");
618 $bdb->transaction('ROLLBACK');
621 printf("Registration %s for login %s deleted<br>\n", $usr_obj->code, $usr_obj->login);
626 if (($bdb = BriskDB::create()) == FALSE) {
627 log_crit("stat-day: database connection failed");
631 // retrieve list of active tournaments
633 SELECT usr.*, guar.login AS guar_login
635 JOIN %susers AS guar ON guar.code = usr.guar_code
636 WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer))
637 AND usr.disa_reas = %d ORDER BY usr.lintm;",
639 USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE,
640 USER_DIS_REA_NU_TOBECHK);
641 if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) {
642 log_crit("stat-day: select from tournaments failed");
646 $usr_n = pg_numrows($usr_pg);
647 $tab_lines = "<tr><th></th><th>User</th><th>EMail</th><th>Guar</th><th>Apprendice</th><th>Date</th></tr>";
648 for ($i = 0 ; $i < $usr_n ; $i++) {
649 $usr_obj = pg_fetch_object($usr_pg, $i);
651 $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><td>%s</td></tr>\n",
652 $usr_obj->code, ($nocheck ? "" : "CHECKED"),
653 eschtml($usr_obj->login), eschtml($usr_obj->email), eschtml($usr_obj->guar_login),
654 ($usr_obj->type & USER_FLAG_TY_APPR ? "Yes" : "No"),
660 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
661 <title>Brisk: email verified user management.</title>
662 <?php echo "$s_style"; ?>
665 <h2> E-mail verified user management.</h2>
666 <?php if ($status != "") { echo "$status"; } ?>
667 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
668 <table class="the_tab">
673 <input type="submit" name="f_accept" value="Accept">
674 <input type="submit" name="f_delete" value="Delete">
680 } // else of if ($action ...
681 } // else of if ($do ...