PageRenderTime 31ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/takeeditcp.php

https://github.com/Bigjoos/U-232-V1
PHP | 302 lines | 267 code | 9 blank | 26 comment | 132 complexity | e09f7752cb9f1d6a4540c34c577c22c0 MD5 | raw file
  1. <?php
  2. /**
  3. * http://btdev.net:1337/svn/test/Installer09_Beta
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 BTDev Installer v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn.
  8. **/
  9. /*
  10. +------------------------------------------------
  11. | $Date$ 010810
  12. | $Revision$ 2.0
  13. | $Author$ Bigjoos
  14. | $URL$
  15. | $takeeditcp
  16. |
  17. +------------------------------------------------
  18. */
  19. require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
  20. require_once(INCL_DIR.'user_functions.php');
  21. require_once(INCL_DIR.'page_verify.php');
  22. require_once(INCL_DIR.'password_functions.php');
  23. dbconn();
  24. loggedinorreturn();
  25. $lang = array_merge( load_language('global'), load_language('takeeditcp') );
  26. $newpage = new page_verify();
  27. $newpage->check('tkepe');
  28. function resize_image($in)
  29. {
  30. $out = array(
  31. 'img_width' => $in['cur_width'],
  32. 'img_height' => $in['cur_height']);
  33. if ( $in['cur_width'] > $in['max_width'] )
  34. {
  35. $out['img_width'] = $in['max_width'];
  36. $out['img_height'] = ceil( ( $in['cur_height'] * ( ( $in['max_width'] * 100 ) / $in['cur_width'] ) ) / 100 );
  37. $in['cur_height'] = $out['img_height'];
  38. $in['cur_width'] = $out['img_width'];
  39. }
  40. if ( $in['cur_height'] > $in['max_height'] )
  41. {
  42. $out['img_height'] = $in['max_height'];
  43. $out['img_width'] = ceil( ( $in['cur_width'] * ( ( $in['max_height'] * 100 ) / $in['cur_height'] ) ) / 100 );
  44. }
  45. return $out;
  46. }
  47. $action = isset($_POST["action"]) ? htmlspecialchars(trim($_POST["action"])) : '';
  48. $updateset = array();
  49. $urladd = $changedemail ='';
  50. //== Avatars stuffs
  51. if ($action == "avatar") {
  52. $avatars = (isset($_POST['avatars']) && $_POST['avatars'] === 'yes' ? 'yes' : 'no');
  53. $offensive_avatar = (isset($_POST['offensive_avatar']) && $_POST['offensive_avatar'] === 'yes' ? 'yes' : 'no');
  54. $view_offensive_avatar = (isset($_POST['view_offensive_avatar']) && $_POST['view_offensive_avatar'] === 'yes' ? 'yes' : 'no');
  55. $avatar = trim( urldecode( $_POST["avatar"] ) );
  56. if ( preg_match( "/^http:\/\/$/i", $avatar )
  57. or preg_match( "/[?&;]/", $avatar )
  58. or preg_match("#javascript:#is", $avatar )
  59. or !preg_match("#^https?://(?:[^<>*\"]+|[a-z0-9/\._\-!]+)$#iU", $avatar ) )
  60. {
  61. $avatar='';
  62. }
  63. if( !empty($avatar) )
  64. {
  65. $img_size = @GetImageSize( $avatar );
  66. if($img_size == FALSE || !in_array($img_size['mime'], $TBDEV['allowed_ext']))
  67. stderr($lang['takeeditcp_user_error'], $lang['takeeditcp_image_error']);
  68. if($img_size[0] < 5 || $img_size[1] < 5)
  69. stderr($lang['takeeditcp_user_error'], $lang['takeeditcp_small_image']);
  70. if ( ( $img_size[0] > $TBDEV['av_img_width'] ) OR ( $img_size[1] > $TBDEV['av_img_height'] ) )
  71. {
  72. $image = resize_image( array(
  73. 'max_width' => $TBDEV['av_img_width'],
  74. 'max_height' => $TBDEV['av_img_height'],
  75. 'cur_width' => $img_size[0],
  76. 'cur_height' => $img_size[1]));
  77. }
  78. else
  79. {
  80. $image['img_width'] = $img_size[0];
  81. $image['img_height'] = $img_size[1];
  82. }
  83. $updateset[] = "av_w = " . sqlesc($image['img_width']);
  84. $updateset[] = "av_h = " . sqlesc($image['img_height']);
  85. }
  86. $updateset[] = 'offensive_avatar = '.sqlesc($offensive_avatar);
  87. $updateset[] = 'view_offensive_avatar = '.sqlesc($view_offensive_avatar);
  88. $updateset[] = "avatar = " . sqlesc($avatar);
  89. $updateset[] = 'avatars = '.sqlesc($avatars);
  90. $action = "avatar";
  91. }
  92. //== Signature stuffs
  93. elseif ($action == "signature") {
  94. $signatures = (isset($_POST['signatures']) && $_POST["signatures"] != "" ? "yes" : "no");
  95. $signature = trim( urldecode( $_POST["signature"] ) );
  96. if ( preg_match( "/^http:\/\/$/i", $signature )
  97. or preg_match( "/[?&;]/", $signature )
  98. or preg_match("#javascript:#is", $signature )
  99. or !preg_match("#^https?://(?:[^<>*\"]+|[a-z0-9/\._\-!]+)$#iU", $signature ))
  100. {
  101. $signature='';
  102. }
  103. if( !empty($signature) )
  104. {
  105. $img_size = @GetImageSize( $signature );
  106. if($img_size == FALSE || !in_array($img_size['mime'], $TBDEV['allowed_ext']))
  107. stderr('USER ERROR', 'Not an image or unsupported image!');
  108. if($img_size[0] < 5 || $img_size[1] < 5)
  109. stderr('USER ERROR', 'Image is too small');
  110. if ( ( $img_size[0] > $TBDEV['sig_img_width'] ) OR ( $img_size[1] > $TBDEV['sig_img_height'] ) )
  111. {
  112. $image = resize_image( array(
  113. 'max_width' => $TBDEV['sig_img_width'],
  114. 'max_height' => $TBDEV['sig_img_height'],
  115. 'cur_width' => $img_size[0],
  116. 'cur_height' => $img_size[1]));
  117. }
  118. else
  119. {
  120. $image['img_width'] = $img_size[0];
  121. $image['img_height'] = $img_size[1];
  122. }
  123. $updateset[] = "sig_w = " . sqlesc($image['img_width']);
  124. $updateset[] = "sig_h = " . sqlesc($image['img_height']);
  125. $updateset[] = "signature = " . sqlesc("[img]".$signature."[/img]\n");
  126. }
  127. $updateset[] = "signatures = '$signatures'";
  128. if (isset($_POST["info"]) && (($info = $_POST["info"]) != $CURUSER["info"])){
  129. $updateset[] = "info = " . sqlesc($info);
  130. }
  131. $action = "signature";
  132. }
  133. //== Security Stuffs
  134. elseif ($action == "security") {
  135. if (!mkglobal("email:chpassword:passagain:chmailpass:secretanswer"))
  136. stderr("Error", $lang['takeeditcp_no_data']);
  137. if ($chpassword != "")
  138. {
  139. if (strlen($chpassword) > 40)
  140. stderr("Error", $lang['takeeditcp_pass_long']);
  141. if ($chpassword != $passagain)
  142. stderr("Error", $lang['takeeditcp_pass_not_match']);
  143. $secret = mksecret();
  144. $passhash = make_passhash( $secret, md5($chpassword) );
  145. $updateset[] = "secret = " . sqlesc($secret);
  146. $updateset[] = "passhash = " . sqlesc($passhash);
  147. logincookie($CURUSER["id"], md5($passhash.$_SERVER["REMOTE_ADDR"]));
  148. }
  149. if ($email != $CURUSER["email"])
  150. {
  151. if (!validemail($email))
  152. stderr("Error", $lang['takeeditcp_not_valid_email']);
  153. $r = @sql_query("SELECT id FROM users WHERE email=" . sqlesc($email)) or sqlerr();
  154. if ( mysql_num_rows($r) > 0 || ($CURUSER["passhash"] != make_passhash( $CURUSER['secret'], md5($chmailpass) ) ) )
  155. stderr("Error", $lang['takeeditcp_address_taken']);
  156. $changedemail = 1;
  157. }
  158. if ($secretanswer != '') {
  159. if (strlen($secretanswer) > 40)
  160. stderr("Sorry", "secret answer is too long (max is 40 chars)");
  161. if (strlen($secretanswer) < 6)
  162. stderr("Sorry", "secret answer is too sort (min is 6 chars)");
  163. $new_secret_answer = md5($secretanswer);
  164. $updateset[] = "hintanswer = " . sqlesc($new_secret_answer);
  165. }
  166. if(get_parked() == '1'){
  167. if (isset($_POST["parked"]) && ($parked = $_POST["parked"]) != $CURUSER["parked"]){
  168. $updateset[] = "parked = " . sqlesc($parked);
  169. }
  170. }
  171. if(get_anonymous() != '0'){
  172. $anonymous = (isset($_POST['anonymous']) && $_POST["anonymous"] != "" ? "yes" : "no");
  173. $updateset[] = "anonymous = ".sqlesc($anonymous);
  174. }
  175. if (isset($_POST["hidecur"]) && ($hidecur = $_POST["hidecur"]) != $CURUSER["hidecur"]){
  176. $updateset[] = "hidecur = " . sqlesc($hidecur);
  177. }
  178. if (isset($_POST["show_email"]) && ($show_email = $_POST["show_email"]) != $CURUSER["show_email"]){
  179. $updateset[] = "show_email= " . sqlesc($show_email);
  180. }
  181. if (isset($_POST["paranoia"]) && ($paranoia = $_POST["paranoia"]) != $CURUSER["paranoia"]){
  182. $updateset[] = "paranoia= " . sqlesc($paranoia);
  183. }
  184. if (isset($_POST["changeq"]) && (($changeq = (int)$_POST["changeq"]) != $CURUSER["passhint"]) && is_valid_id($changeq)){
  185. $updateset[] = "passhint = " . sqlesc($changeq);
  186. }
  187. if ($changedemail) {
  188. $sec = mksecret();
  189. $hash = md5($sec . $email . $sec);
  190. $obemail = urlencode($email);
  191. $updateset[] = "editsecret = " . sqlesc($sec);
  192. $thishost = $_SERVER["HTTP_HOST"];
  193. $thisdomain = preg_replace('/^www\./is', "", $thishost);
  194. $body = str_replace(array('<#USERNAME#>', '<#SITENAME#>', '<#USEREMAIL#>', '<#IP_ADDRESS#>', '<#CHANGE_LINK#>'),
  195. array($CURUSER['username'], $TBDEV['site_name'], $email, $_SERVER['REMOTE_ADDR'], "{$TBDEV['baseurl']}/confirmemail.php?uid={$CURUSER['id']}&key=$hash&email=$obemail"),
  196. $lang['takeeditcp_email_body']);
  197. mail($email, "$thisdomain {$lang['takeeditcp_confirm']}", $body, "From: {$TBDEV['site_email']}");
  198. $urladd .= "&mailsent=1";
  199. }
  200. $action = "security";
  201. }
  202. //== Torrent stuffs
  203. elseif ($action == "torrents") {
  204. $pmnotif = isset($_POST["pmnotif"]) ? $_POST["pmnotif"] : '';
  205. $emailnotif = isset($_POST["emailnotif"]) ? $_POST["emailnotif"] : '';
  206. $notifs = ($pmnotif == 'yes' ? "[pm]" : "");
  207. $notifs .= ($emailnotif == 'yes' ? "[email]" : "");
  208. $r = @sql_query("SELECT id FROM categories") or sqlerr();
  209. $rows = mysql_num_rows($r);
  210. for ($i = 0; $i < $rows; ++$i)
  211. {
  212. $a = mysql_fetch_assoc($r);
  213. if (isset($_POST["cat{$a['id']}"]) && $_POST["cat{$a['id']}"] == 'yes')
  214. $notifs .= "[cat{$a['id']}]";
  215. }
  216. $updateset[] = "notifs = '$notifs'";
  217. $viewscloud = (isset($_POST['viewscloud']) && $_POST["viewscloud"] != "" ? "yes" : "no");{
  218. $updateset[] = "viewscloud = ".sqlesc($viewscloud);
  219. }
  220. $clear_new_tag_manually = (isset($_POST['clear_new_tag_manually']) && $_POST["clear_new_tag_manually"] != "" ? "yes" : "no");{
  221. $updateset[] = "clear_new_tag_manually = " . sqlesc($clear_new_tag_manually);
  222. }
  223. $action = "torrents";
  224. }
  225. //== Personal stuffs
  226. elseif ($action == "personal") {
  227. //status update
  228. if(isset($_POST['status']) && ($status = $_POST['status']) && !empty($status)) {
  229. $status_archive = ((isset($CURUSER['archive']) && is_array(unserialize($CURUSER['archive']))) ? unserialize($CURUSER['archive']) : array());
  230. if(!empty($CURUSER['last_status']))
  231. $status_archive[] = array('status'=>$CURUSER['last_status'],'date'=>$CURUSER['last_update']);
  232. sql_query('INSERT INTO ustatus(userid,last_status,last_update,archive) VALUES('.$CURUSER['id'].','.sqlesc($status).','.TIME_NOW.','.sqlesc(serialize($status_archive)).') ON DUPLICATE KEY UPDATE last_status=values(last_status),last_update=values(last_update),archive=values(archive)') or sqlerr(__FILE__,__LINE__);
  233. }
  234. //end status update;
  235. if (isset($_POST['stylesheet']) && (($stylesheet = (int)$_POST['stylesheet']) != $CURUSER['stylesheet']) && is_valid_id($stylesheet))
  236. $updateset[] = 'stylesheet = ' . sqlesc($stylesheet);
  237. if (isset($_POST["country"]) && (($country = $_POST["country"]) != $CURUSER["country"]) && is_valid_id($country))
  238. $updateset[] = "country = $country";
  239. if (isset($_POST["torrentsperpage"]) && (($torrentspp = min(100, 0 + $_POST["torrentsperpage"])) != $CURUSER["torrentsperpage"]))
  240. $updateset[] = "torrentsperpage = $torrentspp";
  241. if (isset($_POST["topicsperpage"]) && (($topicspp = min(100, 0 + $_POST["topicsperpage"])) != $CURUSER["topicsperpage"]))
  242. $updateset[] = "topicsperpage = $topicspp";
  243. if (isset($_POST["postsperpage"]) && (($postspp = min(100, 0 + $_POST["postsperpage"])) != $CURUSER["postsperpage"]))
  244. $updateset[] = "postsperpage = $postspp";
  245. if (isset($_POST["gender"]) && ($gender = $_POST["gender"]) != $CURUSER["gender"])
  246. $updateset[] = "gender = " . sqlesc($gender);
  247. $shoutboxbg = 0 + $_POST["shoutboxbg"];
  248. $updateset[] = "shoutboxbg = " . sqlesc($shoutboxbg);
  249. if(isset($_POST["user_timezone"]) && preg_match('#^\-?\d{1,2}(?:\.\d{1,2})?$#', $_POST['user_timezone']))
  250. $updateset[] = "time_offset = " . sqlesc($_POST['user_timezone']);
  251. $updateset[] = "auto_correct_dst = " .(isset($_POST['checkdst']) ? 1 : 0);
  252. $updateset[] = "dst_in_use = " .(isset($_POST['manualdst']) ? 1 : 0);
  253. if (isset($_POST["google_talk"]) && ($google_talk = $_POST["google_talk"]) != $CURUSER["google_talk"]){
  254. $updateset[] = "google_talk= " . sqlesc($google_talk);
  255. }
  256. if (isset($_POST["msn"]) && ($msn = $_POST["msn"]) != $CURUSER["msn"]){
  257. $updateset[] = "msn= " . sqlesc($msn);
  258. }
  259. if (isset($_POST["aim"]) && ($aim = $_POST["aim"]) != $CURUSER["aim"]){
  260. $updateset[] = "aim= " . sqlesc($aim);
  261. }
  262. if (isset($_POST["yahoo"]) && ($yahoo = $_POST["yahoo"]) != $CURUSER["yahoo"]){
  263. $updateset[] = "yahoo= " . sqlesc($yahoo);
  264. }
  265. if (isset($_POST["icq"]) && ($icq = $_POST["icq"]) != $CURUSER["icq"]){
  266. $updateset[] = "icq= " . sqlesc($icq);
  267. }
  268. if (isset($_POST["website"]) && ($website = $_POST["website"]) != $CURUSER["website"]){
  269. $updateset[] = "website= " . sqlesc($website);
  270. }
  271. $updateset[] = 'website = '.sqlesc($website);
  272. $action = "personal";
  273. }
  274. //== Pm stuffs
  275. elseif ($action == "pm") {
  276. $acceptpms_choices = array('yes' => 1, 'friends' => 2, 'no' => 3);
  277. $acceptpms = (isset($_POST['acceptpms']) ? $_POST['acceptpms'] : 'all');
  278. if (isset($acceptpms_choices[$acceptpms]))
  279. $updateset[] = "acceptpms = " . sqlesc($acceptpms);
  280. $deletepms = isset($_POST["deletepms"]) ? "yes" : "no";
  281. $updateset[] = "deletepms = '$deletepms'";
  282. $savepms = (isset($_POST['savepms']) && $_POST["savepms"] != "" ? "yes" : "no");
  283. $updateset[] = "savepms = '$savepms'";
  284. $subscription_pm = $_POST["subscription_pm"];
  285. $updateset[] = "subscription_pm = " . sqlesc($subscription_pm);
  286. $action = "pm";
  287. }
  288. //== End == then update the sets :)
  289. if (sizeof($updateset)>0)
  290. @sql_query("UPDATE users SET " . implode(",", $updateset) . " WHERE id = " . $CURUSER["id"]) or sqlerr(__FILE__, __LINE__);
  291. $mc1->delete_value('MyUser_'.$CURUSER['id']);
  292. header("Location: {$TBDEV['baseurl']}/usercp.php?edited=1&action=$action" . $urladd);
  293. ?>