PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/inc/classes/manage.class.php

https://github.com/Laurelai/tsukiboards
PHP | 4602 lines | 4050 code | 375 blank | 177 comment | 981 complexity | 05741b6fad9baf617ffa2d4dcc051621 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * arcNET 0.2
  4. *
  5. * arcNET uses core code from ONEECHAN and KUSABA X 0.9.3
  6. *
  7. * http://tsukihi.me
  8. *
  9. * http://img.oneechan.org
  10. *
  11. * +------------------------------------------------------------------------------+
  12. * Manage Class
  13. * +------------------------------------------------------------------------------+
  14. * Manage functions, along with the pages available
  15. * +------------------------------------------------------------------------------+
  16. */
  17. class Manage {
  18. /* Show the header of the manage page */
  19. function Header() {
  20. global $dwoo_data, $tpl_page;
  21. if (is_file(KU_ROOTDIR . 'inc/pages/modheader.html')) {
  22. $tpl_includeheader = file_get_contents(KU_ROOTDIR . 'inc/pages/modheader.html');
  23. } else {
  24. $tpl_includeheader = '';
  25. }
  26. $dwoo_data->assign('includeheader', $tpl_includeheader);
  27. }
  28. /* Show the footer of the manage page */
  29. function Footer() {
  30. global $dwoo_data, $dwoo, $tpl_page;
  31. $dwoo_data->assign('page', $tpl_page);
  32. $board_class = new Board('');
  33. $dwoo->output(KU_TEMPLATEDIR . '/manage.tpl', $dwoo_data);
  34. }
  35. // Creates a salt to be used for passwords
  36. function CreateSalt() {
  37. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  38. $salt = '';
  39. for ($i = 0; $i < 3; ++$i) {
  40. $salt .= $chars[mt_rand(0, strlen($chars) - 1)];
  41. }
  42. return $salt;
  43. }
  44. /* Validate the current session */
  45. function ValidateSession($is_menu = false) {
  46. global $tc_db, $tpl_page;
  47. if (isset($_SESSION['manageusername']) && isset($_SESSION['managepassword'])) {
  48. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `username` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']) . " AND `password` = " . $tc_db->qstr($_SESSION['managepassword']) . " LIMIT 1");
  49. if (count($results) == 0) {
  50. session_destroy();
  51. exitWithErrorPage(_gettext('Invalid session.'), '<a href="manage_page.php">'. _gettext('Log in again.') . '</a>');
  52. }
  53. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staff` SET `lastactive` = " . time() . " WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']));
  54. return true;
  55. } else {
  56. if (!$is_menu) {
  57. $this->LoginForm();
  58. die($tpl_page);
  59. } else {
  60. return false;
  61. }
  62. }
  63. }
  64. /* Show the login form and halt execution */
  65. function LoginForm() {
  66. global $tc_db, $tpl_page;
  67. if (file_exists(KU_ROOTDIR . 'inc/pages/manage_login.html')) {
  68. $tpl_page .= file_get_contents(KU_ROOTDIR . 'inc/pages/manage_login.html');
  69. }
  70. }
  71. /* Log moderator IP's */
  72. function LogStaffIP(){
  73. global $tc_db;
  74. $getlog = $tc_db->GetAll("SELECT HIGH_PRIORITY `iplog` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']). " LIMIT 1");
  75. $ip = $_SERVER['REMOTE_ADDR'];
  76. if(filter_var($ip, FILTER_VALIDATE_IP)) {
  77. $encip = md5_encrypt($ip, KU_RANDOMSEED);
  78. $logevents = 2;
  79. if(isset($getlog[0]['iplog'])){
  80. $log = $getlog[0]['iplog'];
  81. $currentlog = explode('|', $log);
  82. foreach($currentlog as $log){
  83. if(!isset($log)){
  84. unset($log);
  85. }
  86. }
  87. $currentlog[] = $encip;
  88. if(count($currentlog)>$logevents){
  89. unset($currentlog[0]);
  90. }
  91. if(is_array($currentlog)){
  92. $log = implode('|', $currentlog);
  93. }
  94. }
  95. else{
  96. $log = $encip;
  97. }
  98. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staff` SET `iplog` = ".$tc_db->qstr($log)." WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']));
  99. }
  100. return true;
  101. }
  102. /* Check login names and create session if user/pass is correct */
  103. function CheckLogin() {
  104. global $tc_db, $action;
  105. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "loginattempts` WHERE `timestamp` < '" . (time() - 1200) . "'");
  106. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `ip` FROM `" . KU_DBPREFIX . "loginattempts` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' LIMIT 6");
  107. if (count($results) > 5) {
  108. exitWithErrorPage(_gettext('System lockout'), _gettext('Sorry, because of your numerous failed logins, you have been locked out from logging in for 20 minutes. Please wait and then try again.'));
  109. } else {
  110. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `username`, `password`, `salt` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = " . $tc_db->qstr($_POST['username']) . " AND `type` != 3 LIMIT 1");
  111. if (count($results) > 0) {
  112. if (empty($results[0]['salt'])) {
  113. if (md5($_POST['password']) == $results[0]['password']) {
  114. $salt = $this->CreateSalt();
  115. $tc_db->Execute("UPDATE `" .KU_DBPREFIX. "staff` SET salt = '" .$salt. "' WHERE username = " .$tc_db->qstr($_POST['username']));
  116. $newpass = md5($_POST['password'] . $salt);
  117. $tc_db->Execute("UPDATE `" .KU_DBPREFIX. "staff` SET password = '" .$newpass. "' WHERE username = " .$tc_db->qstr($_POST['username']));
  118. $_SESSION['manageusername'] = $_POST['username'];
  119. $_SESSION['managepassword'] = $newpass;
  120. $_SESSION['token'] = md5($_SESSION['manageusername'] . $_SESSION['managepassword'] . rand(0,100));
  121. $this->SetModerationCookies();
  122. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "loginattempts` WHERE `ip` < '" . $_SERVER['REMOTE_ADDR'] . "'");
  123. $action = 'posting_rates';
  124. $this->LogStaffIP();
  125. management_addlogentry(_gettext('Logged in'), 1);
  126. die('<script type="text/javascript">top.location.href = \''. KU_CGIPATH .'/manage.php\';</script>');
  127. } else {
  128. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "loginattempts` ( `username` , `ip` , `timestamp` ) VALUES ( " . $tc_db->qstr($_POST['username']) . " , '" . $_SERVER['REMOTE_ADDR'] . "' , '" . time() . "' )");
  129. exitWithErrorPage(_gettext('Incorrect username/password.'));
  130. }
  131. } else {
  132. if (md5($_POST['password'] . $results[0]['salt']) == $results[0]['password']) {
  133. $_SESSION['manageusername'] = $_POST['username'];
  134. $_SESSION['managepassword'] = md5($_POST['password'] . $results[0]['salt']);
  135. $_SESSION['token'] = md5($_SESSION['manageusername'] . $_SESSION['managepassword'] . rand(0,100));
  136. $this->SetModerationCookies();
  137. $action = 'posting_rates';
  138. $this->LogStaffIP();
  139. management_addlogentry(_gettext('Logged in'), 1);
  140. die('<script type="text/javascript">top.location.href = \''. KU_CGIPATH .'/manage.php\';</script>');
  141. } else {
  142. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "loginattempts` ( `username` , `ip` , `timestamp` ) VALUES ( " . $tc_db->qstr($_POST['username']) . " , '" . $_SERVER['REMOTE_ADDR'] . "' , '" . time() . "' )");
  143. exitWithErrorPage(_gettext('Incorrect username/password.'));
  144. }
  145. }
  146. } else {
  147. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "loginattempts` ( `username` , `ip` , `timestamp` ) VALUES ( " . $tc_db->qstr($_POST['username']) . " , '" . $_SERVER['REMOTE_ADDR'] . "' , '" . time() . "' )");
  148. exitWithErrorPage(_gettext('Incorrect username/password.'));
  149. }
  150. }
  151. }
  152. /* Set mod cookies for boards */
  153. function SetModerationCookies() {
  154. global $tc_db, $tpl_page;
  155. if (isset($_SESSION['manageusername'])) {
  156. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `boards` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']) . " LIMIT 1");
  157. if ($this->CurrentUserIsAdministrator() || $results[0][0] == 'allboards') {
  158. setcookie("kumod", "allboards", time() + 3600, KU_BOARDSFOLDER, KU_DOMAIN);
  159. } else {
  160. if ($results[0][0] != '') {
  161. setcookie("kumod", $results[0][0], time() + 3600, KU_BOARDSFOLDER, KU_DOMAIN);
  162. }
  163. }
  164. }
  165. }
  166. function CheckToken($posttoken) {
  167. if ($posttoken != $_SESSION['token']) {
  168. // Something is strange
  169. session_destroy();
  170. exitWithErrorPage(_gettext('Invalid Token'));
  171. }
  172. }
  173. /* Log current user out */
  174. function Logout() {
  175. global $tc_db, $tpl_page;
  176. setcookie('kumod', '', time() - 3600, KU_BOARDSFOLDER, KU_DOMAIN);
  177. session_destroy();
  178. unset($_SESSION['manageusername']);
  179. unset($_SESSION['managepassword']);
  180. unset($_SESSION['token']);
  181. die('<script type="text/javascript">top.location.href = \''. KU_CGIPATH .'/manage.php\';</script>');
  182. }
  183. /* If the user logged in isn't an admin, kill the script */
  184. function AdministratorsOnly() {
  185. global $tc_db, $tpl_page;
  186. if (!$this->CurrentUserIsAdministrator()) {
  187. exitWithErrorPage('That page is for admins only.');
  188. }
  189. }
  190. /* If the user logged in isn't an moderator or higher, kill the script */
  191. function ModeratorsOnly() {
  192. global $tc_db, $tpl_page;
  193. if ($this->CurrentUserIsAdministrator()) {
  194. return true;
  195. } else {
  196. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `type` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . $_SESSION['manageusername'] . "' AND `password` = '" . $_SESSION['managepassword'] . "' LIMIT 1");
  197. foreach ($results as $line) {
  198. if ($line['type'] != 2) {
  199. exitWithErrorPage(_gettext('That page is for moderators and administrators only.'));
  200. }
  201. }
  202. }
  203. }
  204. /* See if the user logged in is an admin */
  205. function CurrentUserIsAdministrator() {
  206. global $tc_db, $tpl_page;
  207. if ($_SESSION['manageusername'] == '' || $_SESSION['managepassword'] == '' || $_SESSION['token'] == '') {
  208. $_SESSION['manageusername'] = '';
  209. $_SESSION['managepassword'] = '';
  210. $_SESSION['token'] = '';
  211. return false;
  212. }
  213. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `type` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . $_SESSION['manageusername'] . "' AND `password` = '" . $_SESSION['managepassword'] . "' LIMIT 1");
  214. foreach ($results as $line) {
  215. if ($line['type'] == 1) {
  216. return true;
  217. } else {
  218. return false;
  219. }
  220. }
  221. /* If the function reaches this point, something is fishy. Kill their session */
  222. session_destroy();
  223. exitWithErrorPage(_gettext('Invalid session, please log in again.'));
  224. }
  225. /* See if the user logged in is a moderator */
  226. function CurrentUserIsModerator() {
  227. global $tc_db, $tpl_page;
  228. if ($_SESSION['manageusername'] == '' || $_SESSION['managepassword'] == '' || $_SESSION['token'] == '') {
  229. $_SESSION['manageusername'] = '';
  230. $_SESSION['managepassword'] = '';
  231. $_SESSION['token'] = '';
  232. return false;
  233. }
  234. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `type` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . $_SESSION['manageusername'] . "' AND `password` = '" . $_SESSION['managepassword'] . "' LIMIT 1");
  235. foreach ($results as $line) {
  236. if ($line['type'] == 2) {
  237. return true;
  238. } else {
  239. return false;
  240. }
  241. }
  242. /* If the function reaches this point, something is fishy. Kill their session */
  243. session_destroy();
  244. exitWithErrorPage(_gettext('Invalid session, please log in again.'));
  245. }
  246. /* See if the user logged in is a moderator of a specified board */
  247. function CurrentUserIsModeratorOfBoard($board, $username) {
  248. global $tc_db, $tpl_page;
  249. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `type`, `boards` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . $username . "' LIMIT 1");
  250. if (count($results) > 0) {
  251. foreach ($results as $line) {
  252. if ($line['boards'] == 'allboards') {
  253. return true;
  254. } else {
  255. if ($line['type'] == '1') {
  256. return true;
  257. } else {
  258. $array_boards = explode('|', $line['boards']);
  259. if (in_array($board, $array_boards)) {
  260. return true;
  261. } else {
  262. return false;
  263. }
  264. }
  265. }
  266. }
  267. } else {
  268. return false;
  269. }
  270. }
  271. /*
  272. * +------------------------------------------------------------------------------+
  273. * Manage pages
  274. * +------------------------------------------------------------------------------+
  275. */
  276. /*
  277. * +------------------------------------------------------------------------------+
  278. * Home Pages
  279. * +------------------------------------------------------------------------------+
  280. */
  281. /* View Announcements */
  282. function announcements() {
  283. global $tc_db, $tpl_page;
  284. $this->ModeratorsOnly();
  285. $tpl_page .= '<h1><center>'. _gettext('Announcements') .'</center></h1>'. "\n";
  286. $entries = 0;
  287. /* Get all of the announcements, ordered with the newest one placed on top */
  288. $results = $tc_db->GetAll("SELECT * FROM `".KU_DBPREFIX."announcements` ORDER BY `postedat` DESC");
  289. foreach($results AS $line) {
  290. $entries++;
  291. $tpl_page .= '<h2>'.stripslashes($line['subject']).' '. _gettext('by') .' ';
  292. $tpl_page .= stripslashes($line['postedby']);
  293. $tpl_page .= ' - '.date("n/j/y @ g:iA T", $line['postedat']);
  294. $tpl_page .= '</h2>' .
  295. '<p>'. stripslashes($line['message']) . '</p>';
  296. }
  297. }
  298. function posting_rates() {
  299. global $tc_db, $tpl_page;
  300. $tpl_page .= '<h2>'. _gettext('Posting rates (past hour)') . '</h2><br />';
  301. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  302. if (count($results) > 0) {
  303. $tpl_page .= '<table border="1" cellspacing="2" cellpadding="2" width="100%"><tr><th>'. _gettext('Board') . '</th><th>'. _gettext('Threads') . '</th><th>'. _gettext('Replies') . '</th><th>'. _gettext('Posts') . '</th></tr>';
  304. foreach ($results as $line) {
  305. $rows_threads = $tc_db->GetOne("SELECT HIGH_PRIORITY count(id) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `parentid` = 0 AND `timestamp` >= " . (time() - 3600));
  306. $rows_replies = $tc_db->GetOne("SELECT HIGH_PRIORITY count(id) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `parentid` != 0 AND `timestamp` >= " . (time() - 3600));
  307. $rows_posts = $rows_threads + $rows_replies;
  308. $threads_perminute = $rows_threads;
  309. $replies_perminute = $rows_replies;
  310. $posts_perminute = $rows_posts;
  311. $tpl_page .= '<tr><td><strong><a href="'. KU_WEBFOLDER . $line['name'] . '">'. $line['name'] . '</a></strong></td><td>'. $threads_perminute . '</td><td>'. $replies_perminute . '</td><td>'. $posts_perminute . '</td></tr>';
  312. }
  313. $tpl_page .= '</table>';
  314. } else {
  315. $tpl_page .= _gettext('No boards');
  316. }
  317. }
  318. function statistics() {
  319. global $tc_db, $tpl_page;
  320. $tpl_page .= '<h2>'. _gettext('Statistics') .'</h2><br />';
  321. $tpl_page .= '<img src="manage_page.php?graph&type=day" />
  322. <img src="manage_page.php?graph&type=week" />
  323. <img src="manage_page.php?graph&type=postnum" />
  324. <img src="manage_page.php?graph&type=unique" />
  325. <img src="manage_page.php?graph&type=posttime" />';
  326. }
  327. function changepwd() {
  328. global $tc_db, $tpl_page;
  329. $tpl_page .= '<h2>'. _gettext('Change account password') . '</h2><br />';
  330. if (isset($_POST['oldpwd']) && isset($_POST['newpwd']) && isset($_POST['newpwd2'])) {
  331. $this->CheckToken($_POST['token']);
  332. if ($_POST['oldpwd'] != '' && $_POST['newpwd'] != '' && $_POST['newpwd2'] != '') {
  333. if ($_POST['newpwd'] == $_POST['newpwd2']) {
  334. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staff` WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']) . "");
  335. foreach ($results as $line) {
  336. $staff_passwordenc = $line['password'];
  337. $staff_salt = $line['salt'];
  338. }
  339. if (md5($_POST['oldpwd'].$staff_salt) == $staff_passwordenc) {
  340. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staff` SET `password` = '" . md5($_POST['newpwd'].$staff_salt) . "' WHERE `username` = " . $tc_db->qstr($_SESSION['manageusername']) . "");
  341. $_SESSION['managepassword'] = md5($_POST['newpwd'].$staff_salt);
  342. $tpl_page .= _gettext('Password successfully changed.');
  343. } else {
  344. $tpl_page .= _gettext('The old password you provided did not match the current one.');
  345. }
  346. } else {
  347. $tpl_page .= _gettext('The second password did not match the first.');
  348. }
  349. } else {
  350. $tpl_page .= _gettext('Please fill in all required fields.');
  351. }
  352. $tpl_page .= '<hr />';
  353. }
  354. $tpl_page .= '<form action="manage_page.php?action=changepwd" method="post">
  355. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  356. <label for="oldpwd">'. _gettext('Old password') . ':</label>
  357. <input type="password" name="oldpwd" /><br />
  358. <label for="newpwd">'. _gettext('New password') . ':</label>
  359. <input type="password" name="newpwd" /><br />
  360. <label for="newpwd2">'. _gettext('New password again') . ':</label>
  361. <input type="password" name="newpwd2" /><br />
  362. <input type="submit" value="' ._gettext('Change account password') . '" />
  363. </form>';
  364. }
  365. /*
  366. * +------------------------------------------------------------------------------+
  367. * Site Administration Pages
  368. * +------------------------------------------------------------------------------+
  369. */
  370. function addannouncement() {
  371. global $tc_db, $tpl_page;
  372. $this->AdministratorsOnly();
  373. $disptable = true; $formval = 'add'; $title = _gettext('Announcement Management');
  374. if(isset($_GET['act'])) {
  375. if ($_GET['act'] == 'edit') {
  376. if (isset($_POST['announcement'])) {
  377. $this->CheckToken($_POST['token']);
  378. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "announcements` SET `subject` = " . $tc_db->qstr($_POST['subject']) . ", `message` = " . $tc_db->qstr($_POST['announcement']) . " WHERE `id` = " . $tc_db->qstr($_GET['id']));
  379. $tpl_page .= '<hr /><h3>'. _gettext('Announcement edited') .'</h3><hr />';
  380. management_addlogentry(_gettext('Edited an announcement'));
  381. }
  382. $formval = 'edit&amp;id='. $_GET['id']; $title .= ' - Edit';
  383. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "announcements` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  384. $values = $results[0]; $disptable = false;
  385. } elseif ($_GET['act'] == 'del') {
  386. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "announcements` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  387. $tpl_page .= '<hr /><h3>'. _gettext('Announcement successfully deleted') .'</h3><hr />';
  388. management_addlogentry(_gettext('Deleted an announcement'), 9);
  389. } elseif ($_GET['act'] == 'add' && isset($_POST['announcement']) && isset($_POST['subject'])) {
  390. if (!empty($_POST['announcement']) && !empty($_POST['subject'])) {
  391. $tpl_page .= '<hr />';
  392. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "announcements` ( `subject` , `message` , `postedat` , `postedby` ) VALUES ( " . $tc_db->qstr($_POST['subject']) . " , " . $tc_db->qstr($_POST['announcement']) . " , '" . time() . "' , " . $tc_db->qstr($_SESSION['manageusername']) . " )");
  393. $tpl_page .= '<h3>'. _gettext('Announcement successfully added.') . '</h3>';
  394. management_addlogentry(_gettext('Added an announcement'), 9);
  395. $tpl_page .= '<hr />';
  396. } else {
  397. $tpl_page .= '<hr />'. _gettext('You must enter a subject as well as a post.') .'<hr />';
  398. }
  399. }
  400. }
  401. $tpl_page .= '<h2>'. $title . '</h2><br />
  402. <form method="post" action="?action=addannouncement&amp;act='. $formval . '">
  403. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  404. <table><tr><td>
  405. <label for="subject">'. _gettext('Subject') . ':</label>
  406. </td><td>
  407. <input type="text" id="subject" name="subject" value="'. (isset($values['subject']) ? $values['subject'] : '') . '" />
  408. <div class="desc">'. _gettext('Can not be left blank') . '</div>
  409. </td></tr><tr><td>
  410. <label for="announcement">'. _gettext('Post') . ':</label>
  411. </td><td>
  412. <textarea id="announcement" name="announcement" rows="25" cols="80">' . (isset($values['message']) ? htmlspecialchars($values['message']) : '') . '</textarea>
  413. </td></tr></table>
  414. <input type="submit" value="'. _gettext('Add') . '" />
  415. </form>
  416. <script type="text/javascript">
  417. $(document).ready(function() {
  418. $("#announcement").markItUp(myHtmlSettings);
  419. });
  420. </script>
  421. ';
  422. if ($disptable) {
  423. $tpl_page .= '<br /><hr /><h1>'. _gettext('Edit/Delete announcement') .'</h1>';
  424. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "announcements` ORDER BY `id` DESC");
  425. if (count($results) > 0) {
  426. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Date Added') .'</th><th>'. _gettext('Subject') .'</th><th>'. _gettext('Message') .'</th><th>'. _gettext('Edit/Delete') .'</th></tr>';
  427. foreach ($results as $line) {
  428. $tpl_page .= '<tr><td>'. date('F j, Y, g:i a', $line['postedat']) . '</td><td>'. $line['subject'] . '</td><td>'. $line['message'] . '</td><td>[<a href="?action=addannouncement&amp;act=edit&amp;id='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=addannouncement&amp;act=del&amp;id='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  429. }
  430. $tpl_page .= '</table>';
  431. } else {
  432. $tpl_page .= _gettext('No announcements yet.');
  433. }
  434. }
  435. }
  436. /* Edit Dwoo templates */
  437. function templates() {
  438. global $tc_db, $tpl_page;
  439. $this->AdministratorsOnly();
  440. $files = array();
  441. $tpl_page .= '<h2>'. _gettext('Template editor') .'</h2><br />';
  442. if ($dh = opendir(KU_TEMPLATEDIR)) {
  443. while (($file = readdir($dh)) !== false) {
  444. if($file != '.' && $file != '..')
  445. $files[] = $file;
  446. }
  447. closedir($dh);
  448. }
  449. sort($files);
  450. if(isset($_POST['templatedata']) && isset($_POST['template'])) {
  451. $this->CheckToken($_POST['token']);
  452. $file = basename($_POST['template']);
  453. if (in_array($file, $files)) {
  454. if(file_exists(KU_TEMPLATEDIR . '/'. $file)) {
  455. file_put_contents(KU_TEMPLATEDIR . '/'. $file, $_POST['templatedata']);
  456. $tpl_page .= '<hr /><h3>'. _gettext('Template edited') .'</h3><hr />';
  457. if (isset($_POST['rebuild'])) {
  458. $this->rebuildall();
  459. }
  460. unset($_POST['template']);
  461. unset($_POST['templatedata']);
  462. }
  463. }
  464. }
  465. if(!isset($_POST['templatedata']) && !isset($_POST['template'])) {
  466. $tpl_page .= '<form method="post" action="?action=templates">
  467. <label for="template">' ._gettext('Template'). ':</label>
  468. <select name="template" id="template">';
  469. foreach($files as $template) {
  470. $tpl_page .='<option name="'. $template .'">'. $template . '</option>';
  471. }
  472. $tpl_page .= '</select>';
  473. }
  474. if(!isset($_POST['templatedata']) && isset($_POST['template'])) {
  475. $file = basename($_POST['template']);
  476. if (in_array($file, $files)) {
  477. if(file_exists(KU_TEMPLATEDIR . '/'. $file)) {
  478. $tpl_page .= '<form method="post" action="?action=templates">
  479. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  480. <input type="hidden" name="template" value="'. $file .'" />
  481. <textarea wrap=off rows=40 cols=100 name="templatedata">'. htmlspecialchars(file_get_contents(KU_TEMPLATEDIR . '/'. $file)) . '</textarea>
  482. <label for="rebuild">'. _gettext('Rebuild HTML after edit?') .'</label>
  483. <input type="checkbox" name="rebuild" /><br /><br />
  484. <div class="desc">'. _gettext('Visit <a href="http://wiki.dwoo.org/">http://wiki.dwoo.org/</a> for syntax information.') . '</div>
  485. <div class="desc">'. sprintf(_gettext('To access Kusaba variables, use {%%KU_VARNAME}, for example {%%KU_BOARDSPATH} would be replaced with %s'), KU_BOARDSPATH) . '</div>
  486. <div class="desc">'. _gettext('Enclose text in {t}{/t} blocks to allow them to be translated for different languages.') . '</div><br /><br />';
  487. }
  488. }
  489. }
  490. $tpl_page .= '<input type="submit" value="' ._gettext('Edit') . '" /></form>';
  491. }
  492. function index() {
  493. global $tpl_page;
  494. $this->AdministratorsOnly();
  495. $faq = KU_ROOTDIR . 'index.php';
  496. if (!empty($_POST['niggers'])) {
  497. file_put_contents($faq, $_POST['niggers']);
  498. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  499. }
  500. $content = file_get_contents(KU_ROOTDIR . 'index.php');
  501. $tpl_page .= '<h2>'. _gettext('Index.php') .'</h2> Raw PHP editor for the index.php page.<br /><br />'. "\n" .
  502. '<form action="?action=index" method="post">'. "\n" .
  503. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  504. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  505. '</form>'. "\n";
  506. }
  507. # SQL Dumper
  508. function sqldump() {
  509. global $tc_db, $tpl_page;
  510. $this->AdministratorsOnly();
  511. $tpl_page .= '<h2>' . _gettext('Execute a MySQL dump') . '</h2><br />';
  512. $tpl_page .= '<table width="400px"><tr><td>Connecting to server...</td><td>';
  513. $con = mysql_connect(KU_DBHOST, KU_DBUSERNAME, KU_DBPASSWORD);
  514. if (!$con) {
  515. $tpl_page .= '[&nbsp;<span style="color:#FF0000">FAILED</span>&nbsp;]</td></tr><tr><td colspan="2">' . mysql_error() . '</td></tr></table><br /><br />A dump cannot be taken until connection error(s) are corrected.';
  516. } else {
  517. $tpl_page .= '[&nbsp;&nbsp;&nbsp;<span style="color:#00FF00">OK</span>&nbsp;&nbsp;&nbsp;]</td></tr><tr><td>Connecting to database...</td><td>';
  518. $db_selected = mysql_select_db(KU_DBDATABASE, $con);
  519. if (!$db_selected) {
  520. $tpl_page .= '[&nbsp;<span style="color:#FF0000">FAILED</span>&nbsp;]</td></tr><tr><td colspan="2">' . mysql_error() . '</td></tr></table><br /><br />A dump cannot be taken until database error(s) are corrected.';
  521. } else {
  522. $tpl_page .= '[&nbsp;&nbsp;&nbsp;<span style="color:#00FF00">OK</span>&nbsp;&nbsp;&nbsp;]</td></tr></table><br /><br />A dump can be taken.&nbsp;&nbsp;&nbsp;[&nbsp;<a href="manage_page.php?action=sqldump&dump=1">Execute</a>&nbsp;]';
  523. }
  524. }
  525. if (isset($_GET['dump'])) {
  526. header('Content-type: text/plain');
  527. header('Content-Disposition: attachment; filename="' . date('Y') . '.' . date('m') . '.' . date ('d') . '.http@www' . KU_DOMAIN . '.sql"');
  528. _mysqldump($db_selected);
  529. die();
  530. }
  531. }
  532. /* Add, edit, delete, and view news entries */
  533. function news() {
  534. global $tc_db, $tpl_page;
  535. $this->AdministratorsOnly();
  536. $disptable = true; $formval = 'add'; $title = _gettext('News Management');
  537. if(isset($_GET['act'])) {
  538. if ($_GET['act'] == 'edit') {
  539. if (isset($_POST['news'])) {
  540. $this->CheckToken($_POST['token']);
  541. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "front` SET `subject` = " . $tc_db->qstr($_POST['subject']) . ", `message` = " . $tc_db->qstr($_POST['news']) . ", `email` = " . $tc_db->qstr($_POST['email']) . " WHERE `id` = " . $tc_db->qstr($_GET['id']) . " AND `page` = 0");
  542. $tpl_page .= '<hr /><h3>'. _gettext('News post edited') .'</h3><hr />';
  543. management_addlogentry(_gettext('Edited a news entry'), 9);
  544. }
  545. $formval = 'edit&amp;id='. $_GET['id']; $title .= ' - Edit';
  546. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "front` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  547. $values = $results[0];
  548. $disptable = false;
  549. } elseif ($_GET['act'] == 'del') {
  550. $results = $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "front` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  551. $tpl_page .= '<hr /><h3>'. _gettext('News post deleted') .'</h3><hr />';
  552. management_addlogentry(_gettext('Deleted a news entry'), 9);
  553. } elseif ($_GET['act'] == 'add') {
  554. if (isset($_POST['news']) && isset($_POST['subject']) && isset($_POST['email'])) {
  555. if (!empty($_POST['news']) || !empty($_POST['subject'])) {
  556. $this->CheckToken($_POST['token']);
  557. $tpl_page .= '<hr />';
  558. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "front` ( `page`, `subject` , `message` , `timestamp` , `poster` , `email` ) VALUES ( '0', " . $tc_db->qstr($_POST['subject']) . " , " . $tc_db->qstr($_POST['news']) . " , '" . time() . "' , " . $tc_db->qstr($_SESSION['manageusername']) . " , " . $tc_db->qstr($_POST['email']) . " )");
  559. $tpl_page .= '<h3>'. _gettext('News entry successfully added.') . '</h3>';
  560. management_addlogentry(_gettext('Added a news entry'), 9);
  561. $tpl_page .= '<hr />';
  562. } else {
  563. $tpl_page .= '<hr />'. _gettext('You must enter a subject as well as a post.') .'<hr />';
  564. }
  565. }
  566. }
  567. }
  568. $tpl_page .= '<h2>'. $title . '</h2><br />
  569. <form method="post" action="?action=news&amp;act='. $formval . '">
  570. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  571. <table><tr>
  572. <td><label for="subject">'. _gettext('Subject') . ':</label></td>
  573. <td><input type="text" size="50" id="subject" name="subject" value="'. (isset($values['subject']) ? $values['subject'] : '') . '" />
  574. <div class="desc">'. _gettext('Can not be left blank.') . '</div></td></tr><tr>
  575. <td><label for="news"> '. _gettext('Post') . ':</label></td>
  576. <td><textarea id="news" name="news" rows="25" cols="80">' . (isset($values['message']) ? htmlspecialchars($values['message']) : '') . '</textarea><br /></td></tr><tr>
  577. <td><label for="email">'. _gettext('E-mail') . ':</label></td>
  578. <td><input type="text" id="email" name="email" value="'. (isset($values['postedemail']) ? $values['postedemail'] : '') . '" />
  579. <div class="desc">'. _gettext('Can be left blank.') . '</div></td></tr></table>
  580. <input type="submit" value="'. _gettext('Add') . '" />
  581. </form>
  582. <script type="text/javascript">
  583. $(document).ready(function() {
  584. $("#news").markItUp(myHtmlSettings);
  585. });
  586. </script>
  587. ';
  588. if ($disptable) {
  589. $tpl_page .= '<br /><hr /><h1>'. _gettext('Edit/Delete News') .'</h1>';
  590. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "front` WHERE `page` = 0 ORDER BY `timestamp` DESC");
  591. if (count($results) > 0) {
  592. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Date Added') .'</th><th>'. _gettext('Subject') .'</th><th>'. _gettext('Message') .'</th><th>'. _gettext('Edit/Delete') .'</th></tr>';
  593. foreach ($results as $line) {
  594. $tpl_page .= '<tr><td>'. date('F j, Y, g:i a', $line['timestamp']) . '</td><td>'. $line['subject'] . '</td><td>'. $line['message'] . '</td><td>[<a href="?action=news&amp;act=edit&amp;id='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=news&amp;act=del&amp;id='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  595. }
  596. $tpl_page .= '</table>';
  597. } else {
  598. $tpl_page .= _gettext('No news posts yet.');
  599. }
  600. }
  601. }
  602. function faq() {
  603. global $tc_db, $tpl_page;
  604. $this->AdministratorsOnly();
  605. $faq = KU_ROOTDIR . 'faq.php';
  606. if (!empty($_POST['niggers'])) {
  607. file_put_contents($faq, $_POST['niggers']);
  608. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  609. }
  610. $content = file_get_contents(KU_ROOTDIR . 'faq.php');
  611. $tpl_page .= '<h2>'. _gettext('Frequently Asked Questions') .'</h2> Raw PHP editor for the FAQ page.<br /><br />'. "\n" .
  612. '<form action="?action=faq" method="post">'. "\n" .
  613. '<textarea name="niggers" id="faqEditor" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  614. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  615. '</form>
  616. <script type="text/javascript">
  617. $(document).ready(function() {
  618. $("#faqEditor").markItUp(myHtmlSettings);
  619. });
  620. </script>
  621. '. "\n";
  622. }
  623. function rules() {
  624. global $tc_db, $tpl_page;
  625. $this->AdministratorsOnly();
  626. if (!empty($_POST['rules'])) {
  627. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "front` SET `message` = " . $tc_db->qstr($_POST['rules']) . " WHERE `id` = " . $tc_db->qstr($_POST['ruleId']) . " AND `page` = 2");
  628. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  629. $tpl_page .= $tc_db->ErrorMsg();
  630. }
  631. $vals = $tc_db->GetAll("SELECT `id`, `message` FROM `" . KU_DBPREFIX . "front` WHERE `page` = 2 ORDER BY `id` LIMIT 1");
  632. if (count($vals) == 0) {
  633. $id = $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "front` ( `page`, `subject` , `message` , `timestamp` , `poster` , `email` ) VALUES ( '2', 'Rules', '', '" . time() . "', '', '')");
  634. $content = '';
  635. $tpl_page .= 'Inserted rules post with Id ' . $id;
  636. } else {
  637. $id = $vals[0]['id'];
  638. $content = $vals[0]['message'];
  639. }
  640. $tpl_page .= '<h2>'. _gettext('Rules Management') .'</h2> Raw HTML editor for the Rules page.<br /><br />'. "\n" .
  641. '<form action="?action=rules" method="post">'. "\n" .
  642. '<input type="hidden" name="ruleId" value="' . $id . '" />'."\n" .
  643. '<textarea name="rules" id="rulesEditor" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  644. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  645. '</form>
  646. <script type="text/javascript">
  647. $(document).ready(function() {
  648. $("#rulesEditor").markItUp(myHtmlSettings);
  649. });
  650. </script>
  651. '. "\n";
  652. }
  653. function staffpage() {
  654. global $tpl_page;
  655. $this->AdministratorsOnly();
  656. $faq = KU_ROOTDIR . 'staff.php';
  657. if (!empty($_POST['niggers'])) {
  658. file_put_contents($faq, $_POST['niggers']);
  659. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  660. }
  661. $content = file_get_contents(KU_ROOTDIR . 'staff.php');
  662. $tpl_page .= '<h2>'. _gettext('Staff') .'</h2> Raw PHP editor for the Staff page.<br /><br />'. "\n" .
  663. '<form action="?action=staffpage" method="post">'. "\n" .
  664. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  665. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  666. '</form>'. "\n";
  667. }
  668. function legal() {
  669. global $tpl_page;
  670. $this->AdministratorsOnly();
  671. $faq = KU_ROOTDIR . 'legal.php';
  672. if (!empty($_POST['niggers'])) {
  673. file_put_contents($faq, $_POST['niggers']);
  674. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  675. }
  676. $content = file_get_contents(KU_ROOTDIR . 'legal.php');
  677. $tpl_page .= '<h2>'. _gettext('Legal') .'</h2> Raw PHP editor for the Legal page.<br /><br />'. "\n" .
  678. '<form action="?action=legal" method="post">'. "\n" .
  679. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  680. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  681. '</form>'. "\n";
  682. }
  683. function boardman() {
  684. global $tpl_page;
  685. $this->AdministratorsOnly();
  686. $faq = KU_ROOTDIR . 'boardlist.php';
  687. if (!empty($_POST['niggers'])) {
  688. file_put_contents($faq, $_POST['niggers']);
  689. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  690. }
  691. $content = file_get_contents(KU_ROOTDIR . 'boardlist.php');
  692. $tpl_page .= '<h2>'. _gettext('Boardlist Template') .'</h2> Raw PHP editor for the boards table.<br /><br />'. "\n" .
  693. '<form action="?action=boardman" method="post">'. "\n" .
  694. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  695. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  696. '</form>'. "\n";
  697. }
  698. function tempfooter() {
  699. global $tpl_page;
  700. $this->AdministratorsOnly();
  701. $faq = KU_ROOTDIR . 'footer.php';
  702. if (!empty($_POST['niggers'])) {
  703. file_put_contents($faq, $_POST['niggers']);
  704. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  705. }
  706. $content = file_get_contents(KU_ROOTDIR . 'footer.php');
  707. $tpl_page .= '<h2>'. _gettext('Footer Template') .'</h2> Raw PHP editor for the footer template.<br /><br />'. "\n" .
  708. '<form action="?action=tempfooter" method="post">'. "\n" .
  709. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  710. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  711. '</form>'. "\n";
  712. }
  713. function tempheader() {
  714. global $tpl_page;
  715. $this->AdministratorsOnly();
  716. $faq = KU_ROOTDIR . 'header.php';
  717. if (!empty($_POST['niggers'])) {
  718. file_put_contents($faq, $_POST['niggers']);
  719. $tpl_page .= '<hr />'. _gettext('Templates successfully edited.') .'<hr />';
  720. }
  721. $content = file_get_contents(KU_ROOTDIR . 'header.php');
  722. $tpl_page .= '<h2>'. _gettext('Header Template') .'</h2> Raw PHP editor for the header template.<br /><br />'. "\n" .
  723. '<form action="?action=tempheader" method="post">'. "\n" .
  724. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  725. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  726. '</form>'. "\n";
  727. }
  728. function boardhtml() {
  729. global $tpl_page;
  730. $this->AdministratorsOnly();
  731. $faq = KU_ROOTDIR . 'boards.html';
  732. if (!empty($_POST['niggers'])) {
  733. file_put_contents($faq, $_POST['niggers']);
  734. $tpl_page .= '<hr />'. _gettext('boards.html successfully edited. REMEMBER TO REBUILD HTML') .'<hr />';
  735. }
  736. $content = file_get_contents(KU_ROOTDIR . 'boards.html');
  737. $tpl_page .= '<h2>'. _gettext('Header Template') .'</h2> Raw PHP editor for boards.html<br /><br />'. "\n" .
  738. '<form action="?action=tempheader" method="post">'. "\n" .
  739. '<textarea name="niggers" rows="25" cols="140">' . $content . '</textarea><br />' . "\n" .
  740. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  741. '</form>'. "\n";
  742. }
  743. function blotter() {
  744. global $tc_db, $tpl_page;
  745. $this->AdministratorsOnly();
  746. if (!KU_BLOTTER) exitWithErrorPage(_gettext('Blotter is disabled'));
  747. $tpl_page .= '<h2>' ._gettext('Blotter'). '</h2><br />';
  748. $act = 'add'; $values = array();
  749. if (isset($_GET['act'])) {
  750. switch($_GET['act']) {
  751. case 'add':
  752. if (isset($_POST['message'])) {
  753. $this->CheckToken($_POST['token']);
  754. $important = (isset($_POST['important'])) ? 1 : 0;
  755. $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "blotter` (`at`, `message`, `important`) VALUES ('" . time() . "', " . $tc_db->qstr($_POST['message']) . ", '" . $important . "')");
  756. $tpl_page .= '<h3>'. _gettext('Blotter entry added.') . '</h3>';
  757. clearBlotterCache();
  758. }
  759. break;
  760. case 'del':
  761. if (is_numeric($_GET['id'])) {
  762. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "blotter` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  763. $tpl_page .= '<hr /><h3>'. _gettext('Blotter entry deleted.') . '</h3><hr />';
  764. clearBlotterCache();
  765. } else {
  766. exitWithErrorPage(_gettext('Invalid ID'));
  767. }
  768. break;
  769. case 'edit':
  770. if (is_numeric($_GET['id'])) {
  771. $act = 'edit&amp;id=' .$_GET['id'];
  772. if (isset($_POST['message'])) {
  773. $this->CheckToken($_POST['token']);
  774. $important = (isset($_POST['important'])) ? 1 : 0;
  775. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "blotter` SET `message` = " . $tc_db->qstr($_POST['message']) . ", `important` = '" . $important . "' WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  776. $tpl_page .= '<h3>'. _gettext('Blotter entry updated.') . '</h3>';
  777. clearBlotterCache();
  778. }
  779. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "blotter` WHERE `id` = " . $tc_db->qstr($_GET['id']) . " LIMIT 1");
  780. $values = $results[0];
  781. } else {
  782. exitWithErrorPage(_gettext('Invalid ID'));
  783. }
  784. break;
  785. default:
  786. exitWithErrorPage(_gettext('Invalid value for \'act\''));
  787. break;
  788. }
  789. }
  790. $tpl_page .= '<form action="?action=blotter&amp;act=' .$act. '" method="post">
  791. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  792. <label for="message">' ._gettext('Message'). ':</label>
  793. <input type="text" id="message" name="message" value="' .(isset($values['message']) ? $values['message'] : ''). '" size="75" /><br />
  794. <label for="important">' ._gettext('Important'). ':</label>
  795. <input type="checkbox" id="important" name="important" ';
  796. if (isset($values['important']) && $values['important'] == 1) $tpl_page .= 'checked="checked" ';
  797. $tpl_page .= '/><br />
  798. <input type="submit" value="' ._gettext('Submit'). '" /><br />
  799. </form><br /><br />';
  800. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "blotter` ORDER BY `id` DESC");
  801. if (count($results) > 0) {
  802. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('At') . '</th><th>'. _gettext('Message') . '</th><th>'. _gettext('Important') . '</th><th>&nbsp;</th></tr>';
  803. foreach ($results as $line) {
  804. $tpl_page .= '<tr><td>'. date('m/d/y', $line['at']) . '</td><td>'. $line['message'] . '</td><td>';
  805. $tpl_page .= ($line['important'] == 1) ? _gettext('Yes') : _gettext('No');
  806. $tpl_page .= '</td><td>[<a href="?action=blotter&amp;act=edit&amp;id='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=blotter&amp;act=del&amp;id='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  807. }
  808. $tpl_page .= '</table>';
  809. } else {
  810. $tpl_page .= _gettext('No blotter entries');
  811. }
  812. }
  813. /* Display disk space used per board, and finally total in a large table */
  814. function spaceused() {
  815. global $tc_db, $tpl_page;
  816. $this->AdministratorsOnly();
  817. $tpl_page .= '<h2>'. _gettext('Disk space used') . '</h2><br />';
  818. $spaceused_res = 0;
  819. $spaceused_src = 0;
  820. $spaceused_thumb = 0;
  821. $spaceused_total = 0;
  822. $files_res = 0;
  823. $files_src = 0;
  824. $files_thumb = 0;
  825. $files_total = 0;
  826. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Board') .'</th><th>'. _gettext('Area') .'</th><th>'. _gettext('Files') .'</th><th>'. _gettext('Space Used') .'</th></tr>';
  827. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `name` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  828. foreach ($results as $line) {
  829. list($spaceused_board_res, $files_board_res) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/res');
  830. list($spaceused_board_src, $files_board_src) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/src');
  831. list($spaceused_board_thumb, $files_board_thumb) = recursive_directory_size(KU_BOARDSDIR . $line['name'] . '/thumb');
  832. $spaceused_board_total = $spaceused_board_res + $spaceused_board_src + $spaceused_board_thumb;
  833. $files_board_total = $files_board_res + $files_board_src + $files_board_thumb;
  834. $spaceused_res += $spaceused_board_res;
  835. $files_res += $files_board_res;
  836. $spaceused_src += $spaceused_board_src;
  837. $files_src += $files_board_src;
  838. $spaceused_thumb += $spaceused_board_thumb;
  839. $files_thumb += $files_board_thumb;
  840. $spaceused_total += $spaceused_board_total;
  841. $files_total += $files_board_total;
  842. $tpl_page .= '<tr><td rowspan="4">/'.$line['name'].'/</td><td>res/</td><td>'. number_format($files_board_res) . '</td><td>'. ConvertBytes($spaceused_board_res) . '</td></tr>';
  843. $tpl_page .= '<tr><td>src/</td><td>'. number_format($files_board_src) . '</td><td>'. ConvertBytes($spaceused_board_src) . '</td></tr>';
  844. $tpl_page .= '<tr><td>thumb/</td><td>'. number_format($files_board_thumb) . '</td><td>'. ConvertBytes($spaceused_board_thumb) . '</td></tr>';
  845. $tpl_page .= '<tr><td><strong>'. _gettext('Total') .'</strong></td><td>'. number_format($files_board_total) . '</td><td>'. ConvertBytes($spaceused_board_total) . '</td></tr>';
  846. }
  847. $tpl_page .= '<tr><td rowspan="4"><strong>'. _gettext('All boards') .'</strong></td><td>res/</td><td>'. number_format($files_res) . '</td><td>'. ConvertBytes($spaceused_res) . '</td></tr>';
  848. $tpl_page .= '<tr><td>src/</td><td>'. number_format($files_src) . '</td><td>'. ConvertBytes($spaceused_src) . '</td></tr>';
  849. $tpl_page .= '<tr><td>thumb/</td><td>'. number_format($files_thumb) . '</td><td>'. ConvertBytes($spaceused_thumb) . '</td></tr>';
  850. $tpl_page .= '<tr><td><strong>'. _gettext('Total') .'</strong></td><td>'. number_format($files_total) . '</td><td>'. ConvertBytes($spaceused_total) . '</td></tr>';
  851. $tpl_page .= '</table>';
  852. management_addlogentry(_gettext('Viewed disk space used'), 0);
  853. }
  854. function staff() { //183 lines
  855. global $tc_db, $tpl_page;
  856. $this->AdministratorsOnly();
  857. $tpl_page .= '<h2>' ._gettext('Staff'). '</h2><br />';
  858. if (isset($_GET['add']) && !empty($_POST['username']) && !empty($_POST['password'])) {
  859. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" .KU_DBPREFIX. "staff` WHERE `username` = " .$tc_db->qstr($_POST['username']));
  860. if (count($results) == 0) {
  861. if ($_POST['type'] < 3 && $_POST['type'] >= 0) {
  862. $this->CheckToken($_POST['token']);
  863. $salt = $this->CreateSalt();
  864. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" .KU_DBPREFIX. "staff` ( `username` , `password` , `salt` , `type` , `addedon` ) VALUES (" .$tc_db->qstr($_POST['username']). " , '" .md5($_POST['password'] . $salt). "' , '" .$salt. "' , '" .$_POST['type']. "' , '" .time(). "' )");
  865. $log = _gettext('Added'). ' ';
  866. switch ($_POST['type']) {
  867. case 0:
  868. $log .= _gettext('Janitor');
  869. break;
  870. case 1:
  871. $log .= _gettext('Administrator');
  872. break;
  873. case 2:
  874. $log .= _gettext('Moderator');
  875. break;
  876. }
  877. $log .= ' '. $_POST['username'];
  878. management_addlogentry($log, 6);
  879. $tpl_page .= _gettext('Staff member successfully added.');
  880. } else {
  881. exitWithErrorPage('Invalid type');
  882. }
  883. } else {
  884. $tpl_page .= _gettext('A staff member with that ID already exists.');
  885. }
  886. } elseif (isset($_GET['del']) && $_GET['del'] > 0) {
  887. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staff` WHERE `id` = " . $tc_db->qstr($_GET['del']) . "");
  888. if (count($results) > 0) {
  889. $username = $results[0]['username'];
  890. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "staff` WHERE `id` = " . $tc_db->qstr($_GET['del']) . "");
  891. $tpl_page .= _gettext('Staff successfully deleted') . '<hr />';
  892. management_addlogentry(_gettext('Deleted staff member') . ': '. $username, 6);
  893. } else {
  894. $tpl_page .= _gettext('Invalid staff ID.');
  895. }
  896. } elseif (isset($_GET['edit']) && $_GET['edit'] > 0) {
  897. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staff` WHERE `id` = " . $tc_db->qstr($_GET['edit']) . "");
  898. if (count($results) > 0) {
  899. if (isset($_POST['submitting'])) {
  900. $this->CheckToken($_POST['token']);
  901. $username = $results[0]['username'];
  902. $type = $results[0]['type'];
  903. $boards = array();
  904. if (isset($_POST['modsallboards'])) {
  905. $newboards = array('allboards');
  906. } else {
  907. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY name FROM `" . KU_DBPREFIX . "boards`");
  908. foreach ($results as $line) {
  909. $boards = array_merge($boards, array($line['name']));
  910. }
  911. $changed_boards = array();
  912. $newboards = array();
  913. while (list($postkey, $postvalue) = each($_POST)) {
  914. if (substr($postkey, 0, 8) == "moderate") {
  915. $changed_boards = array_merge($changed_boards, array(substr($postkey, 8)));
  916. }
  917. }
  918. while (list(, $thisboard_name) = each($boards)) {
  919. if (in_array($thisboard_name, $changed_boards)) {
  920. $newboards = array_merge($newboards, array($thisboard_name));
  921. }
  922. }
  923. }
  924. $logentry = _gettext('Updated staff member') . ' - ';
  925. if ($_POST['type'] == '1') {
  926. $logentry .= _gettext('Administrator');
  927. } elseif ($_POST['type'] == '2') {
  928. $logentry .= _gettext('Moderator');
  929. } elseif ($_POST['type'] == '0') {
  930. $logentry .= _gettext('Janitor');
  931. } else {
  932. exitWithErrorPage('Something went wrong.');
  933. }
  934. $logentry .= ': '. $username;
  935. if ($_POST['type'] != '1') {
  936. $logentry .= ' - '. _gettext('Moderates') . ': ';
  937. if (isset($_POST['modsallboards'])) {
  938. $logentry .= strtolower(_gettext('All boards'));
  939. } else {
  940. $logentry .= '/'. implode('/, /', $newboards) . '/';
  941. }
  942. }
  943. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "staff` SET `boards` = " . $tc_db->qstr(implode('|', $newboards)) . " , `type` = " .$tc_db->qstr($_POST['type']). " WHERE `id` = " . $tc_db->qstr($_GET['edit']) . "");
  944. management_addlogentry($logentry, 6);
  945. $tpl_page .= _gettext('Staff successfully updated') . '<hr />';
  946. }
  947. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staff` WHERE `id` = '" . $_GET['edit'] . "'");
  948. $username = $results[0]['username'];
  949. $type = $results[0]['type'];
  950. $boards = explode('|', $results[0]['boards']);
  951. $tpl_page .= '<form action="manage_page.php?action=staff&edit=' .$_GET['edit']. '" method="post">
  952. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  953. <label for="username">' ._gettext('Username'). ':</label>
  954. <input type="text" id="username" name="username" value="' .$username. '" disabled="disabled" /><br />
  955. <label for="type">' ._gettext('Type'). ':</label>
  956. <select id="type" name="type">';
  957. $tpl_page .= ($type==1) ? '<option value="1" selected="selected">' ._gettext('Administrator'). '</option>' : '<option value="1">' ._gettext('Administrator'). '</option>';
  958. $tpl_page .= ($type==2) ? '<option value="2" selected="selected">' ._gettext('Moderator'). '</option>' : '<option value="2">' ._gettext('Moderator'). '</option>';
  959. $tpl_page .= ($type==0) ? '<option value="0" selected="selected">' ._gettext('Janitor'). '</option>' : '<option value="0">' ._gettext('Janitor'). '</option>';
  960. $tpl_page .= '</select><br /><br />';
  961. $tpl_page .= _gettext('Moderates') . '<br />
  962. <label for="modsallboards"><strong>' ._gettext('All boards'). '</strong></label>'. "\n";
  963. $tpl_page .= ($boards==array('allboards')) ? '<input type="checkbox" name="modsallboards" checked="checked" />' : '<input type="checkbox" name="modsallboards" />';
  964. $tpl_page .= '<br />' ._gettext('or'). '<br />';
  965. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards`");
  966. foreach ($results as $line) {
  967. $tpl_page .= '<label for="moderate'. $line['name'] . '">'. $line['name'] . '</label><input type="checkbox" name="moderate'. $line['name'] . '" ';
  968. if (in_array($line['name'], $boards)) {
  969. $tpl_page .= 'checked="checked" ';
  970. }
  971. $tpl_page .= '/><br />';
  972. }
  973. $tpl_page .= '<input type="submit" value="'. _gettext('Modify staff member') . '" name="submitting" />
  974. </form><br />';
  975. }
  976. }
  977. $tpl_page .= '<form action="manage_page.php?action=staff&add" method="post">
  978. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  979. <label for="username">' ._gettext('Username'). ':</label>
  980. <input type="text" id="username" name="username" /><br />
  981. <label for="password">' ._gettext('Password'). ':</label>
  982. <input type="text" id="password" name="password" /><br />
  983. <label for="type">' ._gettext('Type'). ':</label>
  984. <select id="type" name="type">
  985. <option value="1">' ._gettext('Administrator'). '</option>
  986. <option value="2">' ._gettext('Moderator'). '</option>
  987. <option value="0">' ._gettext('Janitor'). '</option>
  988. </select><br />
  989. <input type="submit" value="' ._gettext('Add staff member'). '" />
  990. </form>
  991. <hr /><br />';
  992. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Username') . '</th><th>'. _gettext('Added on') . '</th><th>'. _gettext('Last active') . '</th><th>IP Log</th><th>'. _gettext('Moderating boards') . '</th><th>&nbsp;</th></tr>'. "\n";
  993. $i = 1;
  994. while($i <= 3) {
  995. if ($i == 1) {
  996. $stafftype = 'Administrator';
  997. $numtype = 1;
  998. } elseif ($i == 2) {
  999. $stafftype = 'Moderator';
  1000. $numtype = 2;
  1001. } elseif ($i == 3) {
  1002. $stafftype = 'Janitor';
  1003. $numtype = 0;
  1004. }
  1005. $tpl_page .= '<tr><td align="center" colspan="6"><font size="+1"><strong>'. _gettext($stafftype) . '</strong></font></td></tr>'. "\n";
  1006. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "staff` WHERE `type` = '" .$numtype. "' ORDER BY `username` ASC");
  1007. if (count($results) > 0) {
  1008. foreach ($results as $line) {
  1009. $tpl_page .= '<tr><td>' .$line['username']. '</td><td>' .date("y/m/d(D)H:i", $line['addedon']). '</td><td>';
  1010. if ($line['lastactive'] == 0) {
  1011. $tpl_page .= _gettext('Never');
  1012. } elseif ((time() - $line['lastactive']) > 300) {
  1013. $tpl_page .= timeDiff($line['lastactive'], false);
  1014. } else {
  1015. $tpl_page .= _gettext('Online now');
  1016. }
  1017. $tpl_page.='</td><td>';
  1018. $iplog = explode('|', $line['iplog']);
  1019. foreach($iplog as $ip){
  1020. $ip = md5_decrypt($ip,KU_RANDOMSEED);
  1021. if(filter_var($ip,FILTER_VALIDATE_IP)){
  1022. $tpl_page.='[<a href="/manage_page.php?action=ipsearch&ip='.$ip.'">'.$ip.'</a>]';
  1023. }
  1024. }
  1025. $tpl_page .= '</td><td>';
  1026. if ($line['boards'] != '' || $line['type'] == 1) {
  1027. if ($line['boards'] == 'allboards' || $line['type'] == 1) {
  1028. $tpl_page .= _gettext('All boards') ;
  1029. } else {
  1030. $tpl_page .= '<strong>/'. implode('/</strong>, <strong>/', explode('|', $line['boards'])) . '/</strong>';
  1031. }
  1032. } else {
  1033. $tpl_page .= _gettext('No boards');
  1034. }
  1035. $tpl_page .= '</td><td>[<a href="?action=staff&edit='. $line['id'] . '">'. _gettext('Edit') . '</a>] [<a href="?action=staff&del='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>'. "\n";
  1036. }
  1037. } else {
  1038. $tpl_page .= '<tr><td colspan="6">'. _gettext('None') . '</td></tr>'. "\n";
  1039. }
  1040. $i++;
  1041. }
  1042. $tpl_page .= '</table>';
  1043. }
  1044. /* Display moderators and administrators actions which were logged */
  1045. function modlog() {
  1046. global $tc_db, $tpl_page;
  1047. $this->AdministratorsOnly();
  1048. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "modlog` WHERE `timestamp` < '" . (time() - KU_MODLOGDAYS * 86400) . "'");
  1049. $tpl_page .= '<h2>'. ('ModLog') . '</h2><br />
  1050. <table cellspacing="2" cellpadding="1" border="1" width="100%"><tr><th>'. _gettext('Time') .'</th><th>'. _gettext('User') .'</th><th width="100%">'. _gettext('Action') .'</th></tr>';
  1051. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "modlog` ORDER BY `timestamp` DESC");
  1052. foreach ($results as $line) {
  1053. $tpl_page .= "<tr><td>" . date("y/m/d(D)H:i", $line['timestamp']) . "</td><td>" . $line['user'] . "</td><td>" . $line['entry'] . "</td></tr>";
  1054. }
  1055. $tpl_page .= '</table>';
  1056. }
  1057. function proxyban() {
  1058. global $tpl_page;
  1059. $this->AdministratorsOnly();
  1060. $tpl_page .= '<h2>'. _gettext('Ban proxy list') . '</h2><br />';
  1061. if (isset($_FILES['imagefile'])) {
  1062. $bans_class = new Bans;
  1063. $ips = 0;
  1064. $successful = 0;
  1065. $proxies = file($_FILES['imagefile']['tmp_name']);
  1066. # Ban time function added by Courtney
  1067. $bantime = $_POST['btime'];
  1068. foreach($proxies as $proxy) {
  1069. if (preg_match('/.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+.*/', $proxy)) {
  1070. $proxy = trim($proxy);
  1071. $ips++;
  1072. if ($bans_class->BanUser(preg_replace('/:.*/', '', $proxy), 'SERVER', 1, 0, '', 'IP from proxylist automatically banned', '', 0, 0, 1, true)) {
  1073. $successful++;
  1074. }
  1075. }
  1076. }
  1077. management_addlogentry(sprintf(_gettext('Banned %d IP addresses using an IP address list.'), $successful), 8);
  1078. $tpl_page .= $successful . ' of '. $ips . ' IP addresses banned.';
  1079. } else {
  1080. $tpl_page .= '<form id="postform" action="'. KU_CGIPATH . '/manage_page.php?action=proxyban" method="post" enctype="multipart/form-data"> '. _gettext('Proxy list') .'<input type="file" name="imagefile" size="35" accesskey="f" /><br />
  1081. <input type="submit" value="'. _gettext('Submit') .'" />
  1082. <br />'. _gettext('The proxy list is assumed to be in plaintext *.*.*.*:port or *.*.*.* format, one IP per line.') .'<br /><br /><hr />';
  1083. }
  1084. }
  1085. function sql() {
  1086. global $tc_db, $tpl_page;
  1087. $this->AdministratorsOnly();
  1088. $tpl_page .= '<h2>'. _gettext('SQL query') . '</h2><br />';
  1089. if (isset($_POST['query'])) {
  1090. $this->CheckToken($_POST['token']);
  1091. $tpl_page .= '<hr />';
  1092. $result = $tc_db->Execute($_POST['query']);
  1093. if ($result) {
  1094. $tpl_page .= _gettext('Query executed successfully');
  1095. } else {
  1096. $tpl_page .= 'Error: '. $tc_db->ErrorMsg();
  1097. }
  1098. $tpl_page .= '<hr />';
  1099. management_addlogentry(_gettext('Inserted SQL'), 0);
  1100. }
  1101. $tpl_page .= '<form method="post" action="?action=sql">
  1102. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1103. <textarea name="query" rows="20" cols="60"></textarea>
  1104. <br /><br />
  1105. <input type="submit" value="'. _gettext('Inject') . '" />
  1106. </form>';
  1107. }
  1108. function cleanup() {
  1109. global $tc_db, $tpl_page;
  1110. $this->AdministratorsOnly();
  1111. $tpl_page .= '<h2>'. _gettext('Cleanup') . '</h2><br />';
  1112. if (isset($_POST['run'])) {
  1113. $tpl_page .= '<hr />'. _gettext('Deleting non-deleted replies which belong to deleted threads.') .'<hr />';
  1114. $this->delorphanreplies(true);
  1115. $tpl_page .= '<hr />'. _gettext('Deleting unused images.') .'<hr />';
  1116. $this->delunusedimages(true);
  1117. $tpl_page .= '<hr />'. _gettext('Removing posts deleted more than one week ago from the database.') .'<hr />';
  1118. $results = $tc_db->GetAll("SELECT `name`, `type`, `id` FROM `" . KU_DBPREFIX . "boards`");
  1119. foreach ($results AS $line) {
  1120. if ($line['type'] != 1) {
  1121. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `IS_DELETED` = 1 AND `deleted_timestamp` < " . (time() - 604800) . "");
  1122. }
  1123. }
  1124. $tpl_page .= _gettext('Optimizing all tables in database.') .'<hr />';
  1125. if (KU_DBTYPE == 'mysql' || KU_DBTYPE == 'mysqli') {
  1126. $results = $tc_db->GetAll("SHOW TABLES");
  1127. foreach ($results AS $line) {
  1128. $tc_db->Execute("OPTIMIZE TABLE `" . $line[0] . "`");
  1129. }
  1130. }
  1131. if (KU_DBTYPE == 'postgres7' || KU_DBTYPE == 'postgres8' || KU_DBTYPE == 'postgres') {
  1132. $results = $tc_db->GetAll("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'");
  1133. foreach ($results AS $line) {
  1134. $tc_db->Execute("VACUUM ANALYZE `" . $line[0] . "`");
  1135. }
  1136. }
  1137. $tpl_page .= _gettext('Cleanup finished.');
  1138. management_addlogentry(_gettext('Ran cleanup'), 2);
  1139. } else {
  1140. $tpl_page .= '<form action="manage_page.php?action=cleanup" method="post">'. "\n" .
  1141. ' <input name="run" id="run" type="submit" value="'. _gettext('Run Cleanup') . '" />'. "\n" .
  1142. '</form>';
  1143. }
  1144. }
  1145. /*
  1146. * +------------------------------------------------------------------------------+
  1147. * Boards Administration Pages
  1148. * +------------------------------------------------------------------------------+
  1149. */
  1150. function adddelboard() {
  1151. global $tc_db, $tpl_page, $board_class;
  1152. $this->AdministratorsOnly();
  1153. if (isset($_POST['directory'])) {
  1154. $this->CheckToken($_POST['token']);
  1155. if (isset($_POST['add'])) {
  1156. $tpl_page .= $this->addBoard($_POST['directory'], $_POST['desc']);
  1157. } elseif (isset($_POST['del'])) {
  1158. if (isset($_POST['confirmation'])) {
  1159. $tpl_page .= $this->delBoard($_POST['directory'], $_POST['confirmation']);
  1160. } else {
  1161. $tpl_page .= $this->delBoard($_POST['directory']);
  1162. }
  1163. }
  1164. }
  1165. $tpl_page .= '<h2>'. _gettext('Add board') . '</h2><br />
  1166. <form action="manage_page.php?action=adddelboard" method="post">
  1167. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1168. <input type="hidden" name="add" id="add" value="add" />
  1169. <label for="directory">'. _gettext('Directory') . ':</label>
  1170. <input type="text" name="directory" id="directory" />
  1171. <div class="desc">'. _gettext('The directory of the board.') . ' <strong>'. _gettext('Only put in the letter(s) of the board directory, no slashes!') . '</strong></div><br />
  1172. <label for="desc">'. _gettext('Description') . ':</label>
  1173. <input type="text" name="desc" id="desc" />
  1174. <div class="desc">'. _gettext('The name of the board.') . '</div><br />
  1175. <label for="firstpostid">'. _gettext('First Post ID') . ':</label>
  1176. <input type="text" name="firstpostid" id="firstpostid" value="1" />
  1177. <div class="desc">'. _gettext('The first post of this board will recieve this ID.') . '</div><br />
  1178. <input type="submit" value="'. _gettext('Add Board') .'" />
  1179. </form><br /><hr />
  1180. <h2>'. _gettext('Delete board') .'</h2><br />
  1181. <form action="manage_page.php?action=adddelboard" method="post">
  1182. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1183. <input type="hidden" name="del" id="del" value="del" />
  1184. <label for="directory">'. _gettext('Directory') .':</label>' .
  1185. $this->MakeBoardListDropdown('directory', $this->BoardList($_SESSION['manageusername'])) .
  1186. '<br />
  1187. <input type="submit" value="'. _gettext('Delete board') .'" />
  1188. </form>';
  1189. }
  1190. function addBoard($dir, $desc) {
  1191. global $tc_db;
  1192. $this->AdministratorsOnly();
  1193. $output = '';
  1194. $output .= '<h2>'. _gettext('Add Results') .'</h2><br />';
  1195. $dir = cleanBoardName($dir);
  1196. if ($dir != '' && $desc != '') {
  1197. if (strtolower($dir) != 'allboards') {
  1198. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($dir) . "");
  1199. if (count($results) == 0) {
  1200. if (mkdir(KU_BOARDSDIR . $dir, 0777) && mkdir(KU_BOARDSDIR . $dir . '/res', 0777) && mkdir(KU_BOARDSDIR . $dir . '/src', 0777) && mkdir(KU_BOARDSDIR . $dir . '/thumb', 0777)) {
  1201. file_put_contents(KU_BOARDSDIR . $dir . '/.htaccess', 'DirectoryIndex '. KU_FIRSTPAGE . '');
  1202. file_put_contents(KU_BOARDSDIR . $dir . '/src/.htaccess', 'AddType text/plain .ASM .C .CPP .CSS .JAVA .JS .LSP .PHP .PL .PY .RAR .SCM .TXT'. "\n" . 'SetHandler default-handler');
  1203. if ($_POST['firstpostid'] < 1) {
  1204. $_POST['firstpostid'] = 1;
  1205. }
  1206. $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "boards` ( `name` , `desc` , `createdon`, `start`, `image`, `includeheader` ) VALUES ( " . $tc_db->qstr($dir) . " , " . $tc_db->qstr($desc) . " , '" . time() . "', " . $_POST['firstpostid'] . ", '', '' )");
  1207. $boardid = $tc_db->Insert_Id();
  1208. $filetypes = $tc_db->GetAll("SELECT " . KU_DBPREFIX . "filetypes.id FROM " . KU_DBPREFIX . "filetypes WHERE " . KU_DBPREFIX . "filetypes.filetype = 'JPG' OR " . KU_DBPREFIX . "filetypes.filetype = 'GIF' OR " . KU_DBPREFIX . "filetypes.filetype = 'PNG';");
  1209. foreach ($filetypes AS $filetype) {
  1210. $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "board_filetypes` ( `boardid` , `typeid` ) VALUES ( " . $boardid . " , " . $filetype['id'] . " );");
  1211. }
  1212. $board_class = new Board($dir);
  1213. $board_class->RegenerateAll();
  1214. unset($board_class);
  1215. $output .= _gettext('Board successfully added.') . '<br /><br /><a href="'. KU_BOARDSPATH . '/'. $dir . '/">/'. $dir . '/</a>!<br />';
  1216. $output .= '<form action="?action=boardopts" method="post"><input type="hidden" name="board" value="'. $dir . '" /><input type="submit" style="border: 1px solid; background: none; text-align: center;" value="'. _gettext('Click to edit board options') .'" /><br /><hr /></form>';
  1217. management_addlogentry(_gettext('Added board') . ': /'. $dir . '/', 3);
  1218. } else {
  1219. $output .= '<br />'. _gettext('Unable to create directories.');
  1220. }
  1221. } else {
  1222. $output .= _gettext('A board with that name already exists.');
  1223. }
  1224. } else {
  1225. $output .= _gettext('That name is for internal use. Please pick another.');
  1226. }
  1227. } else {
  1228. $output .= _gettext('Please fill in all required fields.');
  1229. }
  1230. return $output;
  1231. }
  1232. function delboard($dir, $confirm = '') {
  1233. global $tc_db;
  1234. $this->AdministratorsOnly();
  1235. $output = '';
  1236. $output .= '<h2>'. _gettext('Delete Results') .'</h2><br />';
  1237. if (!empty($dir)) {
  1238. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($dir) . "");
  1239. foreach ($results as $line) {
  1240. $board_id = $line['id'];
  1241. $board_dir = $line['name'];
  1242. }
  1243. if (count($results) > 0) {
  1244. if (!empty($confirm)) {
  1245. if (removeBoard($board_dir)) {
  1246. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = '" . $board_id . "'");
  1247. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "boards` WHERE `id` = '" . $board_id . "'");
  1248. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "board_filetypes` WHERE `boardid` = '" . $board_id . "'");
  1249. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  1250. $menu_class = new Menu();
  1251. $menu_class->Generate();
  1252. $output .= _gettext('Board successfully deleted.');
  1253. management_addlogentry(_gettext('Deleted board') .': /'. $dir . '/', 3);
  1254. } else {
  1255. // Error
  1256. $output .= _gettext('Unable to delete board.');
  1257. }
  1258. } else {
  1259. $output .= sprintf(_gettext('Are you absolutely sure you want to delete %s?'),'/'. $board_dir . '/') .
  1260. '<br />
  1261. <form action="manage_page.php?action=adddelboard" method="post">
  1262. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1263. <input type="hidden" name="del" id="del" value="del" />
  1264. <input type="hidden" name="directory" id="directory" value="'. $dir . '" />
  1265. <input type="hidden" name="confirmation" id="confirmation" value="yes" />
  1266. <input type="submit" value="'. _gettext('Continue') .'" />
  1267. </form><br />';
  1268. }
  1269. } else {
  1270. $output .= _gettext('A board with that name does not exist.');
  1271. }
  1272. }
  1273. $output .= '<br />';
  1274. return $output;
  1275. }
  1276. /* Replace words in posts with something else */
  1277. function wordfilter() {
  1278. global $tc_db, $tpl_page;
  1279. $this->AdministratorsOnly();
  1280. $tpl_page .= '<h2>'. _gettext('Wordfilter') . '</h2><br />';
  1281. if (isset($_POST['word'])) {
  1282. $this->CheckToken($_POST['token']);
  1283. if ($_POST['word'] != '' && $_POST['replacedby'] != '') {
  1284. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "wordfilter` WHERE `word` = " . $tc_db->qstr($_POST['word']) . "");
  1285. if (count($results) == 0) {
  1286. $wordfilter_boards = array();
  1287. foreach ($results as $line) {
  1288. $wordfilter_word = $line['word'];
  1289. }
  1290. $wordfilter_boards = array();
  1291. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards`");
  1292. foreach ($_POST['wordfilter'] as $board) {
  1293. $check = $tc_db->GetOne("SELECT `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($board));
  1294. if (!empty($check)) {
  1295. $wordfilter_boards[] = $board;
  1296. }
  1297. }
  1298. $is_regex = (isset($_POST['regex'])) ? '1' : '0';
  1299. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "wordfilter` ( `word` , `replacedby` , `boards` , `time` , `regex` ) VALUES ( " . $tc_db->qstr($_POST['word']) . " , " . $tc_db->qstr($_POST['replacedby']) . " , " . $tc_db->qstr(implode('|', $wordfilter_boards)) . " , '" . time() . "' , '" . $is_regex . "' )");
  1300. $tpl_page .= _gettext('Word successfully added.');
  1301. management_addlogentry(sprintf(_gettext("Added word to wordfilter: %s - Changes to: %s - Boards: /%s/"),$_POST['word'], $_POST['replacedby'], implode('/, /', $wordfilter_boards)), 11);
  1302. } else {
  1303. $tpl_page .= _gettext('That word already exists.');
  1304. }
  1305. } else {
  1306. $tpl_page .= _gettext('Please fill in all required fields.');
  1307. }
  1308. $tpl_page .= '<hr />';
  1309. } elseif (isset($_GET['delword'])) {
  1310. if ($_GET['delword'] > 0) {
  1311. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "wordfilter` WHERE `id` = " . $tc_db->qstr($_GET['delword']) . "");
  1312. if (count($results) > 0) {
  1313. foreach ($results as $line) {
  1314. $del_word = $line['word'];
  1315. }
  1316. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "wordfilter` WHERE `id` = " . $tc_db->qstr($_GET['delword']) . "");
  1317. $tpl_page .= _gettext('Word successfully removed.');
  1318. management_addlogentry(_gettext('Removed word from wordfilter') . ': '. $del_word, 11);
  1319. } else {
  1320. $tpl_page .= _gettext('That ID does not exist.');
  1321. }
  1322. $tpl_page .= '<hr />';
  1323. }
  1324. } elseif (isset($_GET['editword'])) {
  1325. if ($_GET['editword'] > 0) {
  1326. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "wordfilter` WHERE `id` = " . $tc_db->qstr($_GET['editword']) . "");
  1327. if (count($results) > 0) {
  1328. if (!isset($_POST['replacedby'])) {
  1329. foreach ($results as $line) {
  1330. $tpl_page .= '<form action="manage_page.php?action=wordfilter&editword='.$_GET['editword'].'" method="post">
  1331. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1332. <label for="word">'. _gettext('Word') .':</label>
  1333. <input type="text" name="word" value="'.$line['word'].'" disabled /><br />
  1334. <label for="replacedby">'. _gettext('Is replaced by') .':</label>
  1335. <input type="text" name="replacedby" value="'.$line['replacedby'].'" /><br />
  1336. <label for="regex">'. _gettext('Regular expression') .':</label>
  1337. <input type="checkbox" name="regex"';
  1338. if ($line['regex'] == '1') {
  1339. $tpl_page .= ' checked';
  1340. }
  1341. $tpl_page .= ' /><br />
  1342. <label>'. _gettext('Boards') .':</label><br />';
  1343. $array_boards = array();
  1344. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards`");
  1345. foreach ($resultsboard as $lineboard) {
  1346. $array_boards = array_merge($array_boards, array($lineboard['name']));
  1347. }
  1348. foreach ($array_boards as $this_board_name) {
  1349. $tpl_page .= '<label for="wordfilter[]">'. $this_board_name . '</label><input type="checkbox" name="wordfilter[]" value="'.$this_board_name.'"';
  1350. if (in_array($this_board_name, explode("|", $line['boards'])) && explode("|", $line['boards']) != '') {
  1351. $tpl_page .= 'checked ';
  1352. }
  1353. $tpl_page .= ' /><br />';
  1354. }
  1355. $tpl_page .= '<br />
  1356. <input type="submit" value="'. _gettext('Edit word') .'" />
  1357. </form>';
  1358. }
  1359. } else {
  1360. $this->CheckToken($_POST['token']);
  1361. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "wordfilter` WHERE `id` = " . $tc_db->qstr($_GET['editword']) . "");
  1362. if (count($results) > 0) {
  1363. foreach ($results as $line) {
  1364. $wordfilter_word = $line['word'];
  1365. }
  1366. $wordfilter_boards = array();
  1367. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards`");
  1368. if (isset($_POST['wordfilter'])){
  1369. foreach ($_POST['wordfilter'] as $board) {
  1370. $check = $tc_db->GetOne("SELECT `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($board));
  1371. if (!empty($check)) {
  1372. $wordfilter_boards[] = $board;
  1373. }
  1374. }
  1375. }
  1376. $is_regex = (isset($_POST['regex'])) ? '1' : '0';
  1377. $tc_db->Execute("UPDATE `". KU_DBPREFIX ."wordfilter` SET `replacedby` = " . $tc_db->qstr($_POST['replacedby']) . " , `boards` = " . $tc_db->qstr(implode('|', $wordfilter_boards)) . " , `regex` = '" . $is_regex . "' WHERE `id` = " . $tc_db->qstr($_GET['editword']) . "");
  1378. $tpl_page .= _gettext('Word successfully updated.');
  1379. management_addlogentry(_gettext('Updated word on wordfilter') . ': '. $wordfilter_word, 11);
  1380. } else {
  1381. $tpl_page .= _gettext('Unable to locate that word.');
  1382. }
  1383. }
  1384. } else {
  1385. $tpl_page .= _gettext('That ID does not exist.');
  1386. }
  1387. $tpl_page .= '<hr />';
  1388. }
  1389. } else {
  1390. $tpl_page .= '<form action="manage_page.php?action=wordfilter" method="post">
  1391. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1392. <label for="word">'. _gettext('Word') .':</label>
  1393. <input type="text" name="word" /><br />
  1394. <label for="replacedby">'. _gettext('Is replaced by') .':</label>
  1395. <input type="text" name="replacedby" /><br />
  1396. <label for="regex">'. _gettext('Regular expression') .':</label>
  1397. <input type="checkbox" name="regex" /><br />
  1398. <label>'. _gettext('Boards') .':</label><br />';
  1399. $array_boards = array();
  1400. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY name FROM `" . KU_DBPREFIX . "boards`");
  1401. $array_boards = array_merge($array_boards, $resultsboard);
  1402. $tpl_page .= $this->MakeBoardListCheckboxes('wordfilter', $array_boards) .
  1403. '<br />
  1404. <input type="submit" value="'. _gettext('Add word') .'" />
  1405. </form>
  1406. <hr />';
  1407. }
  1408. $tpl_page .= '<br />';
  1409. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "wordfilter`");
  1410. if ($results > 0) {
  1411. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Word') . '</th><th>'. _gettext('Replacement') . '</th><th>'. _gettext('Boards') . '</th><th>&nbsp;</th></tr>'. "\n";
  1412. foreach ($results as $line) {
  1413. $tpl_page .= '<tr><td>'. $line['word'] . '</td><td>'. $line['replacedby'] . '</td><td>';
  1414. if (explode('|', $line['boards']) != '') {
  1415. $tpl_page .= '<strong>/'. implode('/</strong>, <strong>/', explode('|', $line['boards'])) . '/</strong>&nbsp;';
  1416. } else {
  1417. $tpl_page .= _gettext('No boards');
  1418. }
  1419. $tpl_page .= '</td><td>[<a href="manage_page.php?action=wordfilter&editword='. $line['id'] . '">'. _gettext('Edit') . '</a>] [<a href="manage_page.php?action=wordfilter&delword='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>'. "\n";
  1420. }
  1421. $tpl_page .= '</table>';
  1422. }
  1423. }
  1424. /* Ad Management */
  1425. function ads() {
  1426. global $tc_db, $tpl_page;
  1427. $this->AdministratorsOnly();
  1428. $tpl_page .= '<h2>'. _gettext('Ad Management') .'</h2><span style="font-size: 100%; font-weight: 600;">'. _gettext('Anything can go here, such as banners, links, etc. It doesn\'t have to be just ads.') .'</span>'. "\n";
  1429. if (isset($_GET['edit']) && ($_GET['edit'] == 1 || $_GET['edit'] == 2)) {
  1430. if (isset($_POST['code']) and !empty($_POST['code'])) {
  1431. $this->CheckToken($_POST['token']);
  1432. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "ads` SET `disp` = " . $tc_db->qstr($_POST['disp']) . ", `code` = " . $tc_db->qstr($_POST['code']) . " WHERE `id` = " . $tc_db->qstr($_GET['edit']) . "");
  1433. $tpl_page .= '<hr /><h3>'. _gettext('Ad Edited.') .'</h3><p style="text-align: center;">'.sprintf(_gettext('Click %shere%s to return to Ad Management.'),'<a href="?action=ads">','</a>') .'</p><hr />'. "\n";
  1434. management_addlogentry(_gettext('Edited an ad'));
  1435. }
  1436. $results = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "ads` WHERE `id` = '" . $_GET['edit'] . "'");
  1437. foreach ($results as $ad) {
  1438. $tpl_page .= '<form action="?action=ads&edit='. $_GET['edit'] . '" method="post">'. "\n" .
  1439. '<input type="hidden" name="token" value="' . $_SESSION['token'] . '" />' . "\n" .
  1440. '<label for="pos">'. _gettext('Position') .':</label>'. "\n" .
  1441. '<input type="text" disabled="disabled" name="pos" value="'. $ad['position'] . '" /><br />'. "\n" .
  1442. '<label for="code">'. _gettext('Code') .':</label>'. "\n" .
  1443. '<textarea name="code" rows="10" cols="25">' . htmlspecialchars($ad['code']) . '</textarea>' . "\n" .
  1444. '<label for="disp">'. _gettext('Display') .':</label>'. "\n" .
  1445. '<input type="text" maxlength="1" name="disp" value="'. $ad['disp'] . '" /><div class="desc">'. _gettext('Put <strong>0</strong> for no display, <strong>1</strong> to display.') .'</div><br />'. "\n" .
  1446. '<input type="submit" value="'. _gettext('Edit') . '" /><br />'. "\n";
  1447. }
  1448. } else {
  1449. $results = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "ads`");
  1450. if (count($results) > 0) {
  1451. $tpl_page .= '<table border="1">'. "\n";
  1452. $tpl_page .= '<tr><th>'. _gettext('Position') .'</th><th>'. _gettext('Display') .'</th><th>'. _gettext('Code') .'</th><th>&nbsp;</th></tr>'. "\n";
  1453. foreach ($results as $line) {
  1454. $find = array('<', '>');
  1455. $replace = array ('&lt;', '&gt;');
  1456. if ($line['disp'] == 0) {
  1457. $disp = 'Not Displayed';
  1458. } elseif ($line['disp'] == 1) {
  1459. $disp = _gettext('Displayed');
  1460. }
  1461. $tpl_page .= '<tr><td>'. $line['position'] . '</td><td>'. $disp . '</td><td>'. str_replace($find, $replace, $line['code']) . '</td><td><a href="?action=ads&edit='. $line['id'] . '">'. _gettext('Edit') .'</a></td></tr>'. "\n";
  1462. }
  1463. $tpl_page .= '</table>'. "\n";
  1464. } else {
  1465. $tpl_page .= _gettext('There was an error during install, and the ads table didn\'t get populated.');
  1466. }
  1467. }
  1468. }
  1469. /* Add or delete Embed Entries */
  1470. function embeds() {
  1471. global $tc_db, $tpl_page;
  1472. $this->AdministratorsOnly();
  1473. $disptable = true; $formval = 'add'; $title = _gettext('Embed Management');
  1474. if(isset($_GET['act'])) {
  1475. if ($_GET['act'] == 'edit') {
  1476. if (isset($_POST['embeds'])) {
  1477. $this->CheckToken($_POST['token']);
  1478. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "embeds` SET `filetype` = " . $tc_db->qstr(trim($_POST['filetype'])) . ", `videourl` = " . $tc_db->qstr(trim($_POST['videourl'])) . ", `name` = " . $tc_db->qstr(trim($_POST['name'])) . ", `width` = " . $tc_db->qstr(trim($_POST['width'])) . ", `height` = " . $tc_db->qstr(trim($_POST['height'])) . ", `code` = " . $tc_db->qstr(trim($_POST['embeds'])) . " WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  1479. $tpl_page .= '<hr /><h3>'. _gettext('Embed Edited') .'</h3><hr />';
  1480. management_addlogentry(_gettext('Edited an embed'), 9);
  1481. }
  1482. $formval = 'edit&amp;id='. $_GET['id']; $title .= ' - Edit';
  1483. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "embeds` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  1484. $values = $results[0];
  1485. $disptable = false;
  1486. } elseif ($_GET['act'] == 'del') {
  1487. $results = $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "embeds` WHERE `id` = " . $tc_db->qstr($_GET['id']) . "");
  1488. $tpl_page .= '<hr /><h3>'. _gettext('Embed deleted') .'</h3><hr />';
  1489. management_addlogentry(_gettext('Deleted an Embed'), 9);
  1490. } elseif ($_GET['act'] == 'add') {
  1491. if (isset($_POST['embeds']) && isset($_POST['name']) && isset($_POST['filetype']) && isset($_POST['videourl'])) {
  1492. if ($_POST['embeds'] != '') {
  1493. $this->CheckToken($_POST['token']);
  1494. $width = ($_POST['width'] != '') ? $_POST['width'] : KU_YOUTUBEWIDTH;
  1495. $height = ($_POST['height'] != '') ? $_POST['height'] : KU_YOUTUBEHEIGHT;
  1496. $tpl_page .= '<hr />';
  1497. if ($_POST['embeds'] != '') {
  1498. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "embeds` ( `name` , `filetype` , `videourl` , `width` , `height` , `code` ) VALUES ( " . $tc_db->qstr(trim($_POST['name'])) . " , " . $tc_db->qstr(trim($_POST['filetype'])) . " , " . $tc_db->qstr(trim($_POST['videourl'])) . " , " . $tc_db->qstr(trim($width)) . " , " . $tc_db->qstr(trim($height)) . " , " . $tc_db->qstr(trim($_POST['embeds'])) . " )");
  1499. $tpl_page .= '<h3>'. _gettext('Embed successfully added.') . '</h3>';
  1500. management_addlogentry(_gettext('Added an Embed'), 9);
  1501. } else {
  1502. $tpl_page .= _gettext('You must enter code.');
  1503. }
  1504. $tpl_page .= '<hr />';
  1505. }
  1506. }
  1507. }
  1508. }
  1509. $tpl_page .= '<h2>'. $title . '</h2><br />
  1510. <form method="post" action="?action=embeds&amp;act='. $formval . '">
  1511. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1512. <label for="name">'. _gettext('Site Name') . ':</label>
  1513. <input type="text" id="name" name="name" value="'. (isset($values['name']) ? $values['name'] : ''). '" />
  1514. <div class="desc">'. _gettext('Can not be left blank.') . '</div><br />
  1515. <label for="filetype">'. _gettext('Filetype') . ':</label>
  1516. <input type="text" id="filetype" name="filetype" maxlength="3" value="'. (isset($values['filetype']) ? $values['filetype'] : '') . '" />
  1517. <div class="desc">'. _gettext('Can not be left blank, or longer than 3 characters') . '</div><br />
  1518. <label for="videourl">'. _gettext('Video URL Start') . ':</label>
  1519. <input type="text" id="videourl" name="videourl" value="'. (isset($values['videourl']) ? $values['videourl'] : '') . '" />
  1520. <div class="desc">'. _gettext('Can not be left blank. This is what comes before the embed ID. Example: \'http://www.youtube.com/watch?v=\'') . '</div><br />
  1521. <label for="embeds">'. _gettext('Code') . ':</label>
  1522. <textarea id="embeds" name="embeds" rows="25" cols="80">' . (isset($values['code']) ? htmlspecialchars($values['code']) : '') . '</textarea><br />
  1523. <label for="width">'. _gettext('Width') . ':</label>
  1524. <input type="text" id="width" name="width" value="'. (isset($values['width']) ? $values['width'] : '') . '" />
  1525. <div class="desc">'. _gettext('This can be left blank. It will be reset with the default width set in config.php') . '</div><br />
  1526. <label for="height">'. _gettext('Height') . ':</label>
  1527. <input type="text" id="height" name="height" value="'. (isset($values['height']) ? $values['height'] : '') . '" />
  1528. <div class="desc">'. _gettext('This can be left blank. It will be reset with the default height set in config.php') . '</div><br />
  1529. <div class="desc">'. _gettext('When adding an embed, please check <a href="http://www.kusabax.org/wiki/embedding">http://www.kusabax.org/wiki/embedding</a> and check if there is a tutorial image for the site you are adding. Put this image in the /inc/embedhelp/ folder, or create your own in this folder if one does not exist. The image must be the same as the site name in all lowercase.') . '</div><br />
  1530. <input type="submit" value="'. _gettext('Edit') .'" />
  1531. </form>';
  1532. if ($disptable) {
  1533. $tpl_page .= '<br /><hr /><h1>'. _gettext('Edit/Delete Embeds') .'</h1>';
  1534. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "embeds` ORDER BY `id` ASC");
  1535. if (count($results) > 0) {
  1536. $find = array('<', '>');
  1537. $replace = array ('&lt;', '&gt;');
  1538. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('Site Name') .'</th><th>'. _gettext('Filetype') .'</th><th>'. _gettext('Video URL Start') .'</th><th>'. _gettext('Width') .'</th><th>'. _gettext('Height') .'</th><th>'. _gettext('Code') .'</th></tr>';
  1539. foreach ($results as $line) {
  1540. $tpl_page .= '<tr><td>'. $line['name'] . '</td><td>'. $line['filetype'] . '</td><td>'. $line['videourl'] . '</td><td>'. $line['width'] . '</td><td>'. $line['height'] . '</td><td>'. str_replace($find, $replace, $line['code']) . '</td><td>[<a href="?action=embeds&amp;act=edit&amp;id='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=embeds&amp;act=del&amp;id='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  1541. }
  1542. $tpl_page .= '</table>';
  1543. } else {
  1544. $tpl_page .= _gettext('No Embeds yet.');
  1545. }
  1546. }
  1547. }
  1548. function movethread() {
  1549. global $tc_db, $tpl_page;
  1550. $this->AdministratorsOnly();
  1551. $tpl_page .= '<h2>'. _gettext('Move thread') . '</h2><br />';
  1552. if (isset($_POST['id']) && isset($_POST['board_from']) && isset($_POST['board_to'])) {
  1553. $this->CheckToken($_POST['token']);
  1554. // Get the IDs for the from and to boards
  1555. $board_from_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_POST['board_from']) . "");
  1556. $board_to_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_POST['board_to']) . "");
  1557. $board_from = $_POST['board_from'];
  1558. $board_to = $_POST['board_to'];
  1559. $id = $tc_db->qstr($_POST['id']);
  1560. if (isset($_POST['mf'])) {
  1561. $image = $tc_db->GetOne("SELECT `file` FROM " .KU_DBPREFIX. "posts WHERE `boardid` = " .$board_from_id. " AND `id` = " .$id);
  1562. $filetype = $tc_db->GetOne("SELECT `file_type` FROM " .KU_DBPREFIX. "posts WHERE `boardid` = " .$board_from_id. " AND `id` = " .$id);
  1563. $from_pic = KU_BOARDSDIR . $board_from . '/src/'. $image . '.'. $filetype;
  1564. $from_thumb = KU_BOARDSDIR . $board_from . '/thumb/'. $image . 's'. '.'. $filetype;
  1565. $from_cat = KU_BOARDSDIR . $board_from . '/thumb/'. $image . 'c'. '.'. $filetype;
  1566. $to_pic = KU_BOARDSDIR . $board_to . '/src/'. $image . '.'. $filetype;
  1567. $to_thumb = KU_BOARDSDIR . $board_to . '/thumb/'. $image . 's'. '.'. $filetype;
  1568. $to_cat = KU_BOARDSDIR . $board_to . '/thumb/'. $image . 'c'. '.'. $filetype;
  1569. @rename($from_pic, $to_pic);
  1570. @rename($from_thumb, $to_thumb);
  1571. @rename($from_cat, $to_cat);
  1572. @unlink($from_pic);
  1573. @unlink($from_thumb);
  1574. @unlink($from_cat);
  1575. }
  1576. $from_html = KU_BOARDSDIR . $board_from . '/res/'. $_POST['id'] . '.html';
  1577. $from_html_50 = KU_BOARDSDIR . $board_from . '/res/'. $_POST['id'] . '+50.html';
  1578. $from_html_100 = KU_BOARDSDIR . $board_from . '/res/'. $_POST['id'] . '-100.html';
  1579. @unlink($from_html);
  1580. @unlink($from_html_50);
  1581. @unlink($from_html_100);
  1582. $tc_db->Execute("START TRANSACTION");
  1583. $new_id = $tc_db->GetOne("SELECT COALESCE(MAX(id),0) + 1 FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_to_id);
  1584. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `id` = " . $new_id . ", `boardid` = " .$board_to_id. " WHERE `boardid` = " .$board_from_id. " AND `id` = " . $id);
  1585. processPost($new_id, $new_id, $id, $board_from, $board_to, $board_to_id);
  1586. $results = $tc_db->GetAll("SELECT `id` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " .$board_from_id. " AND `parentid` = " . $id . " ORDER BY `id` ASC");
  1587. foreach ($results as $line) {
  1588. if (isset($_POST['mf'])) {
  1589. $image = $tc_db->GetOne("SELECT `file` FROM `" .KU_DBPREFIX. "posts` WHERE `boardid` = " .$board_from_id. " AND `id` = " .$line['id']);
  1590. $filetype = $tc_db->GetOne("SELECT `file_type` FROM `" .KU_DBPREFIX. "posts` WHERE `boardid` = " .$board_from_id. " AND `id` = " .$line['id']);
  1591. $from_pic = KU_BOARDSDIR . $board_from . '/src/'. $image . '.'. $filetype;
  1592. $from_thumb = KU_BOARDSDIR . $board_from . '/thumb/'. $image . 's'. '.'. $filetype;
  1593. $from_cat = KU_BOARDSDIR . $board_from . '/thumb/'. $image . 'c'. '.'. $filetype;
  1594. $to_pic = KU_BOARDSDIR . $board_to . '/src/'. $image . '.'. $filetype;
  1595. $to_thumb = KU_BOARDSDIR . $board_to . '/thumb/'. $image . 's'. '.'. $filetype;
  1596. $to_cat = KU_BOARDSDIR . $board_to . '/thumb/'. $image . 'c'. '.'. $filetype;
  1597. @rename($from_pic, $to_pic);
  1598. @rename($from_thumb, $to_thumb);
  1599. @rename($from_cat, $to_cat);
  1600. @unlink($from_pic);
  1601. @unlink($from_thumb);
  1602. @unlink($from_cat);
  1603. }
  1604. $insert_id = $tc_db->GetOne("SELECT COALESCE(MAX(id),0) + 1 FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_to_id);
  1605. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `id` = " . $insert_id . ", `boardid` = " .$board_to_id. " WHERE `boardid` = " .$board_from_id. " AND `id` = " . $line['id']);
  1606. processPost($insert_id, $new_id, $id, $board_from, $board_to, $board_to_id);
  1607. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `parentid` = " . $new_id . " WHERE `boardid` = " . $board_to_id . " AND `id` = " . $insert_id);
  1608. }
  1609. $tc_db->Execute("COMMIT");
  1610. $board_class = new Board($board_from);
  1611. $board_class->RegenerateThreads();
  1612. $board_class->RegeneratePages();
  1613. unset($board_class);
  1614. $board_class = new Board($board_to);
  1615. $board_class->RegenerateThreads();
  1616. $board_class->RegeneratePages();
  1617. unset($board_class);
  1618. $tpl_page .= _gettext('Move complete.') . ' <br /><hr />';
  1619. }
  1620. $tpl_page .= '<form action="?action=movethread" method="post">
  1621. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  1622. <label for="id">'. _gettext('ID') . ':</label>
  1623. <input type="text" name="id" />
  1624. <br />
  1625. <label for="board_from">'. _gettext('From') . ':</label>' .
  1626. $this->MakeBoardListDropdown('board_from', $this->BoardList($_SESSION['manageusername'])) .
  1627. '<br />
  1628. <label for="board_to">' ._gettext('To') . ':</label>' .
  1629. $this->MakeBoardListDropdown('board_to', $this->BoardList($_SESSION['manageusername'])) .
  1630. '<br />
  1631. <label for="mf">'. _gettext('Move Files') .':</label>
  1632. <input type="checkbox" id="mf" name="mf" /><br />
  1633. <input type="submit" value="'. _gettext('Move thread') . '" />';
  1634. }
  1635. /* Search for posts by IP */
  1636. function ipsearch() {
  1637. global $tc_db, $tpl_page;
  1638. $this->AdministratorsOnly();
  1639. $tpl_page .= '<h2>'. _gettext('IP Address Search') .'</h2><br />'. "\n";
  1640. if (isset($_GET['ip']) && !empty($_GET['board'])) {
  1641. if ($_GET['board'] == 'all') {
  1642. $queryextra = "";
  1643. } else {
  1644. $queryextra = "`boardid` IN (" . $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "") . ") AND";
  1645. }
  1646. $results = $tc_db->GetAll("SELECT `" . KU_DBPREFIX . "posts`.`id` AS id, `" . KU_DBPREFIX . "posts`.`parentid` AS parentid, `" . KU_DBPREFIX . "posts`.`ip` AS ip, `" . KU_DBPREFIX . "posts`.`message` AS message, `" . KU_DBPREFIX . "posts`.`file` AS file, `" . KU_DBPREFIX . "posts`.`file_type` AS file_type, `" . KU_DBPREFIX . "boards`.`name` AS boardname FROM `" . KU_DBPREFIX . "posts`, `" . KU_DBPREFIX . "boards` WHERE ".$queryextra." `ipmd5` = '" . md5(KU_SALT.$_GET['ip']) . "' AND `IS_DELETED` = 0 AND `" . KU_DBPREFIX . "boards`.`id` = `" . KU_DBPREFIX . "posts`.`boardid` ORDER BY `boardid`");
  1647. if (count($results) > 0) {
  1648. foreach ($results as $line) {
  1649. $tpl_page .= '<table border="1" width="100%">'. "\n" .
  1650. '<tr><th width="10%">'. _gettext('Post Number') .'</th><th width="10%">'. _gettext('File') .'</th><th width="70%">'. _gettext('Message') .'</th><th width=10%">'. _gettext('IP Address') .'</th></tr>'. "\n";
  1651. $real_parentid = ($line['parentid'] == 0) ? $line['id'] : $line['parentid'];
  1652. $tpl_page .= '<tr><td><a href="'. KU_BOARDSPATH . '/'. $line['boardname'] . '/res/'. $real_parentid . '.html#'. $line['id'] . '">/'. $line['boardname'] . '/'. $line['id'] . '</td><td>'. (($line['file_type'] == 'jpg' || $line['file_type'] == 'gif' || $line['file_type'] == 'png') ? ('<a href="'. KU_WEBPATH .'/'. $line['boardname'] . '/src/'. $line['file'] . '.'. $line['file_type'] . '"><img border=0 src="'. KU_WEBPATH .'/'. $line['boardname'] . '/thumb/'. $line['file'] . 's.'. $line['file_type'] . '"></a>') : ('')) . '</td><td>'. $line['message'] . '</td><td>'. md5_decrypt($line['ip'], KU_RANDOMSEED) . '</tr>';
  1653. }
  1654. $tpl_page .= '</table>'. "\n";
  1655. } else {
  1656. $tpl_page .= _gettext('No results found for') .' '. $_GET['ip'] . '<br />'. "\n";
  1657. }
  1658. } else {
  1659. $tpl_page .= '<form action="?" method="get">'. "\n" .
  1660. '<input type="hidden" name="action" value="ipsearch" />'. "\n" .
  1661. '<label for="board">'. _gettext('Board') . ':</label>'. "\n" .
  1662. $this->MakeBoardListDropdown('board', $this->BoardList($_SESSION['manageusername']), true) . '<br />'. "\n" .
  1663. '<label for="ip">'. _gettext('IP') . ':</label>'. "\n" .
  1664. '<input type="text" name="ip" value="'. (isset($_GET['ip']) ? $_GET['ip'] : ''). '" /><br />'. "\n" .
  1665. '<input type="submit" value="'. _gettext('IP Search') . '" />'. "\n";
  1666. }
  1667. }
  1668. /* Search for text in posts */
  1669. function search() {
  1670. global $tc_db, $tpl_page;
  1671. $this->AdministratorsOnly();
  1672. if (isset($_GET['query'])) {
  1673. $search_query = $_GET['query'];
  1674. if (isset($_GET['s'])) {
  1675. $s = $_GET['s'];
  1676. } else {
  1677. $s = 0;
  1678. }
  1679. $search_query_array = explode('KUSABA_AND', $search_query);
  1680. $trimmed = trim($search_query);
  1681. $limit = 10;
  1682. if ($trimmed == '') {
  1683. $tpl_page .= _gettext('Please enter a search query.');
  1684. exit;
  1685. }
  1686. $boardlist = $this->BoardList($_SESSION['manageusername']);
  1687. $likequery = '';
  1688. foreach ($search_query_array as $search_split) {
  1689. $likequery .= "`message` LIKE " . $tc_db->qstr(str_replace('_', '\_', $search_split)) . " AND ";
  1690. }
  1691. $likequery = substr($likequery, 0, -4);
  1692. $query = '';
  1693. $query .= "SELECT `" . KU_DBPREFIX . "posts`.`id` AS id, `" . KU_DBPREFIX . "posts`.`parentid` AS parentid, `" . KU_DBPREFIX . "posts`.`message` AS message, `" . KU_DBPREFIX . "boards`.`name` AS boardname FROM `" . KU_DBPREFIX . "posts`, `" . KU_DBPREFIX . "boards` WHERE `IS_DELETED` = 0 AND " . $likequery . " AND `" . KU_DBPREFIX . "boards`.`id` = `" . KU_DBPREFIX . "posts`.`boardid` ORDER BY `timestamp` DESC";
  1694. $numresults = $tc_db->GetAll($query);
  1695. $numrows = count($numresults);
  1696. if ($numrows == 0) {
  1697. $tpl_page .= '<h4>'. _gettext('Results') . '</h4>';
  1698. $tpl_page .= '<p>'. _gettext('Sorry, your search returned zero results.') . '</p>';
  1699. } else {
  1700. $query .= " LIMIT $limit OFFSET $s";
  1701. $results = $tc_db->GetAll($query);
  1702. $tpl_page .= '<p style="font-size: 1.5em;">'. _gettext('Results for') .': <strong>'. $search_query . '</strong></p>';
  1703. $count = 1 + $s;
  1704. foreach ($results as $line) {
  1705. $tpl_page .= '<span style="font-size: 1.5em;">'. $count . '.</span> <span style="font-size: 1.3em;">'. _gettext('Board') .': /'. $line['boardname'] . '/, <a href="'.KU_BOARDSPATH . '/'. $line['boardname'] . '/res/';
  1706. if ($line['parentid'] == 0) {
  1707. $tpl_page .= $line['id'] . '.html">';
  1708. } else {
  1709. $tpl_page .= $line['parentid'] . '.html#'. $line['id'] . '">';
  1710. }
  1711. if ($line['parentid'] == 0) {
  1712. $tpl_page .= _gettext('Thread') .' #'. $line['id'];
  1713. } else {
  1714. $tpl_page .= _gettext('Thread') .' #'. $line['parentid'] . ', Post #'. $line['id'];
  1715. }
  1716. $tpl_page .= '</a></span>';
  1717. $regexp = '/(';
  1718. foreach ($search_query_array as $search_word) {
  1719. $regexp .= preg_quote($search_word) . '|';
  1720. }
  1721. $regexp = substr($regexp, 0, -1) . ')/';
  1722. //$line['message'] = preg_replace_callback($regexp, array(&$this, 'search_callback'), stripslashes($line['message']));
  1723. $line['message'] = stripslashes($line['message']);
  1724. $tpl_page .= '<fieldset>'. $line['message'] . '</fieldset><br />';
  1725. $count++;
  1726. }
  1727. $currPage = (($s / $limit) + 1);
  1728. $tpl_page .= '<br />';
  1729. if ($s >= 1) {
  1730. $prevs = ($s - $limit);
  1731. $tpl_page .= "&nbsp;<a href=\"?action=search&s=$prevs&query=" . urlencode($search_query) . "\">&lt;&lt; "._gettext('Prev')." 10</a>&nbsp&nbsp;";
  1732. }
  1733. $pages = intval($numrows / $limit);
  1734. if ($numrows % $limit) {
  1735. $pages++;
  1736. }
  1737. if (!((($s + $limit) / $limit) == $pages) && $pages != 1) {
  1738. $news = $s + $limit;
  1739. $tpl_page .= "&nbsp;<a href=\"?action=search&s=$news&query=" . urlencode($search_query) . "\">"._gettext('Next')." 10 &gt;&gt;</a>";
  1740. }
  1741. $a = $s + ($limit);
  1742. if ($a > $numrows) {
  1743. $a = $numrows;
  1744. }
  1745. $b = $s + 1;
  1746. $tpl_page .= $this->search_results_display($a, $b, $numrows);
  1747. }
  1748. }
  1749. $tpl_page .= '<form action="?" method="get">
  1750. <input type="hidden" name="action" value="search" />
  1751. <input type="hidden" name="s" value="0" />
  1752. <strong>'. _gettext('Query') .'</strong>:<br /><input type="text" name="query" ';
  1753. if (isset($_GET['query'])) {
  1754. $tpl_page .= 'value="'. $_GET['query'] . '" ';
  1755. }
  1756. $tpl_page .= 'size="52" /><br />
  1757. <input type="submit" value="'. _gettext('Search') .'" /><br /><br />
  1758. <h1>'. _gettext('Search Help') .'</h1>
  1759. '. _gettext('Separate search terms with the word <strong>KUSABA_AND</strong>') .' <br /><br />
  1760. '. _gettext('To find a single phrase anywhere in a post\'s message, use:') .'<br />
  1761. %'. _gettext('some phrase here') .'%<br /><br />
  1762. '. _gettext('To find a phrase at the beginning of a post\'s message:') .'<br />
  1763. '. _gettext('some phrase here') .'%<br /><br />
  1764. '. _gettext('To find a phrase at the end of a post\'s message:') .'<br />
  1765. %'. _gettext('some phrase here') .'<br /><br />
  1766. '. _gettext('To find two phrases anywhere in a post\'s message, use:') .'<br />
  1767. %'. _gettext('first phrase here') .'%KUSABA_AND%'. _gettext('second phrase here') .'%<br /><br />
  1768. </form>';
  1769. }
  1770. function search_callback($matches) {
  1771. print_r($matches);
  1772. return '<strong>'. $matches[0] . '</strong>';
  1773. }
  1774. function search_results_display($a, $b, $numrows) {
  1775. return '<p>'. _gettext('Results') . ' <strong>'. $b . '</strong> to <strong>'. $a . '</strong> of <strong>'. $numrows . '</strong></p>'. "\n" .
  1776. '<hr />';
  1777. }
  1778. // Credits to Eman for this code
  1779. function viewthread() {
  1780. global $tc_db, $tpl_page;
  1781. $tpl_page .= '<h2>'. _gettext('View Threads (including deleted)') .'</h2>';
  1782. $board = isset($_GET['board']) ? $_GET['board'] : '';
  1783. $thread = isset($_GET['thread']) ? $_GET['thread'] : '';
  1784. if (!$thread ) {
  1785. $thread = "0";
  1786. }
  1787. if (!$board) {
  1788. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `name`, `id` FROM `". KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  1789. $tpl_page .= "
  1790. <style type=\"text/css\">
  1791. input {
  1792. display: inline !important;
  1793. width: auto !important;
  1794. float: none !important;
  1795. margin-bottom: 0px !important;
  1796. }
  1797. th,td {
  1798. font-size: 14px !important;
  1799. }
  1800. </style>";
  1801. $tpl_page .= '<form method="get" action=""><input type="hidden" name="action" value="viewthread" />'. _gettext('Select Board') .': <select name="board">';
  1802. foreach ($results as $line) {
  1803. $name = $line['name'];
  1804. $id = $line['id'];
  1805. $tpl_page .= "<option value=\"$name\">/$name/</option>";
  1806. }
  1807. $tpl_page .= '</select>&nbsp;<input type=submit value="'. _gettext('Go') .'" />';
  1808. } else {
  1809. $board_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `". KU_DBPREFIX . "boards` WHERE `name` = ".$tc_db->qstr($board));
  1810. $tpl_page .= "
  1811. <style type=\"text/css\">
  1812. input {
  1813. display: inline !important;
  1814. width: auto !important;
  1815. float: none !important;
  1816. margin-bottom: 0px !important;
  1817. }
  1818. th,td {
  1819. font-size: 14px !important;
  1820. }
  1821. </style>
  1822. <form method=\"get\" action=\"\">
  1823. <input type=\"hidden\" name=\"action\" value=\"viewthread\" />
  1824. <input type=\"hidden\" name=\"board\" value=\"$board\" />";
  1825. if ($thread == "0" ) {
  1826. $tpl_page .= "<h2>". sprintf(_gettext('All threads on /%s/'), $board) ."</h2>";
  1827. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = $board_id AND (`id` = ".$tc_db->qstr($thread)." OR `parentid` = ".$tc_db->qstr($thread).") ORDER BY `id` DESC LIMIT 500");
  1828. } else {
  1829. $tpl_page .= "<h2>". sprintf(_gettext('Thread %s on /%s/'), $thread, $board) ."</h2>";
  1830. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = $board_id AND (`id` = ".$tc_db->qstr($thread)." OR `parentid` = ".$tc_db->qstr($thread).") ORDER BY `id` ASC");
  1831. }
  1832. $time = round(microtime(), 5);
  1833. $first = "1";
  1834. foreach ($results as $line) {
  1835. $bans = "";
  1836. $id = $line['id'];
  1837. $ip = md5_decrypt($line['ip'], KU_RANDOMSEED);
  1838. $filename = $line['file'];
  1839. $file_original = $line['file_original'];
  1840. $filetype = $line['file_type'];
  1841. $filesize_formatted = $line['file_size_formatted'];
  1842. $image_w = $line['image_w'];
  1843. $image_h = $line['image_h'];
  1844. $message = $line['message'];
  1845. $name = $line['name'];
  1846. $tripcode = $line['tripcode'];
  1847. $timestamp = date(r, $line['timestamp']);
  1848. $subject = $line['subject'];
  1849. $posterauthority = $line['posterauthority'];
  1850. $deleted = isset($line['IS_DELETED']) ? $line['IS_DELETED'] : $line['is_deleted'] ;
  1851. if ($thread == "0") {
  1852. $view = "<a href=\"?action=viewthread&board=$board&thread=$id\">[". _gettext('View') ."]</a>";
  1853. } else {
  1854. $view = "";
  1855. }
  1856. if ($name == "") {
  1857. $name = _gettext('Anonymous');
  1858. } else {
  1859. $name = "<font color=\"blue\">$name</font>";
  1860. }
  1861. if ($tripcode != "") {
  1862. $tripcode = "<font color=\"green\">!$tripcode</font>";
  1863. }
  1864. if ($subject != "") {
  1865. $subject = "<font color=\"red\">$subject</font> - ";
  1866. }
  1867. if ($posterauthority == "1") {
  1868. $posterauthority = "<font color=\"purple\"><strong>##Admin##</strong></font>";
  1869. } elseif ($posterauthority == "2") {
  1870. $posterauthority = "<font color=\"red\"><strong>##Mod##</strong></font>";
  1871. } else {
  1872. $posterauthority = "";
  1873. }
  1874. if ($deleted == "1") {
  1875. $deleted = "<font color=green><blink><strong>". _gettext('DELETED') ."</strong></blink></font> - ";
  1876. } else {
  1877. $deleted = "";
  1878. if ($first == "1") {
  1879. $bans = "</td><td width=80px style=\"text-align: right; vertical-align: top;\">[<a href=\"manage_page.php?action=&boarddir=$board&delthreadid=$id\">D</a> <a href=\"manage_page.php?action=delposts&boarddir=$board&delthreadid=$id&postid=$id\">&amp;</a> <a href=\"manage_page.php?action=bans&banboard=$board&banpost=$id\">B</a>]";
  1880. } else {
  1881. $bans = "</td><td width=80px style=\"text-align: right; vertical-align: top;\">[<a href=\"manage_page.php?action=delposts&boarddir=$board&delpostid=$id\">D</a> <a href=\"manage_page.php?action=delposts&boarddir=$board&delpostid=$id&postid=$id\">&amp;</a> <a href=\"manage_page.php?action=bans&banboard=$board&banpost=$id\">B</a>]";
  1882. }
  1883. }
  1884. if ($bans == "") {
  1885. $bans = "</td><td>&nbsp;</td>";
  1886. }
  1887. $tpl_page .= "
  1888. <table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
  1889. <tbody>
  1890. <tr>
  1891. <td style=\"vertical-align: top;\">$deleted$subject$name$tripcode $posterauthority $timestamp ". _gettext('No.') ." $id ". _gettext('IP') .": $ip $view $bans
  1892. </td>
  1893. </tr>
  1894. ";
  1895. if ($filename != "") {
  1896. $tpl_page .= "
  1897. <tr>
  1898. <td colspan=\"2\" style=\"vertical-align: top;\">". _gettext('File') .": <a href=\"". KU_WEBPATH ."/$board/src/$filename.$filetype\" target=_new>$filename.$filetype</a> -( $filesize_formatted, {$image_w}x{$image_h}, $file_original.$filetype )</td>
  1899. </tr>
  1900. ";
  1901. }
  1902. $tpl_page .= "
  1903. </tbody></table>
  1904. <table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
  1905. <tbody>
  1906. <tr>";
  1907. if ($filename != "") {
  1908. $tpl_page .= "
  1909. <td style=\"vertical-align: top; width: 200px;\"><center><a href=\"". KU_WEBPATH ."/$board/src/$filename.$filetype\" target=\"_new\"><img src=\"". KU_WEBPATH ."/$board/thumb/{$filename}s.$filetype\" border=\"0\"></a></center></td>
  1910. ";
  1911. }
  1912. if ($message == "") {
  1913. $message = "&nbsp;";
  1914. }
  1915. $tpl_page .= "<td style=\"vertical-align: top; height: 100%;\">$message</td></tr></tbody></table><br />";
  1916. $first = "0";
  1917. }
  1918. $time2 = round(microtime(), 5);
  1919. $generation = $time2 - $time;
  1920. $generation = abs($generation);
  1921. $tpl_page .= '
  1922. '. _gettext('Render Time') .':'. $generation .' '._gettext('Seconds').'
  1923. <!--<h2>'. _gettext('Ban') .'</h2>
  1924. '. _gettext('Reason') .': <input type="text" name="banreason" value="'. _gettext('You Are Banned') .'" />&nbsp;&nbsp;
  1925. '. _gettext('Duration') .': <input type="text" name="banduration" value="0" />&nbsp;&nbsp;
  1926. '. _gettext('Appeal') .': <input type="text" name="banappeal" value="0" />&nbsp;&nbsp;
  1927. <input type="submit" value="'. _gettext('Submit') .'" />-->
  1928. </form>';
  1929. }
  1930. }
  1931. /* View a thread marked as deleted */
  1932. function viewdeletedthread() {
  1933. global $tc_db, $tpl_page;
  1934. $this->AdministratorsOnly();
  1935. $tpl_page .= '<h2>'. _gettext('View deleted thread') . '</h2><br />'. "\n";
  1936. if (isset($_GET['board']) && isset($_GET['threadid']) && $_GET['threadid'] > 0) {
  1937. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "");
  1938. foreach ($results as $line) {
  1939. $board_id = $line['id'];
  1940. $board_dir = $line['name'];
  1941. }
  1942. if (count($results) > 0) {
  1943. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts_" . $board_dir . "` WHERE `id` = " . $tc_db->qstr($_GET['threadid']) . "");
  1944. foreach ($results as $line) {
  1945. $thread_isdeleted = $line['IS_DELETED'];
  1946. $thread_parentid = $line['parentid'];
  1947. }
  1948. if ($thread_isdeleted == 1 && $thread_parentid == 0) {
  1949. foreach ($results as $line) {
  1950. if ($line['name'] != '') {
  1951. $name = $line['name'];
  1952. } else {
  1953. $name = _gettext('Anonymous') .' ';
  1954. }
  1955. $tpl_page .= '<div style="width: 75%; border: 1px solid #CCC; padding: 5px;">'. "\n";
  1956. $tpl_page .= $name . $line['tripcode'] . formatDate($line['postedat']) . ' | '. _gettext('No.') .' '. $line['id'] . ' | '. _gettext('IP') .': '. md5_decrypt($line['ip'], KU_RANDOMSEED) . '<br />'. "\n";
  1957. if (isset($line['filename'])) {
  1958. $tpl_page .= '<a href="'. KU_WEBPATH . '/'. $_GET['board'] . '/src/'. $line['filename'] . '.'. $line['filetype'] . '" target="_blank">'. $line['filename'] . '.'. $line['filetype'] . '</a><br />'. "\n" .
  1959. '<a href="'. KU_WEBPATH . '/'. $_GET['board'] . '/src/'. $line['filename'] . '.'. $line['filetype'] . '" target="_blank"><img src="'. KU_WEBPATH . '/'. $_GET['board'] . '/thumb/'. $line['filename'] . 's.'. $line['filetype'] . '" border="0" alt="'. $line['filename'] . '.'. $line['filetype'] . '" /></a>'. "\n";
  1960. }
  1961. $tpl_page .= $line['message'];
  1962. $tpl_page .= '</div><br />';
  1963. }
  1964. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts_" . $board_dir . "` WHERE `parentid` = " . $tc_db->qstr($_GET['threadid']) . "");
  1965. foreach ($results as $line) {
  1966. if ($line['name'] != '') {
  1967. $name = $line['name'] . ' ';
  1968. } else {
  1969. $name = _gettext('Anonymous') .' ';
  1970. }
  1971. $tpl_page .= '<div style="width: 75%; border: 1px solid #CCC; padding: 5px;">'. "\n";
  1972. $tpl_page .= $name . $line['tripcode'] . formatDate($line['postedat']) . ' | No. '. $line['id'] . ' | IP: '. md5_decrypt($line['ip'], KU_RANDOMSEED) . '<br />'. "\n";
  1973. if ($line['filename'] != '') {
  1974. $tpl_page .= '<a href="'. KU_WEBPATH . '/'. $_GET['board'] . '/src/'. $line['filename'] . '.'. $line['filetype'] . '" target="_blank">'. $line['filename'] . '.'. $line['filetype'] . '</a><br />'. "\n" .
  1975. '<a href="'. KU_WEBPATH . '/'. $_GET['board'] . '/src/'. $line['filename'] . '.'. $line['filetype'] . '" target="_blank"><img src="'. KU_WEBPATH . '/'. $_GET['board'] . '/thumb/'. $line['filename'] . 's.'. $line['filetype'] . '" border="0" alt="'. $line['filename'] . '.'. $line['filetype'] . '" /></a>'. "\n";
  1976. }
  1977. $tpl_page .= $line['message'];
  1978. $tpl_page .= '</div><br />';
  1979. }
  1980. } else {
  1981. $tpl_page .= _gettext('That\'s either not a thread, or it\'s not deleted.') ;
  1982. }
  1983. }
  1984. } else {
  1985. $tpl_page .= '<form method="get" action="?">'. "\n" .
  1986. '<input type="hidden" name="action" value="viewthread" />'. "\n" .
  1987. '<label for="board">'. _gettext('Board') . ':</label>'. "\n" .
  1988. $this->MakeBoardListDropdown('board', $this->BoardList($_SESSION['manageusername'])) . "\n" .
  1989. '<br />'. "\n" .
  1990. '<label for="threadid">'. _gettext('Thread') . ':</label>'. "\n" .
  1991. '<input type="text" name="threadid" /><br />'. "\n" .
  1992. '<input type="submit" value="'. _gettext('View deleted thread') . '" />'. "\n" .
  1993. '</form>';
  1994. }
  1995. }
  1996. /* Add, view, and delete filetypes */
  1997. function editfiletypes() {
  1998. global $tc_db, $tpl_page;
  1999. $this->AdministratorsOnly();
  2000. $tpl_page .= '<h2>'. _gettext('Edit filetypes') . '</h2><br />';
  2001. if (isset($_GET['do'])) {
  2002. if ($_GET['do'] == 'addfiletype') {
  2003. if (isset($_POST['filetype']) || isset($_POST['image'])) {
  2004. $this->CheckToken($_POST['token']);
  2005. if ($_POST['filetype'] != '' && $_POST['image'] != '') {
  2006. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "filetypes` ( `filetype` , `mime` , `image` , `image_w` , `image_h` ) VALUES ( " . $tc_db->qstr($_POST['filetype']) . " , " . $tc_db->qstr($_POST['mime']) . " , " . $tc_db->qstr($_POST['image']) . " , " . $tc_db->qstr($_POST['image_w']) . " , " . $tc_db->qstr($_POST['image_h']) . " )");
  2007. $tpl_page .= _gettext('Filetype added.');
  2008. }
  2009. } else {
  2010. $tpl_page .= '<form action="?action=editfiletypes&do=addfiletype" method="post">
  2011. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2012. <label for="filetype">'. _gettext('Filetype') .':</label>
  2013. <input type="text" name="filetype" />
  2014. <div class="desc">'. _gettext('The extension this will be applied to. <strong>Must be lowercase</strong>') .'</div><br />
  2015. <label for="mime">'. _gettext('MIME type') .':</label>
  2016. <input type="text" name="mime" />
  2017. <div class="desc">'. _gettext('The MIME type which must be present with an image uploaded in this type. Leave blank to disable.') .'</div><br />
  2018. <label for="image">Image:</label>
  2019. <input type="text" name="image" value="generic.png" />
  2020. <div class="desc">'. _gettext('The image which will be used, found in inc/filetypes.') .'</div><br />
  2021. <label for="image_w">'. _gettext('Image width') .':</label>
  2022. <input type="text" name="image_w" value="48" />
  2023. <div class="desc">'. _gettext('The width of the image. Needs to be set to prevent the page from jumping around while images load.') .'</div><br />
  2024. <label for="image_h">'. _gettext('Image height') .':</label>
  2025. <input type="text" name="image_h" value="48" />
  2026. <div class="desc">'. _gettext('The height of the image. Needs to be set to prevent the page from jumping around while images load.') .'.</div><br />
  2027. <input type="submit" value="'. _gettext('Add') .'" />
  2028. </form>';
  2029. }
  2030. $tpl_page .= '<br /><hr />';
  2031. }
  2032. if ($_GET['do'] == 'editfiletype' && $_GET['filetypeid'] > 0) {
  2033. if (isset($_POST['filetype'])) {
  2034. if ($_POST['filetype'] != '' && $_POST['image'] != '') {
  2035. $this->CheckToken($_POST['token']);
  2036. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "filetypes` SET `filetype` = " . $tc_db->qstr($_POST['filetype']) . " , `mime` = " . $tc_db->qstr($_POST['mime']) . " , `image` = " . $tc_db->qstr($_POST['image']) . " , `image_w` = " . $tc_db->qstr($_POST['image_w']) . " , `image_h` = " . $tc_db->qstr($_POST['image_h']) . " WHERE `id` = " . $tc_db->qstr($_GET['filetypeid']) . "");
  2037. if (KU_APC) {
  2038. apc_delete('filetype|'. $_POST['filetype']);
  2039. }
  2040. $tpl_page .= _gettext('Filetype updated.');
  2041. }
  2042. } else {
  2043. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "filetypes` WHERE `id` = " . $tc_db->qstr($_GET['filetypeid']) . "");
  2044. if (count($results) > 0) {
  2045. foreach ($results as $line) {
  2046. $tpl_page .= '<form action="?action=editfiletypes&do=editfiletype&filetypeid='. $_GET['filetypeid'] . '" method="post">
  2047. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2048. <label for="filetype">'. _gettext('Filetype') .':</label>
  2049. <input type="text" name="filetype" value="'. $line['filetype'] . '" />
  2050. <div class="desc">'. _gettext('The extension this will be applied to. <strong>Must be lowercase</strong>') .'</div><br />
  2051. <label for="mime">'. _gettext('MIME type') .':</label>
  2052. <input type="text" name="mime" value="'. $line['mime'] . '" />
  2053. <div class="desc">'. _gettext('The MIME type which must be present with an image uploaded in this type. Leave blank to disable.') .'</div><br />
  2054. <label for="image">'. _gettext('Image') .':</label>
  2055. <input type="text" name="image" value="'. $line['image'] . '" />
  2056. <div class="desc">'. _gettext('The image which will be used, found in inc/filetypes.') .'</div><br />
  2057. <label for="image_w">'. _gettext('Image width') .':</label>
  2058. <input type="text" name="image_w" value="'. $line['image_w'] . '" />
  2059. <div class="desc">'. _gettext('The width of the image. Needs to be set to prevent the page from jumping around while images load.') .'</div><br />
  2060. <label for="image_h">'. _gettext('Image height') .':</label>
  2061. <input type="text" name="image_h" value="'. $line['image_h'] . '" />
  2062. <div class="desc">'. _gettext('The height of the image. Needs to be set to prevent the page from jumping around while images load.') .'.</div><br />
  2063. <input type="submit" value="'. _gettext('Edit') .'" />
  2064. </form>';
  2065. }
  2066. } else {
  2067. $tpl_page .= _gettext('Unable to locate a filetype with that ID.');
  2068. }
  2069. }
  2070. $tpl_page .= '<br /><hr />';
  2071. }
  2072. if ($_GET['do'] == 'deletefiletype' && $_GET['filetypeid'] > 0) {
  2073. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "filetypes` WHERE `id` = " . $tc_db->qstr($_GET['filetypeid']) . "");
  2074. $tpl_page .= _gettext('Filetype deleted.');
  2075. $tpl_page .= '<br /><hr />';
  2076. }
  2077. }
  2078. $tpl_page .= '<a href="?action=editfiletypes&do=addfiletype">'. _gettext('Add filetype') .'</a><br /><br />';
  2079. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "filetypes` ORDER BY `filetype` ASC");
  2080. if (count($results) > 0) {
  2081. $tpl_page .= '<table border="1" width="100%"><tr><th>'. _gettext('ID') .'</th><th>'. _gettext('Filetype') .'</th><th>'. _gettext('Image') .'</th><th>'. _gettext('Edit/Delete') .'</th></tr>';
  2082. foreach ($results as $line) {
  2083. $tpl_page .= '<tr><td>'. $line['id'] . '</td><td>'. $line['filetype'] . '</td><td>'. $line['image'] . '</td><td>[<a href="?action=editfiletypes&do=editfiletype&filetypeid='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=editfiletypes&do=deletefiletype&filetypeid='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  2084. }
  2085. $tpl_page .= '</table>';
  2086. } else {
  2087. $tpl_page .= _gettext('There are currently no filetypes.');
  2088. }
  2089. }
  2090. /* Add, view, and delete sections */
  2091. function editsections() {
  2092. global $tc_db, $tpl_page;
  2093. $this->AdministratorsOnly();
  2094. $tpl_page .= '<h2>'. _gettext('Edit sections') . '</h2><br />';
  2095. if (isset($_GET['do'])) {
  2096. if ($_GET['do'] == 'addsection') {
  2097. if (isset($_POST['name'])) {
  2098. if ($_POST['name'] != '' && $_POST['abbreviation'] != '') {
  2099. $this->CheckToken($_POST['token']);
  2100. $tc_db->Execute("INSERT HIGH_PRIORITY INTO `" . KU_DBPREFIX . "sections` ( `name` , `abbreviation` , `order` , `hidden` ) VALUES ( " . $tc_db->qstr($_POST['name']) . " , " . $tc_db->qstr($_POST['abbreviation']) . " , " . $tc_db->qstr($_POST['order']) . " , '" . (isset($_POST['hidden']) ? '1' : '0') . "' )");
  2101. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  2102. $menu_class = new Menu();
  2103. $menu_class->Generate();
  2104. $tpl_page .= _gettext('Section added.');
  2105. }
  2106. } else {
  2107. $tpl_page .= '<form action="?action=editsections&do=addsection" method="post">
  2108. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2109. <label for="name">'. _gettext('Name') .':</label><input type="text" name="name" /><div class="desc">'. _gettext('The name of the section') .'</div><br />
  2110. <label for="abbreviation">'. _gettext('Abbreviation') .':</label><input type="text" name="abbreviation" /><div class="desc">'. _gettext('Abbreviation (less then 10 characters)') .'</div><br />
  2111. <label for="order">'. _gettext('Order') .':</label><input type="text" name="order" /><div class="desc">'. _gettext('Order to show this section with others, in ascending order') .'</div><br />
  2112. <label for="hidden">'. _gettext('Hidden') .':</label><input type="checkbox" name="hidden" /><div class="desc">'. _gettext('If checked, this section will be collapsed by default when a user visits the site.') .'</div><br />
  2113. <input type="submit" value="'. _gettext('Add') .'" />
  2114. </form>';
  2115. }
  2116. $tpl_page .= '<br /><hr />';
  2117. }
  2118. if ($_GET['do'] == 'editsection' && $_GET['sectionid'] > 0) {
  2119. if (isset($_POST['name'])) {
  2120. if ($_POST['name'] != '' && $_POST['abbreviation'] != '') {
  2121. $this->CheckToken($_POST['token']);
  2122. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "sections` SET `name` = " . $tc_db->qstr($_POST['name']) . " , `abbreviation` = " . $tc_db->qstr($_POST['abbreviation']) . " , `order` = " . $tc_db->qstr($_POST['order']) . " , `hidden` = '" . (isset($_POST['hidden']) ? '1' : '0') . "' WHERE `id` = '" . $_GET['sectionid'] . "'");
  2123. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  2124. $menu_class = new Menu();
  2125. $menu_class->Generate();
  2126. $tpl_page .= _gettext('Section updated.');
  2127. }
  2128. } else {
  2129. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "sections` WHERE `id` = " . $tc_db->qstr($_GET['sectionid']) . "");
  2130. if (count($results) > 0) {
  2131. foreach ($results as $line) {
  2132. $tpl_page .= '<form action="?action=editsections&do=editsection&sectionid='. $_GET['sectionid'] . '" method="post">
  2133. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2134. <input type="hidden" name="id" value="'. $_GET['sectionid'] . '" />
  2135. <label for="name">'. _gettext('Name') .':</label>
  2136. <input type="text" name="name" value="'. $line['name'] . '" />
  2137. <div class="desc">'. _gettext('The name of the section') .'</div><br />
  2138. <label for="abbreviation">'. _gettext('Abbreviation') .':</label>
  2139. <input type="text" name="abbreviation" value="'. $line['abbreviation'] . '" />
  2140. <div class="desc">'. _gettext('Abbreviation (less then 10 characters)') .'</div><br />
  2141. <label for="order">'. _gettext('Order') .':</label>
  2142. <input type="text" name="order" value="'. $line['order'] . '" />
  2143. <div class="desc">'. _gettext('Order to show this section with others, in ascending order') .'</div><br />
  2144. <label for="hidden">'. _gettext('Hidden') .':</label>
  2145. <input type="checkbox" name="hidden" '. ($line['hidden'] == 0 ? '' : 'checked') . ' />
  2146. <div class="desc">'. _gettext('If checked, this section will be collapsed by default when a user visits the site.') .'</div><br />
  2147. <input type="submit" value="'. _gettext('Edit') .'" />
  2148. </form>';
  2149. }
  2150. } else {
  2151. $tpl_page .= _gettext('Unable to locate a section with that ID.');
  2152. }
  2153. }
  2154. $tpl_page .= '<br /><hr />';
  2155. }
  2156. if ($_GET['do'] == 'deletesection' && isset($_GET['sectionid'])) {
  2157. if ($_GET['sectionid'] > 0) {
  2158. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "sections` WHERE `id` = " . $tc_db->qstr($_GET['sectionid']) . "");
  2159. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  2160. $menu_class = new Menu();
  2161. $menu_class->Generate();
  2162. $tpl_page .= _gettext('Section deleted.') . '<br /><hr />';
  2163. }
  2164. }
  2165. }
  2166. $tpl_page .= '<a href="?action=editsections&do=addsection">'. _gettext('Add section') .'</a><br /><br />';
  2167. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "sections` ORDER BY `order` ASC");
  2168. if (count($results) > 0) {
  2169. $tpl_page .= '<table border="1" width="100%"><tr><th>'.('ID') .'</th><th>'.('Order') .'</th><th>'. _gettext('Abbreviation') .'</th><th>'. _gettext('Name') .'</th><th>'. _gettext('Edit/Delete') .'</th></tr>';
  2170. foreach ($results as $line) {
  2171. $tpl_page .= '<tr><td>'. $line['id'] . '</td><td>'. $line['order'] . '</td><td>'. $line['abbreviation'] . '</td><td>'. $line['name'] . '</td><td>[<a href="?action=editsections&do=editsection&sectionid='. $line['id'] . '">'. _gettext('Edit') .'</a>] [<a href="?action=editsections&do=deletesection&sectionid='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  2172. }
  2173. $tpl_page .= '</table>';
  2174. } else {
  2175. $tpl_page .= _gettext('There are currently no sections.');
  2176. }
  2177. }
  2178. /* Rebuild all boards */
  2179. function rebuildall() {
  2180. global $tc_db, $tpl_page;
  2181. $this->AdministratorsOnly();
  2182. $tpl_page .= '<h2>'. _gettext('Rebuild all HTML files') . '</h2><br />';
  2183. $time_start = time();
  2184. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards`");
  2185. foreach ($results as $line) {
  2186. $board_class = new Board($line['name']);
  2187. $board_class->RegenerateAll();
  2188. $tpl_page .= sprintf(_gettext('Regenerated %s'), '/'. $line['name'] . '/') . '<br />';
  2189. unset($board_class);
  2190. flush();
  2191. }
  2192. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  2193. $menu_class = new Menu();
  2194. $menu_class->Generate();
  2195. $tpl_page .= _gettext('Regenerated menu pages') .'<br />';
  2196. $tpl_page .= sprintf(_gettext('Great Success! It only took <strong>%d</strong> seconds to rebuild.'), time() - $time_start);
  2197. management_addlogentry(_gettext('Rebuilt all boards and threads'), 2);
  2198. unset($board_class);
  2199. }
  2200. /*
  2201. * +------------------------------------------------------------------------------+
  2202. * Boards Pages
  2203. * +------------------------------------------------------------------------------+
  2204. */
  2205. function boardopts() {
  2206. global $tc_db, $tpl_page;
  2207. $this->AdministratorsOnly();
  2208. $tpl_page .= '<h2>'. _gettext('Board options') . '</h2><br />';
  2209. if (isset($_GET['updateboard']) && isset($_POST['order']) && isset($_POST['maxpages']) && isset($_POST['maxage']) && isset($_POST['messagelength'])) {
  2210. $this->CheckToken($_POST['token']);
  2211. if (!$this->CurrentUserIsModeratorOfBoard($_GET['updateboard'], $_SESSION['manageusername'])) {
  2212. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2213. }
  2214. $boardid = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['updateboard']) . " LIMIT 1");
  2215. if ($boardid != '') {
  2216. if ($_POST['order'] >= 0 && $_POST['maxpages'] >= 0 && $_POST['markpage'] >= 0 && $_POST['maxage'] >= 0 && $_POST['messagelength'] >= 0 && ($_POST['defaultstyle'] == '' || in_array($_POST['defaultstyle'], explode(':', KU_STYLES)) || in_array($_POST['defaultstyle'], explode(':', KU_TXTSTYLES)))) {
  2217. $filetypes = array();
  2218. while (list($postkey, $postvalue) = each($_POST)) {
  2219. if (substr($postkey, 0, 9) == 'filetype_') {
  2220. $filetypes[] = substr($postkey, 9);
  2221. }
  2222. }
  2223. $updateboard_enablecatalog = isset($_POST['enablecatalog']) ? '1' : '0';
  2224. $updateboard_enablenofile = isset($_POST['enablenofile']) ? '1' : '0';
  2225. $updateboard_redirecttothread = isset($_POST['redirecttothread']) ? '1' : '0';
  2226. $updateboard_enablereporting = isset($_POST['enablereporting']) ? '1' : '0';
  2227. $updateboard_enablecaptcha = isset($_POST['enablecaptcha']) ? '1' : '0';
  2228. $updateboard_forcedanon = isset($_POST['forcedanon']) ? '1' : '0';
  2229. $updateboard_trial = isset($_POST['trial']) ? '1' : '0';
  2230. $updateboard_popular = isset($_POST['popular']) ? '1' : '0';
  2231. $updateboard_enablearchiving = isset($_POST['enablearchiving']) ? '1' : '0';
  2232. $updateboard_showid = isset($_POST['showid']) ? '1' : '0';
  2233. $updateboard_compactlist = isset($_POST['compactlist']) ? '1' : '0';
  2234. $updateboard_locked = isset($_POST['locked']) ? '1' : '0';
  2235. if (($_POST['type'] == '0' || $_POST['type'] == '1' || $_POST['type'] == '2' || $_POST['type'] == '3') && ($_POST['uploadtype'] == '0' || $_POST['uploadtype'] == '1' || $_POST['uploadtype'] == '2')) {
  2236. if (!($_POST['uploadtype'] != '0' && $_POST['type'] == '3')) {
  2237. if(count($_POST['allowedembeds']) > 0) {
  2238. $updateboard_allowedembeds = '';
  2239. $results = $tc_db->GetAll("SELECT `filetype` FROM `" . KU_DBPREFIX . "embeds`");
  2240. foreach ($results as $line) {
  2241. if(in_array($line['filetype'], $_POST['allowedembeds'])) {
  2242. $updateboard_allowedembeds .= $line['filetype'].',';
  2243. }
  2244. }
  2245. if ($updateboard_allowedembeds != '') {
  2246. $updateboard_allowedembeds = substr($updateboard_allowedembeds, 0, -1);
  2247. }
  2248. }
  2249. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "boards` SET `type` = " . $tc_db->qstr($_POST['type']) . " , `uploadtype` = " . $tc_db->qstr($_POST['uploadtype']) . " , `order` = " . $tc_db->qstr(intval($_POST['order'])) . " , `section` = " . $tc_db->qstr(intval($_POST['section'])) . " , `desc` = " . $tc_db->qstr($_POST['desc']) . " , `locale` = " . $tc_db->qstr($_POST['locale']) . " , `showid` = '" . $updateboard_showid . "' , `compactlist` = '" . $updateboard_compactlist . "' , `locked` = '" . $updateboard_locked . "' , `maximagesize` = " . $tc_db->qstr($_POST['maximagesize']) . " , `messagelength` = " . $tc_db->qstr($_POST['messagelength']) . " , `maxpages` = " . $tc_db->qstr($_POST['maxpages']) . " , `maxage` = " . $tc_db->qstr($_POST['maxage']) . " , `markpage` = " . $tc_db->qstr($_POST['markpage']) . " , `maxreplies` = " . $tc_db->qstr($_POST['maxreplies']) . " , `image` = " . $tc_db->qstr($_POST['image']) . " , `includeheader` = " . $tc_db->qstr($_POST['includeheader']) . " , `redirecttothread` = '" . $updateboard_redirecttothread . "' , `anonymous` = " . $tc_db->qstr($_POST['anonymous']) . " , `forcedanon` = '" . $updateboard_forcedanon . "' , `embeds_allowed` = " . $tc_db->qstr($updateboard_allowedembeds) . " , `trial` = '" . $updateboard_trial . "' , `popular` = '" . $updateboard_popular . "' , `defaultstyle` = " . $tc_db->qstr($_POST['defaultstyle']) . " , `enablereporting` = '" . $updateboard_enablereporting . "', `enablecaptcha` = '" . $updateboard_enablecaptcha . "' , `enablenofile` = '" . $updateboard_enablenofile . "' , `enablearchiving` = '" . $updateboard_enablearchiving . "', `enablecatalog` = '" . $updateboard_enablecatalog . "' , `loadbalanceurl` = " . $tc_db->qstr($_POST['loadbalanceurl']) . " , `loadbalancepassword` = " . $tc_db->qstr($_POST['loadbalancepassword']) . " WHERE `name` = " . $tc_db->qstr($_GET['updateboard']) . "");
  2250. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "board_filetypes` WHERE `boardid` = '" . $boardid . "'");
  2251. foreach ($filetypes as $filetype) {
  2252. $tc_db->Execute("INSERT INTO `" . KU_DBPREFIX . "board_filetypes` ( `boardid`, `typeid` ) VALUES ( '" . $boardid . "', " . $tc_db->qstr($filetype) . " )");
  2253. }
  2254. require_once KU_ROOTDIR . 'inc/classes/menu.class.php';
  2255. $menu_class = new Menu();
  2256. $menu_class->Generate();
  2257. if (isset($_POST['submit_regenerate'])) {
  2258. $board_class = new Board($_GET['updateboard']);
  2259. $board_class->RegenerateAll();
  2260. }
  2261. $tpl_page .= _gettext('Update successful.');
  2262. management_addlogentry(_gettext('Updated board configuration') . " - /" . $_GET['updateboard'] . "/", 4);
  2263. } else {
  2264. $tpl_page .= _gettext('Sorry, embed may only be enabled on normal imageboards.');
  2265. }
  2266. } else {
  2267. $tpl_page .= _gettext('Sorry, a generic error has occurred.');
  2268. }
  2269. } else {
  2270. $tpl_page .= _gettext('Integer values must be entered correctly.');
  2271. }
  2272. } else {
  2273. $tpl_page .= _gettext('Unable to locate a board named') . ' <strong>'. $_GET['updateboard'] . '</strong>.';
  2274. }
  2275. } elseif (isset($_POST['board'])) {
  2276. if (!$this->CurrentUserIsModeratorOfBoard($_POST['board'], $_SESSION['manageusername'])) {
  2277. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2278. }
  2279. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_POST['board']) . "");
  2280. if (count($resultsboard) > 0) {
  2281. foreach ($resultsboard as $lineboard) {
  2282. $tpl_page .= '<div class="container">
  2283. <form action="?action=boardopts&updateboard='.urlencode($_POST['board']).'" method="post">
  2284. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />';
  2285. /* Directory */
  2286. $tpl_page .= '<label for="board">'. _gettext('Directory') .':</label>
  2287. <input type="text" name="board" value="'.$_POST['board'].'" disabled />
  2288. <div class="desc">'. _gettext('The directory of the board.') .'</div><br />';
  2289. /* Description */
  2290. $tpl_page .= '<label for="desc">'. _gettext('Description') .':</label>
  2291. <input type="text" name="desc" value="'.$lineboard['desc'].'" />
  2292. <div class="desc">'. _gettext('The name of the board.') .'</div><br />';
  2293. /* Locale */
  2294. $tpl_page .= '<label for="locale">'. _gettext('Locale') .':</label>
  2295. <input type="text" name="locale" value="'.$lineboard['locale'].'" />
  2296. <div class="desc">'. _gettext('Locale to use on this board. Leave blank to use the locale defined in config.php') .'</div><br />';
  2297. /* Board type */
  2298. $tpl_page .= '<label for="type">'. _gettext('Board type') .':</label>
  2299. <select name="type">
  2300. <option value="0"';
  2301. if ($lineboard['type'] == '0') { $tpl_page .= ' selected="selected"'; }
  2302. $tpl_page .= '>'. _gettext('Normal imageboard') .'</option>
  2303. <option value="1"';
  2304. if ($lineboard['type'] == '1') { $tpl_page .= ' selected="selected"'; }
  2305. $tpl_page .= '>'. _gettext('Text board') .'</option><option value="2"';
  2306. if ($lineboard['type'] == '2') { $tpl_page .= ' selected="selected"'; }
  2307. $tpl_page .= '>'. _gettext('Oekaki imageboard') .'</option><option value="3"';
  2308. if ($lineboard['type'] == '3') { $tpl_page .= ' selected="selected"'; }
  2309. $tpl_page .= '>'. _gettext('Upload imageboard') .'</option>
  2310. </select>
  2311. <div class="desc">'. _gettext('The type of posts which will be accepted on this board. A normal imageboard will feature image and extended format posts, a text board will have no images, an Oekaki board will allow users to draw images and use them in their posts, and an Upload imageboard will be styled more towards file uploads.') .' '. _gettext('Default') .': <strong>Normal Imageboard</strong></div><br />';
  2312. /* Upload type */
  2313. $tpl_page .= '<label for="uploadtype">'. _gettext('Upload type') .':</label>
  2314. <select name="uploadtype">
  2315. <option value="0"';
  2316. if ($lineboard['uploadtype'] == '0') {
  2317. $tpl_page .= ' selected="selected"';
  2318. }
  2319. $tpl_page .= '>'. _gettext('No embedding') .'</option>
  2320. <option value="1"';
  2321. if ($lineboard['uploadtype'] == '1') {
  2322. $tpl_page .= ' selected="selected"';
  2323. }
  2324. $tpl_page .= '>'. _gettext('Images and embedding') .'</option>
  2325. <option value="2"';
  2326. if ($lineboard['uploadtype'] == '2') {
  2327. $tpl_page .= ' selected="selected"';
  2328. }
  2329. $tpl_page .= '>'. _gettext('Embedding only') .'</option>
  2330. </select>
  2331. <div class="desc">'. _gettext('Whether or not to allow embedding of videos.') .' '. _gettext('Default') .'.: <strong>'. _gettext('No Embedding') .'</strong></div><br />';
  2332. /* Order */
  2333. $tpl_page .= '<label for="order">'. _gettext('Order') .':</label>
  2334. <input type="text" name="order" value="'.$lineboard['order'].'" />
  2335. <div class="desc">'. _gettext('Order to show board in menu list, in ascending order.') .' '. _gettext('Default') .': <strong>0</strong></div><br />';
  2336. /* Section */
  2337. $tpl_page .= '<label for="section">'. _gettext('Section') .':</label>' .
  2338. $this->MakeSectionListDropdown('section', $lineboard['section']) .
  2339. '<div class="desc">'. _gettext('The section the board is in. This is used for displaying the list of boards on the top and bottom of pages.') .'<br />'. _gettext('If this is set to <em>Select a Board</em>, <strong>it will not be shown in the menu</strong>.') .'</div><br />';
  2340. /* Load balancer URL */
  2341. $tpl_page .= '<label for="loadbalanceurl">'. _gettext('Load balance URL') .':</label>
  2342. <input type="text" name="loadbalanceurl" value="'.$lineboard['loadbalanceurl'].'" />
  2343. <div class="desc">'. _gettext('The full http:// URL to the load balance script for this board. The script will handle file uploads, and creation of thumbnails. Only one script per board can be used, and there must be a src and thumb dir in the same folder as the script. Set to nothing to disable.') .'</div><br />';
  2344. /* Load balancer password */
  2345. $tpl_page .= '<label for="loadbalancepassword">'. _gettext('Load balance password') .':</label>
  2346. <input type="text" name="loadbalancepassword" value="'.$lineboard['loadbalancepassword'].'" />
  2347. <div class="desc">'. _gettext('The password which will be passed to the script above. The script must have this same password entered at the top, in the configuration area.') .'</div><br />';
  2348. /* Allowed filetypes */
  2349. $tpl_page .= '<label>'. _gettext('Allowed filetypes') .':</label>
  2350. <div class="desc">'. _gettext('What filetypes users are allowed to upload.') .'</div><br />';
  2351. $filetypes = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `filetype` FROM `" . KU_DBPREFIX . "filetypes` ORDER BY `filetype` ASC");
  2352. foreach ($filetypes as $filetype) {
  2353. $tpl_page .= '<label for="filetype_'. $filetype['id'] . '">'. strtoupper($filetype['filetype']) . '</label><input type="checkbox" name="filetype_'. $filetype['id'] . '"';
  2354. $filetype_isenabled = $tc_db->GetOne("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "board_filetypes` WHERE `boardid` = '" . $lineboard['id'] . "' AND `typeid` = '" . $filetype['id'] . "' LIMIT 1");
  2355. if ($filetype_isenabled == 1) {
  2356. $tpl_page .= ' checked';
  2357. }
  2358. $tpl_page .= ' /><br />';
  2359. }
  2360. /* Allowed embeds */
  2361. $tpl_page .= '<label>'. _gettext('Allowed embeds') .':</label>
  2362. <div class="desc">'. _gettext('What embed sites are allowed on this board. Only useful on board with embedding enabled.') .'</div><br />';
  2363. $embeds = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `filetype`, `name` FROM `" . KU_DBPREFIX . "embeds` ORDER BY `filetype` ASC");
  2364. foreach ($embeds as $embed) {
  2365. $tpl_page .= '<label for="allowedembeds[]">'. $embed['name'] . '</label><input type="checkbox" name="allowedembeds[]" value="'. $embed['filetype'] . '"';
  2366. if (in_array($embed['filetype'], explode(',', $lineboard['embeds_allowed']))) {
  2367. $tpl_page .= ' checked';
  2368. }
  2369. $tpl_page .= ' /><br />';
  2370. }
  2371. /* Maximum image size */
  2372. $tpl_page .= '<label for="maximagesize">'. _gettext('Maximum image size') .':</label>
  2373. <input type="text" name="maximagesize" value="'.$lineboard['maximagesize'].'" />
  2374. <div class="desc">'. _gettext('Maxmimum size of uploaded images, in <strong>bytes</strong>.') . ' '. _gettext('Default') .': <strong>1024000</strong></div><br />';
  2375. /* Maximum message length */
  2376. $tpl_page .= '<label for="messagelength">'. _gettext('Maximum message length') .':</label>
  2377. <input type="text" name="messagelength" value="'.$lineboard['messagelength'].'" />
  2378. <div class="desc">'. _gettext('Default') .': <strong>8192</strong></div><br />';
  2379. /* Maximum board pages */
  2380. $tpl_page .= '<label for="maxpages">'. _gettext('Maximum board pages') .':</label>
  2381. <input type="text" name="maxpages" value="'.$lineboard['maxpages'].'" />
  2382. <div class="desc">'. _gettext('Default') .': <strong>11</strong></div><br />';
  2383. /* Maximum thread age */
  2384. $tpl_page .= '<label for="maxage">'. _gettext('Maximum thread age (Hours)') .':</label>
  2385. <input type="text" name="maxage" value="'.$lineboard['maxage'].'" />
  2386. <div class="desc">'. _gettext('Default') .': <strong>0</strong></div><br />';
  2387. /* Mark page */
  2388. $tpl_page .= '<label for="maxage">'. _gettext('Mark page') .':</label>
  2389. <input type="text" name="markpage" value="'.$lineboard['markpage'].'" />
  2390. <div class="desc">'. _gettext('Threads which reach this page or further will be marked to be deleted in two hours.') .' '. _gettext('Default') .': <strong>9</strong></div><br />';
  2391. /* Maximum thread replies */
  2392. $tpl_page .= '<label for="maxreplies">'. _gettext('Maximum thread replies') .':</label>
  2393. <input type="text" name="maxreplies" value="'.$lineboard['maxreplies'].'" />
  2394. <div class="desc">'. _gettext('The number of replies a thread can have before autosaging to the back of the board.') . ' '. _gettext('Default') .': <strong>200</strong></div><br />';
  2395. /* Header image */
  2396. $tpl_page .= '<label for="image">'. _gettext('Header image') .':</label>
  2397. <input type="text" name="image" value="'.$lineboard['image'].'" />
  2398. <div class="desc">'. _gettext('Overrides the header set in the config file. Leave blank to use configured global header image. Needs to be a full url including http://. Set to none to show no header image.') .'</div><br />';
  2399. /* Include header */
  2400. $tpl_page .= '<label for="includeheader">'. _gettext('Include header') .':</label>
  2401. <textarea name="includeheader" rows="12" cols="80">'.htmlspecialchars($lineboard['includeheader']).'</textarea>
  2402. <div class="desc">'. _gettext('Raw HTML which will be inserted at the top of each page of the board.') .'</div><br />';
  2403. /* Anonymous */
  2404. $tpl_page .= '<label for="anonymous">'. _gettext('Anonymous') .':</label>
  2405. <input type="text" name="anonymous" value="'. $lineboard['anonymous'] . '" />
  2406. <div class="desc">'. _gettext('Name to display when a name is not attached to a post.') . ' '. _gettext('Default') .': <strong>'. _gettext('Anonymous') .'</strong></div><br />';
  2407. /* Locked */
  2408. $tpl_page .= '<label for="locked">'. _gettext('Locked') .':</label>
  2409. <input type="checkbox" name="locked" ';
  2410. if ($lineboard['locked'] == '1') {
  2411. $tpl_page .= 'checked ';
  2412. }
  2413. $tpl_page .= ' />
  2414. <div class="desc">'. _gettext('Only moderators of the board and admins can make new posts/replies') .'</div><br />';
  2415. /* Show ID */
  2416. $tpl_page .= '<label for="showid">'. _gettext('Show ID') .':</label>
  2417. <input type="checkbox" name="showid" ';
  2418. if ($lineboard['showid'] == '1') {
  2419. $tpl_page .= 'checked ';
  2420. }
  2421. $tpl_page .= ' />
  2422. <div class="desc">'. _gettext('If enabled, each post will display the poster\'s ID, which is a representation of their IP address.') .'</div><br />';
  2423. /* Show ID */
  2424. $tpl_page .= '<label for="compactlist">'. _gettext('Compact list') .':</label>
  2425. <input type="checkbox" name="compactlist" ';
  2426. if ($lineboard['compactlist'] == '1') {
  2427. $tpl_page .= 'checked ';
  2428. }
  2429. $tpl_page .= ' />
  2430. <div class="desc">'. _gettext('Text boards only. If enabled, the list of threads displayed on the front page will be formatted differently to be compact.') . '</div><br />';
  2431. /* Enable reporting */
  2432. $tpl_page .= '<label for="enablereporting">'. _gettext('Enable reporting') .':</label>
  2433. <input type="checkbox" name="enablereporting"';
  2434. if ($lineboard['enablereporting'] == '1') {
  2435. $tpl_page .= ' checked';
  2436. }
  2437. $tpl_page .= ' />'. "\n" .
  2438. '<div class="desc">'. _gettext('Reporting allows users to report posts, adding the post to the report list.') .' '. _gettext('Default') .': <strong>'. _gettext('Yes') .'</strong></div><br />';
  2439. /* Enable captcha */
  2440. $tpl_page .= '<label for="enablecaptcha">'. _gettext('Enable captcha') .':</label>
  2441. <input type="checkbox" name="enablecaptcha"';
  2442. if ($lineboard['enablecaptcha'] == '1') {
  2443. $tpl_page .= ' checked';
  2444. }
  2445. $tpl_page .= ' />
  2446. <div class="desc">'. _gettext('Enable/disable captcha system for this board. If captcha is enabled, in order for a user to post, they must first correctly enter the text on an image.') .' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2447. /* Enable archiving */
  2448. $tpl_page .= '<label for="enablearchiving">'. _gettext('Enable archiving') .':</label>
  2449. <input type="checkbox" name="enablearchiving"';
  2450. if ($lineboard['enablearchiving'] == '1') {
  2451. $tpl_page .= ' checked';
  2452. }
  2453. $tpl_page .= ' />
  2454. <div class="desc">'. _gettext('Enable/disable thread archiving for this board (not available if load balancer is used). If enabled, when a thread is pruned or deleted through this panel with the archive checkbox checked, the thread and its images will be moved into the arch directory, found in the same directory as the board. To function properly, you must create and set proper permissions to /boardname/arch, /boardname/arch/res, /boardname/arch/src, and /boardname/arch/thumb') .' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2455. /* Enable catalog */
  2456. $tpl_page .= '<label for="enablecatalog">'. _gettext('Enable catalog') .':</label>
  2457. <input type="checkbox" name="enablecatalog"';
  2458. if ($lineboard['enablecatalog'] == '1') {
  2459. $tpl_page .= ' checked';
  2460. }
  2461. $tpl_page .= ' />
  2462. <div class="desc">'. _gettext('If set to yes, a catalog.html file will be built with the other files, displaying the original picture of every thread in a box. This will only work on normal/oekaki imageboards.') .' '. _gettext('Default') .': <strong>'. _gettext('Yes') .'</strong></div><br />';
  2463. /* Enable "no file" posting */
  2464. $tpl_page .= '<label for="enablenofile">'. _gettext('Enable \'no file\' posting') .':</label>
  2465. <input type="checkbox" name="enablenofile"';
  2466. if ($lineboard['enablenofile'] == '1') {
  2467. $tpl_page .= ' checked';
  2468. }
  2469. $tpl_page .= ' />
  2470. <div class="desc">'. _gettext('If set to yes, new threads will not require an image to be posted.') . ' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2471. /* Redirect to thread */
  2472. $tpl_page .= '<label for="redirecttothread">'. _gettext('Redirect to thread') .':</label>
  2473. <input type="checkbox" name="redirecttothread"';
  2474. if ($lineboard['redirecttothread'] == '1') {
  2475. $tpl_page .= ' checked';
  2476. }
  2477. $tpl_page .= ' />
  2478. <div class="desc">'. _gettext('If set to yes, users will be redirected to the thread they replied to/posted after posting. If set to no, users will be redirected to the first page of the board.') . ' '. _gettext('Default') .': <strong>'.('No') .'</strong></div><br />';
  2479. /* Forced anonymous */
  2480. $tpl_page .= '<label for="forcedanon">'. _gettext('Forced anonymous') .':</label>
  2481. <input type="checkbox" name="forcedanon"';
  2482. if ($lineboard['forcedanon'] == '1') {
  2483. $tpl_page .= ' checked';
  2484. }
  2485. $tpl_page .= ' />
  2486. <div class="desc">'. _gettext('If set to yes, users will not be allowed to enter a name, making everyone appear as Anonymous') . ' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2487. /* Trial */
  2488. $tpl_page .= '<label for="trial">'. _gettext('Trial') .':</label>
  2489. <input type="checkbox" name="trial"';
  2490. if ($lineboard['trial'] == '1') {
  2491. $tpl_page .= ' checked';
  2492. }
  2493. $tpl_page .= ' />
  2494. <div class="desc">'. _gettext('If set to yes, this board will appear in italics in the menu') . ' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2495. /* Popular */
  2496. $tpl_page .= '<label for="popular">'. _gettext('Popular') .':</label>
  2497. <input type="checkbox" name="popular"';
  2498. if ($lineboard['popular'] == '1') {
  2499. $tpl_page .= ' checked';
  2500. }
  2501. $tpl_page .= ' />
  2502. <div class="desc">'. _gettext('If set to yes, this board will appear in bold in the menu') . ' '. _gettext('Default') .': <strong>'. _gettext('No') .'</strong></div><br />';
  2503. /* Default style */
  2504. $tpl_page .= '<label for="defaultstyle">'. _gettext('Default style') .':</label>
  2505. <select name="defaultstyle">
  2506. <option value=""';
  2507. $tpl_page .= ($lineboard['defaultstyle'] == '') ? ' selected="selected"' : '';
  2508. $tpl_page .= '>'. _gettext('Use Default') .'</option>';
  2509. $styles = explode(':', KU_STYLES);
  2510. foreach ($styles as $stylesheet) {
  2511. $tpl_page .= '<option value="'. $stylesheet . '"';
  2512. $tpl_page .= ($lineboard['defaultstyle'] == $stylesheet) ? ' selected="selected"' : '';
  2513. $tpl_page .= '>'. ucfirst($stylesheet) . '</option>';
  2514. }
  2515. $stylestxt = explode(':', KU_TXTSTYLES);
  2516. foreach ($stylestxt as $stylesheet) {
  2517. $tpl_page .= '<option value="'. $stylesheet . '"';
  2518. $tpl_page .= ($lineboard['defaultstyle'] == $stylesheet) ? ' selected="selected"' : '';
  2519. $tpl_page .= '>[TXT] '. ucfirst($stylesheet) . '</option>';
  2520. }
  2521. $tpl_page .= '</select>
  2522. <div class="desc">'. _gettext('The style which will be set when the user first visits the board.') .' '. _gettext('Default') .': <strong>'. _gettext('Use Default') .'</strong></div><br />';
  2523. /* Submit form */
  2524. $tpl_page .= '<input type="submit" name="submit_regenerate" value="'. _gettext('Update and regenerate board') .'" /><br /><input type="submit" name="submit_noregenerate" value="'. _gettext('Update without regenerating board') .'" />
  2525. </form>
  2526. </div><br />';
  2527. }
  2528. } else {
  2529. $tpl_page .= _gettext('Unable to locate a board named') . ' <strong>'. $_POST['board'] . '</strong>.';
  2530. }
  2531. } else {
  2532. $tpl_page .= '<form action="?action=boardopts" method="post">
  2533. <label for="board">'. _gettext('Board') .':</label>' .
  2534. $this->MakeBoardListDropdown('board', $this->BoardList($_SESSION['manageusername'])) .
  2535. '<input type="submit" value="'. _gettext('Go') .'" />
  2536. </form>';
  2537. }
  2538. }
  2539. function unstickypost() {
  2540. global $tc_db, $tpl_page, $board_class;
  2541. $this->ModeratorsOnly();
  2542. $tpl_page .= '<h2>'. _gettext('Manage stickies') . '</h2><br />';
  2543. if (isset($_GET['postid']) && isset($_GET['board'])) {
  2544. if ($_GET['postid'] > 0 && $_GET['board'] != '') {
  2545. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "");
  2546. if (count($results) > 0) {
  2547. if (!$this->CurrentUserIsModeratorOfBoard($_GET['board'], $_SESSION['manageusername'])) {
  2548. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2549. }
  2550. foreach ($results as $line) {
  2551. $sticky_board_name = $line['name'];
  2552. $sticky_board_id = $line['id'];
  2553. }
  2554. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $sticky_board_id ." AND `IS_DELETED` = '0' AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2555. if (count($results) > 0) {
  2556. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `stickied` = '0' WHERE `boardid` = " . $sticky_board_id ." AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2557. $board_class = new Board($sticky_board_name);
  2558. $board_class->RegenerateAll();
  2559. unset($board_class);
  2560. $tpl_page .= _gettext('Thread successfully un-stickied');
  2561. management_addlogentry(_gettext('Unstickied thread') . ' #' . intval($_GET['postid']) . ' - /' . $sticky_board_name . '/', 5);
  2562. } else {
  2563. $tpl_page .= _gettext('Invalid thread ID. This may have been caused by the thread recently being deleted.');
  2564. }
  2565. } else {
  2566. $tpl_page .= _gettext('Invalid board directory.');
  2567. }
  2568. $tpl_page .= '<hr />';
  2569. }
  2570. }
  2571. $tpl_page .= $this->stickyforms();
  2572. }
  2573. function stickypost() {
  2574. global $tc_db, $tpl_page, $board_class;
  2575. $this->ModeratorsOnly();
  2576. $tpl_page .= '<h2>'. _gettext('Manage stickies') . '</h2><br />';
  2577. if (isset($_GET['postid']) && isset($_GET['board'])) {
  2578. if ($_GET['postid'] > 0 && $_GET['board'] != '') {
  2579. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "");
  2580. if (count($results) > 0) {
  2581. if (!$this->CurrentUserIsModeratorOfBoard($_GET['board'], $_SESSION['manageusername'])) {
  2582. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2583. }
  2584. foreach ($results as $line) {
  2585. $sticky_board_name = $line['name'];
  2586. $sticky_board_id = $line['id'];
  2587. }
  2588. $result = $tc_db->GetOne("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $sticky_board_id . " AND `IS_DELETED` = '0' AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2589. if ($result > 0) {
  2590. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `stickied` = '1' WHERE `boardid` = " . $sticky_board_id . " AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2591. $board_class = new Board($sticky_board_name);
  2592. $board_class->RegenerateAll();
  2593. unset($board_class);
  2594. $tpl_page .= _gettext('Thread successfully stickied.');
  2595. management_addlogentry(_gettext('Stickied thread') . ' #' . intval($_GET['postid']) . ' - /' . $sticky_board_name . '/', 5);
  2596. } else {
  2597. $tpl_page .= _gettext('Invalid thread ID. This may have been caused by the thread recently being deleted.');
  2598. }
  2599. } else {
  2600. $tpl_page .= _gettext('Invalid board directory.');
  2601. }
  2602. $tpl_page .= '<hr />';
  2603. }
  2604. }
  2605. $tpl_page .= $this->stickyforms();
  2606. }
  2607. /* Create forms for stickying a post */
  2608. function stickyforms() {
  2609. global $tc_db;
  2610. $output = '<table width="100%" border="0">
  2611. <tr><td width="50%"><h1>'. _gettext('Sticky') . '</h1></td><td width="50%"><h1>'. _gettext('Unsticky') . '</h1></td></tr>
  2612. <tr><td style="vertical-align:top;"><br />
  2613. <form action="manage_page.php" method="get"><input type="hidden" name="action" value="stickypost" />
  2614. <label for="board">'. _gettext('Board') .':</label>' .
  2615. $this->MakeBoardListDropdown('board', $this->BoardList($_SESSION['manageusername'])) .
  2616. '<br />
  2617. <label for="postid">'. _gettext('Thread') .':</label>
  2618. <input type="text" name="postid" /><br />
  2619. <label for="submit">&nbsp;</label>
  2620. <input name="submit" type="submit" value="'. _gettext('Sticky') .'" />
  2621. </form>
  2622. </td><td>';
  2623. $results_boards = $tc_db->GetAll("SELECT HIGH_PRIORITY `name`, `id` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  2624. foreach ($results_boards as $line_board) {
  2625. $output .= '<h2>/'. $line_board['name'] . '/</h2>';
  2626. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line_board['id'] . " AND `IS_DELETED` = '0' AND `parentid` = '0' AND `stickied` = '1'");
  2627. if (count($results) > 0) {
  2628. foreach ($results as $line) {
  2629. $output .= '<a href="?action=unstickypost&board='. $line_board['name'] . '&postid='. $line['id'] . '">#'. $line['id'] . '</a><br />';
  2630. }
  2631. } else {
  2632. $output .= 'No stickied threads.<br />';
  2633. }
  2634. }
  2635. $output .= '</td></tr></table>';
  2636. return $output;
  2637. }
  2638. function lockpost() {
  2639. global $tc_db, $tpl_page, $board_class;
  2640. $this->ModeratorsOnly();
  2641. $tpl_page .= '<h2>'. _gettext('Manage locked threads') . '</h2><br />';
  2642. if (isset($_GET['postid']) && isset($_GET['board'])) {
  2643. if ($_GET['postid'] > 0 && $_GET['board'] != '') {
  2644. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "");
  2645. if (count($results) > 0) {
  2646. if (!$this->CurrentUserIsModeratorOfBoard($_GET['board'], $_SESSION['manageusername'])) {
  2647. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2648. }
  2649. foreach ($results as $line) {
  2650. $lock_board_name = $line['name'];
  2651. $lock_board_id = $line['id'];
  2652. }
  2653. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $lock_board_id . " AND `IS_DELETED` = '0' AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2654. if (count($results) > 0) {
  2655. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `locked` = '1' WHERE `boardid` = " . $lock_board_id . " AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2656. $board_class = new Board($lock_board_name);
  2657. $board_class->RegenerateAll();
  2658. unset($board_class);
  2659. $tpl_page .= _gettext('Thread successfully locked.');
  2660. management_addlogentry(_gettext('Locked thread') . ' #'. intval($_GET['postid']) . ' - /'. intval($_GET['board']) . '/', 5);
  2661. } else {
  2662. $tpl_page .= _gettext('Invalid thread ID. This may have been caused by the thread recently being deleted.');
  2663. }
  2664. } else {
  2665. $tpl_page .= _gettext('Invalid board directory.');
  2666. }
  2667. $tpl_page .= '<hr />';
  2668. }
  2669. }
  2670. $tpl_page .= $this->lockforms();
  2671. }
  2672. function unlockpost() {
  2673. global $tc_db, $tpl_page, $board_class;
  2674. $tpl_page .= '<h2>'. _gettext('Manage locked threads') . '</h2><br />';
  2675. if ($_GET['postid'] > 0 && $_GET['board'] != '') {
  2676. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['board']) . "");
  2677. if (count($results) > 0) {
  2678. if (!$this->CurrentUserIsModeratorOfBoard($_GET['board'], $_SESSION['manageusername'])) {
  2679. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2680. }
  2681. foreach ($results as $line) {
  2682. $lock_board_name = $line['name'];
  2683. $lock_board_id = $line['id'];
  2684. }
  2685. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $lock_board_id . " AND `IS_DELETED` = '0' AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2686. if (count($results) > 0) {
  2687. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `locked` = '0' WHERE `boardid` = " . $lock_board_id . " AND `parentid` = '0' AND `id` = " . $tc_db->qstr($_GET['postid']) . "");
  2688. $board_class = new Board($lock_board_name);
  2689. $board_class->RegenerateAll();
  2690. unset($board_class);
  2691. $tpl_page .= _gettext('Thread successfully unlocked.');
  2692. management_addlogentry(_gettext('Unlocked thread') . ' #'. intval($_GET['postid']) . ' - /'. intval($_GET['board']) . '/', 5);
  2693. } else {
  2694. $tpl_page .= _gettext('Invalid thread ID. This may have been caused by the thread recently being deleted.');
  2695. }
  2696. } else {
  2697. $tpl_page .= _gettext('Invalid board directory.');
  2698. }
  2699. $tpl_page .= '<hr />';
  2700. }
  2701. $tpl_page .= $this->lockforms();
  2702. }
  2703. function lockforms() {
  2704. global $tc_db;
  2705. $output = '<table width="100%" border="0">
  2706. <tr><td width="50%"><h1>'. _gettext('Lock') . '</h1></td><td width="50%"><h1>'. _gettext('Unlock') . '</h1></td></tr>
  2707. <tr><td><br />
  2708. <form action="manage_page.php" method="get"><input type="hidden" name="action" value="lockpost" />
  2709. <label for="board">'. _gettext('Board') .':</label>' .
  2710. $this->MakeBoardListDropdown('board', $this->BoardList($_SESSION['manageusername'])) .
  2711. '<br />
  2712. <label for="postid">'. _gettext('Thread') .':</label>
  2713. <input type="text" name="postid" /><br />
  2714. <label for="submit">&nbsp;</label>
  2715. <input name="submit" type="submit" value="'. _gettext('Lock') .'" />
  2716. </form>
  2717. </td><td>';
  2718. $results_boards = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  2719. foreach ($results_boards as $line_board) {
  2720. $output .= '<h2>/'. $line_board['name'] . '/</h2>';
  2721. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line_board['id'] . " AND `IS_DELETED` = '0' AND `parentid` = '0' AND `locked` = '1'");
  2722. if (count($results) > 0) {
  2723. foreach ($results as $line) {
  2724. $output .= '<a href="?action=unlockpost&board='. $line_board['name'] . '&postid='. $line['id'] . '">#'. $line['id'] . '</a><br />';
  2725. }
  2726. } else {
  2727. $output .= 'No locked threads.<br />';
  2728. }
  2729. }
  2730. $output .= '</td></tr></table>';
  2731. return $output;
  2732. }
  2733. /* Delete a post, or multiple posts */
  2734. function delposts($multidel=false) {
  2735. global $tc_db, $tpl_page, $board_class;
  2736. $isquickdel = false;
  2737. if (isset($_POST['boarddir']) || isset($_GET['boarddir'])) {
  2738. if (!isset($_GET['boarddir']) && isset($_POST['boarddir'])) {
  2739. $this->CheckToken($_POST['token']);
  2740. }
  2741. if (isset($_GET['boarddir'])) {
  2742. $isquickdel = true;
  2743. $_POST['boarddir'] = $_GET['boarddir'];
  2744. if (isset($_GET['delthreadid'])) {
  2745. $_POST['delthreadid'] = $_GET['delthreadid'];
  2746. }
  2747. if (isset($_GET['delpostid'])) {
  2748. $_POST['delpostid'] = $_GET['delpostid'];
  2749. }
  2750. }
  2751. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_POST['boarddir']) . "");
  2752. if (count($results) > 0) {
  2753. if (!$this->CurrentUserIsModeratorOfBoard($_POST['boarddir'], $_SESSION['manageusername'])) {
  2754. exitWithErrorPage(_gettext('You are not a moderator of this board.'));
  2755. }
  2756. foreach ($results as $line) {
  2757. $board_id = $line['id'];
  2758. $board_dir = $line['name'];
  2759. }
  2760. if (isset($_GET['cp'])) {
  2761. $cp = '&amp;cp=y&amp;instant=y';
  2762. }
  2763. if (isset($_POST['delthreadid'])) {
  2764. if ($_POST['delthreadid'] > 0) {
  2765. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_id . " AND `IS_DELETED` = '0' AND `id` = " . $tc_db->qstr($_POST['delthreadid']) . " AND `parentid` = '0'");
  2766. if (count($results) > 0) {
  2767. if (isset($_POST['fileonly'])) {
  2768. foreach ($results as $line) {
  2769. if (!empty($line['file'])) {
  2770. $del = unlink(KU_ROOTDIR . $_POST['boarddir'] . '/src/'. $line['file'] . '.'. $line['file_type']);
  2771. if ($del) {
  2772. @unlink(KU_ROOTDIR . $_POST['boarddir'] . '/thumb/'. $line['file'] . 's.'. $line['file_type']);
  2773. @unlink(KU_ROOTDIR . $_POST['boarddir'] . '/thumb/'. $line['file'] . 'c.'. $line['file_type']);
  2774. $tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `file` = 'removed', `file_md5` = '' WHERE `boardid` = " . $board_id . " AND `id` = ".$_POST['delthreadid']." LIMIT 1");
  2775. $tpl_page .= '<hr />File successfully deleted<hr />';
  2776. } else {
  2777. $tpl_page .= '<hr />That file has already been deleted.<hr />';
  2778. }
  2779. } else {
  2780. $tpl_page .= '<hr />Error: That thread doesn\'t have a file associated with it.<hr />';
  2781. }
  2782. }
  2783. } else {
  2784. foreach ($results as $line) {
  2785. $delthread_id = $line['id'];
  2786. }
  2787. $post_class = new Post($delthread_id, $board_dir, $board_id);
  2788. if (isset($_POST['archive'])) {
  2789. $numposts_deleted = $post_class->Delete(true);
  2790. } else {
  2791. $numposts_deleted = $post_class->Delete();
  2792. }
  2793. $board_class = new Board($board_dir);
  2794. $board_class->RegenerateAll();
  2795. unset($board_class);
  2796. unset($post_class);
  2797. $tpl_page .= _gettext('Thread '.$delthread_id.' successfully deleted.');
  2798. management_addlogentry(_gettext('Deleted thread') . ' #<a href="?action=viewthread&thread='. $delthread_id . '&board='. $_POST['boarddir'] . '">'. $delthread_id . '</a> ('. $numposts_deleted . ' replies) - /'. $board_dir . '/', 7);
  2799. if (!empty($_GET['postid'])) {
  2800. $tpl_page .= '<br /><br /><meta http-equiv="refresh" content="1;url='. KU_CGIPATH . '/manage_page.php?action=bans&banboard='. $_GET['boarddir'] . '&banpost='. $_GET['postid'] . $cp . '"><a href="'. KU_CGIPATH . '/manage_page.php?action=bans&banboard='. $_GET['boarddir'] . '&banpost='. $_GET['postid'] . $cp . '">'. _gettext('Redirecting') . '</a> to ban page...';
  2801. } elseif ($isquickdel) {
  2802. $tpl_page .= '<br /><br /><meta http-equiv="refresh" content="1;url='. KU_BOARDSPATH . '/'. $_GET['boarddir'] . '/"><a href="'. KU_BOARDSPATH . '/'. $_GET['boarddir'] . '/">'. _gettext('Redirecting') . '</a> back to board...';
  2803. }
  2804. }
  2805. } else {
  2806. $tpl_page .= _gettext('Invalid thread ID '.$delpost_id.'. This may have been caused by the thread recently being deleted.');
  2807. }
  2808. }
  2809. } elseif (isset($_POST['delpostid'])) {
  2810. if ($_POST['delpostid'] > 0) {
  2811. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_id . " AND `IS_DELETED` = '0' AND `id` = " . $tc_db->qstr($_POST['delpostid']) . "");
  2812. if (count($results) > 0) {
  2813. if (isset($_POST['fileonly'])) {
  2814. foreach ($results as $line) {
  2815. if (!empty($line['file'])) {
  2816. $del = @unlink(KU_ROOTDIR . $_POST['boarddir'] . '/src/'. $line['file'] . '.'. $line['file_type']);
  2817. if ($del) {
  2818. @unlink(KU_ROOTDIR . $_POST['boarddir'] . '/thumb/'. $line['file'] . 's.'. $line['file_type']);
  2819. @unlink(KU_ROOTDIR . $_POST['boarddir'] . '/thumb/'. $line['file'] . 'c.'. $line['file_type']);
  2820. $tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `file` = 'removed', `file_md5` = '' WHERE `boardid` = " . $board_id . " AND `id` = ".$_POST['delpostid']." LIMIT 1");
  2821. $tpl_page .= '<hr />File successfully deleted<hr />';
  2822. } else {
  2823. $tpl_page .= '<hr />That file has already been deleted.<hr />';
  2824. }
  2825. } else {
  2826. $tpl_page .= '<hr />Error: That thread doesn\'t have a file associated with it.<hr />';
  2827. }
  2828. }
  2829. } else {
  2830. foreach ($results as $line) {
  2831. $delpost_id = $line['id'];
  2832. $delpost_parentid = $line['parentid'];
  2833. }
  2834. $post_class = new Post($delpost_id, $board_dir, $board_id);
  2835. $post_class->Delete();
  2836. $board_class = new Board($board_dir);
  2837. $board_class->RegenerateThreads($delpost_parentid);
  2838. $board_class->RegeneratePages();
  2839. unset($board_class);
  2840. unset($post_class);
  2841. $tpl_page .= _gettext('Post '.$delpost_id.' successfully deleted.');
  2842. management_addlogentry(_gettext('Deleted post') . ' #<a href="?action=viewthread&thread='. $delpost_parentid . '&board='. $_POST['boarddir'] . '#'. $delpost_id . '">'. $delpost_id . '</a> - /'. $board_dir . '/', 7);
  2843. if ($_GET['postid'] != '') {
  2844. $tpl_page .= '<br /><br /><meta http-equiv="refresh" content="1;url='. KU_CGIPATH . '/manage_page.php?action=bans&banboard='. $_GET['boarddir'] . '&banpost='. $_GET['postid'] . $cp . '"><a href="'. KU_CGIPATH . '/manage_page.php?action=bans&banboard='. $_GET['boarddir'] . '&banpost='. $_GET['postid'] . '">'. _gettext('Redirecting') . '</a> to ban page...';
  2845. } elseif ($isquickdel) {
  2846. $tpl_page .= '<br /><br /><meta http-equiv="refresh" content="1;url='. KU_BOARDSPATH . '/'. $_GET['boarddir'] . '/res/'. $delpost_parentid . '.html"><a href="'. KU_BOARDSPATH . '/'. $_GET['boarddir'] . '/res/'. $delpost_parentid . '.html">'. _gettext('Redirecting') . '</a> back to thread...';
  2847. }
  2848. }
  2849. } else {
  2850. $tpl_page .= _gettext('Invalid thread ID '.$delpost_id.'. This may have been caused by the thread recently being deleted.');
  2851. }
  2852. }
  2853. }
  2854. } else {
  2855. $tpl_page .= _gettext('Invalid board directory.');
  2856. }
  2857. }
  2858. $tpl_page .= '<h2>'. _gettext('Delete thread/post') . '</h2><br />';
  2859. if (!$multidel) {
  2860. $tpl_page .= '<form action="manage_page.php?action=delposts" method="post">
  2861. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2862. <label for="boarddir">'. _gettext('Board') .':</label>' .
  2863. $this->MakeBoardListDropdown('boarddir', $this->BoardList($_SESSION['manageusername'])) .
  2864. '<br />
  2865. <label for="delthreadid">'. _gettext('Thread') .':</label>
  2866. <input type="text" name="delthreadid" /><br />
  2867. <label for="fileonly">'. _gettext('File Only') .':</label>
  2868. <input type="checkbox" id="fileonly" name="fileonly" /><br />
  2869. <input type="submit" value="'. _gettext('Delete thread') .'" />
  2870. </form>
  2871. <br /><hr />
  2872. <form action="manage_page.php?action=delposts" method="post">
  2873. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  2874. <label for="boarddir">'. _gettext('Board') .':</label>' .
  2875. $this->MakeBoardListDropdown('boarddir', $this->BoardList($_SESSION['manageusername'])) .
  2876. '<br />
  2877. <label for="delpostid">'. _gettext('Post') .':</label>
  2878. <input type="text" name="delpostid" /><br />
  2879. <label for="archive">'. _gettext('Archive') .':</label>
  2880. <input type="checkbox" id="archive" name="archive" /><br />
  2881. <label for="fileonly">'. _gettext('File Only') .':</label>
  2882. <input type="checkbox" id="fileonly" name="fileonly" /><br />
  2883. <input type="submit" value="'. _gettext('Delete post') .'" />
  2884. </form>';
  2885. }
  2886. }
  2887. /*
  2888. * +------------------------------------------------------------------------------+
  2889. * Moderation Pages
  2890. * +------------------------------------------------------------------------------+
  2891. */
  2892. function del_rs() {
  2893. global $tc_db, $tpl_page;
  2894. $this->ModeratorsOnly();
  2895. $tpl_page .="<h2>Rapidshare Board Management</h2>";
  2896. // If the file to delete is set, delete it right away,
  2897. if(isset($_GET['del'])) {
  2898. $tc_db->Execute("DELETE FROM `".KU_DBPREFIX."rs_links` WHERE `id` = ".$tc_db->qstr($_GET['del'])." LIMIT 1");
  2899. $tpl_page .="Download ". $_GET['del'] . " removed.";
  2900. } elseif (isset($_POST['del'])) {
  2901. $tc_db->Execute("DELETE FROM `".KU_DBPREFIX."rs_links` WHERE `id` = ".$tc_db->qstr($_POST['del'])." LIMIT 1");
  2902. $tpl_page .="Download ". $_POST['del'] . " removed.";
  2903. } else {
  2904. $tpl_page .="<form action='https://manage.hurr.ca/manage_page.php?action=del_rs' method='POST'>
  2905. <input name='del' width='20' type='text'><input type='submit' value='Delete Post'>";
  2906. }
  2907. }
  2908. /* View and delete reports */
  2909. function reports() {
  2910. global $tc_db, $tpl_page;
  2911. $this->ModeratorsOnly();
  2912. $tpl_page .= '<h2>'. _gettext('Reports') . '</h2><br />';
  2913. if (isset($_GET['clear'])) {
  2914. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "reports` WHERE `id` = " . $tc_db->qstr($_GET['clear']) . " LIMIT 1");
  2915. if (count($results) > 0) {
  2916. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "reports` SET `cleared` = '1' WHERE `id` = " . $tc_db->qstr($_GET['clear']));
  2917. $tpl_page .= 'Report successfully cleared.<hr />';
  2918. }
  2919. }
  2920. $query = "SELECT * FROM `" . KU_DBPREFIX . "reports` WHERE `cleared` = 0";
  2921. if (!$this->CurrentUserIsAdministrator()) {
  2922. $boardlist = $this->BoardList($_SESSION['manageusername']);
  2923. if (!empty($boardlist)) {
  2924. $query .= ' AND (';
  2925. foreach ($boardlist as $board) {
  2926. $query .= ' `board` = \''. $board['name'] .'\' OR';
  2927. }
  2928. $query = substr($query, 0, -3) . ')';
  2929. } else {
  2930. $tpl_page .= _gettext('You do not moderate any boards.');
  2931. }
  2932. }
  2933. $resultsreport = $tc_db->GetAll($query);
  2934. if (count($resultsreport) > 0) {
  2935. $tpl_page .= '<table border="1" width="100%"><tr><th>Board</th><th>Post</th><th>File</th><th>Message</th><th>Reason</th><th>Reporter IP</th><th>Action</th></tr>';
  2936. foreach ($resultsreport as $linereport) {
  2937. $reportboardid = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($linereport['board']) . "");
  2938. $results = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $reportboardid . " AND `id` = " . $tc_db->qstr($linereport['postid']) . "");
  2939. foreach ($results as $line) {
  2940. if ($line['IS_DELETED'] == 0) {
  2941. $tpl_page .= '<tr><td>/'. $linereport['board'] . '/</td><td><a href="'. KU_BOARDSPATH . '/'. $linereport['board'] . '/res/';
  2942. if ($line['parentid'] == '0') {
  2943. $tpl_page .= $linereport['postid'];
  2944. $post_threadorpost = 'thread';
  2945. } else {
  2946. $tpl_page .= $line['parentid'];
  2947. $post_threadorpost = 'post';
  2948. }
  2949. $tpl_page .= '.html#'. $linereport['postid'] . '">'. $line['id'] . '</a></td><td>';
  2950. if ($line['file'] == 'removed') {
  2951. $tpl_page .= 'removed';
  2952. } elseif ($line['file'] == '') {
  2953. $tpl_page .= 'none';
  2954. } elseif ($line['file_type'] == 'jpg' || $line['file_type'] == 'gif' || $line['file_type'] == 'png') {
  2955. $tpl_page .= '<a href="'. KU_BOARDSPATH . '/'. $linereport['board'] . '/src/'. $line['file'] . '.'. $line['file_type'] . '"><img src="'. KU_BOARDSPATH . '/'. $linereport['board'] . '/thumb/'. $line['file'] . 's.'. $line['file_type'] . '" border="0"></a>';
  2956. } else {
  2957. $tpl_page .= '<a href="'. KU_BOARDSPATH . '/'. $linereport['board'] . '/src/'. $line['file'] . '.'. $line['file_type'] . '">File</a>';
  2958. }
  2959. $tpl_page .= '</td><td>';
  2960. if ($line['message'] != '') {
  2961. $tpl_page .= stripslashes($line['message']);
  2962. } else {
  2963. $tpl_page .= '&nbsp;';
  2964. }
  2965. $tpl_page .= '</td><td>';
  2966. if ($linereport['reason'] != '') {
  2967. $tpl_page .= htmlspecialchars(stripslashes($linereport['reason']));
  2968. } else {
  2969. $tpl_page .= '&nbsp;';
  2970. }
  2971. $tpl_page .= '</td><td>'. md5_decrypt($linereport['ip'], KU_RANDOMSEED) . '</td><td><a href="?action=reports&clear='. $linereport['id'] . '">Clear</a>&nbsp;&#91;<a href="?action=delposts&boarddir='. $linereport['board'] . '&del'. $post_threadorpost . 'id='. $line['id'] . '" title="Delete" onclick="return confirm(\'Are you sure you want to delete this thread/post?\');">D</a>&nbsp;<a href="'. KU_CGIPATH . '/manage_page.php?action=delposts&boarddir='. $linereport['board'] . '&del'. $post_threadorpost . 'id='. $line['id'] . '&postid='. $line['id'] . '" title="Delete &amp; Ban" onclick="return confirm(\'Are you sure you want to delete and ban this poster?\');">&amp;</a>&nbsp;<a href="?action=bans&banboard='. $linereport['board'] . '&banpost='. $line['id'] . '" title="Ban">B</a>&#93;</td></tr>';
  2972. } else {
  2973. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "reports` SET `cleared` = 1 WHERE id = " . $linereport['id'] . "");
  2974. }
  2975. }
  2976. }
  2977. $tpl_page .= '</table>';
  2978. } else {
  2979. $tpl_page .= 'No reports to show.';
  2980. }
  2981. }
  2982. /* Addition, modification, deletion, and viewing of bans */
  2983. function bans() {
  2984. global $tc_db, $tpl_page, $bans_class;
  2985. $this->ModeratorsOnly();
  2986. $reason = KU_BANREASON;
  2987. $ban_ip = ''; $ban_hash = ''; $ban_parentid = 0; $multiban = Array();
  2988. if (isset($_POST['modban']) && is_array($_POST['post']) && $_POST['board']) {
  2989. $ban_board_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_POST['board']) . "");
  2990. if (!empty($ban_board_id)) {
  2991. foreach ( $_POST['post'] as $post ) {
  2992. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = '" . $ban_board_id . "' AND `id` = " . intval($post) . "");
  2993. if (count($results) > 0) {
  2994. $multiban[] = md5_decrypt($results[0]['ip'], KU_RANDOMSEED);
  2995. $multiban_hash[] = $results[0]['file_md5'];
  2996. $multiban_parentid[] = $results[0]['parentid'];
  2997. }
  2998. }
  2999. }
  3000. }
  3001. if (isset($_GET['banboard']) && isset($_GET['banpost'])) {
  3002. $ban_board_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['banboard']) . "");
  3003. $ban_board = $_GET['banboard'];
  3004. $ban_post_id = $_GET['banpost'];
  3005. if (!empty($ban_board_id)) {
  3006. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = '" . $ban_board_id . "' AND `id` = " . $tc_db->qstr($_GET['banpost']) . "");
  3007. if (count($results) > 0) {
  3008. $ban_ip = md5_decrypt($results[0]['ip'], KU_RANDOMSEED);
  3009. $ban_hash = $results[0]['file_md5'];
  3010. $ban_parentid = $results[0]['parentid'];
  3011. } else {
  3012. $tpl_page.= _gettext('A post with that ID does not exist.') . '<hr />';
  3013. }
  3014. }
  3015. }
  3016. $instantban = false;
  3017. if ((isset($_GET['instant']) || isset($_GET['cp'])) && $ban_ip) {
  3018. if (isset($_GET['cp'])) {
  3019. $ban_reason = "You have been banned for posting Child Pornography. Your IP has been logged, and the proper authorities will be notified.";
  3020. } else {
  3021. if($_GET['reason']) {
  3022. $ban_reason = urldecode($_GET['reason']);
  3023. } else {
  3024. $ban_Reason = KU_BANREASON;
  3025. }
  3026. }
  3027. $instantban = true;
  3028. }
  3029. $tpl_page .= '<h2>'. _gettext('Bans') . '</h2><br />';
  3030. if (((isset($_POST['ip']) || isset($_POST['multiban'])) && isset($_POST['seconds']) && (!empty($_POST['ip']) || (empty($_POST['ip']) && !empty($_POST['multiban'])))) || $instantban) {
  3031. if ($_POST['seconds'] >= 0 || $instantban) {
  3032. $banning_boards = array();
  3033. $ban_boards = '';
  3034. if (isset($_POST['banfromall']) || $instantban) {
  3035. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `name` FROM `" . KU_DBPREFIX . "boards`");
  3036. foreach ($results as $line) {
  3037. if (!$this->CurrentUserIsModeratorOfBoard($line['name'], $_SESSION['manageusername'])) {
  3038. exitWithErrorPage('/'. $line['name'] . '/: '. _gettext('You can only make bans applying to boards you moderate.'));
  3039. }
  3040. }
  3041. } else {
  3042. if (empty($_POST['bannedfrom'])) {
  3043. exitWithErrorPage(_gettext('Please select a board.'));
  3044. }
  3045. if(isset($_POST['deleteposts'])) {
  3046. $_POST['deletefrom'] = $_POST['bannedfrom'];
  3047. }
  3048. foreach($_POST['bannedfrom'] as $board) {
  3049. if (!$this->CurrentUserIsModeratorOfBoard($board, $_SESSION['manageusername'])) {
  3050. exitWithErrorPage('/'. $board . '/: '. _gettext('You can only make bans applying to boards you moderate.'));
  3051. }
  3052. }
  3053. $ban_boards = implode('|', $_POST['bannedfrom']);
  3054. }
  3055. $ban_globalban = (isset($_POST['banfromall']) || $instantban) ? 1 : 0;
  3056. $ban_allowread = ($_POST['allowread'] == 0 || $instantban) ? 0 : 1;
  3057. if (isset($_POST['quickbanboardid'])) {
  3058. $ban_board_id = $_POST['quickbanboardid'];
  3059. }
  3060. if(isset($_POST['quickbanboard'])) {
  3061. $ban_board = $_POST['quickbanboard'];
  3062. }
  3063. if(isset($_POST['quickbanpostid'])) {
  3064. $ban_post_id = $_POST['quickbanpostid'];
  3065. }
  3066. $ban_ip = ($instantban) ? $ban_ip : $_POST['ip'];
  3067. $ban_duration = ($_POST['seconds'] == 0 || $instantban) ? 0 : $_POST['seconds'];
  3068. $ban_type = ($_POST['type'] <= 2 && $_POST['type'] >= 0) ? $_POST['type'] : 0;
  3069. $ban_reason = ($instantban) ? $ban_reason : $_POST['reason'];
  3070. $ban_note = ($instantban) ? '' : $_POST['staffnote'];
  3071. $ban_appealat = 0;
  3072. if (KU_APPEAL != '' && !$instantban) {
  3073. $ban_appealat = intval($_POST['appealdays'] * 86400);
  3074. if ($ban_appealat > 0) $ban_appealat += time();
  3075. }
  3076. if (isset($_POST['multiban']))
  3077. $ban_ips = unserialize($_POST['multiban']);
  3078. else
  3079. $ban_ips = Array($ban_ip);
  3080. $i = 0;
  3081. foreach ($ban_ips as $ban_ip) {
  3082. $ban_msg = '';
  3083. $whitelist = $tc_db->GetAll("SELECT `ipmd5` FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = 2");
  3084. if (in_array(md5($ban_ip), $whitelist)) {
  3085. exitWithErrorPage(_gettext('That IP is on the whitelist'));
  3086. }
  3087. if ($bans_class->BanUser($ban_ip, $_SESSION['manageusername'], $ban_globalban, $ban_duration, $ban_boards, $ban_reason, $ban_note, $ban_appealat, $ban_type, $ban_allowread)) {
  3088. $regenerated = array();
  3089. if (((KU_BANMSG != '' || $_POST['banmsg'] != '') && isset($_POST['addbanmsg']) && (isset($_POST['quickbanpostid']) || isset($_POST['quickmultibanpostid']))) || $instantban ) {
  3090. $ban_msg = ((KU_BANMSG == $_POST['banmsg']) || empty($_POST['banmsg'])) ? KU_BANMSG : $_POST['banmsg'];
  3091. if (isset($ban_post_id))
  3092. $postids = Array($ban_post_id);
  3093. else
  3094. $postids = unserialize($_POST['quickmultibanpostid']);
  3095. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `parentid`, `message` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $tc_db->qstr($ban_board_id) . " AND `id` = ".$tc_db->qstr($postids[$i])." LIMIT 1");
  3096. foreach($results AS $line) {
  3097. $tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `message` = ".$tc_db->qstr($line['message'] . $ban_msg)." WHERE `boardid` = " . $tc_db->qstr($ban_board_id) . " AND `id` = ".$tc_db->qstr($postids[$i]));
  3098. clearPostCache($postids[$i], $ban_board_id);
  3099. if ($line['parentid']==0) {
  3100. if (!in_array($postids, $regenerated)) {
  3101. $regenerated[] = $postids[$i];
  3102. }
  3103. } else {
  3104. if (!in_array($line['parentid'], $regenerated)) {
  3105. $regenerated[] = $line['parentid'];
  3106. }
  3107. }
  3108. }
  3109. }
  3110. $tpl_page .= _gettext('Ban successfully placed.')."<br />";
  3111. } else {
  3112. exitWithErrorPage(_gettext('Sorry, a generic error has occurred.'));
  3113. }
  3114. $logentry = _gettext('Banned') . ' '. $ban_ip;
  3115. $logentry .= ($ban_duration == 0) ? ' '. _gettext('without expiration') : ' '. _gettext('until') . ' '. date('F j, Y, g:i a', time() + $ban_duration);
  3116. $logentry .= ' - '. _gettext('Reason') . ': '. $ban_reason . (($ban_note) ? (" (".$ban_note.")") : ("")). ' - '. _gettext('Banned from') . ': ';
  3117. $logentry .= ($ban_globalban == 1) ? _gettext('All boards') . ' ' : '/'. implode('/, /', explode('|', $ban_boards)) . '/ ';
  3118. management_addlogentry($logentry, 8);
  3119. $ban_ip = '';
  3120. $i++;
  3121. }
  3122. if (count($regenerated) > 0) {
  3123. $board_class = new Board($ban_board);
  3124. foreach($regenerated as $thread) {
  3125. $board_class->RegenerateThreads($thread);
  3126. }
  3127. $board_class->RegeneratePages();
  3128. unset($board_class);
  3129. }
  3130. if(isset($_POST['deleteposts'])) {
  3131. $tpl_page .= '<br />';
  3132. $this->deletepostsbyip(true);
  3133. }
  3134. if ((isset($_GET['instant']) && !isset($_GET['cp']))) {
  3135. die("success");
  3136. }
  3137. if (isset($_POST['banhashtime']) && $_POST['banhashtime'] !== '' && ($_POST['hash'] !== '' || isset($_POST['multibanhashes'])) && $_POST['banhashtime'] >= 0) {
  3138. if (isset($_POST['multibanhashes']))
  3139. $banhashes = unserialize($_POST['multibanhashes']);
  3140. else
  3141. $banhashes = Array($_POST['hash']);
  3142. foreach ($banhashes as $banhash){
  3143. $results = $tc_db->GetOne("SELECT HIGH_PRIORITY COUNT(*) FROM `".KU_DBPREFIX."bannedhashes` WHERE `md5` = ".$tc_db->qstr($banhash)." LIMIT 1");
  3144. if ($results == 0) {
  3145. $tc_db->Execute("INSERT INTO `".KU_DBPREFIX."bannedhashes` ( `md5` , `bantime` , `description` ) VALUES ( ".$tc_db->qstr($banhash)." , ".$tc_db->qstr($_POST['banhashtime'])." , ".$tc_db->qstr($_POST['banhashdesc'])." )");
  3146. management_addlogentry('Banned md5 hash '. $banhash . ' with a description of '. $_POST['banhashdesc'], 8);
  3147. }
  3148. }
  3149. }
  3150. if (!empty($_POST['quickbanboard']) && !empty($_POST['quickbanthreadid'])) {
  3151. $tpl_page .= '<br /><br /><meta http-equiv="refresh" content="1;url='. KU_BOARDSPATH . '/'. $_POST['quickbanboard'] . '/';
  3152. if ($_POST['quickbanthreadid'] != '0') $tpl_page .= 'res/'. $_POST['quickbanthreadid'] . '.html';
  3153. $tpl_page .= '"><a href="'. KU_BOARDSPATH . '/'. $_POST['quickbanboard'] . '/';
  3154. if ($_POST['quickbanthreadid'] != '0') $tpl_page .= 'res/'. $_POST['quickbanthreadid'] . '.html';
  3155. $tpl_page .= '">'. _gettext('Redirecting') . '</a>...';
  3156. }
  3157. } else {
  3158. $tpl_page .= _gettext('Please enter a positive amount of seconds, or zero for a permanent ban.');
  3159. }
  3160. $tpl_page .= '<hr />';
  3161. } elseif (isset($_GET['delban']) && $_GET['delban'] > 0) {
  3162. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `id` = " . $tc_db->qstr($_GET['delban']) . "");
  3163. if (count($results) > 0) {
  3164. $unban_ip = md5_decrypt($results[0]['ip'], KU_RANDOMSEED);
  3165. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "banlist` WHERE `id` = " . $tc_db->qstr($_GET['delban']) . "");
  3166. $bans_class->UpdateHtaccess();
  3167. $tpl_page .= _gettext('Ban successfully removed.');
  3168. management_addlogentry(_gettext('Unbanned') . ' '. $unban_ip, 8);
  3169. } else {
  3170. $tpl_page .= _gettext('Invalid ban ID');
  3171. }
  3172. $tpl_page .= '<br /><hr />';
  3173. } elseif (isset($_GET['delhashid'])) {
  3174. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "bannedhashes` WHERE `id` = " . $tc_db->qstr($_GET['delhashid']) . "");
  3175. if (count($results) > 0) {
  3176. $tc_db->Execute("DELETE FROM `" . KU_DBPREFIX . "bannedhashes` WHERE `id` = " . $tc_db->qstr($_GET['delhashid']) . "");
  3177. $tpl_page .= _gettext('Hash removed from ban list.') . '<br /><hr />';
  3178. }
  3179. }
  3180. flush();
  3181. $isquickban = false;
  3182. $tpl_page .= '<form action="manage_page.php?action=bans" method="post" name="banform">';
  3183. if ((!empty($ban_ip) && isset($_GET['banboard']) && isset($_GET['banpost'])) || (!empty($multiban) && isset($_POST['board']) && isset($_POST['post']))) {
  3184. $isquickban = true;
  3185. $tpl_page .= '<input type="hidden" name="quickbanboard" value="'. (isset($_GET['banboard']) ? $_GET['banboard'] : $_POST['board']) . '" />';
  3186. if(!empty($multiban)) {
  3187. $tpl_page .= '<input type="hidden" name="quickbanboardid" value="'. $ban_board_id . '" /><input type="hidden" name="quickmultibanthreadid" value="'. htmlspecialchars(serialize($multiban_parentid)) . '" /><input type="hidden" name="quickmultibanpostid" value="'. htmlspecialchars(serialize($_POST['post'])) . '" />';
  3188. } else {
  3189. $tpl_page .= '<input type="hidden" name="quickbanboardid" value="'. $ban_board_id . '" /><input type="hidden" name="quickbanthreadid" value="'. $ban_parentid . '" /><input type="hidden" name="quickbanpostid" value="'. $_GET['banpost'] . '" />';
  3190. }
  3191. } elseif (isset($_GET['ip'])) {
  3192. $ban_ip = $_GET['ip'];
  3193. }
  3194. $tpl_page .= '<fieldset>
  3195. <legend>'. _gettext('IP address and ban type') . '</legend>
  3196. <label for="ip">'. _gettext('IP') . ':</label>';
  3197. if (!$multiban) {
  3198. $tpl_page .= '<input type="text" name="ip" id="ip" value="'. $ban_ip . '" />
  3199. <br /><label for="deleteposts">'. _gettext('Delete all posts by this IP') . ':</label>
  3200. <input type="checkbox" name="deleteposts" id="deleteposts" />';
  3201. }
  3202. else {
  3203. $tpl_page .= '<input type="hidden" name="multiban" value="'.htmlspecialchars(serialize($multiban)).'">
  3204. <input type="hidden" name="multibanhashes" value="'.htmlspecialchars(serialize($multiban_hash)).'"> Multiple IPs
  3205. <br /><label for="deleteposts">'. _gettext('Delete all posts by these IPs') . ':</label>
  3206. <input type="checkbox" name="deleteposts" id="deleteposts" />';
  3207. }
  3208. $tpl_page .= '<br />
  3209. <label for="allowread">'. _gettext('Allow read') . ':</label>
  3210. <select name="allowread" id="allowread"><option value="1">'._gettext('Yes').'</option><option value="0">'._gettext('No').'</option></select>
  3211. <div class="desc">'. _gettext('Whether or not the user(s) affected by this ban will be allowed to read the boards.') . '<br /><strong>'. _gettext('Warning') . ':</strong> '. _gettext('Selecting "No" will prevent any reading of any page on the level of the boards on the server. It will also act as a global ban.') . '</div><br />
  3212. <label for="type">'. _gettext('Type') . ':</label>
  3213. <select name="type" id="type"><option value="0">'. _gettext('Single IP') . '</option><option value="1">'. _gettext('IP Range') . '</option><option value="2">'. _gettext('Whitelist') . '</option></select>
  3214. <div class="desc">'. _gettext('The type of ban. A single IP can be banned by providing the full address. A whitelist ban prevents that IP from being banned. An IP range can be banned by providing the IP range you would like to ban, in this format: 123.123.12') . '</div><br />';
  3215. if ($isquickban && KU_BANMSG != '') {
  3216. $tpl_page .= '<label for="addbanmsg">'. _gettext('Add ban message') . ':</label>
  3217. <input type="checkbox" name="addbanmsg" id="addbanmsg" checked="checked" />
  3218. <div class="desc">'. _gettext('If checked, the configured ban message will be added to the end of the post.') . '</div><br />
  3219. <label for="banmsg">'. _gettext('Ban message') . ':</label>
  3220. <input type="text" name="banmsg" id="banmsg" value="'. htmlspecialchars(KU_BANMSG) . '" size='. strlen(KU_BANMSG) . '" />';
  3221. }
  3222. $tpl_page .='</fieldset>
  3223. <fieldset>
  3224. <legend> '. _gettext('Ban from') . '</legend>
  3225. <label for="banfromall"><strong>'. _gettext('All boards') . '</strong></label>
  3226. <input type="checkbox" name="banfromall" id="banfromall" /><br /><hr /><br />' .
  3227. $this->MakeBoardListCheckboxes('bannedfrom', $this->BoardList($_SESSION['manageusername'])) .
  3228. '</fieldset>';
  3229. if (isset($ban_hash)) {
  3230. $tpl_page .= '<fieldset>
  3231. <legend>'. _gettext('Ban file') . '</legend>
  3232. <input type="hidden" name="hash" value="'. $ban_hash . '" />
  3233. <label for="banhashtime">'. _gettext('Ban file hash for') . ':</label>
  3234. <input type="text" name="banhashtime" id="banhashtime" />
  3235. <div class="desc">'. _gettext('The amount of time to ban the hash of the image which was posted under this ID. Leave blank to not ban the image, 0 for an infinite global ban, or any number of seconds for that duration of a global ban.') . '</div><br />
  3236. <label for="banhashdesc">'. _gettext('Ban file hash description') . ':</label>
  3237. <input type="text" name="banhashdesc" id="banhashdesc" />
  3238. <div class=desc">'. _gettext('The description of the image being banned. Not applicable if the above box is blank.') . '</div>
  3239. </fieldset>';
  3240. }
  3241. $tpl_page .= '<fieldset>
  3242. <legend>'. _gettext('Ban duration, reason, and appeal information') . '</legend>
  3243. <label for="seconds">'. _gettext('Seconds') . ':</label>
  3244. <input type="text" name="seconds" id="seconds" />
  3245. <div class="desc">'. _gettext('Presets') . ':&nbsp;<a href="#" onclick="document.banform.seconds.value=\'3600\';return false;">1hr</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'86400\';return false;">1d</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'259200\';return false;">3d</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'604800\';return false;">1w</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'1209600\';return false;">2w</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'2592000\';return false;">30d</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'31536000\';return false;">1yr</a>&nbsp;<a href="#" onclick="document.banform.seconds.value=\'0\';return false;">'. _gettext('never') .'</a></div><br />
  3246. <label for="reason">'. _gettext('Reason') . ':</label>
  3247. <input type="text" name="reason" id="reason" value="'. $reason . '" />
  3248. <div class="desc">'. _gettext('Presets') .':&nbsp;';
  3249. $banReasons = unserialize(TSUKI_BANREASONS);
  3250. foreach ($banReasons as $key => $value) {
  3251. $tpl_page .= '<a href="#" onclick="document.banform.reason.value=\''. _gettext($value) .'\';return false;">' . _gettext($key) . '</a>&nbsp;';
  3252. }
  3253. $tpl_page .= '</a></div><br />
  3254. <label for="staffnote">'. _gettext('Staff Note') . '</label>
  3255. <input type="text" name="staffnote" id="staffnote" />
  3256. <div class="desc">'. _gettext('Presets') . ':&nbsp;';
  3257. foreach ($banReasons as $key => $value) {
  3258. $tpl_page .= '<a href="#" onclick="document.banform.staffnote.value=\''. _gettext($value) .'\';return false;">' . _gettext($key) . '</a>&nbsp;';
  3259. }
  3260. $tpl_page .= '|| '. _gettext('This message will be shown only on this page and only to staff, not to the user.') .'</div><br />';
  3261. if (KU_APPEAL != '') {
  3262. $tpl_page .= '<label for="appealdays">'. _gettext('Appeal (days)') . ':</label>
  3263. <input type="text" name="appealdays" id="appealdays" value="5" />
  3264. <div class="desc">'. _gettext('Presets') . ':&nbsp;<a href="#" onclick="document.banform.appealdays.value=\'0\';return false;">'. _gettext('No Appeal') .'</a>&nbsp;<a href="#" onclick="document.banform.appealdays.value=\'5\';return false;">5 '. _gettext('days') .'</a>&nbsp;<a href="#" onclick="document.banform.appealdays.value=\'10\';return false;">10 '. _gettext('days') .'</a>&nbsp;<a href="#" onclick="document.banform.appealdays.value=\'30\';return false;">30 '. _gettext('days') .'</a></div><br />';
  3265. }
  3266. $tpl_page .= '</fieldset>
  3267. <input type="submit" value="'. _gettext('Add ban') . '" /><img src="clear.gif" />
  3268. </form><br>
  3269. <span style="color:red"><b>ATTENTION! If you ban a spammer, also filter their spam in <a href="manage_page.php?action=spam">Block & Ban Content</a>!!!</span>
  3270. <hr /><br />';
  3271. for ($i = 2; $i >= 0; $i--) {
  3272. switch ($i) {
  3273. case 2:
  3274. $tpl_page .= '<strong>'. _gettext('Whitelisted IPs') . ':</strong><br />';
  3275. break;
  3276. case 1:
  3277. $tpl_page .= '<br /><strong>'. _gettext('IP Range Bans') . ':</strong><br />';
  3278. break;
  3279. case 0:
  3280. if (!empty($ban_ip))
  3281. $tpl_page .= '<br /><strong>'. _gettext('Previous bans on this IP') . ':</strong><br />';
  3282. else
  3283. $tpl_page .= '<br /><strong>'. _gettext('Single IP Bans') . ':</strong><br />';
  3284. break;
  3285. }
  3286. if (isset($_GET['allbans'])) {
  3287. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = '" . $i . "' AND `by` != 'SERVER' ORDER BY `id` DESC");
  3288. $hiddenbans = 0;
  3289. } elseif (isset($_GET['limit'])) {
  3290. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = '" . $i . "' ORDER BY `id` DESC LIMIT ".intval($_GET['limit']));
  3291. $hiddenbans = 0;
  3292. } else {
  3293. if (!empty($ban_ip) && $i == 0) {
  3294. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `ipmd5` = '" . md5(KU_SALT.$ban_ip) . "' AND `type` = '" . $i . "' AND `by` != 'SERVER' ORDER BY `id` DESC");
  3295. } else {
  3296. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = '" . $i . "' AND `by` != 'SERVER' ORDER BY `id` DESC LIMIT 15");
  3297. // Get the number of bans in the database of this type
  3298. $hiddenbans = $tc_db->GetAll("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = '" . $i . "'");
  3299. // Subtract 15 from the count, since we only want the number not shown
  3300. $hiddenbans = $hiddenbans[0][0] - 15;
  3301. }
  3302. }
  3303. if (count($results) > 0) {
  3304. $tpl_page .= '<table border="1" width="100%"><tr><th>';
  3305. $tpl_page .= ($i == 1) ? _gettext('IP Range') : _gettext('IP Address');
  3306. $tpl_page .= '</th><th>'. _gettext('Boards') . '</th><th>'. _gettext('Reason') . '</th><th>'. _gettext('Staff Note') . '</th><th>'. _gettext('Date added') . '</th><th>'. _gettext('Expires/Expired') . '</th><th>'. _gettext('Added By') . '</th><th>&nbsp;</th></tr>';
  3307. foreach ($results as $line) {
  3308. $tpl_page .= '<tr><td><a href="?action=bans&ip='. md5_decrypt($line['ip'], KU_RANDOMSEED) . '">'. md5_decrypt($line['ip'], KU_RANDOMSEED) . '</a></td><td>';
  3309. if ($line['globalban'] == 1) {
  3310. $tpl_page .= '<strong>'. _gettext('All boards') . '</strong>';
  3311. } elseif (!empty($line['boards'])) {
  3312. $tpl_page .= '<strong>/'. implode('/</strong>, <strong>/', explode('|', $line['boards'])) . '/</strong>&nbsp;';
  3313. }
  3314. $tpl_page .= '</td><td>';
  3315. $tpl_page .= (!empty($line['reason'])) ? htmlentities(stripslashes($line['reason'])) : '&nbsp;';
  3316. $tpl_page .= '</td><td>';
  3317. $tpl_page .= (!empty($line['staffnote'])) ? htmlentities(stripslashes($line['staffnote'])) : '&nbsp;';
  3318. $tpl_page .= '</td><td>'. date("F j, Y, g:i a", $line['at']) . '</td><td>';
  3319. $tpl_page .= ($line['until'] == 0) ? '<strong>'. _gettext('Does not expire') . '</strong>' : date("F j, Y, g:i a", $line['until']);
  3320. $tpl_page .= '</td><td>'. $line['by'] . '</td><td>[<a href="manage_page.php?action=bans&delban='. $line['id'] . '">'. _gettext('Delete') .'</a>]</td></tr>';
  3321. }
  3322. $tpl_page .= '</table>';
  3323. if ($hiddenbans > 0) {
  3324. $tpl_page .= sprintf(_gettext('%s bans not shown.'), $hiddenbans) .
  3325. ' <a href="?action=bans&allbans=1">'. _gettext('View all bans') . '</a>'.' <a href="?action=bans&limit=100">View last 100 bans</a>';
  3326. }
  3327. } else {
  3328. $tpl_page .= _gettext('There are currently no bans');
  3329. }
  3330. }
  3331. $tpl_page .= '<br /><br /><strong>'. _gettext('File hash bans') . ':</strong><br /><table border="1" width="100%"><tr><th>'. _gettext('Hash') . '</th><th>'. _gettext('Description') . '</th><th>'. _gettext('Ban time') . '</th><th>&nbsp;</th></tr>';
  3332. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `".KU_DBPREFIX."bannedhashes` ". ((!isset($_GET['allbans'])) ? ("LIMIT 5") : ("")));
  3333. if (count($results) == 0) {
  3334. $tpl_page .= '<tr><td colspan="4">'. _gettext('None') . '</td></tr>';
  3335. } else {
  3336. foreach ($results as $line) {
  3337. $tpl_page .= '<tr><td>'. $line['md5'] . '</td><td>'. $line['description'] . '</td><td>';
  3338. $tpl_page .= ($line['bantime'] == 0) ? '<strong>'. _gettext('Does not expire') . '</strong>' : $line['bantime'] . ' seconds';
  3339. $tpl_page .= '</td><td>[<a href="?action=bans&delhashid='. $line['id'] . '">x</a>]</td></tr>';
  3340. }
  3341. }
  3342. $tpl_page .= '</table>';
  3343. }
  3344. function proxycheck () {
  3345. /*
  3346. SamAir Proxy List Checker
  3347. Copyright (C) 2006 The SamAir Security (http://www.samair.ru/)
  3348. Version: 1.2 free, 2006/12/02
  3349. Free version limitations: you can check not more than 20 proxies per attempt.
  3350. */
  3351. set_time_limit(200);
  3352. /*
  3353. //Script configuration//////////////////////////////////////////////////////////
  3354. */
  3355. //------------------------------------------------------------------------------
  3356. //Define what type of checked proxies do you want to save in .txt files.
  3357. //Good proxies (elite and anonymous) saved in good.txt file. You can change the name
  3358. //of this file.
  3359. $goodfilename = "good.txt";
  3360. //Do you want to save bad proxies (yes/no)?
  3361. $badproxies = "no"; // if "yes" they saved in "badproxies.txt" file
  3362. //Do you want to save transparent proxies (yes/no)?
  3363. $transparent = "no"; // if "yes" they saved in "transparent.txt" file
  3364. //Do you want to save CoDeen proxies (yes/no)?
  3365. $codeen = "yes"; // if "yes" they saved in "codeen.txt" file
  3366. //------------------------------------------------------------------------------
  3367. //Define font colors of proxy types in checking results table
  3368. //Elite proxies
  3369. $celite = "#008000";
  3370. //Anonymous proxies
  3371. $canonymous = "#000080";
  3372. //CoDeen proxies
  3373. $ccodeen = "#000000";
  3374. //Transparent proxies
  3375. $ctransparent = "#996633";
  3376. //Bad or timeouted proxies
  3377. $cbadproxy = "#999999";
  3378. /*
  3379. End of script configuration/////////////////////////////////////////////////////
  3380. */
  3381. print "<form method=\"POST\" action=\"manage_page.php?action=proxycheck\">
  3382. <p><textarea rows=\"20\" cols=\"22\" name=\"send\"></textarea></p>
  3383. <br>
  3384. <input type=\"checkbox\" name=\"transparent\" value=\"ON\" checked> show transparent proxies in test results
  3385. <br>
  3386. <br>
  3387. <input type=\"checkbox\" name=\"badproxy\" value=\"ON\" checked> show bad proxies in test results
  3388. <br>
  3389. <br>
  3390. <input type=\"checkbox\" name=\"codeen\" value=\"ON\" checked> show CoDeen proxies in test results
  3391. <br>
  3392. <br>
  3393. <input type=\"submit\" value=\"send\">
  3394. </form>";
  3395. if(isset($_POST['send']))
  3396. {
  3397. $send = $_POST['send'];
  3398. print "Wait...<br><br>";
  3399. flush();
  3400. print "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"95%\">
  3401. <tr>
  3402. <td bgcolor=\"#C0C0C0\" align=\"center\" width=\"33%\"><b>Proxy port:IP</b></td>
  3403. <td bgcolor=\"#C0C0C0\" align=\"center\" width=\"33%\"><b>Type</b></td>
  3404. <td bgcolor=\"#C0C0C0\" align=\"center\" width=\"33%\"><b>Country</b></td>
  3405. </tr>
  3406. ";
  3407. $result = "http://www.samair.ru/proxy-service/proxyjudge.php?send=$send";
  3408. $result1 = file($result);
  3409. foreach($result1 as $line)
  3410. {
  3411. $line = trim($line);
  3412. @list($proxy, $type, $country) = explode("|", $line);
  3413. if($type == "live CoDeeN proxy" AND !isset($_POST['codeen'])) continue;
  3414. if($type == "transparent" AND !isset($_POST['transparent'])) continue;
  3415. if($type == "bad proxy or timeout" AND !isset($_POST['badproxy'])) continue;
  3416. if($type == "elite")
  3417. {
  3418. $fontcolor = $celite;
  3419. $handle = fopen(KU_ROOTDIR . $goodfilename, "a");
  3420. flock($handle,LOCK_EX);
  3421. fwrite($handle, $proxy . "\n");
  3422. flock($handle,LOCK_UN);
  3423. fclose($handle);
  3424. }
  3425. if($type == "anonymous")
  3426. {
  3427. $fontcolor = $canonymous;
  3428. $handle = fopen($goodfilename, "a");
  3429. flock($handle,LOCK_EX);
  3430. fwrite($handle, $proxy . "\n");
  3431. flock($handle,LOCK_UN);
  3432. fclose($handle);
  3433. }
  3434. if($type == "live CoDeeN proxy")
  3435. {
  3436. $fontcolor = $ccodeen;
  3437. if($codeen == "yes")
  3438. {
  3439. $handle = fopen("codeen.txt", "a");
  3440. flock($handle,LOCK_EX);
  3441. fwrite($handle, $proxy . "\n");
  3442. flock($handle,LOCK_UN);
  3443. fclose($handle);
  3444. }
  3445. }
  3446. if($type == "transparent")
  3447. {
  3448. $fontcolor = $ctransparent;
  3449. if($transparent == "yes")
  3450. {
  3451. $handle = fopen("transparent.txt", "a");
  3452. flock($handle,LOCK_EX);
  3453. fwrite($handle, $proxy . "\n");
  3454. flock($handle,LOCK_UN);
  3455. fclose($handle);
  3456. }
  3457. }
  3458. if($type == "bad proxy or timeout")
  3459. {
  3460. $fontcolor = $cbadproxy;
  3461. if($badproxies == "yes")
  3462. {
  3463. $handle = fopen("badproxies.txt", "a");
  3464. flock($handle,LOCK_EX);
  3465. fwrite($handle, $proxy . "\n");
  3466. flock($handle,LOCK_UN);
  3467. fclose($handle);
  3468. }
  3469. }
  3470. @$type = "<font color=\"". $fontcolor . "\">" . $type . "</font>";
  3471. print "<tr><td>" . $proxy . "</td><td>" . $type . "</td><td>" . $country . "</td></tr>\n";
  3472. }
  3473. print "<tr><td height=\"25\" colspan=\"3\" align=\"center\" valign=\"middle\"><small>Powered by <a href=\"http://samair.ru/\">SamAir Security</a></small></td></tr>\n";
  3474. print "</table>";
  3475. }
  3476. }
  3477. function appeals() {
  3478. global $tc_db, $tpl_page, $bans_class;
  3479. $this->ModeratorsOnly();
  3480. $tpl_page .= '<h2>'. _gettext('Appeals') . '</h2><br />';
  3481. $ban_ip = '';
  3482. if (isset($_GET['accept'])) {
  3483. if ($_GET['accept'] > 0) {
  3484. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `id` = " . $tc_db->qstr($_GET['accept']) . "");
  3485. if (count($results) > 0) {
  3486. foreach ($results as $line) {
  3487. $unban_ip = md5_decrypt($line['ip'], KU_RANDOMSEED);
  3488. }
  3489. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "banlist` SET `expired` = 1, `appealat` = -4 WHERE `id` = " . $tc_db->qstr($_GET['accept']) . "");
  3490. $bans_class->UpdateHtaccess();
  3491. $tpl_page .= _gettext('Ban successfully removed.');
  3492. management_addlogentry('Accepted appeal #'.$_GET['accept'].' from: '. $unban_ip, 8);
  3493. } else {
  3494. $tpl_page .= _gettext('Invalid ID');
  3495. }
  3496. $tpl_page .= '<hr />';
  3497. }
  3498. } elseif (isset($_GET['deny'])) {
  3499. if ($_GET['deny'] > 0) {
  3500. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `id` = " . $tc_db->qstr($_GET['deny']) . "");
  3501. if (count($results) > 0) {
  3502. foreach ($results as $line) {
  3503. $unban_ip = md5_decrypt($line['ip'], KU_RANDOMSEED);
  3504. }
  3505. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "banlist` SET `appealat` = -2 WHERE `id` = " . $tc_db->qstr($_GET['deny']) . "");
  3506. $bans_class->UpdateHtaccess();
  3507. $tpl_page .= _gettext('Appeal successfully denied.');
  3508. management_addlogentry(_gettext('Denied the ban appeal for') . ' '. $unban_ip, 8);
  3509. } else {
  3510. $tpl_page .= _gettext('Invalid ID');
  3511. }
  3512. $tpl_page .= '<hr />';
  3513. }
  3514. }
  3515. flush();
  3516. for ($i = 1; $i >= 0; $i--) {
  3517. if ($i == 1) {
  3518. $tpl_page .= '<strong>'. _gettext('IP Range bans') . ':</strong><br />';
  3519. } else {
  3520. $tpl_page .= '<br /><strong>'. _gettext('Single IP Bans') . ':</strong><br />';
  3521. }
  3522. if ($ban_ip != '') {
  3523. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `ipmd5` = '" . md5(KU_SALT.$ban_ip) . "' AND `type` = '" . $i . "' AND `expired` = 0 ORDER BY `id` DESC");
  3524. } else {
  3525. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "banlist` WHERE `type` = '" . $i . "' AND `appealat` = -1 AND `expired` = 0 ORDER BY `id` DESC");
  3526. }
  3527. if (count($results) > 0) {
  3528. $tpl_page .= '<table border="1" width="100%"><tr><th>';
  3529. if ($i == 1) {
  3530. $tpl_page .= 'IP Range';
  3531. } else {
  3532. $tpl_page .= 'IP Address';
  3533. }
  3534. $tpl_page .= '</th><th>Boards</th><th>Reason</th><th>Staff Note</th><th>Date Added</th><th>Expires</th><th>Added By</th><th>Appeal Message</th><th>Deny</th><th>Accept</th></tr>';
  3535. foreach ($results as $line) {
  3536. $tpl_page .= '<tr>';
  3537. $tpl_page .= '<td><a href="?action=bans&ip='. md5_decrypt($line['ip'], KU_RANDOMSEED) . '">'. md5_decrypt($line['ip'], KU_RANDOMSEED) . '</a></td><td>';
  3538. if ($line['globalban'] == '1') {
  3539. $tpl_page .= '<strong>'. _gettext('All boards') . '</strong>';
  3540. } else {
  3541. if ($line['boards'] != '') {
  3542. $tpl_page .= '<strong>/'. implode('/</strong>, <strong>/', explode('|', $line['boards'])) . '/</strong>&nbsp;';
  3543. }
  3544. }
  3545. $tpl_page .= '</td><td>';
  3546. if ($line['reason'] != '') {
  3547. $tpl_page .= htmlentities(stripslashes($line['reason']));
  3548. } else {
  3549. $tpl_page .= '&nbsp;';
  3550. }
  3551. $tpl_page .= '</td><td>';
  3552. if ($line['staffnote'] != '') {
  3553. $tpl_page .= htmlentities(stripslashes($line['staffnote']));
  3554. } else {
  3555. $tpl_page .= '&nbsp;';
  3556. }
  3557. $tpl_page .= '</td><td>'. date("F j, Y, g:i a", $line['at']) . '</td><td>';
  3558. if ($line['until'] == '0') {
  3559. $tpl_page .= '<strong>'. _gettext('Does not expire') . '</strong>';
  3560. } else {
  3561. $tpl_page .= date("F j, Y, g:i a", $line['until']);
  3562. }
  3563. $tpl_page .= '</td><td>'. $line['by'] . '</td>
  3564. <td>'.$line['appeal'].'</td>
  3565. <td><a href="manage_page.php?action=appeals&deny='. $line['id'] . '">:(</a></td>
  3566. <td><a href="manage_page.php?action=appeals&accept='. $line['id'] . '">:)</a></td>';
  3567. $tpl_page .= '</tr>';
  3568. }
  3569. $tpl_page .= '</table>';
  3570. if ($hiddenbans>0) {
  3571. $tpl_page .= sprintf(_gettext('%s bans not shown.'), $hiddenbans) .
  3572. ' <a href="?action=bans&allbans=1">'. _gettext('View all bans') . '</a>'.' <a href="?action=bans&limit=100">View last 100 bans</a>';
  3573. }
  3574. } else {
  3575. $tpl_page .= _gettext('There are currently no bans.');
  3576. }
  3577. }
  3578. }
  3579. /* Search for all posts by a selected IP address and delete them */
  3580. function deletepostsbyip($from_ban = false) {
  3581. global $tc_db, $tpl_page, $board_class;
  3582. $this->ModeratorsOnly();
  3583. if (!$from_ban) {
  3584. $tpl_page .= '<h2>'. _gettext('Delete all posts by IP') . '</h2><br />';
  3585. }
  3586. if (isset($_POST['ip']) || isset($_POST['multiban'])) {
  3587. if ($_POST['ip'] != '' || !empty($_POST['multiban'])) {
  3588. if (!$from_ban) {
  3589. $this->CheckToken($_POST['token']);
  3590. }
  3591. $deletion_boards = array();
  3592. $deletion_new_boards = array();
  3593. $board_ids = '';
  3594. if (isset($_POST['banfromall'])) {
  3595. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards`");
  3596. foreach ($results as $line) {
  3597. if (!$this->CurrentUserIsModeratorOfBoard($line['name'], $_SESSION['manageusername'])) {
  3598. exitWithErrorPage('/'. $line['name'] . '/: '. _gettext('You can only delete posts from boards you moderate.'));
  3599. }
  3600. $delete_boards[$line['id']] = $line['name'];
  3601. $board_ids .= $line['id'] . ',';
  3602. }
  3603. } else {
  3604. if (empty($_POST['deletefrom'])) {
  3605. exitWithErrorPage(_gettext('Please select a board.'));
  3606. }
  3607. foreach($_POST['deletefrom'] as $board) {
  3608. if (!$this->CurrentUserIsModeratorOfBoard($board, $_SESSION['manageusername'])) {
  3609. exitWithErrorPage('/'. $board . '/: '. _gettext('You can only delete posts from boards you moderate.'));
  3610. }
  3611. $id = $tc_db->GetOne("SELECT `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($board));
  3612. $board_ids .= $tc_db->qstr($id) . ',';
  3613. $delete_boards[$id] = $board;
  3614. }
  3615. }
  3616. $board_ids = substr($board_ids, 0, -1);
  3617. $i = 0;
  3618. if (isset($_POST['multiban']))
  3619. $ips = unserialize($_POST['multiban']);
  3620. else
  3621. $ips = Array($_POST['ip']);
  3622. foreach ($ips as $ip) {
  3623. $i = 0;
  3624. $post_list = $tc_db->GetAll("SELECT `id`, `boardid` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` IN (" . $board_ids . ") AND `IS_DELETED` = '0' AND `ipmd5` = '" . md5(KU_SALT.$ip) . "'");
  3625. if (count($post_list) > 0) {
  3626. foreach ($post_list as $post) {
  3627. $i++;
  3628. $post_class = new Post($post['id'], $delete_boards[$post['boardid']], $post['boardid']);
  3629. $post_class->Delete();
  3630. $boards_deleted[$post['boardid']] = $delete_boards[$post['boardid']];
  3631. unset($post_class);
  3632. }
  3633. $tpl_page .= _gettext('All threads/posts by that IP in selected boards successfully deleted.') . '<br /><strong>'. $i . '</strong> posts were removed.<br />';
  3634. management_addlogentry(_gettext('Deleted posts by ip') . ' '. $ip, 7);
  3635. }
  3636. else {
  3637. $tpl_page .= _gettext('No posts for that IP found');
  3638. }
  3639. if (isset($boards_deleted)) {
  3640. foreach ($boards_deleted as $board) {
  3641. $board_class = new Board($board);
  3642. $board_class->RegenerateAll();
  3643. unset($board_class);
  3644. }
  3645. }
  3646. }
  3647. $tpl_page .= '<hr />';
  3648. }
  3649. }
  3650. if (!$from_ban) {
  3651. $tpl_page .= '<form action="?action=deletepostsbyip" method="post">
  3652. <input type="hidden" name="token" value="' . $_SESSION['token'] . '" />
  3653. <fieldset><legend>IP</legend>
  3654. <label for="ip">'. _gettext('IP') .':</label>
  3655. <input type="text" id="ip" name="ip"';
  3656. if (isset($_GET['ip'])) {
  3657. $tpl_page .= ' value="'. $_GET['ip'] . '"';
  3658. }
  3659. $tpl_page .= ' /></fieldset><br /><fieldset>
  3660. <legend>'. _gettext('Boards') .'</legend>
  3661. <label for="banfromall"><strong>'. _gettext('All boards') .'</strong></label>
  3662. <input type="checkbox" id="banfromall" name="banfromall" /><br /><hr /><br />' .
  3663. $this->MakeBoardListCheckboxes('deletefrom', $this->BoardList($_SESSION['manageusername'])) .
  3664. '<br /></fieldset>
  3665. <input type="submit" value="'. _gettext('Delete posts') .'" />
  3666. </form>';
  3667. }
  3668. }
  3669. /* View recently uploaded images */
  3670. function recentimages() {
  3671. global $tc_db, $tpl_page;
  3672. $this->ModeratorsOnly();
  3673. if (!isset($_SESSION['imagesperpage'])) {
  3674. $_SESSION['imagesperpage'] = 50;
  3675. }
  3676. if (isset($_GET['show'])) {
  3677. if ($_GET['show'] == '25' || $_GET['show'] == '50' || $_GET['show'] == '75' || $_GET['show'] == '100') {
  3678. $_SESSION['imagesperpage'] = $_GET['show'];
  3679. }
  3680. }
  3681. $tpl_page .= '<h2>'. _gettext('Recently uploaded images') . '</h2><br />
  3682. '._gettext('Number of images to show per page').': <a href="?action=recentimages&show=25">25</a>, <a href="?action=recentimages&show=50">50</a>, <a href="?action=recentimages&show=75">75</a>, <a href="?action=recentimages&show=100">100</a> '._gettext('(note that this is a rough limit, more may be shown)').'<br />';
  3683. if (isset($_POST['clear'])) {
  3684. if ($_POST['clear'] != '') {
  3685. $clear_decrypted = md5_decrypt($_POST['clear'], KU_RANDOMSEED);
  3686. if ($clear_decrypted != '') {
  3687. $clear_unserialized = unserialize($clear_decrypted);
  3688. foreach ($clear_unserialized as $clear_sql) {
  3689. $tc_db->Execute($clear_sql);
  3690. }
  3691. $tpl_page .= _gettext('Successfully marked previous images as reviewed.').'<hr />';
  3692. }
  3693. }
  3694. }
  3695. $dayago = (time() - 86400);
  3696. $imagesshown = 0;
  3697. $reviewsql_array = array();
  3698. if ($imagesshown <= $_SESSION['imagesperpage']) {
  3699. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `" . KU_DBPREFIX . "boards`.`name` AS `boardname`, `" . KU_DBPREFIX . "posts`.`boardid` AS boardid, `" . KU_DBPREFIX . "posts`.`id` AS id, `" . KU_DBPREFIX . "posts`.`parentid` AS parentid, `" . KU_DBPREFIX . "posts`.`file` AS file, `" . KU_DBPREFIX . "posts`.`file_type` AS file_type, `" . KU_DBPREFIX . "posts`.`thumb_w` AS thumb_w, `" . KU_DBPREFIX . "posts`.`thumb_h` AS thumb_h FROM `" . KU_DBPREFIX . "posts`, `" . KU_DBPREFIX ."boards` WHERE (`file_type` = 'jpg' OR `file_type` = 'gif' OR `file_type` = 'png') AND `reviewed` = 0 AND `IS_DELETED` = 0 AND `" . KU_DBPREFIX . "boards`.`id` = `" . KU_DBPREFIX . "posts`.`boardid` ORDER BY `timestamp` DESC LIMIT " . intval($_SESSION['imagesperpage']));
  3700. if (count($results) > 0) {
  3701. $reviewsql = "UPDATE `" . KU_DBPREFIX . "posts` SET `reviewed` = 1 WHERE ";
  3702. $tpl_page .= '<table border="1">'. "\n";
  3703. foreach ($results as $line) {
  3704. $reviewsql .= '(`boardid` = '.$line['boardid'] .' AND `id` = '. $line['id'] . ') OR ';
  3705. $real_parentid = ($line['parentid'] == 0) ? $line['id'] : $line['parentid'];
  3706. $tpl_page .= '<tr><td><a href="'. KU_BOARDSPATH . '/'. $line['boardname'] . '/res/'. $real_parentid . '.html#'. $line['id'] . '">/'. $line['boardname'] . '/'. $line['id'] . '</td><td><a href="'. KU_BOARDSPATH . '/'. $line['boardname'] . '/res/'. $real_parentid . '.html#'. $line['id'] . '"><img src="'. KU_BOARDSPATH . '/'. $line['boardname'] . '/thumb/'. $line['file'] . 's.'. $line['file_type'] . '" width="'. $line['thumb_w'] . '" height="'. $line['thumb_h'] . '" border="0"></a></td></tr>';
  3707. }
  3708. $tpl_page .= '</table>';
  3709. $reviewsql = substr($reviewsql, 0, -3);
  3710. $reviewsql_array[] = $reviewsql;
  3711. $imagesshown += count($results);
  3712. }
  3713. }
  3714. if ($imagesshown > 0) {
  3715. $tpl_page .= '<br /><br />'. sprintf(_gettext('%s images shown.'), $imagesshown). '<br />';
  3716. $tpl_page .= '<form action="?action=recentimages" method="post">
  3717. <input type="hidden" name="clear" value="'. md5_encrypt(serialize($reviewsql_array), KU_RANDOMSEED) . '" />
  3718. <input type="submit" value="'. _gettext('Clear All On Page As Reviewed') .'" />
  3719. </form><br />';
  3720. } else {
  3721. $tpl_page .= '<br /><br />'. _gettext('No recent images currently need review.') ;
  3722. }
  3723. }
  3724. /* View recently posted posts */
  3725. function recentposts() {
  3726. global $tc_db, $tpl_page;
  3727. $this->ModeratorsOnly();
  3728. if (!isset($_SESSION['postsperpage'])) {
  3729. $_SESSION['postsperpage'] = 50;
  3730. }
  3731. if (isset($_GET['show'])) {
  3732. if ($_GET['show'] == '25' || $_GET['show'] == '50' || $_GET['show'] == '75' || $_GET['show'] == '100') {
  3733. $_SESSION['postsperpage'] = $_GET['show'];
  3734. }
  3735. }
  3736. $tpl_page .= '<h2>'. _gettext('Recent posts') . '</h2><br />
  3737. '._gettext('Number of posts to show per page').': <a href="?action=recentposts&show=25">25</a>, <a href="?action=recentposts&show=50">50</a>, <a href="?action=recentposts&show=75">75</a>, <a href="?action=recentposts&show=100">100</a> '._gettext('(note that this is a rough limit, more may be shown)').'<br />';
  3738. if (isset($_POST['clear'])) {
  3739. if ($_POST['clear'] != '') {
  3740. $clear_decrypted = md5_decrypt($_POST['clear'], KU_RANDOMSEED);
  3741. if ($clear_decrypted != '') {
  3742. $clear_unserialized = unserialize($clear_decrypted);
  3743. foreach ($clear_unserialized as $clear_sql) {
  3744. $tc_db->Execute($clear_sql);
  3745. }
  3746. $tpl_page .= _gettext('Successfully marked previous posts as reviewed.').'<hr />';
  3747. }
  3748. }
  3749. }
  3750. $dayago = (time() - 86400);
  3751. $postsshown = 0;
  3752. $reviewsql_array = array();
  3753. $boardlist = $this->BoardList($_SESSION['manageusername']);
  3754. if ($postsshown <= $_SESSION['postsperpage']) {
  3755. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `" . KU_DBPREFIX . "boards`.`name` AS `boardname`, `" . KU_DBPREFIX . "posts`.`boardid` AS boardid, `" . KU_DBPREFIX . "posts`.`id` AS id, `" . KU_DBPREFIX . "posts`.`parentid` AS parentid, `" . KU_DBPREFIX . "posts`.`message` AS message, `" . KU_DBPREFIX . "posts`.`ip` AS ip FROM `" . KU_DBPREFIX . "posts`, `" . KU_DBPREFIX ."boards` WHERE `" . KU_DBPREFIX . "posts`.`timestamp` > " . $dayago . " AND `reviewed` = 0 AND `IS_DELETED` = 0 AND `" . KU_DBPREFIX . "boards`.`id` = `" . KU_DBPREFIX . "posts`.`boardid` ORDER BY `timestamp` DESC LIMIT " . intval($_SESSION['postsperpage']));
  3756. if (count($results) > 0) {
  3757. $reviewsql = "UPDATE `" . KU_DBPREFIX . "posts` SET `reviewed` = 1 WHERE ";
  3758. $tpl_page .= '<table border="1" width="100%">'. "\n";
  3759. $tpl_page .= '<tr><th width="75px">'._gettext('Post Number').'</th><th>'._gettext('Post Message').'</th><th width="100px">'._gettext('Poster IP').'</th></tr>'. "\n";
  3760. foreach ($results as $line) {
  3761. $reviewsql .= '(`boardid` = '.$line['boardid'] .' AND `id` = '. $line['id'] . ') OR ';
  3762. $real_parentid = ($line['parentid'] == 0) ? $line['id'] : $line['parentid'];
  3763. $tpl_page .= '<tr><td><a href="'. KU_BOARDSPATH . '/'. $line['boardname'] . '/res/'. $real_parentid . '.html#'. $line['id'] . '">/'. $line['boardname'] . '/'. $line['id'] . '</td><td>'. stripslashes($line['message']) . '</td><td>'. md5_decrypt($line['ip'], KU_RANDOMSEED) . '</tr>';
  3764. }
  3765. $tpl_page .= '</table>';
  3766. $reviewsql = substr($reviewsql, 0, -3) . ' LIMIT '. count($results);
  3767. $reviewsql_array[] = $reviewsql;
  3768. $postsshown += count($results);
  3769. }
  3770. }
  3771. if ($postsshown > 0) {
  3772. $tpl_page .= '<br /><br />'. sprintf(_gettext('%s posts shown.'), $postsshown) .'<br />
  3773. <form action="?action=recentposts" method="post">
  3774. <input type="hidden" name="clear" value="'. md5_encrypt(serialize($reviewsql_array), KU_RANDOMSEED) . '" />
  3775. <input type="submit" value="'. _gettext('Clear All On Page As Reviewed') .'" />
  3776. </form><br />';
  3777. } else {
  3778. $tpl_page .= '<br /><br />'. _gettext('No recent posts currently need review.') ;
  3779. }
  3780. }
  3781. /*
  3782. * +------------------------------------------------------------------------------+
  3783. * Misc Functions
  3784. * +------------------------------------------------------------------------------+
  3785. */
  3786. /* Show APC info */
  3787. function apc() {
  3788. global $tpl_page;
  3789. if (KU_APC) {
  3790. $apc_info_system = apc_cache_info();
  3791. $apc_info_user = apc_cache_info('user');
  3792. //print_r($apc_info_user);
  3793. $tpl_page .= '<h2>APC</h2><h3>'. _gettext('System (File cache)') .'</h3><ul>';
  3794. $tpl_page .= '<li>Start time: <strong>'. date("y/m/d(D)H:i", $apc_info_system['start_time']) . '</strong></li>';
  3795. $tpl_page .= '<li>Hits: <strong>'. $apc_info_system['num_hits'] . '</strong></li>';
  3796. $tpl_page .= '<li>Misses: <strong>'. $apc_info_system['num_misses'] . '</strong></li>';
  3797. $tpl_page .= '<li>Entries: <strong>'. $apc_info_system['num_entries'] . '</strong></li>';
  3798. $tpl_page .= '</ul><br /><h3>User (kusaba)</h3><ul>';
  3799. $tpl_page .= '<li>Start time: <strong>'. date("y/m/d(D)H:i", $apc_info_user['start_time']) . '</strong></li>';
  3800. $tpl_page .= '<li>Hits: <strong>'. $apc_info_user['num_hits'] . '</strong></li>';
  3801. $tpl_page .= '<li>Misses: <strong>'. $apc_info_user['num_misses'] . '</strong></li>';
  3802. $tpl_page .= '<li>Entries: <strong>'. $apc_info_user['num_entries'] . '</strong></li>';
  3803. $tpl_page .= '</ul><br /><br /><a href="?action=clearcache">Clear APC cache</a>';
  3804. } else {
  3805. $tpl_page .= 'APC isn\'t enabled!';
  3806. }
  3807. }
  3808. /* Clear the APC cache */
  3809. function clearcache() {
  3810. global $tpl_page;
  3811. if (KU_APC) {
  3812. apc_clear_cache();
  3813. apc_clear_cache('user');
  3814. $tpl_page .= 'APC cache cleared.';
  3815. management_addlogentry(_gettext('Cleared APC cache'), 0);
  3816. } else {
  3817. $tpl_page .= 'APC isn\'t enabled!';
  3818. }
  3819. }
  3820. /* Generate a list of boards a moderator controls */
  3821. function BoardList($username) {
  3822. global $tc_db, $tpl_page;
  3823. $staff_boardsmoderated = array();
  3824. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `boards` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . $username . "' LIMIT 1");
  3825. if ($this->CurrentUserIsAdministrator() || $results[0][0] == 'allboards') {
  3826. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  3827. foreach ($resultsboard as $lineboard) {
  3828. $staff_boardsmoderated = array_merge($staff_boardsmoderated, array(array( 'name' => $lineboard['name'], 'id' => $lineboard['id'])));
  3829. }
  3830. } else {
  3831. if ($results[0][0] != '') {
  3832. foreach ($results as $line) {
  3833. $array_boards = explode('|', $line['boards']);
  3834. }
  3835. foreach ($array_boards as $this_board_name) {
  3836. $this_board_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($this_board_name) . "");
  3837. $staff_boardsmoderated = array_merge($staff_boardsmoderated, array(array('name' => $this_board_name, 'id' => $this_board_id)));
  3838. }
  3839. }
  3840. }
  3841. return $staff_boardsmoderated;
  3842. }
  3843. /* Generate a list of boards in query format */
  3844. function sqlboardlist() {
  3845. global $tc_db, $tpl_page;
  3846. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id` FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
  3847. $sqlboards = '';
  3848. foreach ($results as $line) {
  3849. $sqlboards .= 'posts_'. $line['name'] . ', ';
  3850. }
  3851. return substr($sqlboards, 0, -2);
  3852. }
  3853. /* Generate a dropdown box from a supplied array of boards */
  3854. function MakeBoardListDropdown($name, $boards, $all = false) {
  3855. $output = '<select name="'. $name . '"><option value="">'. _gettext('Select a Board') .'</option>';
  3856. if (!empty($boards)) {
  3857. if ($all) {
  3858. $output .= '<option value="all">'. _gettext('All Boards') .'</option>';
  3859. }
  3860. foreach ($boards as $board) {
  3861. $output .= '<option value="'. $board['name'] . '">/'. $board['name'] . '/</option>';
  3862. }
  3863. }
  3864. $output .= '</select>';
  3865. return $output;
  3866. }
  3867. /* Generate a series of checkboxes from a supplied array of boards */
  3868. function MakeBoardListCheckboxes($boxname, $boards) {
  3869. $output = '';
  3870. if (!empty($boards)) {
  3871. foreach ($boards as $board) {
  3872. $output .= '<label for="'. $boxname .'" >'. $board['name'] . '</label><input type="checkbox" name="'. $boxname . '[]" value="'. $board['name'] . '" /> '."\n";
  3873. }
  3874. }
  3875. return $output;
  3876. }
  3877. /* Generate a dropdown box for all sections */
  3878. function MakeSectionListDropDown($name, $selected) {
  3879. global $tc_db;
  3880. $output = '<select name="'. $name . '"><option value="">'. _gettext('Select a Section') .'</option>'. "\n";
  3881. $results = $tc_db->GetAll("SELECT `id`, `name` FROM `" . KU_DBPREFIX . "sections` ORDER BY `order` ASC");
  3882. if(count($results) > 0) {
  3883. foreach ($results as $section) {
  3884. if ($section['id'] == $selected) {
  3885. $select = ' selected="selected"';
  3886. } else {
  3887. $select = '';
  3888. }
  3889. $output .= '<option value="'. $section['id'] . '"'. $select . '>'. $section['name'] . '</option>'. "\n";
  3890. }
  3891. }
  3892. $output .= '</select><br />'. "\n";
  3893. return $output;
  3894. }
  3895. /* Delete files without their md5 stored in the database */
  3896. function delunusedimages($verbose = false) {
  3897. global $tc_db, $tpl_page;
  3898. $this->AdministratorsOnly();
  3899. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards`");
  3900. foreach ($resultsboard as $lineboard) {
  3901. if ($verbose) {
  3902. $tpl_page .= '<strong>'. _gettext('Looking for unused images in') .' /'. $lineboard['name'] . '/</strong><br />';
  3903. }
  3904. $file_md5list = array();
  3905. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `file_md5` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $lineboard['id'] . " AND `IS_DELETED` = 0 AND `file` != '' AND `file` != 'removed' AND `file_md5` != ''");
  3906. foreach ($results as $line) {
  3907. $file_md5list[] = $line['file_md5'];
  3908. }
  3909. $dir = './'. $lineboard['name'] . '/src';
  3910. $files = glob("$dir/{*.jpg, *.png, *.gif, *.swf}", GLOB_BRACE);
  3911. if (is_array($files)) {
  3912. foreach ($files as $file) {
  3913. if (in_array(md5_file(KU_BOARDSDIR . $lineboard['name'] . '/src/'. basename($file)), $file_md5list) == false) {
  3914. if (time() - filemtime(KU_BOARDSDIR . $lineboard['name'] . '/src/'. basename($file)) > 120) {
  3915. if ($verbose == true) {
  3916. $tpl_page .= sprintf(_gettext('A live record for %s was not found; the file has been removed.'), $file).'<br />';
  3917. }
  3918. unlink(KU_BOARDSDIR . $lineboard['name'] . '/src/'. basename($file));
  3919. @unlink(KU_BOARDSDIR . $lineboard['name'] . '/thumb/'. substr(basename($file), 0, -4) . 's'. substr(basename($file), strlen(basename($file)) - 4));
  3920. @unlink(KU_BOARDSDIR . $lineboard['name'] . '/thumb/'. substr(basename($file), 0, -4) . 'c'. substr(basename($file), strlen(basename($file)) - 4));
  3921. }
  3922. }
  3923. }
  3924. }
  3925. }
  3926. return true;
  3927. }
  3928. /* Delete replies currently not marked as deleted who belong to a thread which is marked as deleted */
  3929. function delorphanreplies($verbose = false) {
  3930. global $tc_db, $tpl_page;
  3931. $this->AdministratorsOnly();
  3932. $resultsboard = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards`");
  3933. foreach ($resultsboard as $lineboard) {
  3934. if ($verbose) {
  3935. $tpl_page .= '<strong>'. _gettext('Looking for orphans in') .' /'. $lineboard['name'] . '/</strong><br />';
  3936. }
  3937. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `parentid` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $lineboard['id'] . " AND `parentid` != '0' AND `IS_DELETED` = 0");
  3938. foreach ($results as $line) {
  3939. $exists_rows = $tc_db->GetAll("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $lineboard['id'] . " AND `id` = '" . $line['parentid'] . "' AND `IS_DELETED` = 0", 1);
  3940. if ($exists_rows[0] == 0) {
  3941. $post_class = new Post($line['id'], $lineboard['name'], $lineboard['id']);
  3942. $post_class->Delete;
  3943. unset($post_class);
  3944. if ($verbose) {
  3945. $tpl_page .= sprintf(_gettext('Reply #%1$s\'s thread (#%2$s) does not exist! It has been deleted.'),$line['id'],$line['parentid']).'<br />';
  3946. }
  3947. }
  3948. }
  3949. }
  3950. return true;
  3951. }
  3952. function spam() {
  3953. global $tpl_page;
  3954. $spam = KU_ROOTDIR . 'spam.txt';
  3955. if (!empty($_POST['spam'])) {
  3956. $this->CheckToken($_POST['token']);
  3957. file_put_contents($spam, $_POST['spam']);
  3958. $tpl_page .= '<hr />'. _gettext('Content filters successfully edited.') .'<hr />';
  3959. }
  3960. $content = htmlspecialchars(file_get_contents(KU_ROOTDIR . 'spam.txt'));
  3961. $tpl_page .= '<h2>'. _gettext('Block &amp; Ban Content') .'</h2> If a post matches any line on this list, it will be blocked from posting and the user banned for one hour.<br />'. "\n" .
  3962. '<form action="?action=spam" method="post">'. "\n" .
  3963. '<input type="hidden" name="token" value="' . $_SESSION['token'] . '" />' . "\n" .
  3964. '<textarea name="spam" rows="25" cols="80">' . htmlspecialchars($content) . '</textarea><br />' . "\n" .
  3965. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  3966. '</form>'. "\n";
  3967. }
  3968. function blockfilter() {
  3969. # BLOCKFILTER - New feature in Hurrchan 1.0.x
  3970. global $tpl_page;
  3971. $spam = KU_ROOTDIR . 'block.txt';
  3972. if (!empty($_POST['spam'])) {
  3973. file_put_contents($spam, $_POST['spam']);
  3974. $tpl_page .= '<hr />'. _gettext('Content filters successfully edited.') .'<hr />';
  3975. }
  3976. $content = htmlspecialchars(file_get_contents(KU_ROOTDIR . 'block.txt'));
  3977. $tpl_page .= '<h2>'. _gettext('Block Content') .'</h2> If a post matches any line on this list, it will be blocked from posting and the user will be given a post failure warning.<br />'. "\n" .
  3978. '<form action="?action=blockfilter" method="post">'. "\n" .
  3979. '<textarea name="spam" rows="25" cols="80">' . htmlspecialchars($content) . '</textarea><br />' . "\n" .
  3980. '<input type="submit" value="'. _gettext('Submit') .'" />'. "\n" .
  3981. '</form>'. "\n";
  3982. }
  3983. function chanspambl() {
  3984. /*
  3985. * Chan Spam Blacklist
  3986. * http://blacklist.oneechan.org/
  3987. *
  3988. * This function will provide a page to add to the chan spam blacklist, and search for IP's already entered.
  3989. */
  3990. global $tpl_page;
  3991. $tpl_page .= '<h2>'. _gettext('Search Chan Spam Blacklist') .'</h2> Search for records of an IP address in the chan spam blacklist.<br />'. "\n" .
  3992. '<form action="http://blacklist.oneechan.org/results.php" method="post">'. "\n" .
  3993. '<input type="text" name="ip">' . "\n" .
  3994. '<input type="submit" />'. "\n" .
  3995. '</form><br /><br /><br />'. "\n" .
  3996. '<h2>Add Blacklist Entry</h2> Add an entry to the chan spam blacklist.<br />'. "\n" .
  3997. '<form action="http://blacklist.oneechan.org/add.php" method="post">'. "\n" .
  3998. '<table><tr><td width="70">IP Address</td><td width="95">BL Type</td><td>Comments</td><td>Spam Content</td><td width="45">&nbsp;</td></tr>'. "\n" .
  3999. '<tr><td><input type="text" name="ip"></td><td>'. "\n" .
  4000. '<select name="type"><option value="Spam">Spam</option><option value="CP">CP</option><option value="Ban Evasion">Ban Evasion</option><option value="Raid/Invasion">Raid/Invasion</option><option value="Shitposting">Shitposting</option><option value="Site Attack">Site Attack</option><option value="NSFW-in-SFW">NSFW-in-SFW</option><option value="Abuse">Other Abuse</option></select></td>'. "\n" .
  4001. '<input type="hidden" name="addchan" value='. KU_NAME .'><input type="hidden" name="adduser" value='. $_SESSION['manageusername'] .'>'. "\n" .
  4002. '<td><input type="text" name="comment"></td><td><input type="text" name="spam"></td><td><input type="submit" name="Add"></tr></table>'. "\n" .
  4003. 'Note: All fields are required for a new entry.</form>'. "\n";
  4004. }
  4005. /* Gets the IP address of a post */
  4006. function getip() {
  4007. global $tc_db, $smarty, $tpl_page;
  4008. if(!$this->CurrentUserIsModerator() && !$this->CurrentUserIsAdministrator()) {
  4009. die();
  4010. }
  4011. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($_GET['boarddir']));
  4012. if (count($results) > 0) {
  4013. if (!$this->CurrentUserIsModeratorOfBoard($_GET['boarddir'], $_SESSION['manageusername'])) {
  4014. die();
  4015. }
  4016. $ip = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $tc_db->qstr($results[0]['id']) . " AND `id` = " . $tc_db->qstr($_GET['id']));
  4017. die("dnb-".$_GET['boarddir']."-".$_GET['id']."-".(($ip[0]['parentid'] == 0) ? ("y") : ("n"))."=".md5_decrypt($ip[0]['ip'], KU_RANDOMSEED));
  4018. }
  4019. die();
  4020. }
  4021. function editpost() {
  4022. global $tc_db, $tpl_page;
  4023. $this->ModeratorsOnly(); /*OR $this->AdministratorsOnly(); */ /*Select whether you want this option was for modetartors or only administators */
  4024. $board = isset($_GET['boarddir']) ? $_GET['boarddir'] : '';
  4025. $editpostid = isset($_GET['editpostid']) ? $_GET['editpostid'] : '';
  4026. $board_id = $tc_db->GetOne("SELECT HIGH_PRIORITY `id` FROM `". KU_DBPREFIX . "boards` WHERE `name` = ".$tc_db->qstr($board));
  4027. if($_POST['message']) {
  4028. $tc_db->Execute("UPDATE `" . KU_DBPREFIX . "posts` SET `message` = ".$tc_db->qstr($_POST['message'])." WHERE `boardid` = ".$board_id." AND `id` = ".$tc_db->qstr($editpostid)." ");
  4029. $board_class = new Board($board);
  4030. $board_class->RegenerateThreads(intval($_POST['thread']));
  4031. $board_class->RegeneratePages();
  4032. unset($board_class);
  4033. $tpl_page .= _gettext('Edit successful.') . ' <br /><hr />';
  4034. }
  4035. $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `parentid`,`message` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_id . " AND `id` = " . $tc_db->qstr($editpostid) . " ");
  4036. foreach ($results as $line) {
  4037. $parentid = $line['parentid'];
  4038. $message = $line['message'];
  4039. }
  4040. if($parentid == 0) { $parentid = $editpostid; }
  4041. $tpl_page .= '<h2>'. _gettext('Edit post ID: '.$editpostid.' from board: /'.$board.'/') . '</h2><br />';
  4042. $tpl_page .= '<form action="" method="post">
  4043. HTML:<br /><textarea cols="80" rows="15" name="message">'.$message.'</textarea><input type="hidden" name="thread" value="'.$parentid.'" /><br /><input type="submit" name="edit" value="Edit" /></form>';
  4044. }
  4045. }
  4046. function _mysqldump($mysql_database)
  4047. {
  4048. $sql="show tables;";
  4049. $result= mysql_query($sql);
  4050. if( $result)
  4051. {
  4052. while( $row= mysql_fetch_row($result))
  4053. {
  4054. _mysqldump_table_structure($row[0]);
  4055. _mysqldump_table_data($row[0]);
  4056. }
  4057. }
  4058. else
  4059. {
  4060. echo "/* no tables in $mysql_database */\n";
  4061. }
  4062. mysql_free_result($result);
  4063. }
  4064. function _mysqldump_table_structure($table)
  4065. {
  4066. echo "/* Table structure for table `$table` */\n";
  4067. echo "DROP TABLE IF EXISTS `$table`;\n\n";
  4068. $sql="show create table `$table`; ";
  4069. $result=mysql_query($sql);
  4070. if( $result)
  4071. {
  4072. if($row= mysql_fetch_assoc($result))
  4073. {
  4074. echo $row['Create Table'].";\n\n";
  4075. }
  4076. }
  4077. mysql_free_result($result);
  4078. }
  4079. function _mysqldump_table_data($table)
  4080. {
  4081. $sql="select * from `$table`;";
  4082. $result=mysql_query($sql);
  4083. if( $result)
  4084. {
  4085. $num_rows= mysql_num_rows($result);
  4086. $num_fields= mysql_num_fields($result);
  4087. if( $num_rows > 0)
  4088. {
  4089. echo "/* dumping data for table `$table` */\n";
  4090. $field_type=array();
  4091. $i=0;
  4092. while( $i < $num_fields)
  4093. {
  4094. $meta= mysql_fetch_field($result, $i);
  4095. array_push($field_type, $meta->type);
  4096. $i++;
  4097. }
  4098. //print_r( $field_type);
  4099. echo "insert into `$table` values\n";
  4100. $index=0;
  4101. while( $row= mysql_fetch_row($result))
  4102. {
  4103. echo "(";
  4104. for( $i=0; $i < $num_fields; $i++)
  4105. {
  4106. if( is_null( $row[$i]))
  4107. echo "null";
  4108. else
  4109. {
  4110. switch( $field_type[$i])
  4111. {
  4112. case 'int':
  4113. echo $row[$i];
  4114. break;
  4115. case 'string':
  4116. case 'blob' :
  4117. default:
  4118. echo "'".mysql_real_escape_string($row[$i])."'";
  4119. }
  4120. }
  4121. if( $i < $num_fields-1)
  4122. echo ",";
  4123. }
  4124. echo ")";
  4125. if( $index < $num_rows-1)
  4126. echo ",";
  4127. else
  4128. echo ";";
  4129. echo "\n";
  4130. $index++;
  4131. }
  4132. }
  4133. }
  4134. mysql_free_result($result);
  4135. echo "\n";
  4136. }
  4137. ?>