From 66f94441ec85a5555c7280aff03ba7e5d661c364 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 15 Oct 2015 07:17:24 +0200 Subject: [PATCH] apprentice workflow completed --- .gitignore | 3 ++ TODO.txt | 10 +++-- bin/briscreen | 2 + doc/RULES.txt | 20 ++++++++++ sql/sql.d/071-apprentice.sql | 8 ++++ test/ip_test.php | 10 +++++ web/Obj/brisk.phh | 6 +-- web/Obj/dbase_pgsql.phh | 72 ++++++++++++++++++++++++++++++++---- web/Obj/mail.phh | 4 +- web/Obj/user.phh | 5 +++ web/commons.js | 2 +- web/index_wr.php | 6 ++- web/usermgmt.php | 23 +++++------- 13 files changed, 140 insertions(+), 31 deletions(-) create mode 100755 bin/briscreen create mode 100644 doc/RULES.txt create mode 100644 sql/sql.d/071-apprentice.sql create mode 100755 test/ip_test.php diff --git a/.gitignore b/.gitignore index bea5755..cf9f65b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ TAGS +doc/relict_output.txt +web/briskin5/players-corr.php + diff --git a/TODO.txt b/TODO.txt index f39c606..a84c3e9 100644 --- a/TODO.txt +++ b/TODO.txt @@ -12,11 +12,15 @@ DONE - usermgmt extension DONE - add close button DONE - add apprentice icon - - guarantee for apprentice - - match counter + - match counters + . sql for match counters + . migration script for old users Phase2 - - MENTORS + - new info system + - guarantee for apprentice + + - MENTORS - listen all - BUDDY LIST diff --git a/bin/briscreen b/bin/briscreen new file mode 100755 index 0000000..f4118ce --- /dev/null +++ b/bin/briscreen @@ -0,0 +1,2 @@ +#!/bin/bash +su - -c "su - -c \"script -q -c \\\"screen -r\\\" /dev/null \" www-data" diff --git a/doc/RULES.txt b/doc/RULES.txt new file mode 100644 index 0000000..5e3f6c4 --- /dev/null +++ b/doc/RULES.txt @@ -0,0 +1,20 @@ + +FINISH REASON: + + 1) complete game | 2) all pass | 3) abandon because too less points + ----------------------+-------------------+---------------------------------------------- + mult deps on win | mult_inc() | mult_inc() + calculate_points() | old_reason_set() | old_reason_set() + game_next(1) | game_next(1) | game_next(0) + game_init() | game_init() | game_init() + + set old_reason + mult++ + game_next(1) + game_init() + + 3) + mult++ + set old_reason + game_next(0) + game_init() diff --git a/sql/sql.d/071-apprentice.sql b/sql/sql.d/071-apprentice.sql new file mode 100644 index 0000000..c3a0193 --- /dev/null +++ b/sql/sql.d/071-apprentice.sql @@ -0,0 +1,8 @@ +-- +-- Table to manage mails sent to users +-- +DROP TABLE #PFX#selfreg_chk; +CREATE TABLE #PFX#selfreg_chk ( + ip integer, -- ip v4 address + atime timestamp DEFAULT to_timestamp(0) -- access time + ); diff --git a/test/ip_test.php b/test/ip_test.php new file mode 100755 index 0000000..f2660c5 --- /dev/null +++ b/test/ip_test.php @@ -0,0 +1,10 @@ +#!/usr/bin/php + \ No newline at end of file diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 29c563c..5fe56c6 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -2,7 +2,7 @@ /* * brisk - brisk.phh * - * Copyright (C) 2006-2014 Matteo Nastasi + * Copyright (C) 2006-2015 Matteo Nastasi * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it @@ -816,13 +816,13 @@ class Table { if ($sitted < PLAYERS_N) { switch ($this->auth_type) { case TABLE_AUTH_TY_CERT: - if ($user->is_cert()) + if ($user->is_cert() && !$user->is_appr()) $act = "sitcert"; else $act = 'resercert'; break; case TABLE_AUTH_TY_AUTH: - if ($user->is_auth()) + if ($user->is_auth() && !$user->is_appr()) $act = "sitreser"; else $act = 'reserved'; diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index b882c63..f7cb1a9 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -2,7 +2,7 @@ /* * brisk - dbase_pgsql.phh * - * Copyright (C) 2006-2012 Matteo Nastasi + * Copyright (C) 2006-2015 Matteo Nastasi * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it @@ -190,6 +190,63 @@ class BriskDB return (TRUE); } + /* + $laddr is native php int (32 or 64 bit) + if ret True is ip is free + */ + function selfreg_check($laddr) + { + GLOBAL $G_dbpfx, $G_selfreg_tout, $G_selfreg_mask; + + $sere_sql = sprintf("DELETE from %sselfreg_chk WHERE atime < now();", $G_dbpfx); + if (($sere_pg = $this->query($sere_sql)) == FALSE) { + return (FALSE); + } + + if (($sere_pg = $this->query($sere_sql)) == FALSE) { + return (FALSE); + } + + $sere_sql = sprintf("SELECT * FROM %sselfreg_chk WHERE (ip & %d) = %d;", + $G_dbpfx, int2four($G_selfreg_mask), int2four($laddr & $G_selfreg_mask)); + if (($sere_pg = $this->query($sere_sql)) == FALSE) { + return(FALSE); + } + + $ret = pg_numrows($sere_pg); + + if ($ret === FALSE) { + return(FALSE); + } + else if ($ret === 0) { + return(TRUE); + } + else if ($ret > 0) { + // already present + return(FALSE); + } + else { + // unreachable branch + return(FALSE); + } + } + + /* + $laddr is native php int (32 or 64 bit) + if ret True is ip is free + */ + function selfreg_set($laddr) + { + GLOBAL $G_dbpfx, $G_selfreg_tout, $G_selfreg_mask; + + $newi_sql = sprintf("INSERT INTO %sselfreg_chk (ip, atime) VALUES (%d, now() + interval '%d seconds');", + $G_dbpfx, int2four($laddr & $G_selfreg_mask), $G_selfreg_tout); + if (($newi_pg = $this->query($newi_sql)) == FALSE) { + return(FALSE); + } + return(TRUE); + } + /* to be able to add mail record code into the record itself I must reserve it before. */ @@ -257,15 +314,16 @@ class BriskDB return TRUE; } - function user_update_flag_ty($code, $old_type, $old_reas, $type, $reas) + function user_update_flag_ty($code, $type, $old_val, $old_reas, $new_val, $new_reas) { GLOBAL $G_dbpfx; - // (u.type & (CAST (X'00ff0000' as integer))) - - $user_sql = sprintf("UPDATE %susers SET (type, disa_reas) = ((%d & (CAST (X'00ff0000' as integer))), %d) -WHERE code = %d AND (type & CAST (X'%08x' as integer)) != 0 AND disa_reas = %d;", - $G_dbpfx, $type, $reas, $code, $old_type, $old_reas); + $user_sql = sprintf("UPDATE %susers SET (type, disa_reas) + = (type & ~(CAST (X'%08x' as integer)) | (CAST (X'%08x' as integer)), %d) + WHERE code = %d AND (type & (CAST (X'%08x' as integer))) + = (CAST (X'%08x' as integer)) AND disa_reas = %d;", + $G_dbpfx, $type, ($new_val ? $type : 0), $new_reas, + $code, $type, ($old_val ? $type : 0), $old_reas); if ( ! (($user_pg = $this->query($user_sql)) != FALSE && pg_affected_rows($user_pg) == 1) ) { return FALSE; diff --git a/web/Obj/mail.phh b/web/Obj/mail.phh index 4d9025f..30b8dba 100644 --- a/web/Obj/mail.phh +++ b/web/Obj/mail.phh @@ -1,5 +1,5 @@ flags & USER_FLAG_TY_APPR); + } + function is_auth() { return ($this->flags & USER_FLAG_AUTH); diff --git a/web/commons.js b/web/commons.js index 1e47fe7..5b6e915 100644 --- a/web/commons.js +++ b/web/commons.js @@ -1029,7 +1029,7 @@ function user_decorator(user) var name, i, sp = "", cl = ""; var flags = user[0] & 0x03 | ((user[0] & 0x0c0000) >> 16); - console.log(user[1]+" FLAGS: "+flags); + // console.log(user[1]+" FLAGS: "+flags); for (i = 0 ; i < 4 ; i++) { if (flags & (1 << i)) { diff --git a/web/index_wr.php b/web/index_wr.php index 1d0b61e..7d816d7 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -796,10 +796,12 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) $not_allowed_msg = nickserv_msg($dt, sprintf($mlang_indwr['tabwait'][$G_lang], $table->wakeup_time - $curtime)); } - else if ($table->auth_type == TABLE_AUTH_TY_CERT && ( ! $user->is_cert() ) ) { + else if ( $table->auth_type == TABLE_AUTH_TY_CERT && + (!$user->is_cert() || $user->is_appr()) ) { $not_allowed_msg = nickserv_msg($dt, $mlang_indwr['mustcert'][$G_lang]); } - else if ($table->auth_type == TABLE_AUTH_TY_AUTH && ( ! $user->is_auth() ) ) { + else if ( $table->auth_type == TABLE_AUTH_TY_AUTH && + (!$user->is_auth() || $user->is_appr()) ) { $not_allowed_msg = nickserv_msg($dt, $mlang_indwr['mustauth'][$G_lang]); } else if ($user->flags & USER_FLAG_TY_FIRONLY && $table->player_n > 0) { diff --git a/web/usermgmt.php b/web/usermgmt.php index f3ea4e1..5dfc9ff 100644 --- a/web/usermgmt.php +++ b/web/usermgmt.php @@ -157,7 +157,7 @@ function main() { SELECT usr.*, guar.login AS guar_login FROM %susers AS usr JOIN %susers AS guar ON guar.code = usr.guar_code - WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) ) + WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer)) AND usr.disa_reas = %d AND usr.code = %d;", $G_dbpfx, $G_dbpfx, USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE, @@ -246,9 +246,8 @@ SELECT usr.*, guar.login AS guar_login SELECT usr.*, guar.login AS guar_login FROM %susers AS usr JOIN %susers AS guar ON guar.code = usr.guar_code - WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) ) - AND usr.disa_reas = %d - ORDER BY usr.lintm;", + WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer)) + AND usr.disa_reas = %d ORDER BY usr.lintm;", $G_dbpfx, $G_dbpfx, USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_ADDED); @@ -367,9 +366,8 @@ SELECT mail.*, usr.email AS email SELECT usr.*, guar.login AS guar_login FROM %susers AS usr JOIN %susers AS guar ON guar.code = usr.guar_code - WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) ) - AND usr.disa_reas = %d - ORDER BY usr.lintm;", + WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer)) + AND usr.disa_reas = %d ORDER BY usr.lintm;", $G_dbpfx, $G_dbpfx, USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_MAILED); @@ -444,10 +442,10 @@ SELECT usr.*, guar.login AS guar_login SELECT usr.*, guar.login AS guar_login FROM %susers AS usr JOIN %susers AS guar ON guar.code = usr.guar_code - WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) ) + WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer)) AND usr.disa_reas = %d AND usr.code = %d;", $G_dbpfx, $G_dbpfx, - USER_FLAG_TY_ALL & ~USER_FLAG_TY_APPR, USER_FLAG_TY_DISABLE, + USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_TOBECHK, $id); if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) { log_crit("stat-day: select from tournaments failed"); @@ -503,11 +501,10 @@ SELECT usr.*, guar.login AS guar_login SELECT usr.*, guar.login AS guar_login FROM %susers AS usr JOIN %susers AS guar ON guar.code = usr.guar_code - WHERE ( (usr.type & (CAST (X'%x' as integer))) = (CAST (X'%x' as integer)) ) - AND usr.disa_reas = %d - ORDER BY usr.lintm;", + WHERE usr.type & (CAST (X'%x' as integer)) = (CAST (X'%x' as integer)) + AND usr.disa_reas = %d ORDER BY usr.lintm;", $G_dbpfx, $G_dbpfx, - USER_FLAG_TY_ALL & ~USER_FLAG_TY_APPR, USER_FLAG_TY_DISABLE, + USER_FLAG_TY_DISABLE, USER_FLAG_TY_DISABLE, USER_DIS_REA_NU_TOBECHK); if (($usr_pg = pg_query($bdb->dbconn->db(), $usr_sql)) == FALSE) { log_crit("stat-day: select from tournaments failed"); -- 2.17.1