diff --git a/web/public_php/stats/stats.php b/web/public_php/stats/stats.php new file mode 100644 index 000000000..1e4e4efd7 --- /dev/null +++ b/web/public_php/stats/stats.php @@ -0,0 +1,403 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('../login/config.php'); + + // LOG database + $StatsDBHost = $DBHost; + $StatsDBUserName = $DBUserName; + $StatsDBPassword = $DBPassword; + $StatsDBName = "stats"; + + error_reporting(E_ERROR | E_PARSE); + set_error_handler('err_callback'); + + // global var + $link = NULL; + $page_max = 100; + $dev_ip="192.168.1.169"; //ip where sql error are displayed + $private_network = "/192\.168\.1\./i"; //ip where the cmd=log&msg=dump function works + $page_name = "stats.php"; + + + + //get the ip of the viewer + function getIp() + { + if (getenv("HTTP_CLIENT_IP")) + { + $ip = getenv("HTTP_CLIENT_IP"); + } + elseif(getenv("HTTP_X_FORWARDED_FOR")) + { + $ip = getenv("HTTP_X_FORWARDED_FOR"); + } + else + { + $ip = getenv("REMOTE_ADDR"); + } + return $ip; + } + + + // if the player ip is the dev ip then the sql error is explain + function die2($debug_str) + { + global $private_network; + if ( preg_match($private_network, getIp()) ) + { + die($debug_str); + } + else + { + die("GENERIC_ERROR"); + } + } + + // get head or post infos return default if no valuees + function getPost($value, $default=NULL) + { + if ( isSet($_GET[$value]) ) { return $_GET[$value]; } + if ( isSet($_POST[$value]) ) { return $_POST[$value]; } + + return $default; + } + + // log error in bdd + function debug($str) + { + global $StatsDBHost; + global $StatsDBUserName; + global $StatsDBPassword; + global $StatsDBName; + global $link; + + $newConnection = 0; + + if ($link == NULL) + { + $link = mysql_connect($StatsDBHost, $StatsDBUserName, $StatsDBPassword) or die2 (__FILE__. " " .__LINE__." Can't connect to database host:$StatsDBHost user:$StatsDBUserName"); + $newConnection = 1; + + mysql_select_db ($StatsDBName, $link) or die2 (__FILE__. " " .__LINE__." Can't access to the table dbname:$StatsDBName"); + } + + + $str = str_replace("'", "", $str); + $str = str_replace( '"', "", $str); + + + $query= "INSERT INTO `log` ( `log` )" + . "VALUES (" + . "'$str'" + . ")"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + if ($newConnection == 1) + { + mysql_close($link); + $link = NULL; + } + + } + function err_callback($errno, $errmsg, $filename, $linenum, $vars) + { + debug("$filename $linenum $errmsg"); + } + + +// debug( getenv("QUERY_STRING") ); + + // extract the cmd + $cmd = getPost("cmd" ,"log"); + if ($cmd == "") + { + echo "0:Missing cmd"; + die2(); + } + + // check for 'clear password' tag + switch ($cmd) + { + // log <=> display php page + case "log": + $date = date('Y-m-d H:i:s', time()); + $ip = getIp(); + $log = getenv("QUERY_STRING"); + $link = mysql_connect($StatsDBHost, $StatsDBUserName, $StatsDBPassword) or die2 (__FILE__. " " .__LINE__." Can't connect to database host:$StatsDBHost user:$StatsDBUserName"); + mysql_select_db ($StatsDBName, $link) or die2 (__FILE__. " " .__LINE__." Can't access to the table dbname:$StatsDBName"); + + + $msg = getPost("msg", ""); + switch ($msg) + { + //display php infos + + + + case "start_download": + + $query = "SELECT max(`session_id`) as `res` from `sessions`"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + $session_id = 1000; + if( mysql_num_rows($result) != 0) + { + $row = mysql_fetch_array($result); + $session_id = $row["res"] + 1; + } + + $now = date("Y-m-d H:i:s", time()); + $server = getPost("server", ""); + $application = getPost("application", ""); + $version = getPost("version", ""); + $lang = getPost("lang",""); + $type = getPost("application", ""); + $package = getPost("package", ""); + $protocol = getPost("protocol", ""); + $size_download =getPost("size_download", ""); + $size_install = getPost("size_install", ""); + $user_id = getPost("user_id", "0"); + $previous_download = getPost("previous_download", "0"); + + + $query= "INSERT INTO `sessions` ( `session_id`, `user_id` , `server`, `application`, `ip` , `lang`, `type`, `package`, `protocol`, `size_download`, `size_install`, `start_download`, `stop_download`, `previous_download` )" + + . "VALUES (" + . "'$session_id', '$user_id' ,'$server', '$application', '$ip', '$lang', '$type', '$package', '$protocol', '$size_download', '$size_install', '$now', '$now', '$previous_download'" + . ")"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + + + $query= "UPDATE `install_users` set install_count = install_count + 1, state='DU_DL', last_install='$now' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + + echo "".$session_id.""; + break; + + case "stop_download": + + $session_id =getPost("session_id", "0"); + $now = date("Y-m-d H:i:s", time()); + $query = "UPDATE `sessions` SET `stop_download` = '$now', `percent_download` ='100' WHERE `session_id` = '$session_id' LIMIT 1"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_IN' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + + break; + // update the percent of download + case "update_download": + + $session_id =getPost("session_id", "0"); + $percent = getPost("percent", "0"); + $now = date("Y-m-d H:i:s", time()); + $query = "UPDATE `sessions` SET `percent_download` ='$percent', `stop_download` = '$now' WHERE `session_id` = '$session_id' LIMIT 1"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + // update the percent of finish + case "update_install": + + $now = date("Y-m-d H:i:s", time()); + $session_id =getPost("session_id", "0"); + $percent = getPost("percent", "0"); + $query = "UPDATE `sessions` SET `percent_install` ='$percent', `stop_download` = '$now' WHERE `session_id` = '$session_id' LIMIT 1"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + + + case "no_install": + + $session_id = getPost("session_id", "0"); + $now = date("Y-m-d H:i:s", time()); + $query = "UPDATE `sessions` SET `size_download` = '0', `start_install` = '$now', `stop_install` = '$now', `percent_install` ='100' WHERE `session_id` = '$session_id' LIMIT 1"; + echo $query; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + // install is finished + case "stop_install": + $session_id = getPost("session_id", "0"); + $now = date("Y-m-d H:i:s", time()); + $query = "UPDATE `sessions` SET `stop_install` = '$now', `stop_download` = '$now', `percent_install` ='100' WHERE `session_id` = '$session_id' LIMIT 1"; + echo $query; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_FI' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + // addd user info to database + case "start_install": + $session_id = getPost("session_id", ""); + $now = date("Y-m-d H:i:s", time()); + $query = "UPDATE `sessions` SET `start_install` = '$now', `stop_download` = '$now' WHERE `session_id` = '$session_id' LIMIT 1"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + + + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_IN' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_video_mode_setup": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_VMS' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_video_mode_setup_high_color": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_VMSHS' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_login_screen": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_AL' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_post_login": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_PL' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_character_selection": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_CS' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + case "login_step_game_entry": + $user_id = getPost("user_id", "0"); + $query= "UPDATE `install_users` set state='DU_AG' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + break; + + + case "login_step_game_exit": + $user_id = getPost("user_id", "0"); + $play_time = getPost("play_time", "0"); + // manualy estimate the duration of the previous session + { + $query = "SELECT `state` from install_users where `user_id` = '$user_id'"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + $state = "AG"; + if( mysql_num_rows($result) > 0) + { + $row = mysql_fetch_array($result); + $state = $row["state"]; + } + + if ($state == "DU_P1") + { + $play_time = $play_time + 30 *60; + } + else if ($state == "DU_P2") + { + $play_time = $play_time + 60* 60; + } + else if ($state == "DU_P3") + { + $play_time = $play_time + 2*60* 60; // P3 will stat P3 + } + } + + + if ($play_time > 2*60*60) // time played > 2 h + { + $query= "UPDATE `install_users` set state='DU_P3' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + } + else if ($play_time > 60*60) // time played > 2 h + { + $query= "UPDATE `install_users` set state='DU_P2' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + } + else if ($play_time > 30*60) // time played > 30 m + { + $query= "UPDATE `install_users` set state='DU_P1' where user_id='$user_id';"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + } + break; + + // addd user info to database + case "init": + $query = "SELECT max(`user_id`) as max_id from `install_users`"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + $user_id = 1; + if( mysql_num_rows($result) != 0) + { + $row = mysql_fetch_array($result); + $user_id = $row["max_id"] + 1; + } + + $install_id = getPost("install_id", "0"); + $os = getPost("os", "Unknown"); + $proc = getPost("proc", "Unknown"); + $memory = getPost("memory", "Unknown"); + $video_card = getPost("video_card", "Unknown"); + $driver_version = getPost("driver_version", "Unknown"); + + $query = "INSERT INTO `install_users` SET `user_id` = '$user_id', `install_id`='$install_id', `os`='$os', `proc`='$proc', `memory`='$memory', `video_card`='$video_card', `driver_version`='$driver_version', `last_install`='".date('Y-m-d H:i:s', time()) . "', `first_install`=`last_install`"; + + + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + echo "$user_id"; + break; + + // first log if empyt user_id is return then must init + case "login": + $install_id = getPost("install_id", "0"); + $query = "SELECT `user_id` from install_users where `install_id` = '$install_id'"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." Can't execute the query: ".$query); + if( mysql_num_rows($result) == 0) + { + echo ""; + break; + } + $row = mysql_fetch_array($result); + $user_id = $row["user_id"]; + echo "$user_id"; + break; + + + + + default: + echo "unknown command: $msg $log"; + } + + + mysql_close($link); + unset($link); + + break; + + default: + echo "0:Unknown command"; + die2(); + } + + +?> diff --git a/web/public_php/stats_query/stats_query.php b/web/public_php/stats_query/stats_query.php new file mode 100644 index 000000000..2f10df25f --- /dev/null +++ b/web/public_php/stats_query/stats_query.php @@ -0,0 +1,939 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('../login/config.php'); + + // LOG database + $StatsDBHost = $DBHost; + $StatsDBUserName = $DBUserName; + $StatsDBPassword = $DBPassword; + $StatsDBName = "stats"; + + error_reporting(E_ERROR | E_PARSE); + set_error_handler('err_callback'); + + // for error handling, buffer all output + + $link = NULL; + $page_name="stats_query.php"; + $page_max = 50; + $dev_ip="192.168.1.169"; //ip WHERE sql error are displayed +// $private_network = "/192\.168\.1\./i"; //ip WHERE the cmd=view function works + + + function toHMS($time) + { + $ret = ""; + if ($time <= 0) { return "0 s";} + if ($time > 60*60*24) + { + $days = floor($time / (60*60*24)); + $time = floor($time - $days * 60*60*24); + if ($days != 0) { + $ret = $ret . $days . "d "; + } + } + + if ($time > 60*60) + { + $hours = floor($time / (60*60)); + $time = floor($time - $hours * 60*60); + if ($hours != 0) { + $ret = $ret . $hours . "h "; + } + } + + if ($time > 60) + { + $mins = floor($time / 60); + $time = floor($time - $mins * 60); + if ($mins != 0) { + $ret = $ret . $mins . "m "; + } + } + if ($time != 0) { + $ret = $ret . $time . "s "; + } + return $ret; + } + + //get the ip of the viewer + function getIp() + { + if (getenv("HTTP_CLIENT_IP")) + { + $ip = getenv("HTTP_CLIENT_IP"); + } + elseif(getenv("HTTP_X_FORWARDED_FOR")) + { + $ip = getenv("HTTP_X_FORWARDED_FOR"); + } + else + { + $ip = getenv("REMOTE_ADDR"); + } + return $ip; + } + + + // if the player ip is the dev ip then the sql error is explain + function die2($debug_str) + { +// global $private_network; +// if ( preg_match($private_network, getIp()) ) +// { + die($debug_str); +// } +// else +// { +// die("GENERIC_ERROR"); +// } + } + + // get head or post infos return default if no valuees + function getPost($value, $default=NULL) + { + if ( isSet($_GET[$value]) ) { return $_GET[$value]; } + if ( isSet($_POST[$value]) ) { return $_POST[$value]; } + return $default; + } + + $cmd = getPost("cmd", "view"); + + $show_dl=getPost("show_dl", "1"); + $show_ddl=getPost("show_ddl", "1"); + $show_du=getPost("show_du", "1"); + $show_hdu=getPost("show_hdu", "1"); + $show_hdu2=getPost("show_hdu2", "1"); + $show_hddetails=getPost("show_hddetails", "0"); + + function getHref() + { + + global $show_dl; + global $show_ddl; + global $show_du; + global $show_hdu; + global $show_hdu2; + global $selected; + global $page_name; + global $display; + global $show_hddetails; + return "$page_name?cmd=view&show_dl=$show_dl&show_ddl=$show_ddl&show_du=$show_du&show_hdu=$show_hdu&show_hdu2=$show_hdu2&selected=$selected&display=$display&show_hddetails=$show_hddetails"; + } + + + // do a simple sql query return the result of the query + function getSimpleQueryResult($query, &$link) + { + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: $query
".mysql_error()."
"); + + if ( ($row = mysql_fetch_array($result)) ) + { + return $row["ret"]; + + } + return ""; + } + + // log error in bdd + function debug($str) + { + global $StatsDBHost; + global $StatsDBUserName; + global $StatsDBPassword; + global $StatsDBName; + global $link; + + $newConnection = 0; + + if ($link == NULL) + { + $link = mysql_connect($StatsDBHost, $StatsDBUserName, $StatsDBPassword) or die2 (__FILE__. " " .__LINE__." can't connect to database host:$StatsDBHost user:$StatsDBUserName"); + $newConnection = 1; + + mysql_select_db ($StatsDBName, $link) or die2 (__FILE__. " " .__LINE__." can't access to the table dbname:$StatsDBName"); + } + + + $str = str_replace("'", "", $str); + $str = str_replace( '"', "", $str); + + + $query= "INSERT INTO `log` ( `log` )" + . "VALUES (" + . "'$str'" + . ")"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + if ($newConnection == 1) + { + mysql_close($link); + $link = NULL; + } + + } + function err_callback($errno, $errmsg, $filename, $linenum, $vars) + { + echo "error: line $linenum, $errmsg
"; + // debug($errmsg); + } + + //extract infos FROM sessions + function getStats($mode, $day, &$link) + { + + $day2 = date('Y-m-d', $day); + $day_first = date('Y-m-d H:i:s', strtotime( date('Y-m-d', $day) ) ); + $day_last = date('Y-m-d H:i:s', strtotime(date('Y-m-d', $day + 3600*24)) - 1); + $condition1 = "install_users.first_install >= '$day_first' AND install_users.first_install <= '$day_last' "; + $condition2 = "`sessions`.`start_download` >= '$day_first' AND `sessions`.`start_download` <= '$day_last' "; + + if (!isSet($condition)) + { + $condition = "1"; + } + $ret = array(); + + if ($mode == 2) + { + + // false = not optimized + if (true) + { + //true == optimized: Request is optimized we use one query instead of many + $query = "SELECT " + ."SUM(IF(install_users.state = 'DU_P3', 1, 0)) AS DU_P3, " + ."SUM(IF(install_users.state = 'DU_P2', 1, 0)) AS DU_P2, " + ."SUM(IF(install_users.state = 'DU_P1', 1, 0)) AS DU_P1, " + ."SUM(IF(install_users.state = 'DU_AG', 1, 0)) AS DU_AG, " + ."SUM(IF(install_users.state = 'DU_CS', 1, 0)) AS DU_CS, " + ."SUM(IF(install_users.state IN ('DU_AL', 'DU_PL' ), 1, 0)) AS DU_AL, " + ."SUM(IF(install_users.state IN ('DU_FI', 'DU_VMS', 'DU_VMSHS' ), 1, 0)) AS DU_FI," + ."SUM(IF(install_users.state = 'DU_IN', 1, 0)) AS DU_IN, " + ."SUM(IF(install_users.state = 'DU_DL', 1, 0)) AS DU_DL " + ."FROM install_users " + ."WHERE $condition1 " + ."AND install_users.user_id " + ."IN ( SELECT sessions.user_id FROM sessions WHERE $condition2 )"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + if ( ($row = mysql_fetch_array($result)) ) + { + + $ret["DU_P3"] = $row["DU_P3"]; + $ret["DU_P2"] = $row["DU_P2"] + $ret["DU_P3"]; + $ret["DU_P1"] = $row["DU_P1"] + $ret["DU_P2"]; + $ret["DU_AG"] = $row["DU_AG"] + $ret["DU_P1"]; + $ret["DU_CS"] = $row["DU_CS"] + $ret["DU_AG"]; + $ret["DU_AL"] = $row["DU_AL"] + $ret["DU_CS"]; + $ret["DU_FI"] = $row["DU_FI"] + $ret["DU_AL"]; + $ret["DU_IN"] = $row["DU_IN"] + $ret["DU_FI"]; + $ret["DU_DL"] = $row["DU_DL"] + $ret["DU_IN"]; + } + + } else { + + $ret["DU_P3"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_P3'", $link) ; + $ret["DU_P2"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_P2'", $link) + $ret['DU_P3']; + $ret["DU_P1"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_P1'", $link) + $ret['DU_P2']; + $ret["DU_AG"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_AG'", $link) + $ret['DU_P1']; + $ret["DU_CS"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`= 'DU_CS'", $link) + $ret['DU_AG']; + $ret["DU_AL"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state` IN ('DU_AL', 'DU_PL' ) ", $link) + $ret['DU_CS']; + $ret["DU_FI"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state` IN ('DU_FI', 'DU_VMS', 'DU_VMSHS' )", $link) + $ret['DU_AL']; + $ret["DU_IN"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_IN'", $link) + $ret['DU_FI']; + $ret["DU_DL"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(`sessions`.`user_id`)) AS ret FROM `sessions`, `install_users` WHERE $condition1 AND `install_users`.`user_id`=`sessions`.`user_id` AND `install_users`.`state`='DU_DL'", $link) + $ret['DU_IN']; + } + } + + $ret["all_session"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2", $link); + + if ($mode == 1) + { + + $ret["distinct_user"] = getSimpleQueryResult("SELECT COUNT(DISTINCT(sessions.user_id)) AS ret FROM `sessions` WHERE $condition2 ORDER BY sessions.user_id", $link); + //true == optimized: Request is optimized we use one query instead of many + if (true) + { + $query = "SELECT" + . " COUNT(session_id) AS all_session," + . " SUM(IF(sessions.previous_download IN ('0', '0.00B', '0.000B'), 1, 0)) AS clean_start," + . " SUM(IF(sessions.percent_download = '100', 1, 0)) AS download_finished," + . " SUM(IF(sessions.percent_install = '100', 1, 0)) AS install_finished," + . " SUM(IF(sessions.package = 'full', 1, 0)) AS download_full," + . " SUM(IF(sessions.lang = 'fr', 1, 0)) AS fr," + . " SUM(IF(sessions.lang = 'en', 1, 0)) AS en," + . " SUM(IF(sessions.lang = 'de', 1, 0)) AS de" + . " FROM sessions" + . " WHERE $condition2"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + if ( ($row = mysql_fetch_array($result) ) ) + { + $ret["all_session"] = $row["all_session"]; + $ret["clean_start"] = $row["clean_start"]; + $ret["download_finished"] = $row["download_finished"]; + $ret["install_finished"] = $row["install_finished"]; + $ret["download_full"] = $row["download_full"]; + $ret["fr"] = $row["fr"]; + $ret["en"] = $row["en"]; + $ret["de"] = $row["de"]; + } + + + } else { + $ret["clean_start"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND previous_download IN ('0', '0.000b', '0.00B')", $link); + $ret["download_finished"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `percent_download` = '100'", $link); + $ret["install_finished"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `percent_install` = '100' ", $link); + $ret["download_full"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `package` = 'full'", $link); + $ret["fr"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `lang` = 'fr'", $link); + $ret["en"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `lang` = 'en'", $link); + $ret["de"] = getSimpleQueryResult("SELECT COUNT(`session_id`) AS ret FROM `sessions` WHERE $condition2 AND `lang` = 'de'", $link); + } + $ret["restart"] = $ret['all_session'] - $ret['clean_start']; + + } + return $ret; + + } + + + + // display download infos + // condition is the condition for displaying users (time condition) + // max_reslut is the number of result that could be displayed + function displayDownload($link) + { + global $show_dl; + global $selected; + + $date = getdate($selected); + $date_first = date('Y-m-d H:i:s', strtotime( date('Y-m-1', $selected) ) ); + $date_first_int = strtotime($date_first); + $date_last = date('Y-m-d H:i:s', strtotime(date('Y-m-1', $selected + 31*24*3600)) - 1); + $date_last_int = strtotime($date_last); + $nbday = round( ($date_last_int +1 - $date_first_int ) / (24*3600)); + + //display sumary infos (if title clicked make apears or disapears the menu) + $old_value = $show_dl; + $show_dl = !$show_dl; + echo '

downloads

'; + $show_dl = $old_value; + + if ($show_dl == 1) + { + + + echo ''."\n"; + echo "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + + + // for each day of the month with download display infos + for ($i = 0; $i < $nbday; $i++) + { + $day = $date_first_int + $i*24*3600; + + if ($day >= time())// + 24*3600) + { + break; + } + $day_first = date('Y-m-d H:i:s', strtotime( date('Y-m-d', $day) ) ); + $day_last = date('Y-m-d H:i:s', strtotime(date('Y-m-d', $day + 3600*24)) - 1); + + $res = getStats(1, $day, $link); + $date_today = getdate($day); + // display only if active download + if ($res['all_session'] != 0 ) + { + + echo "\n" + + . ""; + + + if (date('Y-m-d', $day)==date('Y-m-d', $selected)) + { + echo ""; + } + else + { + echo ""; + } + + echo "" + //. "" + . "" + . "" + . "" + + . "" + . "" + . "" + . "" + . "" + . "" + . "\n"; + } + + } + echo "
week day".$date['month']. " ".$date['year']."distinct users(today)first startrestarttotal downloaddownload finishedinstall finishedfull versionfrende
".$date_today['weekday']."".($i+1)."".($i+1)."".$res['distinct_user']."".$res['all_session']."".$res['clean_start']."".$res['restart']."".($res['restart'] + $res['clean_start'])." (". $res['clean_start']. "+" . $res['restart'] .")".$res['download_finished']."".$res['install_finished']."".$res['download_full']."".$res['fr']."".$res['en']."".$res['de']."
"; + + //display next mont, prev month link + echo ''." < last month". ' '; + echo ", "; + echo ''."next month >". ' '; + } + } + + function displayDistinctUsers($link) + { + global $show_du; + global $selected; + + $date = getdate($selected); + $date_first = date('Y-m-d H:i:s', strtotime( date('Y-m-1', $selected) ) ); + $date_first_int = strtotime($date_first); + $date_last = date('Y-m-d H:i:s', strtotime(date('Y-m-1', $selected + 31*24*3600)) - 1); + $date_last_int = strtotime($date_last); + $nbday = round( ($date_last_int +1 - $date_first_int ) / (24*3600)); + + // when click on title, the content apears or disapers + $old_value = $show_du; + $show_du = !$show_du; + echo '

distinct new users

'; + $show_du = $old_value; + + if ($show_du == 1) + { + echo ''."\n"; + echo "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + for ($i = 0; $i < $nbday; $i++) + { + + $day = $date_first_int + $i*24*3600; + if ($day >= time())// + 24*3600) + { + break; + } +// $row = getStats("`sessions`.`start_download` >= '$day_first' AND `sessions`.`start_download` <= '$day_last' ", $link); + $row = getStats(2, $day, $link); + + $date_today = getdate($day); + if ($row['all_session'] != 0) + { + echo ""; + + echo ""; + if (date('Y-m-d', $day)==date('Y-m-d', $selected)) + { + echo ""; + } + else + { + echo ""; + } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + } + + echo "
week day".$date['month']. " ".$date['year']."started dlfinished dlfinished instarrive loginarrive char selarrive in gameplay 30 minplay 1hrplay 2hr
".$date_today['weekday']."".($i+1)."".($i+1)."".$row["DU_DL"]."".$row["DU_IN"]."".$row["DU_FI"]."".$row["DU_AL"]."".$row["DU_CS"]."".$row["DU_AG"]."".$row["DU_P1"]."".$row["DU_P2"]."".$row["DU_P3"]."
\n"; + echo ''." < last month". ' '; + echo ", "; + echo ''."next month >". ' '; + + } + } + + function displayDownloadDetails($condition, $link) + { + global $page_max; + global $show_ddl; + global $page_download; + global $page_users; + global $page_users2; + global $selected; + + + $query = "SELECT COUNT(`session_id`) AS max" + . " FROM `sessions`" + . " WHERE $condition"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + $max_result = 0; + if ( ($row = mysql_fetch_array($result)) ) { $max_result = $row["max"];} + + //display sumary infos (if title clicked make apears or disapears the menu) + $old_value = $show_ddl; + $show_ddl = !$show_ddl; + echo '

download details('.$max_result.')

'; + $show_ddl = $old_value; + if ($show_ddl == 1) + { + echo ''."\n"; + echo "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + + $query = "SELECT COUNT(`session_id`) AS max FROM `sessions` WHERE $condition"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + $max_result=0; + if ( ($row = mysql_fetch_array($result)) ) { $max_result = $row["max"]; } + + + + $query = "SELECT `session_id` , `user_id` , `server` , `application` , `version` , `ip` , `lang` , `type` , `package` , `protocol` , `size_download` , `size_install` , `start_download` , `stop_download` , `start_install` , `stop_install` , `percent_download` , `percent_install` , `previous_download`" + . " FROM `sessions`" + . " WHERE $condition" + . " ORDER by `user_id` desc, `start_download` desc" + . " LIMIT ".($page_download * $page_max)." , ".$page_max; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + + while ( ($row = mysql_fetch_array($result)) ) + { + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "
user_idiplangskuprotocolsz dlsz inststartstart instfinishtime% dl% instprev dl
" + .$row["user_id"] + ."".$row["ip"]."".$row["lang"]."".$row["package"]."".$row["protocol"]."".$row["size_download"]."".$row["size_install"]."".$row["start_download"]."".$row["start_install"]."".$row["stop_install"]."" . toHMS(strtotime($row["stop_download"]) - strtotime($row["start_download"]) ) ."".$row["percent_download"]."".$row["percent_install"]."".$row["previous_download"]."
\n"; + + for ($i = 1 ;$i < ($max_result / $page_max)+1; $i = $i+1) + { + if ($page_download + 1 == $i) + { + echo ($i)." "; + } + else + { + echo ''.($i). ' '; + } + } + + } + } + + function lastSession($id, $condition, $link) + { + $query = "SELECT install_users.user_id, sessions.session_id, sessions.stop_download, sessions.start_download, sessions.percent_download, sessions.percent_install " + . " FROM install_users, sessions " + . " WHERE install_users.user_id='" . $id . "' AND install_users.user_id = sessions.user_id AND $condition" + . " ORDER BY sessions.session_id DESC"; + + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + if ( ($row = mysql_fetch_array($result)) ) + { + $ret["session_id"] = $row["session_id"]; + $ret["time"] = strtotime($row["stop_download"]) - strtotime($row["start_download"]) ; + $ret["percent"] = $row["percent_download"] . "/". $row["percent_install"]; + return $ret; + } + $ret["time"] = "?"; + $ret["percent"] = "?"; + return $ret; + } + + + + // display infos on user hardware + // condition is the condition for displaying users (time condition) + function displayHardwareNewUserImpl($install_state, $title, $condition, $condition2, $link) + { + + global $page_max; + global $page_users; + global $page_users2; + global $selected; + global $show_hdu; + global $show_hdu2; + global $show_hddetails; + + +// $query = "SELECT COUNT(install_users.user_id) AS max FROM install_users WHERE $condition2 AND install_users.user_id in (SELECT DISTINCT(sessions.user_id) from sessions where $condition)"; + $query = "SELECT COUNT(DISTINCT(sessions.user_id)) AS max FROM `install_users`,`sessions` WHERE $condition2 AND install_users.user_id = sessions.user_id AND $condition"; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + $max_result = 0; + if ( ($row = mysql_fetch_array($result)) ) { $max_result = $row["max"];} + + if ($install_state==1) + { + $old_value = $show_hdu; + $show_hdu = 1-$show_hdu; + echo '

Hardware users - Unfinished install ('.$max_result.')

'; + $show_hdu = $old_value; + $nbpages = $page_users; + } + else + { + $old_value = $show_hdu2; + $show_hdu2 = 1-$show_hdu2; + echo '

Hardware users - Finished install ('.$max_result.')

'; + $show_hdu2 = $old_value; + $nbpages = $page_users2; + } + + // Show / Hide os column + { + $old_value = $show_hddetails; + $show_hddetails = 1 - $show_hddetails; + if ($show_hddetails == 1) + { + echo '

Show details

'; + } + else + { + echo '

Hide details

'; + } + $show_hddetails = $old_value; + } + + + //display sumary infos (if title clicked make apears or disapears the menu) + + if (($install_state==1 && $show_hdu == 1) || ($install_state==2 && $show_hdu2 == 1) ) + { + + + echo ''."\n"; + echo "\n" + . "\n"; + if ($show_hddetails == 0) + { + + echo "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + } + if ($install_state) { echo "\n"; } + echo "\n"; + if ($show_hddetails == 1) + { + echo "\n" + . "\n" + + . "\n" + . "\n"; + } + + echo "\n" + . "\n"; + + $query = "SELECT `install_users`.`user_id` , `install_users`.`first_install`, `install_users`.`last_install`, `install_users`.`install_count`, `install_users`.`os` , `install_users`.`proc` , `install_users`.`memory` , `install_users`.`video_card` , `install_users`.`driver_version`, `install_users`.`state`, " + ."SUM( IF(sessions.stop_download >sessions.start_download, UNIX_TIMESTAMP(sessions.stop_download) - UNIX_TIMESTAMP(sessions.start_download) , 0))AS waiting_time, count(sessions.session_id) AS install_count2" + . " FROM `install_users`, `sessions`" + . " WHERE `sessions`.`user_id` = `install_users`.`user_id` AND $condition AND $condition2" + . " GROUP by `sessions`.`user_id`" + . " ORDER by `sessions`.`user_id` desc" + . " LIMIT ".($nbpages * $page_max)." , ".$page_max; + $result = mysql_query ($query, $link) or die2 (__FILE__. " " .__LINE__." can't execute the query: ".$query); + + + while ( ($row = mysql_fetch_array($result)) ) + { + $ret = lastSession($row["user_id"], $condition, $link); + echo ""; + echo "\n"; + if ($show_hddetails == 0) + { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + if ($install_state) { echo "\n"; } + echo "\n"; + if ($show_hddetails == 1) + { + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + } + echo "\n"; + echo "\n"; + } + echo "
user_idfirst_installlast_installinstall_countinstall timelast install timelast install statememoryosprocvideo_carddriver_versioncurrent state
".$row["user_id"]."".$row["first_install"]."".$row["last_install"]."".$row["install_count2"]."".toHMS($row["waiting_time"])."".toHMS($ret["time"])."".$ret["percent"]."".$row["memory"]."".$row["os"]."".$row["proc"]."".$row["video_card"]."".$row["driver_version"]."".$row["state"]."
\n"; + + } + if (($install_state==1 && $show_hdu == 1) || ($install_state==2 && $show_hdu2 == 1) ) + { + for ($i = 1 ;$i < ($max_result / $page_max)+1; $i = $i+1) + { + if ($nbpages + 1 == $i) + { + echo ($i)." "; + } + else + { + if ($install_state==1) + { + echo ''.($i). ' '; + } + else + { + echo ''.($i). ' '; + } + } + } + } + } + + function displayHardwareNewUser($condition, $link) + { + + global $display; + if ($display == 4) + { + displayHardwareNewUserImpl(1, "unfinished Install", $condition, " install_users.state IN ('DU_DL', 'DU_IN')", $link); + } + if ($display == 5) + { + displayHardwareNewUserImpl(2, "finished Install", $condition, " NOT (install_users.state IN ('DU_DL', 'DU_IN') )", $link); + } + + + + } + + + + // extract the cmd + + if ($cmd == "") + { + echo "0:missing cmd"; + die2(); + } + + // check for 'clear password' tag + switch ($cmd) + { + // log <=> display php pabe + case "view": + $dt = gettimeofday(); + $date = date('Y-m-d H:i:s', time()); + $ip = getIp(); + $log = getenv("query_string"); + $link = mysql_connect($StatsDBHost, $StatsDBUserName, $StatsDBPassword) or die2 (__FILE__. " " .__LINE__." can't connect to database host:$StatsDBHost user:$StatsDBUserName"); + mysql_select_db ($StatsDBName, $link) or die2 (__FILE__. " " .__LINE__." can't access to the table dbname:$StatsDBName"); + + + //verify passwd AND ip is private +// if (preg_match($private_network, getIp()) ) + { + //xhtml header + style + echo ''."\n" + . ''."\n"; + + + echo "\n"; + echo "\n"; + echo "\n"; + + //display summary stat by day for current month + + $selected = getPost("selected", strtotime(date('Y-m-d', time()))); + $page_download = getPost("page_download", "1"); + $page_download = $page_download -1; + if ($page_download < 0) { $page_download = 0;} + $page_users = getPost("page_users", "1"); + $page_users = $page_users -1; + $page_users2 = getPost("page_users2", "1"); + $page_users2 = $page_users2 -1; + if ($page_users < 0) { $page_users = 0;} + if ($page_users2 < 0) { $page_users2 = 0;} + + + $date_first = date('Y-m-d H:i:s', strtotime( date('Y-m-1', $selected) ) ); + $date_first_int = strtotime($date_first); + $date_last = date('Y-m-d H:i:s', strtotime(date('Y-m-1', $selected + 31*24*3600)) - 1); + $date_last_int = strtotime($date_last); + $nbday = round( ($date_last_int +1 - $date_first_int ) / (24*3600)); + + $display = getPost("display", "0"); + + $date = getdate($selected); + // display server time + echo "

server time: ".date("Y-m-d H:i:s", time())."

\n"; + + + + // display title + echo '

'.$date['weekday'].' '.$date['mday'].' '.$date['month'].' '.$date['year'].'

'; + + echo '

downloads

'; + echo '

distinct new users

'; + echo '

download details

'; + echo '

Hardware users - Unfinished install

'; + echo '

Hardware users - Finished install

'; + + echo "

"; + /* + to add display function copy a display* function (add a global variable to indicates if the content must be display + add this variable to the getHref function + */ + if ($display==1) + { + displayDownload($link); + } + if ($display ==2) + { + displayDistinctUsers($link); + } + + //display current session + + $current_day = date("Y-m-d", $selected); + $next_day = date("Y-m-d", $selected + 24*3600); + $condition = "`sessions`.`start_download` >= '$current_day' AND `sessions`.`start_download` < '$next_day'"; + if ($display == 3) + { + displayDownloadDetails($condition, $link); + } + $condition2 = "`install_users`.`first_install` >= '$current_day' AND `install_users`.`first_install` < '$next_day'"; + displayHardwareNewUser($condition2, $link); + + $dt2= gettimeofday(); + echo "

computed in " . ( $dt2["sec"] - $dt["sec"] + ($dt2["usec"] - $dt["usec"]) / 1000000 ). "s"; + echo "\n\n"; + + mysql_close($link); + unset($link); + + } //end check ip + + break; + + default: + echo "0:unknown command"; + die2(); + } + + + +?> + diff --git a/web/public_php/webig/admin.php b/web/public_php/webig/admin.php new file mode 100644 index 000000000..ccc7d6a13 --- /dev/null +++ b/web/public_php/webig/admin.php @@ -0,0 +1,86 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +include_once('thread_utils.php'); +include_once('mail_utils.php'); +include_once('admin_utils.php'); + +if (($user_login != "support" || ($remote_addr != "192.168.1.153" && $remote_addr != "192.168.3.1")) && $remote_addr != "127.0.0.1") +{ + die(); +} + +importParam('recover_forum'); +if ($recover_forum) +{ + echo "recover forum $recover_forum
\n"; + recover_thread($recover_forum); + die(); +} + +importParam('recover_thread'); +importParam('recover_threadthread'); +if ($recover_thread && isset($recover_threadthread)) +{ + echo "recover forum $recover_thread
\n"; + recover_one_thread($recover_thread, $recover_threadthread); + die(); +} + +importParam('rename_forum'); +importParam('into_forum'); +if ($rename_forum) +{ + echo "rename forum $rename_forum into $into_forum
\n"; + rename_forum($rename_forum, $into_forum); + die(); +} + + +importParam('shard'); + +importParam('mailbox'); +importParam('mail'); + +if ($mail) +{ + $mdir = get_user_dir($mailbox, $shard); + readfile($mdir.$mail); + die(); +} +else if ($mailbox) +{ + display_mailbox_content($shard, $mailbox); + die(); +} + +importParam('forum'); +importParam('thread'); + +if ($thread) +{ + display_thread_content($shard, $forum, $thread); + die(); +} +else if ($forum) +{ + display_forum_content($shard, $forum); + die(); +} + +?> \ No newline at end of file diff --git a/web/public_php/webig/admin_interface.php b/web/public_php/webig/admin_interface.php new file mode 100644 index 000000000..bcd4ce4ab --- /dev/null +++ b/web/public_php/webig/admin_interface.php @@ -0,0 +1,119 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +$server = "localhost"; +$port = 80; + +// import HTTP_GET_VARS as _GET if _GET doesn't exist +if (!isset($_GET) && isset($HTTP_GET_VARS)) + $_GET = &$HTTP_GET_VARS; + +echo "
\n"; +echo "SHARD:
\n"; +echo "MAILBOX:
\n"; +echo "FORUM:
\n"; +echo "
\n"; +echo "
\n"; + +if ($_GET["mailbox"]) +{ + echo "Get mailbox ".$_GET["mailbox"]." content:
\n"; + $s = fsockopen($server, $port, &$errno, &$errstr, 30) or die ("ERROR: can't connect to $server:$port"); + fputs($s,"GET /websrv/admin.php?user_login=support&shard=".$_GET["shard"]."&mailbox=".$_GET["mailbox"]." HTTP/1.0\n\n"); + + while(!feof($s)) + { + $l = trim(fgets($s, 2048)); + if (ereg("^FILE:(.*)", $l, $reg)) + echo "".$reg[1]."
\n"; + } + + fclose($s); + echo "

\n"; +} + +if ($_GET["mail"]) +{ + echo "Get mail ".$_GET["mailbox"]."/".$_GET["mail"]." content:
\n"; + $s = fsockopen($server, $port, &$errno, &$errstr, 30) or die ("ERROR: can't connect to $server:$port"); + fputs($s, "GET /websrv/admin.php?user_login=support&shard=".$_GET["shard"]."&mail=".$_GET["mail"]."&mailbox=".$_GET["mailbox"]." HTTP/1.0\n\n"); + + echo "Content of mail:
\n"; + while(!feof($s)) + echo nl2br(htmlentities(trim(fgets($s, 2048)))); + + fclose($s); + echo "

\n"; +} + +if ($_GET["recover_thread"]) +{ + echo "Recover thread ".$_GET["forum"]." ".$_GET["recover_thread"]."
\n"; + $s = fsockopen($server, $port, &$errno, &$errstr, 30) or die ("ERROR: can't connect to $server:$port"); + fputs($s, "GET /websrv/admin.php?user_login=support&shard=".$_GET["shard"]."&recover_thread=".$_GET["forum"]."&recover_threadthread=".$_GET["recover_thread"]." HTTP/1.0\n\n"); + fclose($s); + echo "

\n"; +} + +if ($_GET["forum"]) +{ + echo "Get forum ".$_GET["forum"]." content:
\n"; + $s = fsockopen($server, $port, &$errno, &$errstr, 30) or die ("ERROR: can't connect to $server:$port"); + fputs($s, "GET /websrv/admin.php?user_login=support&shard=".$_GET["shard"]."&forum=".$_GET["forum"]." HTTP/1.0\n\n"); + + while(!feof($s)) + { + $l = trim(fgets($s, 2048)); + if (ereg("^FILE:(.*)", $l, $reg)) + { + echo "".trim($reg[1])."\n"; + if ($reg[1]{0} == '_') + { + echo " recover thread\n"; + } + echo "
\n"; + } + } + + fclose($s); + echo "

\n"; +} + +if ($_GET["thread"]) +{ + echo "Get thread ".$_GET["forum"]."/".$_GET["thread"]." content:
\n"; + $s = fsockopen($server, $port, &$errno, &$errstr, 30) or die ("ERROR: can't connect to $server:$port"); + fputs($s, "GET /websrv/admin.php?user_login=support&shard=".$_GET["shard"]."&forum=".$_GET["forum"]."&thread=".$_GET["thread"]." HTTP/1.0\n\n"); + + echo "Content of thread:
\n"; + while(!feof($s)) + { + $l = trim(fgets($s, 2048)); + if (ereg("^TOPIC:(.*) SUBMIT:(.*)$", $l, $reg)) + echo nl2br(htmlentities(" TOPIC:".$reg[1]."SUBMITED BY: ".$reg[2]."\n")); + if (ereg("^AUTHOR:(.*) DATE:(.*) POST:(.*)", $l, $reg)) + echo nl2br(htmlentities("AUTHOR: ".$reg[1]." DATE:".$reg[2]." POST:".$reg[3]."\n")); + } + + fclose($s); + echo "

\n"; +} + + + +?> \ No newline at end of file diff --git a/web/public_php/webig/admin_utils.php b/web/public_php/webig/admin_utils.php new file mode 100644 index 000000000..f0a70403a --- /dev/null +++ b/web/public_php/webig/admin_utils.php @@ -0,0 +1,62 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +function display_mailbox_content($shard, $user) +{ + $udir = get_user_dir($user, $shard); + + echo "-- MAILBOX $user ($udir)\n"; + $dir = opendir($udir); + while ($dir && ($file = readdir($dir))) + if (ereg("^mail_([0-9]*)\.html", $file) || ereg("^_mail_([0-9]*)\.html", $file)) + echo "FILE:$file\n"; + echo "-- END MAILBOX $user\n"; +} + +function display_forum_content($shard, $user) +{ + $udir = get_user_dir($user, $shard); + + echo "-- FORUM $user ($udir)\n"; + $dir = opendir($udir); + while ($dir && ($file = readdir($dir))) + if (ereg("^thread_([0-9]*)\.index", $file) || ereg("^_thread_([0-9]*)\.index", $file)) + echo "FILE:$file\n"; + echo "-- END FORUM $user\n"; +} + +function display_thread_content($shard, $forum, $thread) +{ + $udir = get_user_dir($forum, $shard); + read_index($udir.$thread, &$header, &$array); + + $a = explode("%%", $header); + + echo "-- THREAD $forum $thread\n"; + echo "TOPIC: ".$a[1]." SUBMIT: ".$a[0]."\n"; + if (count($array) > 0) + { + foreach ($array as $post) + { + echo "AUTHOR: ".$post[0]." DATE: ".$post[2]." POST: ".$post[1]."\n"; + } + } + echo "-- END THREAD $forum $thread\n"; +} + +?> \ No newline at end of file diff --git a/web/public_php/webig/check_mail.php b/web/public_php/webig/check_mail.php new file mode 100644 index 000000000..2d98f32c7 --- /dev/null +++ b/web/public_php/webig/check_mail.php @@ -0,0 +1,38 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + unset($user); + $user = $user_login; + + $user_dir = get_user_dir($user, $shard); + if (!is_dir($user_dir)) + die("0"); + + $fname = $user_dir.'new_mails'; + if (file_exists($fname)) + { + unlink($fname); + die("1"); + } + else + { + die("0"); + } +?> diff --git a/web/public_php/webig/config.php b/web/public_php/webig/config.php new file mode 100644 index 000000000..c525f9b13 --- /dev/null +++ b/web/public_php/webig/config.php @@ -0,0 +1,6 @@ + diff --git a/web/public_php/webig/confirm_remove_mail.php b/web/public_php/webig/confirm_remove_mail.php new file mode 100644 index 000000000..aa13f98d9 --- /dev/null +++ b/web/public_php/webig/confirm_remove_mail.php @@ -0,0 +1,48 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('mail_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the mailbox + // $select_mail_%% mails to be removed + // + + read_template('confirm_delete_mail.html', $confirm_delete_mail); + + $mails = array(); + $selected_mails = ''; + foreach ($_POST as $var => $value) + { + if (matchParam($var, "select_mail_", $mail)) + { + $mails[] = $mail; + $selected_mails .= "\n"; + } + } + + // + + $instance = str_replace(array('%%MAIL%%', '%%SELECTED_MAILS%%'), + array($mails[0], $selected_mails), + $confirm_delete_mail); + + echo $instance; +?> \ No newline at end of file diff --git a/web/public_php/webig/create_thread.php b/web/public_php/webig/create_thread.php new file mode 100644 index 000000000..e11bc45f1 --- /dev/null +++ b/web/public_php/webig/create_thread.php @@ -0,0 +1,88 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('thread_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $shard shard from which the user connects in + // $post_from user who create the thread + // $post_to forum in which the thread is to be created + // $post_subject topic of the new thread + // $post_content content of the first post (optional) + // + + importParam('post_from'); + importParam('post_to'); + importParam('post_subject'); + importParam('post_content'); + + check_character_belongs_to_guild($user_login, $post_to); + + // check mail is valid + //if (!isset($post_from) || !isset($post_to) || !isset($post_subject)) + // die('Incomplete post to send'); + //if ($post_subject == '') $post_subject = 'No Subject'; + + // check recipient has an account + $to_dir = build_user_dir($post_to, $shard); + $to_index = $to_dir.'forum.index'; + + if (!file_exists($to_index)) + { + build_forum_page($post_to); + } + + if (trim($post_subject) != '') + { + $post_from = clean_string($post_from); + $post_to = clean_string($post_to); + $post_subject = clean_string($post_subject); + + // + // send mail to recipient + // + + // create new thread index + add_thread_to_forum_index($post_from, $post_to, $post_subject, $index); + + // create thread file + create_thread($post_from, $post_to, $post_subject, $index); + + // add main post to thread + if ($post_content != "") + add_post($post_from, $post_to, $post_content, $index, $last_date); + + // rebuild thread page + build_thread_page($post_to, $index, $num_posts); + + // update forum index since thread was touched + update_forum_index($post_to, $index, $num_posts, $last_date); + + // rebuild forum page + build_forum_page($post_to); + } + + // redirect browser to new forum page + //redirect("forum.php?forum=$post_to"); + exportParam('forum', $post_to); + //$forum = $post_to; + include('forum.php'); +?> \ No newline at end of file diff --git a/web/public_php/webig/form_post.php b/web/public_php/webig/form_post.php new file mode 100644 index 000000000..6e88f5b97 --- /dev/null +++ b/web/public_php/webig/form_post.php @@ -0,0 +1,152 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('mail_utils.php'); + include_once('thread_utils.php'); + + if ($enter_login) + { + if ($login) + setcookie('user_login', $login, time()+86400); + else + setcookie('user_login'); + } + + if ($rebuild_mailbox) + { + build_mail_page($user); + } + + if ($rebuild_forum) + { + build_forum_page($user); + } + + if ($rebuild_thread) + { + build_thread_page($user, $thread, $num_posts); + } + + if ($remove_thread) + { + remove_thread($user, $thread); + } + + + + function selectUser($var) + { + return "\n"; + } + + echo "Fake post form\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "
\n"; + + echo "


\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "
Login
\n"; + + echo "


\n"; + + echo "Post a mail
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
From".selectUser('mail_from')."
To".selectUser('mail_to')."
Subject
Content
\n"; + + echo "


\n"; + + echo "Rebuild a mail box
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
User".selectUser('user')."
\n"; + + echo "


\n"; + + + + echo "Create a thread in a forum
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
From".selectUser('post_from')."
To".selectUser('post_to')."
Subject
Content
\n"; + + echo "


\n"; + + echo "Post a topic in a thread
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
From".selectUser('post_from')."
To".selectUser('post_to')."
Thread
Content
\n"; + + echo "


\n"; + + echo "Rebuild a forum
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
User".selectUser('user')."
\n"; + + echo "


\n"; + + echo "Rebuild a thread
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
User".selectUser('user')."
Thread
\n"; + + echo "


\n"; + + echo "Remove a thread
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
User".selectUser('user')."
Thread
\n"; + + echo "


\n"; + + echo "\n"; + echo "\n"; + +?> \ No newline at end of file diff --git a/web/public_php/webig/forum.php b/web/public_php/webig/forum.php new file mode 100644 index 000000000..9e154a370 --- /dev/null +++ b/web/public_php/webig/forum.php @@ -0,0 +1,46 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $shard shard from which the user connects in + // $forum forum to view + // + + importParam('forum'); + importParam('page'); + + check_character_belongs_to_guild($user_login, $forum); + + $forum_dir = build_user_dir($forum, $shard); + + $fname = $forum_dir.'forum'.(isset($page) && $page!="" && $page!="0" ? "_$page" : '').'.html'; + if (!file_exists($fname)) + { + include_once('thread_utils.php'); + build_forum_page($forum); + } + + $f = fopen($fname, 'r'); + echo fread($f, filesize($fname)); + fclose($f); +?> \ No newline at end of file diff --git a/web/public_php/webig/index.php b/web/public_php/webig/index.php new file mode 100644 index 000000000..e28ec496a --- /dev/null +++ b/web/public_php/webig/index.php @@ -0,0 +1,21 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + die(); + +?> \ No newline at end of file diff --git a/web/public_php/webig/mail.php b/web/public_php/webig/mail.php new file mode 100644 index 000000000..069a5adee --- /dev/null +++ b/web/public_php/webig/mail.php @@ -0,0 +1,39 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + unset($user); + $user = $user_login; + + importParam('msg'); + + $user_dir = get_user_dir($user, $shard); + $fname = $user_dir."mail_$msg.html"; + if (!is_dir($user_dir) || !file_exists($fname)) + { + include_once('mailbox.php'); + die(); + } + + $f = fopen($fname, 'r'); + echo fread($f, filesize($fname)); + fclose($f); + + /* display_time(); */ +?> \ No newline at end of file diff --git a/web/public_php/webig/mail_utils.php b/web/public_php/webig/mail_utils.php new file mode 100644 index 000000000..4d6dc13f9 --- /dev/null +++ b/web/public_php/webig/mail_utils.php @@ -0,0 +1,177 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +include_once('utils.php'); + +// ------------------------------------- +// add a new thread into user forum index +// ------------------------------------- +function add_mail_to_index(&$from, &$to, &$subject, &$index) +{ + global $shard; + $to_dir = get_user_dir($to, $shard); + $to_index = $to_dir.'mail.index'; + + use_index($to_index); + + $f = fopen($to_index, 'r+'); + read_next_index($f, $index); + append_to_index($f, trim($from).'%%'.strtr(trim($subject), "\n", " ").' %%'.displayable_date().'%%1%%'.$index); + update_next_index($f, $index+1); + fclose($f); +} + +// ------------------------------------- +// remove mail +// ------------------------------------- +function remove_mail($user, $mails) +{ + global $shard; + $mail_dir = get_user_dir($user, $shard); + + read_index($mail_dir.'mail.index', $header, $array); + + sort($mails); + $remove_mail = 0; + + for ($i=0; $i= count($mails) || $array[$i][4] != $mails[$remove_mail]) + $newarray[] = $array[$i]; + else + ++$remove_mail; + + write_index($mail_dir.'mail.index', $header, $newarray); + + build_mail_page($user); +} + +// ------------------------------------- +// create new mail file +// ------------------------------------- +function create_mail(&$from, &$to, &$subject, &$content, &$cleancontent, &$index) +{ + global $shard; + $to_dir = get_user_dir($to, $shard); + + read_template('mail.html', $mail); + + $inst_mailbox = str_replace(array('%%FROM%%', '%%UCFROM%%', '%%DATE%%', '%%SUBJECT%%', '%%CONTENT%%', '%%CLEANCONTENT%%', '%%MAIL%%'), + array($from, ucfirst($from), displayable_date(), ucfirst($subject), $content, $cleancontent, $index), + $mail); + + // build mail message + $f = fopen($to_dir."mail_$index.html", 'w'); + fwrite($f, $inst_mailbox); + fclose($f); + + $f = fopen($to_dir.'new_mails', 'w'); + fwrite($f, '1'); + fclose($f); + + srand((float) microtime()*1000000); + $fname = md5(rand()); + global $USERS_DIR; + if (!@is_dir($USERS_DIR.'/incoming')) + @mkdir($USERS_DIR.'/incoming'); + $f = @fopen($USERS_DIR.'/incoming/'.$fname, "w"); + if ($f) + { + fwrite($f, "shard=$shard to=$to from=$from\n$$$$"); + fclose($f); + } +} + + +// ------------------------------------- +// rebuild user mail box pages +// ------------------------------------- +function build_mail_page($user) +{ + global $shard; + + $user_dir = get_user_dir($user, $shard); + $user_index = $user_dir."mail.index"; + + // open thread index + read_index($user_index, $header, $mails); + + $num_mails = count($mails); + $num_per_page = 10; + $num_pages = (int)(($num_mails+$num_per_page-1) / $num_per_page); + + $mail = $num_mails-1; + $page = 0; + + $altern_color = array("#333333", "#666666"); + $altern_index = 0; + + $links_str = ''; + + read_template('mailbox_main.html', $mailbox_main); + read_template('mailbox_mail.html', $mailbox_mail); + + read_template('browse_link.html', $browse_link); + + do + { + $num_in_page = 0; + $inst_mail = ''; + + while ($num_in_page < 10 && $mail >= 0) + { + $m = &$mails[$mail]; + + $subject = ucfirst(displayable_string($m[1])); + + $inst_mail .= str_replace(array('%%FROM%%', '%%UCFROM%%', '%%SUBJECT%%', '%%DATE%%', '%%USER%%', '%%MAIL%%', '%%COLOR%%'), + array($m[0], ucfirst($m[0]), $subject, $m[2], $user, $m[4], $altern_color[$altern_index]), + $mailbox_mail); + + // step to next message + ++$num_in_page; + --$mail; + $altern_index = 1-$altern_index; + } + + $links_str = ''; + $link_previous = ($page == 0 ? "mailbox.php?page=".$page : "mailbox.php?page=".($page-1)); + for ($i=0; $i<$num_pages; ++$i) + { + $link = ($i == $page ? $i+1 : "".($i+1).""); + $links_str .= str_replace(array('%%LINK%%'), + array($link), + $browse_link); + } + $link_next = (($page == $num_pages-1 || $num_pages <= 1) ? "mailbox.php?page=".$page : "mailbox.php?page=".($page+1)); + + $inst_mailbox = str_replace(array('%%MAILS%%', '%%PREVIOUS%%', '%%LINKS%%', '%%NEXT%%'), + array($inst_mail, $link_previous, $links_str, $link_next), + $mailbox_main); + + $pagename = $user_dir."mailbox".($page==0 ? '' : '_'.$page).'.html'; + + $f = fopen($pagename, 'w'); + fwrite($f, $inst_mailbox); + fclose($f); + + ++$page; + } + while ($mail >= 0); +} + +?> diff --git a/web/public_php/webig/mailbox.php b/web/public_php/webig/mailbox.php new file mode 100644 index 000000000..15207b600 --- /dev/null +++ b/web/public_php/webig/mailbox.php @@ -0,0 +1,49 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + importParam('page'); + + unset($user); + $user = $user_login; + + $user_dir = build_user_dir($user, $shard); + + $fname = $user_dir.'mailbox.html'; + if (!file_exists($fname)) + { + include_once('mail_utils.php'); + build_mail_page($user); + } + + $fname = $user_dir.'mailbox'.(isset($page) && $page!="" && $page!="0" ? "_$page" : '').'.html'; + if (!file_exists($fname)) + die("INTERNAL ERROR 10"); + + $f = fopen($fname, 'r'); + echo fread($f, filesize($fname)); + fclose($f); + + // remove new_mails file when user checks its mailbox + $fname = $user_dir.'new_mails'; + if (file_exists($fname)) + unlink($fname); + + /* display_time(); */ +?> diff --git a/web/public_php/webig/new_mail.php b/web/public_php/webig/new_mail.php new file mode 100644 index 000000000..05383a3e0 --- /dev/null +++ b/web/public_php/webig/new_mail.php @@ -0,0 +1,41 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + // + // INPUT: + // + // $user_login login of the user that write the mail + // $mail_to user to send mail to (optional) + // $mail_subject subject of the mail (optional) + // $mail_content content of the mail (optional) + // + + importParam('mail_to'); + importParam('mail_subject'); + importParam('mail_content'); + + read_template('new_mail.html', $new_mail); + + $instance = str_replace(array('%%FROM%%', '%%UCFROM%%', '%%TO%%', '%%UCTO%%', '%%SUBJECT%%', '%%CONTENT%%'), + array($user_login, ucfirst($user_login), $mail_to, ucfirst($mail_to), ucfirst(displayable_string($mail_subject)), displayable_content($mail_content)), + $new_mail); + + echo $instance; +?> \ No newline at end of file diff --git a/web/public_php/webig/new_post.php b/web/public_php/webig/new_post.php new file mode 100644 index 000000000..494de0733 --- /dev/null +++ b/web/public_php/webig/new_post.php @@ -0,0 +1,43 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $forum forum in which to post + // $thread thread within the forum in which to post + // $subject subject of the thread + // + + importParam('forum'); + importParam('thread'); + importParam('subject'); + + check_character_belongs_to_guild($user_login, $forum); + + read_template('new_post.html', $new_post); + + $instance = str_replace(array('%%SENDER%%', '%%UCSENDER%%', '%%FORUM_POST%%', '%%FORUM%%', '%%UCFORUM%%', '%%THREAD%%', '%%SUBJECT%%'), + array($user_login, ucfirst($user_login), $forum, nameToURL($forum), convert_forum_name($forum), $thread, $subject), + $new_post); + + echo $instance; +?> \ No newline at end of file diff --git a/web/public_php/webig/new_thread.php b/web/public_php/webig/new_thread.php new file mode 100644 index 000000000..d8ec01bc6 --- /dev/null +++ b/web/public_php/webig/new_thread.php @@ -0,0 +1,39 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $forum forum to create thread into + // + + importParam('forum'); + + check_character_belongs_to_guild($user_login, $forum); + + read_template('new_thread.html', $new_thread); + + $instance = str_replace(array('%%SENDER%%', '%%UCSENDER%%', '%%FORUM_POST%%', '%%FORUM%%', '%%UCFORUM%%'), + array($user_login, ucfirst($user_login), $forum, nameToURL($forum), convert_forum_name($forum)), + $new_thread); + + echo $instance; +?> \ No newline at end of file diff --git a/web/public_php/webig/post.php b/web/public_php/webig/post.php new file mode 100644 index 000000000..cf3529f68 --- /dev/null +++ b/web/public_php/webig/post.php @@ -0,0 +1,77 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('thread_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $shard shard from which the client connects in + // $post_from user who post the message + // $post_to forum in which to post the message + // $post_thread thread within the forum in which to post the message + // $post_content content of the post + // + + importParam('post_from'); + importParam('post_to'); + importParam('post_thread'); + importParam('post_content'); + + check_character_belongs_to_guild($user_login, $post_to); + + // check mail is valid + //if (!isset($post_from) || !isset($post_to) || !isset($post_thread) || !isset($post_content)) + // die('Incomplete post to send'); + + // check recipient has an account + $to_dir = build_user_dir($post_to, $shard); + $to_index = $to_dir.'forum.index'; + + if (trim($post_content) != '') + { + $post_from = clean_string($post_from); + $post_to = clean_string($post_to); + $post_content = clean_content($post_content); + + // + // send mail to recipient + // + + // add main post to thread + add_post($post_from, $post_to, $post_content, $post_thread, $last_date); + + // rebuild thread page + build_thread_page($post_to, $post_thread, $num_posts); + + // update forum index since thread was touched + update_forum_index($post_to, $post_thread, $num_posts, $last_date); + + // rebuild forum page + build_forum_page($post_to); + } + + // redirect browser to new forum page + //redirect("thread.php?forum=$post_to&thread=$post_thread"); + exportParam('forum', $post_to); + exportParam('thread', $post_thread); + //$forum = $post_to; + //$thread = $post_thread; + include_once('thread.php'); +?> \ No newline at end of file diff --git a/web/public_php/webig/post_mail.php b/web/public_php/webig/post_mail.php new file mode 100644 index 000000000..a84ade9e6 --- /dev/null +++ b/web/public_php/webig/post_mail.php @@ -0,0 +1,86 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('mail_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that posts a mail + // $shard shard from which the client connects in + // $mail_from login of the user that posts a mail + // $mail_to login of the user that receives the mail + // $mail_subject subject of the mail + // $mail_content content of the mail + // + + importParam('mail_from'); + importParam('mail_to'); + importParam('mail_subject'); + importParam('mail_content'); + + // check mail is valid + //if (!isset($mail_from) || $mail_from == "" || !isset($mail_to) || $mail_to == "" || !isset($mail_subject) || $mail_subject == "" || !isset($mail_content) || $mail_content == "" ) + // die('Incomplete mail to send'); + + // check recipient has an account + + if (trim($mail_content) != '') + { + if ($mail_to == '' || !is_dir($to_dir = get_user_dir($mail_to, $shard))) + { + $mail_subject = "uiMFUndelivrableMail '$mail_subject'"; + $mail_cleansubject = $mail_subject; + $mail_content = "uiMFUndelivrableMailTo '$mail_to'.\nuiMFUndelivrableMailCheck
\n
\nuiMFMailContent
\n$mail_content"; + $mail_cleancontent = "uiMFUndelivrableMailTo '$mail_to'.\nuiMFUndelivrableMailCheck\n\nuiMFMailContent\n$mail_content"; + $mail_to = $mail_from; + $mail_from = 'uiMFMailServer'; + } + else + { + $mail_cleansubject = $mail_subject; + $mail_subject = displayable_string(clean_string($mail_subject)); + $mail_cleancontent = displayable_content($mail_content); + $mail_content = displayable_string($mail_content); + $mail_from = displayable_string(clean_string($mail_from)); + $mail_to = displayable_string(clean_string($mail_to)); + } + + $to_dir = build_user_dir($mail_to, $shard); + $to_index = $to_dir.'mail.index'; + + // + // send mail to recipient + // + + // create new mail index + add_mail_to_index($mail_from, $mail_to, $mail_cleansubject, $mail_index); + + // create mail file + create_mail($mail_from, $mail_to, $mail_subject, $mail_content, $mail_cleancontent, $mail_index); + + // rebuild recipient mailbox page + build_mail_page($mail_to); + } + + + // redirect browser to new forum page + //redirect("mailbox.php"); + include_once('mailbox.php'); + +?> \ No newline at end of file diff --git a/web/public_php/webig/remove_mail.php b/web/public_php/webig/remove_mail.php new file mode 100644 index 000000000..0e20f991d --- /dev/null +++ b/web/public_php/webig/remove_mail.php @@ -0,0 +1,40 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('mail_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the mailbox + // $select_mail_%% mails to be removed + // + + $mails = array(); + + foreach ($_POST as $var => $value) + if (matchParam($var, "select_mail_", $mail)) + $mails[] = $mail; + + if (count($mails) > 0) + remove_mail($user_login, $mails); + + // redirect browser to new mailbox page + //redirect("mailbox.php"); + include_once('mailbox.php'); +?> \ No newline at end of file diff --git a/web/public_php/webig/remove_post.php b/web/public_php/webig/remove_post.php new file mode 100644 index 000000000..900cbf96e --- /dev/null +++ b/web/public_php/webig/remove_post.php @@ -0,0 +1,50 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('thread_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $forum forum to remove posts off + // $thread thread to remove posts off + // $select_post_%% posts to be removed + // + + importParam('forum'); + importParam('thread'); + + check_character_belongs_to_guild($user_login, $forum); + + /* if ($forum == $user_login) */ + { + $posts = array(); + + foreach ($_POST as $var => $value) + if (matchParam($var, "select_post_", $post)) + $posts[] = $post; + + if (count($posts) > 0) + remove_post($forum, $thread, $posts); + } + + // redirect browser to new forum page + //redirect("thread.php?forum=$forum&thread=$thread"); + include_once('thread.php'); +?> \ No newline at end of file diff --git a/web/public_php/webig/remove_thread.php b/web/public_php/webig/remove_thread.php new file mode 100644 index 000000000..47350db4e --- /dev/null +++ b/web/public_php/webig/remove_thread.php @@ -0,0 +1,48 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('thread_utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $forum forum to remove threads off + // $selected_thread_%% threads to be removed + // + + importParam('forum'); + importParam('thread'); + + check_character_belongs_to_guild($user_login, $forum); + + /* if ($forum == $user_login) */ + { + foreach ($_POST as $var => $value) + { + if (matchParam($var, "select_thread_", $thread)) + { + remove_thread($forum, $thread); + } + } + } + + // redirect browser to new forum page + //redirect("forum.php?forum=$forum"); + include_once('forum.php'); +?> \ No newline at end of file diff --git a/web/public_php/webig/template/browse_bar.html b/web/public_php/webig/template/browse_bar.html new file mode 100644 index 000000000..3420f76be --- /dev/null +++ b/web/public_php/webig/template/browse_bar.html @@ -0,0 +1,13 @@ + +
+ + + +%%LINKS%% + + +
uiMFPrevious +
uiMFNext
+
+
+ diff --git a/web/public_php/webig/template/browse_link.html b/web/public_php/webig/template/browse_link.html new file mode 100644 index 000000000..029a7008d --- /dev/null +++ b/web/public_php/webig/template/browse_link.html @@ -0,0 +1 @@ + %%LINK%% diff --git a/web/public_php/webig/template/confirm_delete_mail.html b/web/public_php/webig/template/confirm_delete_mail.html new file mode 100644 index 000000000..02fb89597 --- /dev/null +++ b/web/public_php/webig/template/confirm_delete_mail.html @@ -0,0 +1,50 @@ + + +<i>uiMFDeleteMailTitle</i> + + + + +
+%%SELECTED_MAILS%% + + + + +
+ + + + + + + +
+
+ + + + + +

uiMFEraseMail

+ + + + +
uiWebHome + uiWebBack
+
+
+ + + + + + + +
uiMFEraseMailQuestion
+
+
+
+ + diff --git a/web/public_php/webig/template/forum_main.html b/web/public_php/webig/template/forum_main.html new file mode 100644 index 000000000..0b0240d26 --- /dev/null +++ b/web/public_php/webig/template/forum_main.html @@ -0,0 +1,57 @@ + + +%%UCFORUM%% Forum + + + + +
+ + + + +
+ + + + + + + + + + +
+ + + + +

%%UCFORUM%%

+
+ + +
+
+ + + + + + +%%TOPICS%% +
uiMFTopicsuiMFAuthoruiMFPostsuiMFLastPost
+
+ + + +%%LINKS%% + + + + +
uiWebPreviousuiWebNextuiWebNewTopic
+
+
+
+ + diff --git a/web/public_php/webig/template/forum_topic.html b/web/public_php/webig/template/forum_topic.html new file mode 100644 index 000000000..c4f95a7ca --- /dev/null +++ b/web/public_php/webig/template/forum_topic.html @@ -0,0 +1,7 @@ + + + %%SUBJECT%% + %%UCSENDER%% + %%NUMPOSTS%% + %%DATE%% + diff --git a/web/public_php/webig/template/mail.html b/web/public_php/webig/template/mail.html new file mode 100644 index 000000000..7bd6529ac --- /dev/null +++ b/web/public_php/webig/template/mail.html @@ -0,0 +1,85 @@ + + +Message From %%UCFROM%% + + + + + + + + +
+ + + + + + + + + + +
+
+ + + + + +

uiMFMessageFrom %%UCFROM%%

+ + + + +
uiWebHome + uiWebBack
+
+
+ + +
+ + + +
+ + + +
+ + + +
+ + +
uiMFAuthor%%UCFROM%%
uiMFDate%%DATE%%
uiMFSubject%%SUBJECT%%
uiMFMessage%%CONTENT%%
+
+ + + + + + + + + + + + + + + + + + + + + +
uiWebNewMessage
+
+
+ + diff --git a/web/public_php/webig/template/mailbox_mail.html b/web/public_php/webig/template/mailbox_mail.html new file mode 100644 index 000000000..b9fdc968b --- /dev/null +++ b/web/public_php/webig/template/mailbox_mail.html @@ -0,0 +1,6 @@ + + + %%UCFROM%% + %%SUBJECT%% + %%DATE%% + diff --git a/web/public_php/webig/template/mailbox_main.html b/web/public_php/webig/template/mailbox_main.html new file mode 100644 index 000000000..819cb3cb1 --- /dev/null +++ b/web/public_php/webig/template/mailbox_main.html @@ -0,0 +1,57 @@ + + +Inbox + + + + +
+ + + + +
+ + + + + + + + + + +
+ + + + + +

uiMFInbox

+
+ + +
+
+ + + + + +%%MAILS%% +
uiMFFromuiMFSubjectuiMFDate
+
+ + + +%%LINKS%% + + + + +
uiWebPreviousuiWebNextuiWebNewMessage
+
+
+
+ + diff --git a/web/public_php/webig/template/new_mail.html b/web/public_php/webig/template/new_mail.html new file mode 100644 index 000000000..bdd87ddce --- /dev/null +++ b/web/public_php/webig/template/new_mail.html @@ -0,0 +1,69 @@ + + +New Message + + + + +
+ + + + + +
+ + + + + + + + + + +
+ + + + + +

uiMFNewMessage

+ + + + +
uiWebHome + uiWebBack
+
+ + +
+ + + +
+ + + +
+ + +
To +
+ +
+
uiMFSubject +
+ +
+
uiMFMailBody +
+ +
+
+
+
+
+ + diff --git a/web/public_php/webig/template/new_post.html b/web/public_php/webig/template/new_post.html new file mode 100644 index 000000000..b75c9cc40 --- /dev/null +++ b/web/public_php/webig/template/new_post.html @@ -0,0 +1,57 @@ + + +New Message + + + + +
+ + + + + + + +
+ + + + + + + +
+
+ + + + + +

%%UCFORUM%%

%%SUBJECT%%
+ + + + +
uiWebHome + uiWebBack
+
+
+ + + + + + + + + + +
uiMFNewPost
+ +
+
+
+
+ + diff --git a/web/public_php/webig/template/new_thread.html b/web/public_php/webig/template/new_thread.html new file mode 100644 index 000000000..191d2a77b --- /dev/null +++ b/web/public_php/webig/template/new_thread.html @@ -0,0 +1,53 @@ + + +New Topic + + + + +
+ + + + + + +
+ + + + + + + +
+
+ + + + +

%%UCFORUM%%

+ + + + +
uiWebHome + uiWebBack
+
+
+ + + + + + + + + + +
uiMFNewtopic
+
+
+
+ + diff --git a/web/public_php/webig/template/topic_main.html b/web/public_php/webig/template/topic_main.html new file mode 100644 index 000000000..8db2d374c --- /dev/null +++ b/web/public_php/webig/template/topic_main.html @@ -0,0 +1,65 @@ + + +Topic + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+ + + + + +

%%UCFORUM%%

%%SUBJECT%%
+ + + + +
uiWebHome + uiWebBack
+
+
+ + +

+

+ + + +%%POSTS%% +
 uiMFAuthoruiMFMessages
+
+ + + +%%LINKS%% + + + + +
uiWebPreviousuiWebNextuiWebNewPost
+
+
+
+ + diff --git a/web/public_php/webig/template/topic_post.html b/web/public_php/webig/template/topic_post.html new file mode 100644 index 000000000..122e3cabe --- /dev/null +++ b/web/public_php/webig/template/topic_post.html @@ -0,0 +1,5 @@ + + + %%UCSENDER%%
%%DATE%% + %%CONTENT%% + diff --git a/web/public_php/webig/thread.php b/web/public_php/webig/thread.php new file mode 100644 index 000000000..8cc6e2c11 --- /dev/null +++ b/web/public_php/webig/thread.php @@ -0,0 +1,48 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + include_once('utils.php'); + + // + // INPUT: + // + // $user_login login of the user that consults the forum + // $shard shard from which the client connects in + // $forum forum to view + // $thread thread within forum to view + // + + importParam('forum'); + importParam('thread'); + importParam('page'); + + check_character_belongs_to_guild($user_login, $forum); + + $user_dir = build_user_dir($forum, $shard); + + $fname = $user_dir."thread_$thread".(isset($page) && $page!="" && $page!="0" ? "_$page" : '').".html"; + if (!file_exists($fname)) + { + include_once('forum.php'); + die(); + } + + $f = fopen($fname, 'r'); + echo fread($f, filesize($fname)); + fclose($f); +?> \ No newline at end of file diff --git a/web/public_php/webig/thread_utils.php b/web/public_php/webig/thread_utils.php new file mode 100644 index 000000000..70d6fd2bd --- /dev/null +++ b/web/public_php/webig/thread_utils.php @@ -0,0 +1,440 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +include_once('utils.php'); + + + + +// ------------------------------------- +// add a new thread into user forum index +// ------------------------------------- +function add_thread_to_forum_index(&$from, &$to, &$subject, &$index) +{ + global $shard; + $to_dir = get_user_dir($to, $shard); + $to_index = $to_dir.'forum.index'; + + use_index($to_index); + + $f = fopen($to_index, 'r+'); + read_next_index($f, $index); + append_to_index($f, trim($from).'%%'.strtr(trim($subject), "\n", " ").' %%".displayable_date()."%%1%%'.$index); + update_next_index($f, $index+1); + fclose($f); +} + + +// ------------------------------------- +// create new thread index +// ------------------------------------- +function create_thread(&$from, &$to, &$subject, &$index) +{ + global $shard; + $to_dir = get_user_dir($to, $shard); + + // build mail message + $array = array(); + write_index($to_dir."thread_$index.index", trim($from).'%%'.strtr(trim($subject), "\n", " ").' %%'.displayable_date(), $array); +} + +// ------------------------------------- +// remove thread +// ------------------------------------- +function remove_thread($forum, $thread) +{ + global $shard; + $forum_dir = get_user_dir($forum, $shard); + + read_index($forum_dir.'forum.index', $header, $array); + + for ($i=0; $i= count($posts) || $i != $posts[$remove_post]) + $newarray[] = $array[$i]; + else + ++$remove_post; + + write_index($forum_dir.'thread_'.$thread.'.index', $header, $newarray); + + build_thread_page($forum, $thread, $num_posts); + update_forum_index($forum, $thread, $num_posts, ""); + build_forum_page($forum); +} + + +// ------------------------------------- +// update forum index after a thread is modified +// ------------------------------------- +function update_forum_index($user, $thread, $num_posts, $last_date) +{ + global $shard; + $user_dir = get_user_dir($user, $shard); + $user_index = $user_dir.'forum.index'; + + // read forum index + read_index($user_index, $header, $threads); + + // search for thread line + for ($i=0; $i\n"; + $index = $regs[1]; + read_index($forum_dir.$browse_file, $fheader, $posts); + + $fhdr = explode('%%', $fheader); + + $threads[$index] = trim($fhdr[0]).'%%'.trim($fhdr[1]).'%%'.trim($fhdr[2]).'%%'.count($posts).'%%'.$index; + } + } + + $icontent = array(); + for ($i=0; $i<$header; ++$i) + { + if ($threads[$i] == '') + continue; + + $icontent[] = array($threads[$i]); + } + + write_index($forum_index, $header, $icontent); + + build_forum_page($forum); +} + +// ------------------------------------- +// recover all deleted threads +// ------------------------------------- +function recover_thread($forum) +{ + global $shard; + $forum_dir = get_user_dir($forum, $shard); + + $browse_dir = opendir($forum_dir); + while ($browse_dir && ($browse_file = readdir($browse_dir))) + { + if (ereg("^_thread_([0-9]*)\.(index|html)", $browse_file)) + { + echo "recover file $browse_file
\n"; + rename($forum_dir.'/'.$browse_file, $forum_dir.'/'.substr($browse_file, 1)); + } + } + + build_forum_index($forum); +} + +// ------------------------------------- +// recover all deleted threads +// ------------------------------------- +function recover_one_thread($forum, $thread) +{ + global $shard; + $forum_dir = get_user_dir($forum, $shard); + + if (file_exists($forum_dir.$thread)) + { + rename($forum_dir.$thread, $forum_dir.substr($thread, 1)); + build_forum_index($forum); + } + else if (file_exists($forum_dir.'_thread_'.$thread.'.index')) + { + $file = 'thread_'.$thread.'.index'; + rename($forum_dir.'_'.$file, $forum_dir.$file); + + if (file_exists($forum_dir.'_thread_'.$thread.'.html')) + { + $file = 'thread_'.$thread.'.html'; + rename($forum_dir.'_'.$file, $forum_dir.$file); + } + + build_forum_index(nameToFile($forum)); + } +} + +// ------------------------------------- +// rename forum +// ------------------------------------- +function rename_forum($forum, $into) +{ + global $shard; + + $olddir = build_user_dir($forum); + $newdir = build_user_dir($into); + + $dir = opendir($olddir); + while ($dir && ($file = readdir($dir))) + $files[] = $file; + + foreach ($files as $file) + { + copy($olddir.'/'.$file, $newdir.'/'.$file); + delete($olddir.'/'.$file); + } + + build_forum_page($into); +} + + + +// ------------------------------------- +// rebuild user mail box pages +// ------------------------------------- +function build_forum_page($forum) +{ + global $shard; + $forum_dir = get_user_dir($forum, $shard); + $forum_index = $forum_dir.'forum.index'; + + // open forum index + read_index($forum_index, $header, $threads); + + $num_threads = count($threads); + $num_per_page = 10; + $num_pages = (int)(($num_threads+$num_per_page-1) / $num_per_page); + + $thread = $num_threads-1; + $num_in_page = 0; + $page = 0; + + $altern_color = array("#333333", "#666666"); + + $links_str = ''; + + read_template('forum_main.html', $forum_main); + read_template('forum_topic.html', $forum_topic); + + read_template('browse_link.html', $browse_link); + + do + { + $inst_topic = ''; + $num_in_page = 0; + $altern_index = 0; + + while ($num_in_page < 10 && $thread >= 0) + { + $t = &$threads[$thread]; + + // replace in topic + $subject = ucfirst(displayable_string($t[1])); + + $inst_topic .= str_replace(array('%%SUBJECT%%', '%%SENDER%%', '%%UCSENDER%%', '%%NUMPOSTS%%', '%%DATE%%', '%%FORUM%%', '%%UCFORUM%%', '%%THREAD%%', '%%COLOR%%'), + array(ucfirst($subject), $t[0], ucfirst($t[0]), $t[3], $t[2], nameToURL($forum), convert_forum_name($forum), $t[4], $altern_color[$altern_index]), + $forum_topic); + + // step to next thread + ++$num_in_page; + --$thread; + $altern_index = 1-$altern_index; + } + + $links_str = ''; + $link_previous = ($page == 0 ? "forum.php?page=".$page : "forum.php?page=".($page-1)); + for ($i=0; $i<$num_pages; ++$i) + { + $link = ($i == $page ? $i+1 : "".($i+1).""); + $links_str .= str_replace(array('%%LINK%%'), + array($link), + $browse_link); + } + $link_next = (($page == $num_pages-1 || $num_pages <= 1) ? "forum.php?page=".$page : "forum.php?page=".($page+1)); + + // replace in forum + $inst_forum = str_replace(array('%%TOPICS%%', '%%FORUM_POST%%', '%%FORUM%%', '%%UCFORUM%%', '%%PREVIOUS%%', '%%LINKS%%', '%%NEXT%%'), + array($inst_topic, $forum, nameToURL($forum), convert_forum_name($forum), $link_previous, $links_str, $link_next), + $forum_main); + + $pagename = $forum_dir.'forum'.($page==0 ? '' : '_'.$page).'.html'; + + $f = fopen($pagename, 'w'); + fwrite($f, $inst_forum); + fclose($f); + + ++$page; + + } + while ($thread >= 0); +} + + + + + + + +// ------------------------------------- +// rebuild user mail box pages +// ------------------------------------- +function build_thread_page($forum, $thread, &$num_posts) +{ + global $shard; + $thread_dir = get_user_dir($forum, $shard); + $thread_index = $thread_dir."thread_$thread.index"; + + // open thread index + read_index($thread_index, $header, $posts); + + $header = explode('%%', $header); + + $thread_subject = $header[1]; + + $num_posts = count($posts); + $num_per_page = 10; + $num_pages = (int)(($num_posts+$num_per_page-1) / $num_per_page); + + $post = 0; + $page = 0; + + $altern_color = array("#333333", "#666666"); + $altern_index = 0; + + $links_str = ''; + + read_template('topic_main.html', $topic_main); + read_template('topic_post.html', $topic_post); + + read_template('browse_link.html', $browse_link); + + do + { + $num_in_page = 0; + $inst_post = ''; + + while ($num_in_page < 10 && $post < $num_posts) + { + $p = &$posts[$post]; + + $content = nl2br(displayable_content($p[1])); + + $inst_post .= str_replace(array('%%FORUM%%', '%%UCFORUM%%', '%%SENDER%%', '%%UCSENDER%%', '%%DATE%%', '%%CONTENT%%', '%%POST%%', '%%COLOR%%'), + array(nameToURL($forum), convert_forum_name($forum), $p[0], ucfirst($p[0]), $p[2], $content, $post, $altern_color[$altern_index]), + $topic_post); + + // step to next post + ++$num_in_page; + ++$post; + $altern_index = 1-$altern_index; + } + + $links_str = ''; + $link_previous = ($page == 0 ? "thread.php?thread=$thread&page=".$page : "thread.php?thread=$thread&page=".($page-1)); + for ($i=0; $i<$num_pages; ++$i) + { + $link = ($i == $page ? $i+1 : "".($i+1).""); + $links_str .= str_replace(array('%%LINK%%'), + array($link), + $browse_link); + } + $link_next = (($page == $num_pages-1 || $num_pages <= 1) ? "thread.php?thread=$thread&page=".$page : "thread.php?thread=$thread&page=".($page+1)); + + $inst_topic = str_replace(array('%%POSTS%%', '%%FORUM_POST%%', '%%FORUM%%', '%%UCFORUM%%', '%%THREAD%%', '%%PREVIOUS%%', '%%LINKS%%', '%%NEXT%%', '%%SUBJECT%%'), + array($inst_post, $forum, nameToURL($forum), convert_forum_name($forum), $thread, $link_previous, $links_str, $link_next, ucfirst($thread_subject)), + $topic_main); + + $pagename = $thread_dir."thread_$thread".($page==0 ? '' : '_'.$page).'.html'; + + $f = fopen($pagename, 'w'); + fwrite($f, $inst_topic); + fclose($f); + + ++$page; + } + while ($post < $num_posts); +} + + +?> \ No newline at end of file diff --git a/web/public_php/webig/timer.php b/web/public_php/webig/timer.php new file mode 100644 index 000000000..ce3d85213 --- /dev/null +++ b/web/public_php/webig/timer.php @@ -0,0 +1,34 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + function getmicrotime() + { + list($usec, $sec) = explode(" ",microtime()); + return ((float)$usec + (float)$sec); + } + + $__start = getmicrotime(); + + function display_time() + { + global $__start; + $end = getmicrotime(); + echo (($end-$__start)*1000)." ms"; + } + +?> \ No newline at end of file diff --git a/web/public_php/webig/utils.php b/web/public_php/webig/utils.php new file mode 100644 index 000000000..1b8bd9338 --- /dev/null +++ b/web/public_php/webig/utils.php @@ -0,0 +1,477 @@ + +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +if (!isset($UTILS_PHP)) +{ + +// import HTTP_GET_VARS as _GET if _GET doesn't exist +if (!isset($_GET) && isset($HTTP_GET_VARS)) + $_GET = &$HTTP_GET_VARS; + +// import HTTP_POST_VARS as _GET if _POST doesn't exist +if (!isset($_POST) && isset($HTTP_POST_VARS)) + $_POST = &$HTTP_POST_VARS; + +$allowCookies = false; + +// import HTTP_POST_VARS as _GET if _POST doesn't exist +if ($allowCookies && !isset($_COOKIE) && isset($HTTP_COOKIE_VARS)) + $_COOKIE = &$HTTP_COOKIE_VARS; + +// ------------------------------------- +// import HTTP param (from a GET or POST, or left if already set...) +// ------------------------------------- +function importParam($var, $secureValue = true) +{ + if (!$secureValue && isset($GLOBALS[$var])) + return; + + global $allowCookies, $_GET, $_POST, $_COOKIE; + + if (isset($_GET[$var])) + $GLOBALS[$var] = $_GET[$var]; + else if (isset($_POST[$var])) + $GLOBALS[$var] = $_POST[$var]; + else if ($allowCookies && isset($_COOKIE[$var])) + $GLOBALS[$var] = $_COOKIE[$var]; + else + { + //die("Missing arg '$var'"); + unset($GLOBALS[$var]); + } +} + +// ------------------------------------- +// export HTTP param, as if user sent var in a POST +// ------------------------------------- +function exportParam($var, $value) +{ + global $_POST; + $_POST[$var] = $value; +} + + +// always sent by client +importParam('user_login'); +importParam('shard'); +importParam('session_cookie'); + +$user_login = trim($user_login); +$session_cookie = stripslashes($session_cookie); + +include_once('config.php'); + +$UTILS_PHP = 1; + +// ------------------------------------- +// read an index +// ------------------------------------- +function read_index($file, &$header, &$array) +{ + if (!file_exists($file)) + { + $header = ''; + $array = array(); + return; + } + + $f = fopen($file, 'r'); + + // read header + $header = fgets($f, 512); + + while (!feof($f)) + { + // get a new line + $line = trim(fgets($f, 10240)); + + // check line is not empty + if ($line == "") + continue; + + // explode line + $array[] = explode('%%', $line); + } + + fclose($f); +} + +// ------------------------------------- +// write an index +// ------------------------------------- +function write_index($file, $header, &$array) +{ + $f = fopen($file, 'w'); + + fwrite($f, str_pad(trim($header), 256)); + fwrite($f, "\n"); + + if (count($array) > 0) + { + foreach ($array as $l) + { + fwrite($f, trim(join('%%', $l))); + fwrite($f, "\n"); + } + } + + fclose($f); +} + + +// ------------------------------------- +// write an index +// ------------------------------------- +function use_index($file) +{ + if (!file_exists($file)) + { + $f = fopen($file, 'w'); + update_next_index($f, 0); + fclose($f); + } +} + + + +// ------------------------------------- +// write an index +// ------------------------------------- +function read_next_index($f, &$index) +{ + fseek($f, 0, SEEK_SET); + $index = (int)fgets($f, 512); +} + +// ------------------------------------- +// write an index +// ------------------------------------- +function update_next_index($f, $index) +{ + fseek($f, 0, SEEK_SET); + + fwrite($f, str_pad($index, 256)); + fwrite($f, "\n"); +} + +// ------------------------------------- +// write an index +// ------------------------------------- +function append_to_index($f, $line) +{ + fseek($f, 0, SEEK_END); + + fwrite($f, $line, 8192); + fwrite($f, "\n"); +} + + + + +// ------------------------------------- +// write html prolog +// ------------------------------------- +function write_prolog($f, $title) +{ + fwrite($f, "$title\n"); +} + +// ------------------------------------- +// write html epilog +// ------------------------------------- +function write_epilog($f) +{ + fwrite($f, "\n"); +} + + + + +// ------------------------------------- +// read template file +// ------------------------------------- +function read_template($file, &$template) +{ + global $TEMPLATE_DIR; + $filename = $TEMPLATE_DIR.'/'.$file; + $f = fopen($filename, 'r'); + $template = fread($f, filesize($filename)); + fclose($f); +} + + + +// ------------------------------------- +// redirect +// ------------------------------------- +function redirect($url, $time=0) +{ + echo "Redirecting...\n"; + echo "\n"; + echo "\n"; + echo "\n"; +} + + + +// ------------------------------------- +// convert to forum name +// ------------------------------------- +function convert_forum_name($str) +{ + return ucfirst(strtr($str, '_', ' ')); +} + + +// ------------------------------------- +// clean string +// ------------------------------------- +function clean_string($str) +{ + return strtr($str, array("\n" => '', '%' => '\%')); +} + +// ------------------------------------- +// clean content +// ------------------------------------- +function clean_content($str) +{ + return strtr($str, array("\n" => '\n', '%' => '\%')); +} + +// ------------------------------------- +// displayable string +// ------------------------------------- +function displayable_string($str) +{ + return nl2br(htmlspecialchars(stripslashes($str), ENT_QUOTES)); +} + +// ------------------------------------- +// displayable string +// ------------------------------------- +function displayable_content($str) +{ + return htmlspecialchars(stripcslashes($str), ENT_QUOTES); +} + +// ------------------------------------- +// displayable string +// ------------------------------------- +function displayable_date() +{ + return "date#".date("y/m/d")." ".date("H:i"); +} + + + + + +function matchParam($var, $param, &$value) +{ + $plen = strlen($param); + if (!strncmp($param, $var, $plen)) + { + $value = trim(substr($var, $plen)); + return true; + } + return false; +} + + +function nameToFile($name) +{ + $r = ''; + for ($i=0; $i= chr(127)) + $r .= sprintf("%%%02x", ord($name[$i])); + else + $r .= $name[$i]; + } + return $r; +} + +function nameToURL($name) +{ + $r = ''; + for ($i=0; $i ring_live.characters[user_login].guild_id +// test ring_live.guilds[guild_id].guild_name == $forum +// ------------------------------------- +function check_character_belongs_to_guild($charName, $guildName) +{ + connect_to_ring_db(); + $res = mysql_query( + "SELECT guilds.guild_name FROM guilds + JOIN characters ON characters.guild_id=guilds.guild_id + WHERE char_name='$charName'") + or die("Can't query guild for $charName in DB"); + if (false === ($row = mysql_fetch_row($res))) + die("Guild not found for char $charName in DB"); + if ($row[0] != $guildName) + die("ACCESS DENIED: $charName is not a member of $guildName"); +} + +$remote_addr = $HTTP_SERVER_VARS['REMOTE_ADDR']; +if ($remote_addr == "213.208.119.226" || $remote_addr == "38.117.236.132") +{ + importParam('internal_check'); + if ($internal_check) + { + echo "INTERNAL CHECK\n"; + die("$internal_check:1"); + } +} + + +/* + * check user is valid + */ +if ($user_login == "support" && ($remote_addr == "192.168.1.153" || $remote_addr == "192.168.3.1") || + $remote_addr == "127.0.0.1" ) +{ + echo "SUPPORT MODE!"; + // do not check "support" email that come from rsweb + //echo $HTTP_SERVER_VARS['REMOTE_ADDR']; + //die(); + importParam('translate_user_login'); + if ($translate_user_login) + $user_login = $translate_user_login; +} +else +{ + if (!strstr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'Ryzom')) + die("ERROR: Bad parameters"); + $udir = get_user_dir($user_login, $shard); + $ufile = $udir.'session'; + if (is_dir($udir) && file_exists($ufile)) + { + $file = fopen($ufile, 'r'); + if (!$file) + die("ERROR: Not logged"); + $server_cookie = trim(fgets($file, 1024)); + if ($server_cookie != $session_cookie) + die("ERROR: Authentication failed"); + } + else + { + die("ERROR: Directory not found: ".$udir); + } +} + +} +?> \ No newline at end of file diff --git a/web/public_php/webig/web_add.gif b/web/public_php/webig/web_add.gif new file mode 100644 index 000000000..0ba722baa Binary files /dev/null and b/web/public_php/webig/web_add.gif differ diff --git a/web/public_php/webig/web_back.gif b/web/public_php/webig/web_back.gif new file mode 100644 index 000000000..1247ae4fd Binary files /dev/null and b/web/public_php/webig/web_back.gif differ diff --git a/web/public_php/webig/web_del.gif b/web/public_php/webig/web_del.gif new file mode 100644 index 000000000..937dbafa5 Binary files /dev/null and b/web/public_php/webig/web_del.gif differ diff --git a/web/public_php/webig/web_forward.gif b/web/public_php/webig/web_forward.gif new file mode 100644 index 000000000..060c7c034 Binary files /dev/null and b/web/public_php/webig/web_forward.gif differ diff --git a/web/public_php/webig/web_guild_flag.gif b/web/public_php/webig/web_guild_flag.gif new file mode 100644 index 000000000..711282304 Binary files /dev/null and b/web/public_php/webig/web_guild_flag.gif differ diff --git a/web/public_php/webig/web_home.gif b/web/public_php/webig/web_home.gif new file mode 100644 index 000000000..393115e7c Binary files /dev/null and b/web/public_php/webig/web_home.gif differ diff --git a/web/public_php/webig/web_inbox.gif b/web/public_php/webig/web_inbox.gif new file mode 100644 index 000000000..68fe83a09 Binary files /dev/null and b/web/public_php/webig/web_inbox.gif differ diff --git a/web/public_php/webig/web_message.gif b/web/public_php/webig/web_message.gif new file mode 100644 index 000000000..519aa50d6 Binary files /dev/null and b/web/public_php/webig/web_message.gif differ diff --git a/web/public_php/webig/web_next.gif b/web/public_php/webig/web_next.gif new file mode 100644 index 000000000..4770e34db Binary files /dev/null and b/web/public_php/webig/web_next.gif differ diff --git a/web/public_php/webig/web_post.gif b/web/public_php/webig/web_post.gif new file mode 100644 index 000000000..9729116b4 Binary files /dev/null and b/web/public_php/webig/web_post.gif differ diff --git a/web/public_php/webig/web_previous.gif b/web/public_php/webig/web_previous.gif new file mode 100644 index 000000000..7b2587ec9 Binary files /dev/null and b/web/public_php/webig/web_previous.gif differ diff --git a/web/public_php/webig/web_reply.gif b/web/public_php/webig/web_reply.gif new file mode 100644 index 000000000..f021d6aac Binary files /dev/null and b/web/public_php/webig/web_reply.gif differ diff --git a/web/public_php/webig/web_send.gif b/web/public_php/webig/web_send.gif new file mode 100644 index 000000000..9729116b4 Binary files /dev/null and b/web/public_php/webig/web_send.gif differ diff --git a/web/public_php/webig/web_submit.gif b/web/public_php/webig/web_submit.gif new file mode 100644 index 000000000..e76df3021 Binary files /dev/null and b/web/public_php/webig/web_submit.gif differ diff --git a/web/public_php/webig/web_topic.gif b/web/public_php/webig/web_topic.gif new file mode 100644 index 000000000..06cd8e169 Binary files /dev/null and b/web/public_php/webig/web_topic.gif differ