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

Размер файла: 9Kb
  1. <?php
  2. include 'config.php';
  3. include 'guestbook/mylib.php';
  4. $pflag=0;
  5. if (!checkagent($_SERVER['HTTP_USER_AGENT'])) { noemul(); exit; }
  6. list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
  7. if (!$chatok) { unk_op(); exit; }
  8. session_start();
  9. $message=rmvbadch($_POST['message']);
  10. $agent=$_SERVER['HTTP_USER_AGENT'];
  11. $addr=$_SERVER['REMOTE_ADDR'];
  12. $f=htmlspecialchars(trim($_POST['f']),ENT_QUOTES);
  13. $t=htmlspecialchars(trim($_POST['t']),ENT_QUOTES);
  14. if ((!$f)&&(!$t)) exit;
  15. $tr=htmlspecialchars(trim($_POST['tr']),ENT_QUOTES);
  16. if (!$t) $theme=rmvbadch($_POST['theme']);
  17. $sie=0;
  18. if ($tr) {
  19. $message=tr_conv($message);
  20. if ($f) $theme=tr_conv($theme);
  21. }
  22. $message=htmlspecialchars(trim($message),ENT_QUOTES);
  23. if (!$t) $theme=htmlspecialchars(trim($theme),ENT_QUOTES);
  24. if (ereg("^SIE-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  25. if (ereg("^Alcatel-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  26. if (ereg("^MOT-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  27. if (ereg("^SEC-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  28. if (ereg("^Panasonic-.*",$_SERVER['HTTP_USER_AGENT'])) $sie=1;
  29.  
  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. if (!$t) {
  44. $res=pg_query($conn,"select flag from forums where id='$f';");
  45. if (!pg_numrows($res)) { pg_close($conn); exit; }
  46. $flag=pg_result($res,0,0);
  47. } else {
  48. $res=pg_query($conn,"select forums.id,forums.flag,themes.closed from forums,themes where forums.id=themes.forum and themes.id='$t';");
  49. if (!pg_numrows($res)) { pg_close($conn); exit; }
  50. $f=pg_result($res,0,0);
  51. $flag=pg_result($res,0,1);
  52. $closed=pg_result($res,0,2);
  53. if ($closed) { pg_close($conn); exit; }
  54. }
  55. if (isset($_SESSION['id'])) {
  56. $uid=$_SESSION['id'];
  57. $res=pg_query($conn,"select moder,access,lastagent,temp_ban,lastforum from users where id='$uid';");
  58. if (pg_result($res,0,0)) $uid=0;
  59. $access=pg_result($res,0,1);
  60. $lastagent=pg_result($res,0,2);
  61. $temp_ban=pg_result($res,0,3);
  62. $lastforum=pg_result($res,0,4);
  63. $_SESSION['access']=$access;
  64. } else {
  65. $res=pg_query($conn,"select id,access,lastagent,temp_ban,lastforum from users where login='$login' and passwd='$pass' and moder=0;");
  66. if (pg_numrows($res)==1) {
  67. $uid=pg_result($res,0,0);
  68. $access=pg_result($res,0,1);
  69. $lastagent=pg_result($res,0,2);
  70. $temp_ban=pg_result($res,0,3);
  71. $lastforum=pg_result($res,0,4);
  72. $_SESSION['id']=$uid;
  73. $_SESSION['access']=$access;
  74. }
  75. }
  76. # if ($uid) {
  77. # setcookie("Login", $login, time()+864000, "/");
  78. # setcookie("Password", $pass, time()+864000, "/");
  79. # }
  80.  
  81. if ($agent!=$lastagent) {
  82. session_unset();
  83. setcookie("Login", "", time()-3600, "/");
  84. setcookie("Password", "", time()-3600, "/");
  85. pg_close($conn);
  86. if ($_GET['lang']=='eng') header("Location: index.php?lang=eng");
  87. else header("Location: index.php");
  88. exit;
  89. }
  90.  
  91. if (($message=="")||((!$t)&&($theme=="")))
  92. {
  93. header("Content-type: text/vnd.wap.wml");
  94. ?>
  95. <?xml version="1.0" encoding="utf-8"?>
  96. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  97. <wml>
  98. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  99. <p align="center">
  100. &#x041D;&#x0435; &#x0432;&#x0441;&#x0435; &#x043F;&#x043E;&#x043B;&#x044F; &#x0437;&#x0430;&#x043F;&#x043E;&#x043B;&#x043D;&#x0435;&#x043D;&#x044B;<br/>
  101. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  102. </p>
  103. </card>
  104. </wml>
  105. <?php
  106. pg_close($conn);
  107. exit;
  108. }
  109. if (($message==".")||($message=="..")||($message=="...")||($message=="....")||($message==",")||($message==",,")||($message==",,,")||($message==":")||($message==";"))
  110. {
  111. header("Content-type: text/vnd.wap.wml");
  112. ?>
  113. <?xml version="1.0" encoding="utf-8"?>
  114. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  115. <wml>
  116. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  117. <p align="center">
  118. &#x041D;&#x0435; &#x0432;&#x0441;&#x0435; &#x043F;&#x043E;&#x043B;&#x044F; &#x0437;&#x0430;&#x043F;&#x043E;&#x043B;&#x043D;&#x0435;&#x043D;&#x044B;<br/>
  119. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  120. </p>
  121. </card>
  122. </wml>
  123. <?php
  124. pg_close($conn);
  125. exit;
  126. }
  127. if (!$uid)
  128. {
  129. header("Content-type: text/vnd.wap.wml");
  130. ?>
  131. <?xml version="1.0" encoding="utf-8"?>
  132. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  133. <wml>
  134. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  135. <p align="center">
  136. Bad login or password.
  137. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  138. </p>
  139. </card>
  140. </wml>
  141. <?php
  142. pg_close($conn);
  143. exit;
  144. }
  145. if ($temp_ban > time())
  146. {
  147. header("Content-type: text/vnd.wap.wml");
  148. ?>
  149. <?xml version="1.0" encoding="utf-8"?>
  150. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  151. <wml>
  152. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  153. <p align="center">
  154. <?php print "Banned till ".strftime("%d %b %G %T", $temp_ban)."<br/>\n"; ?>
  155. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  156. </p>
  157. </card>
  158. </wml>
  159. <?php
  160. pg_close($conn);
  161. exit;
  162. }
  163. if ((!$access)&&($flag==1))
  164. {
  165. header("Content-type: text/vnd.wap.wml");
  166. ?>
  167. <?xml version="1.0" encoding="utf-8"?>
  168. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  169. <wml>
  170. <card id="SignErr" title="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
  171. <p align="center">
  172. Access DENIED.<br/>
  173. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  174. </p>
  175. </card>
  176. </wml>
  177. <?php
  178. pg_close($conn);
  179. exit;
  180. }
  181.  
  182. if ($access<4) {
  183. $message=substr($message, 0, 600);
  184. $theme=substr($theme, 0, 140);
  185. }
  186. $dtime=time()-300;
  187.  
  188. $res=pg_query($conn,"select message from threads where uid='$uid' and time > '$dtime' order by id desc limit 1;");
  189.  
  190. if (pg_numrows($res)) {
  191. if ($message==pg_result($res,0,0)) {
  192. header("Content-type: text/vnd.wap.wml");
  193. ?>
  194. <?xml version="1.0" encoding="utf-8"?>
  195. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  196. <wml>
  197. <?php
  198. print "<card id=\"SignDup\" title=\"Wait\" ontimer=\"http://wap.katrinka.ru/forum.php?lang=".$lang."&amp;t=".$t."&amp;f=".$f."&amp;".SID."\">\n";
  199. ?>
  200. <timer value="20"/>
  201. <p align="center">
  202. Please wait... We are taking you back to the forum...<br/>
  203. <a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
  204. </p>
  205. </card>
  206. </wml>
  207. <?php
  208. pg_close($conn);
  209. exit;
  210. }
  211. }
  212. $mtime=time();
  213. pg_query($conn,"begin;");
  214. if (!$t) {
  215. pg_query($conn,"insert into themes (forum,uid,name,time,lastrepl) values ('$f','$uid','$theme','$mtime','$mtime');");
  216. $res=pg_query($conn,"select currval('public.themes_id_seq');");
  217. $t=pg_result($res,0,0);
  218. pg_query($conn,"update forums set nthemes=nthemes+1 where id='$f';");
  219. pg_query($conn,"insert into threads (theme,message,uid,agent,host,time) values ('$t','$message','$uid','$agent','$addr','$mtime');");
  220. } else {
  221. pg_query($conn,"insert into threads (theme,message,uid,agent,host,time) values ('$t','$message','$uid','$agent','$addr','$mtime');");
  222. pg_query($conn,"update forums set nrepl=nrepl+1 where id='$f';");
  223. pg_query($conn,"update themes set rplnum=rplnum+1,lastrepl='$mtime' where id='$t';");
  224. pg_query($conn,"delete from seen_by where theme='$t';");
  225. }
  226. pg_query($conn,"delete from fseen_by where forum='$f';");
  227. pg_query($conn,"update users set lastact='$mtime',fposts=fposts+1,lastagent='$agent',lastforum='$mtime' where id='$uid';");
  228. pg_query($conn,"end;");
  229. if (!$res) { pg_close($conn); exit; }
  230. pg_close($conn);
  231. $link=sprintf("Location: forum.php?lang=%s&t=%s&f=%s&PHPSESSID=%s", $lang, $t, $f, session_id());
  232. if (!$sie) {
  233. header($link);
  234. } else {
  235. setcookie("Login", $login, time()+864000, "/");
  236. setcookie("Password", $pass, time()+864000, "/");
  237. header("Content-type: text/vnd.wap.wml");
  238. ?>
  239. <?xml version="1.0" encoding="utf-8"?>
  240. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
  241. <wml>
  242. <?php
  243. print "<card id=\"SignOk\" title=\"&#x0421;&#x043F;&#x0430;&#x0441;&#x0438;&#x0431;&#x043E;!\" ontimer=\"http://wap.katrinka.ru/forum.php?lang=".$lang."&amp;t=".$t."&amp;f=".$f."&amp;".SID."\" onenterbackward=\"http://wap.katrinka.ru/\">\n";
  244. ?>
  245. <timer value="10"/>
  246. <p align="center">
  247. &#x0412;&#x0430;&#x0448;&#x0430; &#x0437;&#x0430;&#x043F;&#x0438;&#x0441;&#x044C; &#x0434;&#x043E;&#x0431;&#x0430;&#x0432;&#x043B;&#x0435;&#x043D;&#x0430;<br/>
  248. <?php
  249. print "<a href=\"forum.php?lang=".$lang."&amp;t=".$t."&amp;f=".$f."\">&#x041F;&#x0440;&#x043E;&#x0441;&#x043C;&#x043E;&#x0442;&#x0440;</a>\n";
  250. ?>
  251. </p>
  252. </card>
  253. </wml>
  254. <?php
  255. }
  256. ?>