1
0

profile.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?php
  2. /* $Id: profile.php 3307 2007-12-16 22:32:03Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // common functions
  23. require_once('inc/functions/functions.common.php');
  24. // init template-instance
  25. tmplInitializeInstance($cfg["theme"], "page.profile.tmpl");
  26. // op-switch
  27. $op = tfb_getRequestVar('op');
  28. switch ($op) {
  29. //******************************************************************************
  30. // addProfile -- adding a Profile Information
  31. //******************************************************************************
  32. case "addProfile":
  33. $newProfile["name"] = tfb_getRequestVar('name');
  34. $newProfile["minport"] = tfb_getRequestVar('minport');
  35. $newProfile["maxport"] = tfb_getRequestVar('maxport');
  36. $newProfile["maxcons"] = tfb_getRequestVar('maxcons');
  37. $newProfile["rerequest"] = tfb_getRequestVar('rerequest');
  38. $newProfile["rate"] = tfb_getRequestVar('rate');
  39. $newProfile["maxuploads"] = tfb_getRequestVar('maxuploads');
  40. $newProfile["drate"] = tfb_getRequestVar('drate');
  41. $newProfile["runtime"] = tfb_getRequestVar('runtime');
  42. $newProfile["sharekill"] = tfb_getRequestVar('sharekill');
  43. $newProfile["superseeder"] = tfb_getRequestVar('superseeder');
  44. $pub = tfb_getRequestVar('public');
  45. $newProfile["public"] = ($pub == "") ? 0 : $pub;
  46. if (!empty( $newProfile)) {
  47. AddProfileInfo($newProfile);
  48. AuditAction( $cfg["constants"]["admin"], "New Profile: " . $newProfile["name"] );
  49. }
  50. @header( "location: index.php?iid=profile&op=showProfiles" );
  51. exit();
  52. //******************************************************************************
  53. // modProfile -- edit Profile Information
  54. //******************************************************************************
  55. case "modProfile":
  56. $newProfile["name"] = tfb_getRequestVar('name');
  57. $newProfile["minport"] = tfb_getRequestVar('minport');
  58. $newProfile["maxport"] = tfb_getRequestVar('maxport');
  59. $newProfile["maxcons"] = tfb_getRequestVar('maxcons');
  60. $newProfile["rerequest"] = tfb_getRequestVar('rerequest');
  61. $newProfile["rate"] = tfb_getRequestVar('rate');
  62. $newProfile["maxuploads"] = tfb_getRequestVar('maxuploads');
  63. $newProfile["drate"] = tfb_getRequestVar('drate');
  64. $newProfile["runtime"] = tfb_getRequestVar('runtime');
  65. $newProfile["sharekill"] = tfb_getRequestVar('sharekill');
  66. $newProfile["superseeder"] = tfb_getRequestVar('superseeder');
  67. $pub = tfb_getRequestVar('public');
  68. $newProfile["public"] = ($pub == "") ? 0 : $pub;
  69. $pid = tfb_getRequestVar('pid');
  70. modProfileInfo($pid,$newProfile);
  71. AuditAction($cfg["constants"]["admin"], "Modified Profile: ".$newProfile["name"]);
  72. @header("location: index.php?iid=profile&op=showProfiles");
  73. exit();
  74. //******************************************************************************
  75. // deleteProfile -- delete a Profile Information
  76. //******************************************************************************
  77. case "deleteProfile":
  78. $pid = tfb_getRequestVar('pid');
  79. $profile = getProfile($pid);
  80. deleteProfileInfo($pid);
  81. AuditAction( $cfg["constants"]["admin"], $cfg['_DELETE'] . " Profile: " . $profile["name"] );
  82. @header("location: index.php?iid=profile&op=showProfiles" );
  83. exit();
  84. //******************************************************************************
  85. // resetSettingsUser -- reset (-> delete) per user settings
  86. //******************************************************************************
  87. case "resetSettingsUser":
  88. // permission
  89. if ($cfg["enable_personal_settings"] != 1) {
  90. AuditAction($cfg["constants"]["error"], "ACCESS DENIED: ".$cfg["user"]." tried to reset personal settings");
  91. @error("Personal Settings are disabled. Action has been logged.", "", "");
  92. }
  93. deleteUserSettings($cfg["uid"]);
  94. AuditAction($cfg["constants"]["admin"], "reset personal settings for ".$cfg["user"]);
  95. @header( "location: index.php?iid=profile" );
  96. exit();
  97. //******************************************************************************
  98. // updateSettingsUser -- update per user settings
  99. //******************************************************************************
  100. case "updateSettingsUser":
  101. // permission
  102. if ($cfg["enable_personal_settings"] != 1) {
  103. AuditAction($cfg["constants"]["error"], "ACCESS DENIED: ".$cfg["user"]." tried to reset personal settings");
  104. @error("Personal Settings are disabled. Action has been logged.", "", "");
  105. }
  106. $settings = processSettingsParams(true, true);
  107. saveUserSettings($cfg["uid"], $settings);
  108. AuditAction($cfg["constants"]["admin"], "updated personal settings for ".$cfg["user"]);
  109. @header( "location: index.php?iid=profile" );
  110. exit();
  111. //******************************************************************************
  112. // addCookie -- adding a Cookie Host Information
  113. //******************************************************************************
  114. case "addCookie":
  115. $newCookie["host"] = tfb_getRequestVar('host');
  116. $newCookie["data"] = tfb_getRequestVar('data');
  117. if (!empty($newCookie)) {
  118. AddCookieInfo($newCookie);
  119. AuditAction($cfg["constants"]["admin"], "New Cookie: " . $newCookie["host"] . " | " . $newCookie["data"]);
  120. }
  121. @header("location: index.php?iid=profile&op=showCookies");
  122. exit();
  123. //******************************************************************************
  124. // deleteCookie -- delete a Cookie Host Information
  125. //******************************************************************************
  126. case "deleteCookie":
  127. $cid = tfb_getRequestVar('cid');
  128. $cookie = getCookie($cid);
  129. deleteCookieInfo($cid);
  130. AuditAction($cfg["constants"]["admin"], $cfg['_DELETE'] . " Cookie: " . $cookie["host"]);
  131. @header("location: index.php?iid=profile&op=showCookies");
  132. exit();
  133. //******************************************************************************
  134. // modCookie -- edit a Cookie Host Information
  135. //******************************************************************************
  136. case "modCookie":
  137. $newCookie["host"] = tfb_getRequestVar('host');
  138. $newCookie["data"] = tfb_getRequestVar('data');
  139. $cid = tfb_getRequestVar('cid');
  140. modCookieInfo($cid,$newCookie);
  141. AuditAction($cfg["constants"]["admin"], "Modified Cookie: ".$newCookie["host"]." | ".$newCookie["data"]);
  142. @header("location: index.php?iid=profile&op=showCookies");
  143. exit();
  144. //******************************************************************************
  145. // updateProfile -- update profile
  146. //******************************************************************************
  147. case "updateProfile":
  148. $tmpl->setvar('updateProfile', 1);
  149. $pass1 = tfb_getRequestVar('pass1');
  150. $pass2 = tfb_getRequestVar('pass2');
  151. $hideOffline = tfb_getRequestVar('hideOffline');
  152. $theme = tfb_getRequestVar('theme');
  153. $language = tfb_getRequestVar('language');
  154. if ($pass1 != "")
  155. $_SESSION['user'] = md5($cfg["pagetitle"]);
  156. UpdateUserProfile($cfg["user"], $pass1, $hideOffline, $theme, $language);
  157. $tmpl->setvar('_PROFILEUPDATEDFOR', $cfg['_PROFILEUPDATEDFOR']);
  158. break;
  159. //******************************************************************************
  160. // ShowCookies
  161. //******************************************************************************
  162. case "showCookies":
  163. case "editCookies":
  164. $tmpl->setvar('ShowCookies', 1);
  165. $cid = tfb_getRequestVar('cid'); // Cookie ID
  166. // Used for when editing a cookie
  167. $hostvalue = $datavalue = "";
  168. if (!empty($cid)) {
  169. // Get cookie information from database
  170. $cookie = getCookie($cid);
  171. $hostvalue = " value=\"" . $cookie['host'] . "\"";
  172. $datavalue = " value=\"" . $cookie['data'] . "\"";
  173. }
  174. (!empty($cid)) ? $op2 = "modCookie" : $op2 = "addCookie";
  175. $tmpl->setvar('op', $op2);
  176. $tmpl->setvar('cid', $cid);
  177. $tmpl->setvar('hostvalue', $hostvalue);
  178. $tmpl->setvar('datavalue', $datavalue);
  179. (!empty($cid)) ? $add1 = $cfg['_UPDATE'] : $add1 = "Add";
  180. $tmpl->setvar('add1', $add1);
  181. // We are editing a cookie, so have a link back to cookie list
  182. if (!empty($cid)) {
  183. $tmpl->setvar('empty_cid', 1);
  184. } else {
  185. $tmpl->setvar('empty_cid', 0);
  186. // Output the list of cookies in the database
  187. $sql = "SELECT c.cid AS cid, c.host AS host, c.data AS data FROM tf_cookies AS c, tf_users AS u WHERE u.uid=c.uid AND u.user_id=".$db->qstr($cfg["user"]);
  188. $dat = $db->GetAll( $sql );
  189. if (empty($dat)) {
  190. $tmpl->setvar('empty_dat', 1);
  191. } else {
  192. $tmpl->setvar('empty_dat', 0);
  193. $cookie_data = array();
  194. $tmpl->setvar('_DELETE', $cfg['_DELETE']);
  195. $tmpl->setvar('_EDIT', $cfg['_EDIT']);
  196. foreach ($dat as $cookie) {
  197. array_push($cookie_data, array(
  198. 'cid' => $cookie["cid"],
  199. 'host' => $cookie["host"],
  200. 'data' => $cookie["data"]
  201. )
  202. );
  203. }
  204. $tmpl->setloop('cookie_data', $cookie_data);
  205. }
  206. }
  207. break;
  208. //******************************************************************************
  209. // ShowProfiles
  210. //******************************************************************************
  211. case "showProfiles":
  212. case "editProfiles":
  213. $tmpl->setvar('ShowProfiles', 1);
  214. $pid = tfb_getRequestVar('pid');
  215. (!empty( $pid )) ? $add1 = $cfg['_UPDATE'] : $add1 = "Add";
  216. $tmpl->setvar('add1', $add1);
  217. (!empty( $pid )) ? $op2 = "modProfile" : $op2 = "addProfile";
  218. $tmpl->setvar('op', $op2);
  219. $name = $minport = $maxport = $maxcons = $rerequest = $rate = $maxuploads = $drate = $runtime = $sharekill = $public = "";
  220. $runtime = $cfg['die_when_done'];
  221. $superseeder = 0;
  222. if (!empty($pid)) {
  223. $profile = getProfile( $pid );
  224. $name = " value=\"" . $profile['name'] . "\"";
  225. $minport = " value=\"" . $profile['minport'] . "\"";
  226. $maxport = " value=\"" . $profile['maxport'] . "\"";
  227. $maxcons = " value=\"" . $profile['maxcons'] . "\"";
  228. $rerequest = " value=\"" . $profile['rerequest'] . "\"";
  229. $rate = " value=\"" . $profile['rate'] . "\"";
  230. $maxuploads = " value=\"" . $profile['maxuploads'] . "\"";
  231. $drate = " value=\"" . $profile['drate'] . "\"";
  232. $runtime = $profile['runtime'];
  233. $sharekill = " value=\"" . $profile['sharekill'] . "\"";
  234. $superseeder = $profile['superseeder'];
  235. if ($profile['public'] == 1)
  236. $public = "checked";
  237. }
  238. $tmpl->setvar('name', $name);
  239. $tmpl->setvar('minport', $minport);
  240. $tmpl->setvar('maxport', $maxport);
  241. $tmpl->setvar('maxcons', $maxcons);
  242. $tmpl->setvar('rerequest', $rerequest);
  243. $tmpl->setvar('rate', $rate);
  244. $tmpl->setvar('maxuploads', $maxuploads);
  245. $tmpl->setvar('drate', $drate);
  246. $tmpl->setvar('runtime', $runtime);
  247. $tmpl->setvar('sharekill', $sharekill);
  248. $tmpl->setvar('superseeder', $superseeder);
  249. $tmpl->setvar('public', $public);
  250. $tmpl->setvar('default_name', "TransferProfile");
  251. $tmpl->setvar('default_minport', $cfg['minport']);
  252. $tmpl->setvar('default_maxport', $cfg['maxport']);
  253. $tmpl->setvar('default_maxcons', $cfg['maxcons']);
  254. $tmpl->setvar('default_rerequest', $cfg['rerequest_interval']);
  255. $tmpl->setvar('default_rate', $cfg['max_upload_rate']);
  256. $tmpl->setvar('default_maxuploads', $cfg['max_uploads']);
  257. $tmpl->setvar('default_drate', $cfg['max_download_rate']);
  258. $tmpl->setvar('default_runtime', $cfg['die_when_done']);
  259. $tmpl->setvar('default_sharekill', $cfg['sharekill']);
  260. $tmpl->setvar('default_superseeder', $cfg['superseeder']);
  261. $tmpl->setvar('default_btclient', $cfg['btclient']);
  262. $tmpl->setvar('pid', $pid);
  263. if (!empty($pid)) {
  264. $tmpl->setvar('empty_pid', 1);
  265. } else {
  266. $tmpl->setvar('empty_pid', 0);
  267. // Output the list of profiles in the database
  268. $sql = "SELECT id, name FROM tf_trprofiles WHERE owner = ".$db->qstr($cfg["uid"]);
  269. $dat = $db->GetAll($sql);
  270. if (empty($dat)) {
  271. $tmpl->setvar('empty_dat', 1);
  272. } else {
  273. $tmpl->setvar('empty_dat', 0);
  274. $profile_data = array();
  275. $tmpl->setvar('_DELETE', $cfg['_DELETE']);
  276. $tmpl->setvar('_EDIT', $cfg['_EDIT']);
  277. foreach( $dat as $profile ) {
  278. array_push($profile_data, array(
  279. 'pid' => $profile["id"],
  280. 'name' => $profile["name"]
  281. )
  282. );
  283. }
  284. $tmpl->setloop('profile_data', $profile_data);
  285. }
  286. }
  287. $tmpl->setvar('pid', $pid);
  288. break;
  289. default:
  290. //******************************************************************************
  291. // showIndex -- main view
  292. //******************************************************************************
  293. $tmpl->setvar('showIndex', 1);
  294. $hideChecked = "";
  295. if ($cfg["hide_offline"] == 1)
  296. $hideChecked = "checked=\"checked\"";
  297. $total_activity = GetActivityCount();
  298. $sql= "SELECT user_id, hits, last_visit, time_created, user_level FROM tf_users WHERE user_id=".$db->qstr($cfg["user"]);
  299. list ($user_id, $hits, $last_visit, $time_created, $user_level) = $db->GetRow($sql);
  300. $user_type = $cfg['_NORMALUSER'];
  301. if ($cfg['isAdmin'])
  302. $user_type = $cfg['_ADMINISTRATOR'];
  303. if (IsSuperAdmin())
  304. $user_type = $cfg['_SUPERADMIN'];
  305. $user_activity = GetActivityCount($cfg["user"]);
  306. if ($user_activity == 0)
  307. $user_percent = 0;
  308. else
  309. $user_percent = number_format(($user_activity/$total_activity)*100);
  310. $tmpl->setvar('time_created1', date($cfg['_DATETIMEFORMAT'], $time_created));
  311. $tmpl->setvar('width1', $user_percent*2);
  312. $tmpl->setvar('width2', (200 - ($user_percent*2)));
  313. $tmpl->setvar('user_activity', $user_activity);
  314. $tmpl->setvar('user_percent', $user_percent);
  315. $tmpl->setvar('days_to_keep', $cfg["days_to_keep"]);
  316. $tmpl->setvar('hits', $hits);
  317. $tmpl->setvar('user_type', $user_type);
  318. $tmpl->setvar('_UPLOADS', $cfg['_UPLOADS']);
  319. $tmpl->setvar('_DAYS', $cfg['_DAYS']);
  320. $tmpl->setvar('_JOINED', $cfg['_JOINED']);
  321. $tmpl->setvar('_UPLOADPARTICIPATION', $cfg['_UPLOADPARTICIPATION']);
  322. $tmpl->setvar('_PARTICIPATIONSTATEMENT', $cfg['_PARTICIPATIONSTATEMENT']);
  323. $tmpl->setvar('_USERTYPE', $cfg['_USERTYPE']);
  324. $tmpl->setvar('_TOTALPAGEVIEWS', $cfg['_TOTALPAGEVIEWS']);
  325. $tmpl->setvar('_PERCENTPARTICIPATION', $cfg['_PERCENTPARTICIPATION']);
  326. $tmpl->setvar('_USER', $cfg['_USER']);
  327. $tmpl->setvar('_NEWPASSWORD', $cfg['_NEWPASSWORD']);
  328. $tmpl->setvar('_CONFIRMPASSWORD', $cfg['_CONFIRMPASSWORD']);
  329. $tmpl->setvar('_THEME', $cfg['_THEME']);
  330. $tmpl->setvar('_HIDEOFFLINEUSERS', $cfg['_HIDEOFFLINEUSERS']);
  331. $tmpl->setvar('_USERIDREQUIRED', $cfg['_USERIDREQUIRED']);
  332. $tmpl->setvar('_PASSWORDLENGTH', $cfg['_PASSWORDLENGTH']);
  333. $tmpl->setvar('_PASSWORDNOTMATCH', $cfg['_PASSWORDNOTMATCH']);
  334. $tmpl->setvar('_PLEASECHECKFOLLOWING', $cfg['_PLEASECHECKFOLLOWING']);
  335. $tmpl->setvar('_UPDATE', $cfg['_UPDATE']);
  336. $tmpl->setvar('_LANGUAGE', $cfg['_LANGUAGE']);
  337. // themes
  338. $arThemes = GetThemes();
  339. $theme_list = array();
  340. for($inx = 0; $inx < sizeof($arThemes); $inx++) {
  341. array_push($theme_list, array(
  342. 'arThemes' => preg_replace('/_beta$/',' (beta)',$arThemes[$inx]),
  343. 'arThemes2' => $arThemes[$inx],
  344. 'selected' => ($cfg["theme"] == $arThemes[$inx]) ? "selected=\"selected\"" : ""
  345. )
  346. );
  347. }
  348. $tmpl->setloop('theme_list', $theme_list);
  349. // tf standard themes
  350. $arThemes = GetThemesStandard();
  351. $tfstandard_theme_list = array();
  352. for($inx = 0; $inx < sizeof($arThemes); $inx++) {
  353. $arThemes2[$inx] = "tf_standard_themes/".$arThemes[$inx];
  354. array_push($tfstandard_theme_list, array(
  355. 'arThemes' => $arThemes[$inx],
  356. 'arThemes2' => $arThemes2[$inx],
  357. 'selected' => ($cfg["theme"] == $arThemes2[$inx]) ? "selected=\"selected\"" : ""
  358. )
  359. );
  360. }
  361. $tmpl->setloop('tfstandard_theme_list', $tfstandard_theme_list);
  362. // languages
  363. $arLanguage = GetLanguages();
  364. $language_list = array();
  365. for($inx = 0; $inx < sizeof($arLanguage); $inx++) {
  366. array_push($language_list, array(
  367. 'arLanguage' => $arLanguage[$inx],
  368. 'selected' => ($cfg["language_file"] == $arLanguage[$inx])? "selected=\"selected\"" : "",
  369. 'language_file' => GetLanguageFromFile($arLanguage[$inx])
  370. )
  371. );
  372. }
  373. $tmpl->setloop('language_list', $language_list);
  374. $tmpl->setvar('hideChecked', $hideChecked);
  375. // settings
  376. $tmpl->setvar('enable_personal_settings', $cfg["enable_personal_settings"]);
  377. if ($cfg["enable_personal_settings"] == 1) {
  378. // set template-vars for webapp-settings
  379. $tmpl->setvar('drivespacebar', $cfg["drivespacebar"]);
  380. $tmpl->setvar('servermon_update', $cfg["servermon_update"]);
  381. $tmpl->setvar('transferHosts', $cfg["transferHosts"]);
  382. $tmpl->setvar('transferStatsType', $cfg["transferStatsType"]);
  383. $tmpl->setvar('transferStatsUpdate', $cfg["transferStatsUpdate"]);
  384. // set template-vars for index-settings
  385. tmplSetIndexPageFormVars();
  386. }
  387. break;
  388. }
  389. // set defines
  390. if ($cfg['transfer_profiles'] <= 0) {
  391. $tmpl->setvar('with_profiles', 0);
  392. } else {
  393. if ($cfg['transfer_profiles'] >= 2)
  394. $tmpl->setvar('with_profiles', 1);
  395. else
  396. $tmpl->setvar('with_profiles', ($cfg['isAdmin']) ? 1 : 0);
  397. }
  398. $tmpl->setvar('user', $cfg["user"]);
  399. //
  400. $tmpl->setvar('_PROFILE', $cfg['_PROFILE']);
  401. //
  402. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  403. //
  404. tmplSetTitleBar($cfg["user"]."'s ".$cfg['_PROFILE']);
  405. tmplSetFoot();
  406. tmplSetIidVars();
  407. // parse template
  408. $tmpl->pparse();
  409. ?>