#
# all this part is from mopshop and we will use it to construct the brisk database
#
-
-if [ -f $HOME/.db.conf ]; then
+if [ -f $HOME/.brisk-db.conf ]; then
+ source $HOME/.brisk-db.conf
+elif [ -f $HOME/.db.conf ]; then
source $HOME/.db.conf
else
DBHOST=127.0.0.1
var $rd_from; // referer
var $rd_scristp; // current script step (for each session)
var $rd_kalive; // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server
- var $rd_cache; // store place where failed fwrite data
+ var $rd_cache; // place where store failed fwrite data
var $comm; // commands array
// var $asta_card; //
function reset() {
$curtime = time();
- log_legal($curtime, $this, "STAT:LOGOUT", '');
+ log_legal($curtime, 'xxx', $this, "STAT:LOGOUT", '');
$tmp_sess = $this->sess;
$this->sess = "";
$user_cur->bantime = $bri_user->bantime;
}
- log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
+ log_legal($curtime, 'xxx', $user_cur, "STAT:DESTROY_GAME", $plist);
$this->room_join_wakeup($user_cur, FALSE, 0);
$table_cur->table_token = "";
for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
$plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
}
- log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
+ log_legal($curtime, 'xxx', $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
$this->room_join_wakeup($user_cur, TRUE, -2);
$table_cur->table_token = "";
$to_room = $to_user;
}
- log_legal($curtime, $user,
+ log_legal($curtime, 'xxx', $user,
($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
$user->chat_lst = "$msg";
// function log_legal($curtime, $sess, $name, $where, $mesg)
-function log_legal($curtime, $user, $where, $mesg)
+function log_legal($curtime, $addr, $user, $where, $mesg)
{
- GLOBAL $_SERVER;
if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
/* Unix time | session | nickname | IP | where was | mesg */
fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
- $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
+ $user->name, $addr, $where , $mesg));
fclose($fp);
}
}
* BOOL $proxy = detect( VOID )
* Start detection and return TRUE if a proxy server is detected...
*/
- function detect(){
+ function detect($addr){
GLOBAL $G_proxy_white_list;
$log = "";
foreach($G_proxy_white_list as $authproxy) {
- if ($_SERVER['REMOTE_ADDR'] == $authproxy)
+ if ($addr == $authproxy)
return (FALSE);
}
- if ($this->exists_in_rbl($_SERVER['REMOTE_ADDR']) == TRUE)
+ if ($this->exists_in_rbl($addr) == TRUE)
return (TRUE);
// //scan all headers
//let's do something...
if($log){
- $log = $this->lastLog = date("Y-m-d H:i:s")."\nDetected proxy server: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])." ({$_SERVER['REMOTE_ADDR']})\n".$log;
+ $log = $this->lastLog = date("Y-m-d H:i:s")."\nDetected proxy server: ".gethostbyaddr($addr)." ({$addr})\n".$log;
//mail message
if($this->getConfig('MAIL_ALERT_TO'))
- mail($this->getConfig('MAIL_ALERT_TO'),"Proxy detected at {$_SERVER['REQUEST_URI']}",$log);
+ mail($this->getConfig('MAIL_ALERT_TO'),"Proxy detected at {$addr}",$log);
//write to file
$f = $this->getConfig('LOG_FILE');
}
//init class
-function is_proxy()
+function is_proxy($addr)
{
$proxy = new proxy_detector();
//start detect
- if($proxy->detect()) {
+ if($proxy->detect($addr)) {
//returned TRUE, lets die...
echo "<br><br><div style=\"text-align:center;\"><h1>Accesso attaverso proxy non consentito.</h1><br><br>";
- echo "Se state utilizzando un proxy privato e volete che sia autorizzato mandate il suo indirizzo IP (".$_SERVER['REMOTE_ADDR'].") e il suo proprietario all'indirizzo di posta elettronica <a href=\"mailto:brisk@alternativeoutput.it\">brisk@alternativeoutput.it</a><br><br></div>";
+ echo "Se state utilizzando un proxy privato e volete che sia autorizzato mandate il suo indirizzo IP (".$addr.") e il suo proprietario all'indirizzo di posta elettronica <a href=\"mailto:brisk@alternativeoutput.it\">brisk@alternativeoutput.it</a><br><br></div>";
//parse logged info
echo nl2br($proxy->getLog());
$dt, $user->flags, xcape($user->name), xcape($user_mesg));
$user_cur->step_inc();
}
- log_legal($curtime, $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg);
+ log_legal($curtime, 'xxx', $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg);
}
}
for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
$plist .= '|'.xcapelt($ucodes[$i]);
}
- log_legal($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist);
+ log_legal($curtime, 'xxx', $user, "STAT:BRISKIN5:FINISH_GAME", $plist);
if ($user->table_orig < TABLES_AUTH_N) {
require_once("../Obj/dbase_".$G_dbasetype.".phh");
// Use of proxies isn't allowed.
- if (!$G_is_local && is_proxy()) {
+ if (!$G_is_local && is_proxy($addr)) {
return FALSE;
}
$is_login = TRUE;
}
- log_legal($curtime, $user, "STAT:LOGIN", '');
+ log_legal($curtime, $addr, $user, "STAT:LOGIN", '');
// recovery lost game
if ($user->stat == "table") {
?>
sess = "<?php echo "$sess"; ?>";
- hstm = new http_streaming(window, console, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);});
+hstm = new http_streaming(window, null /* console*/ , gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);});
hstm.hbit_set(heartbit);
tra = new train($('room_tit'));
window.onunload = onunload_cb;
/* for ($i = 0 ; $i < $table->player_n ; $i++) { */
/* $plist .= '|'.$room->user[$table->player[$i]]->sess; */
/* } */
-/* log_legal($curtime, $user, "STAT:CREATE_GAME", $plist); */
+/* log_legal($curtime, 'xxx', $user, "STAT:CREATE_GAME", $plist); */
/* log_wr("pre new Bin5"); */
/* if (($bri = new Bin5($room, $table_idx, $table_token)) == FALSE) */
$DOCUMENT_ROOT="";
$HTTP_HOST="dodo.birds.lan";
+
+class PageFlush {
+
+ var $socket; // socket handler of page stream
+ var $kalive; // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server
+ var $msg; // place where store failed fwrite data
+ var $msg_sz; // size of content
+
+ function PageFlush($socket, $curtime, $kalive, $header_out, $body)
+ {
+ // $body_sz = mb_strlen($body, "ASCII");
+ // add length to header_out
+ $hea = headers_render($header_out);
+
+ $this->socket = $socket;
+ $this->kalive = $curtime + $kalive;
+ $this->msg = $hea.$body;
+ $this->msg_sz = mb_strlen($this->msg, "ASCII");
+ }
+
+ /* return TRUE if is removable from it's list */
+ function try_flush($curtime)
+ {
+ if ($this->kalive < $curtime) {
+ fclose($this->socket);
+ return TRUE;
+ }
+
+ $wret = @fwrite($this->socket, $this->msg);
+ if ($wret == FALSE && $wret !== FALSE) {
+ printf("PageFlush::try_flush: wret 0 but not FALSE\n");
+ }
+ if ($wret == $this->msg_sz) {
+ fclose($this->socket);
+ return TRUE;
+ }
+ $this->msg_sz -= $wret;
+ $this->msg = mb_substr($this->msg, $wret, $this->msg_sz, "ASCII");
+
+ return FALSE;
+ }
+
+}
+
?>
* TODO
*
* - partial write for normal page management
+ * - log legal address fix
* - from room to table
* - from table to room
* - fwrite other issues
}
$s2u = array();
+ $pages_flush = array();
$rndstr = "";
for ($i = 0 ; $i < 4096 ; $i++) {
while ($main_loop) {
$curtime = time();
- printf("IN LOOP: Current opened: %d\n", count($socks));
+ printf("IN LOOP: Current opened: %d pages_flush: %d\n", count($socks), count($pages_flush));
/* Prepare the read array */
if ($shutdown)
index_main($room, $header_out, $addr, $get, $post, $cookie);
$content = ob_get_contents();
ob_end_clean();
- $content_sz = mb_strlen($content, "LATIN1");
- $hea = headers_render($header_out);
-
- // TODO: FIX THIS PART TO A SPAWN WRITE AS CUEUE.
- printf("OUT: [%d]\n", $content_sz);
- for ($w = 0 ; $w < 10 ; $w++) {
- if (($wret = fwrite($new_socket, $content, $content_sz)) == $content_sz
- || $wret <= 0)
- break;
- printf("wret: [%d]\n", $wret);
- $content = substr($content, $wret, $content_sz - $wret);
- usleep(100000);
+
+ $pgflush = new PageFlush($new_socket, $curtime, 20, $header_out, $content);
+
+ if ($pgflush->try_flush($curtime) == FALSE) {
+ // Add $pgflush to the pgflush array
+ array_push($pages_flush, $pgflush);
}
- fclose($new_socket);
+
break;
case SITE_PREFIX."index_wr.php":
$header_out = array();
}
}
+
+ foreach ($pages_flush as $k => $pgflush) {
+ if ($pgflush->try_flush($curtime) == TRUE) {
+ unset($pages_flush[$k]);
+ }
+ }
+
foreach ($socks as $k => $sock) {
if (isset($s2u[intval($sock)])) {
$user = $room->user[$s2u[intval($sock)]];
if ($body != "") {
echo "SPIA: [".substr($body, 0, 60)."...]\n";
- $body_l = mb_strlen($body, "LATIN1");
+ $body_l = mb_strlen($body, "ASCII");
$ret = @fwrite($sock, $body);
if ($ret < $body_l) {
printf("TROUBLE WITH FWRITE: %d\n", $ret);
- $user->rd_cache_set(mb_substr($body, $ret, $body_l - $ret, "LATIN1"));
+ $user->rd_cache_set(mb_substr($body, $ret, $body_l - $ret, "ASCII"));
}
else {
$user->rd_cache_set("");
if (s != null) {
ctx_new = ctx_new + "@BEGIN@" + s + "@END@";
// FIXME: remove this barbarian log
- window.parent.console.log("ifra: CTX_NEW: ["+ctx_new+"]");
+ // window.parent.console.log("ifra: CTX_NEW: ["+ctx_new+"]");
}
else {