Просмотр файла katrinka.ru/chat_sign.php

Размер файла: 10.63Kb
  1. <?php
  2. include 'config.php';
  3. include 'guestbook/mylib.php';
  4. session_start();
  5. $pflag=0;
  6. if (!checkagent($_SERVER['HTTP_USER_AGENT'])) { noemul(); exit; }
  7. list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
  8. if (!$chatok) { unk_op(); exit; }
  9. $message=$_POST['message'];
  10. $agent=$_SERVER['HTTP_USER_AGENT'];
  11. $addr=$_SERVER['REMOTE_ADDR'];
  12. $r=htmlspecialchars(trim($_POST['r']),ENT_QUOTES);
  13. if (!$r) exit;
  14. $to=htmlspecialchars(trim($_POST['to']),ENT_QUOTES);
  15. $tto=htmlspecialchars(trim($_POST['tto']),ENT_QUOTES);
  16. $n=htmlspecialchars(trim($_POST['n']),ENT_QUOTES);
  17. $tr=htmlspecialchars(trim($_POST['tr']),ENT_QUOTES);
  18. $sie=0;
  19. if ($tr) $message=tr_conv($message);
  20. $message=htmlspecialchars(trim($message),ENT_QUOTES);
  21. # if ($addr=='213.33.251.8') $sie=1;
  22. if (ereg("^SIE-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  23. if (ereg("^Alcatel-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  24. if (ereg("^MOT-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  25. if (ereg("^SEC-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  26. if (ereg("^Panasonic-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  27.  
  28. if ($to=='') $to=0;
  29. if ($r==18) $n=0;
  30. $uid=0;
  31. $access=0;
  32. $flag=0;
  33. $lang=$_POST['lang'];
  34. if ((trim($_COOKIE['Login'])!='')&&(trim($_COOKIE['Password'])!='')) {
  35. $login=htmlspecialchars(trim($_COOKIE['Login']),ENT_QUOTES);
  36. $pass=htmlspecialchars(trim($_COOKIE['Password']),ENT_QUOTES);
  37. } else {
  38. $login=htmlspecialchars(trim($_POST['login']),ENT_QUOTES);
  39. $pass=htmlspecialchars(trim($_POST['pass']),ENT_QUOTES);
  40. # $sie=1;
  41. }
  42. if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass"))) exit;
  43. $res=pg_query($conn,"select flag from chat_rooms where id='$r';");
  44. if (!pg_numrows($res)) { pg_close($conn); exit; }
  45. $flag=pg_result($res,0,0);
  46. if (isset($_SESSION['id'])) {
  47. $uid=$_SESSION['id'];
  48. $res=pg_query($conn,"select moder,access,lastagent,temp_ban,lasttag from users where id='$uid';");
  49. if (pg_result($res,0,0)) $uid=0;
  50. $access=pg_result($res,0,1);
  51. $lastagent=pg_result($res,0,2);
  52. $temp_ban=pg_result($res,0,3);
  53. $lasttag=pg_result($res,0,4);
  54. $_SESSION['access']=$access;
  55. } else {
  56. $res=pg_query($conn,"select id,access,lastagent,temp_ban,lasttag from users where login='$login' and passwd='$pass' and moder=0;");
  57. if (pg_numrows($res)==1) {
  58. $uid=pg_result($res,0,0);
  59. $access=pg_result($res,0,1);
  60. $lastagent=pg_result($res,0,2);
  61. $temp_ban=pg_result($res,0,3);
  62. $lasttag=pg_result($res,0,4);
  63. $_SESSION['id']=$uid;
  64. $_SESSION['access']=$access;
  65. }
  66. }
  67. # if ($uid) {
  68. # setcookie("Login", $login, time()+864000, "/");
  69. # setcookie("Password", $pass, time()+864000, "/");
  70. # }
  71.  
  72. if ($agent!=$lastagent) {
  73. session_unset();
  74. setcookie("Login", "", time()-3600, "/");
  75. setcookie("Password", "", time()-3600, "/");
  76. pg_close($conn);
  77. if ($_GET['lang']=='eng') header("Location: index.php?lang=eng");
  78. else header("Location: index.php");
  79. exit;
  80. }
  81.  
  82. if ($message=="")
  83. {
  84. header("Content-type: text/vnd.wap.wml");
  85. ?>
  86. <?xml version="1.0" encoding="utf-8"?>
  87. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  88. <wml>
  89. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  90. <p align="center">
  91. &#x041D;&#x0435; &#x0432;&#x0441;&#x0435; &#x043F;&#x043E;&#x043B;&#x044F; &#x0437;&#x0430;&#x043F;&#x043E;&#x043B;&#x043D;&#x0435;&#x043D;&#x044B;<br/>
  92. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  93. </p>
  94. </card>
  95. </wml>
  96. <?php
  97. pg_close($conn);
  98. exit;
  99. }
  100.  
  101. if (!test_chars($message))
  102. {
  103. header("Content-type: text/vnd.wap.wml");
  104. ?>
  105. <?xml version="1.0" encoding="utf-8"?>
  106. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  107. <wml>
  108. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  109. <p align="center">
  110. Invalid chars entered...
  111. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  112. </p>
  113. </card>
  114. </wml>
  115. <?php
  116. pg_close($conn);
  117. exit;
  118. }
  119. if (($message==".")||($message=="..")||($message=="...")||($message=="....")||($message==",")||($message==",,")||($message==",,,")||($message==":")||($message==";"))
  120. {
  121. header("Content-type: text/vnd.wap.wml");
  122. ?>
  123. <?xml version="1.0" encoding="utf-8"?>
  124. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  125. <wml>
  126. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  127. <p align="center">
  128. &#x041D;&#x0435; &#x0432;&#x0441;&#x0435; &#x043F;&#x043E;&#x043B;&#x044F; &#x0437;&#x0430;&#x043F;&#x043E;&#x043B;&#x043D;&#x0435;&#x043D;&#x044B;<br/>
  129. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  130. </p>
  131. </card>
  132. </wml>
  133. <?php
  134. pg_close($conn);
  135. exit;
  136. }
  137. if (!$uid)
  138. {
  139. header("Content-type: text/vnd.wap.wml");
  140. ?>
  141. <?xml version="1.0" encoding="utf-8"?>
  142. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  143. <wml>
  144. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  145. <p align="center">
  146. Bad login or password.
  147. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  148. </p>
  149. </card>
  150. </wml>
  151. <?php
  152. pg_close($conn);
  153. exit;
  154. }
  155. if ($temp_ban > time())
  156. {
  157. header("Content-type: text/vnd.wap.wml");
  158. ?>
  159. <?xml version="1.0" encoding="utf-8"?>
  160. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  161. <wml>
  162. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  163. <p align="center">
  164. <?php print "Banned till ".strftime("%d %b %G %T", $temp_ban)."<br/>\n"; ?>
  165. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  166. </p>
  167. </card>
  168. </wml>
  169. <?php
  170. pg_close($conn);
  171. exit;
  172. }
  173. if (($r==18)&&($to==0)) {
  174. $res=pg_query($conn,"select id from users where login='$tto' and moder=0;");
  175. if (!pg_numrows($res)) {
  176. header("Content-type: text/vnd.wap.wml");
  177. ?>
  178. <?xml version="1.0" encoding="utf-8"?>
  179. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  180. <wml>
  181. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  182. <p align="center">
  183. No such user.<br/>
  184. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  185. </p>
  186. </card>
  187. </wml>
  188. <?php
  189. pg_close($conn);
  190. exit;
  191. }
  192. $to=pg_result($res,0,0);
  193. }
  194.  
  195. if (((!$access)&&($flag==1)) || ($uid==$to))
  196. {
  197. header("Content-type: text/vnd.wap.wml");
  198. ?>
  199. <?xml version="1.0" encoding="utf-8"?>
  200. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  201. <wml>
  202. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  203. <p align="center">
  204. Access DENIED.<br/>
  205. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  206. </p>
  207. </card>
  208. </wml>
  209. <?php
  210. pg_close($conn);
  211. exit;
  212. }
  213.  
  214. if (($access < 4)&&($uid!=1)) $message=substr($message, 0, 300);
  215.  
  216. if (($n)&&($to)) {
  217. $res=pg_query($conn,"select login from users where id='$to';");
  218. if (pg_numrows($res)) {
  219. $nick=pg_result($res,0,0);
  220. }
  221. $to=0;
  222. $message = sprintf("%s, %s", $nick, $message);
  223. }
  224.  
  225. $dtime=time()-300;
  226.  
  227. if (($message[0]=='/')&&(!$to)) {
  228. $bp=strpos($message, ' ');
  229. if ($bp) $tag=substr($message,1,$bp-1);
  230. else $tag=substr($message,1);
  231. $res=pg_query($conn,"select txt from chat_tags where tag='$tag' order by id;");
  232. $rows=pg_numrows($res);
  233. if ($rows) {
  234. if ($lasttag < $dtime) {
  235. if ($rows > 1) { $tn=rand(0,$rows-1); }
  236. else { $tn=0; }
  237. $message=pg_result($res,$tn,0);
  238. $pflag=1;
  239. } else {
  240. header("Content-type: text/vnd.wap.wml"); ?>
  241. <?xml version="1.0" encoding="utf-8"?>
  242. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  243. <wml>
  244. <?php
  245. print "<card id=\"SignDup\" title=\"Wait\" ontimer=\"http://wap.katrinka.ru/chat.php?lang=".$lang."&amp;r=".$r."&amp;".SID."\">\n";
  246. ?>
  247. <timer value="20"/>
  248. <p align="center">
  249. Tags allowed only once per 5 minutes...<br/>
  250. Please wait... We are taking you back to the chat...<br/>
  251. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  252. </p>
  253. </card>
  254. </wml>
  255. <?php pg_close($conn);
  256. exit;
  257. }
  258. }
  259. }
  260. if ($r==18) {
  261. $res=pg_query($conn,"select message from chat_tet where fr_u='$uid' and time > '$dtime' order by id desc limit 1;");
  262. } else {
  263. $res=pg_query($conn,"select message from chat where fr_u='$uid' and time > '$dtime' order by id desc limit 1;");
  264. }
  265.  
  266. if (pg_numrows($res)) {
  267. if ($message==pg_result($res,0,0)) {
  268. header("Content-type: text/vnd.wap.wml");
  269. ?>
  270. <?xml version="1.0" encoding="utf-8"?>
  271. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  272. <wml>
  273. <?php
  274. print "<card id=\"SignDup\" title=\"Wait\" ontimer=\"http://wap.katrinka.ru/chat.php?lang=".$lang."&amp;r=".$r."&amp;".SID."\">\n";
  275. ?>
  276. <timer value="20"/>
  277. <p align="center">
  278. Please wait... We are taking you back to the chat...<br/>
  279. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  280. </p>
  281. </card>
  282. </wml>
  283. <?php
  284. pg_close($conn);
  285. exit;
  286. }
  287. }
  288. $mtime=time();
  289. pg_query($conn,"begin;");
  290. if ((!$to)||(($n)&&($to))) pg_query($conn,"update users set lastact='$mtime',posts=posts+1,lastagent='$agent' where id='$uid';");
  291. if ($pflag==1) pg_query($conn,"update users set lasttag='$mtime' where id='$uid';");
  292. if ($r==18) {
  293. $res=pg_query($conn,"insert into chat_tet (fr_u,to_u,message,time,host,agent) values ('$uid','$to','$message','$mtime','$addr','$agent');");
  294. } else {
  295. $res=pg_query($conn,"insert into chat (room,fr_u,to_u,message,time,host,agent,flag) values ('$r','$uid','$to','$message','$mtime','$addr','$agent','$pflag');");
  296. }
  297. pg_query($conn,"end;");
  298. if (!$res) { pg_close($conn); exit; }
  299. pg_close($conn);
  300. $link=sprintf("Location: chat.php?lang=%s&r=%s&PHPSESSID=%s", $lang, $r, session_id());
  301. if (!$sie) {
  302. header($link);
  303. } else {
  304. # setcookie("Login", $login, time()+864000, "/");
  305. # setcookie("Password", $pass, time()+864000, "/");
  306. header("Content-type: text/vnd.wap.wml");
  307. ?>
  308. <?xml version="1.0" encoding="utf-8"?>
  309. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  310. <wml>
  311. <?php
  312. print "<card id=\"SignOk\" title=\"&#x0421;&#x043F;&#x0430;&#x0441;&#x0438;&#x0431;&#x043E;!\" ontimer=\"http://wap.katrinka.ru/chat.php?lang=".$lang."&amp;r=".$r."&amp;".SID."\" onenterbackward=\"http://wap.katrinka.ru/\">\n";
  313. ?>
  314. <timer value="10"/>
  315. <p align="center">
  316. &#x0412;&#x0430;&#x0448;&#x0430; &#x0437;&#x0430;&#x043F;&#x0438;&#x0441;&#x044C; &#x0434;&#x043E;&#x0431;&#x0430;&#x0432;&#x043B;&#x0435;&#x043D;&#x0430;<br/>
  317. <?php
  318. print "<a href=\"chat.php?lang=".$lang."&amp;r=".$r."\">&#x041F;&#x0440;&#x043E;&#x0441;&#x043C;&#x043E;&#x0442;&#x0440;</a>\n";
  319. ?>
  320. </p>
  321. </card>
  322. </wml>
  323. <?php
  324. }
  325. ?>