PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/banned/importBans.php

http://globalban-spanish.googlecode.com/
PHP | 230 lines | 165 code | 34 blank | 31 comment | 22 complexity | 6a9baae72b3dadff0847ab236fe8d352 MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of GlobalBan.
  4. Written by Stefan Jonasson <soynuts@unbuinc.net>
  5. Copyright 2008 Stefan Jonasson
  6. GlobalBan is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. GlobalBan is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GlobalBan. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. include_once(ROOTDIR."/include/database/class.BanQueries.php");
  18. include_once(ROOTDIR."/include/database/class.ServerQueries.php");
  19. include_once(ROOTDIR."/include/database/class.ReasonQueries.php");
  20. $lan_file = ROOTDIR.'/languages/'.$LANGUAGE.'/lan_importBans.php';
  21. include(file_exists($lan_file) ? $lan_file : ROOTDIR."/languages/English/lan_importBans.php");
  22. // Import bans from banned_users.cfg file
  23. if($fullPower) {
  24. $bansAdded = false;
  25. $reasonQueries = new ReasonQueries();
  26. // Get list of ban reasons
  27. $banReasons = $reasonQueries->getReasonList();
  28. // If this is set, then that means a server is being added
  29. if(isset($_POST['submitImport'])) {
  30. // Parse input and add bans
  31. $reason = $_POST['reason']; // Reason Id
  32. $tempName = $_FILES['cfgfile']['tmp_name']; // Temp name of when it is uploaded
  33. if(is_uploaded_file($tempName)) {
  34. $bans = "";
  35. $f = fopen($tempName, 'r' );
  36. while( $data = fread( $f, 4096 ) ) { $bans .= $data; }
  37. fclose( $f );
  38. $banLines = explode("\n", $bans);
  39. $banQueries = new BanQueries();
  40. $serverQueries = new ServerQueries();
  41. // Constant Variables
  42. $serverId = $serverQueries->getFirstServer(); // We need to assign it to a valid server for it to display
  43. $nameOfBanned = ""; // Name is unknown
  44. $banner = ""; // Don't know who banner is, so leave empty
  45. $count = 0;
  46. $failed = 0;
  47. $failedIDs = "";
  48. foreach($banLines as $banLine) {
  49. echo $banLine."<br>";
  50. $ban = explode(" ", $banLine);
  51. // 0 = banid (discard)
  52. // 1 = length
  53. // 2 = steamid
  54. $length = $ban[1]; // Length of ban in minutes
  55. $steamId = $ban[2]; // Steam ID of banned
  56. $timeScale = "minutes";
  57. $banId = -1;
  58. if($steamId != "") {
  59. if($length > 0) {
  60. $lengthInSec = $length*60; // Convert to seconds
  61. $expireDate = time() + $lengthInSec; // Expire date
  62. // Add the new ban non-perma ban
  63. $banId = $banQueries->addBan($steamId, $length, $timeScale, $expireDate, $reason, $banner, 0, $nameOfBanned, $serverId, null, '');
  64. } else {
  65. // Add perma ban
  66. $banId = $banQueries->addBan($steamId, $length, $timeScale, time(), $reason, $banner, 0, $nameOfBanned, $serverId, null, '');
  67. }
  68. if($banId > 0) {
  69. $count++;
  70. } else {
  71. $failed++;
  72. $failedIDs .= " - ".$LAN_IMPORTBANS_015.$steamId."<br>";
  73. }
  74. }
  75. }
  76. $bansAdded = true;
  77. }
  78. }
  79. // The XML form was submitted
  80. if(isset($_POST['submitXMLImport'])) {
  81. $reason = $_POST['reasonXML']; // Reason Id
  82. $reason = $_POST['reason']; // Reason Id
  83. $tempName = $_FILES['file']['tmp_name']; // Temp name of when it is uploaded
  84. $count = 0;
  85. $alreadyAdded = 0;
  86. $alreadyDs = "";
  87. $failed = 0;
  88. if(is_uploaded_file($tempName)) {
  89. $banQueries = new BanQueries();
  90. $xml = "";
  91. $f = fopen($tempName, 'r' );
  92. while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
  93. fclose( $f );
  94. preg_match_all("/\<Ban\>(.*?)\<\/Ban\>/s", $xml, $banBlocks);
  95. foreach($banBlocks[1] as $block ) {
  96. preg_match_all( "/\<SteamID\>(.*?)\<\/SteamID\>/", $block, $steamId);
  97. preg_match_all( "/\<IP\>(.*?)\<\/IP\>/", $block, $ip);
  98. preg_match_all( "/\<Name\>(.*?)\<\/Name\>/", $block, $name);
  99. preg_match_all( "/\<Length\>(.*?)\<\/Length\>/", $block, $length);
  100. preg_match_all( "/\<TimeScale\>(.*?)\<\/TimeScale\>/", $block, $timeScale);
  101. preg_match_all( "/\<AddDate\>(.*?)\<\/AddDate\>/", $block, $addDate);
  102. preg_match_all( "/\<ExpireDate\>(.*?)\<\/ExpireDate\>/", $block, $expireDate);
  103. preg_match_all( "/\<Webpage\>(.*?)\<\/Webpage\>/", $block, $webpage);
  104. $id = $banQueries->importBan($steamId[1][0], $name[1][0], $length[1][0], $timeScale[1][0], $addDate[1][0], $expireDate[1][0], $webpage[1][0], $reason, $ip[1][0]);
  105. if($id > 0) {
  106. $count++;
  107. } else {
  108. $alreadyAdded++;
  109. $alreadyDs .= " - ".$LAN_IMPORTBANS_015.$steamId."<br>";
  110. }
  111. }
  112. $bansAdded = true;
  113. }
  114. }
  115. ?>
  116. <?php
  117. // Display that the changes were successful
  118. if($bansAdded) {
  119. ?><h5 class="error"><?php echo $count ?> <?php echo $LAN_IMPORTBANS_001; ?><br/>
  120. <?php
  121. if($alreadyAdded > 0) {
  122. echo $alreadyAdded . $LAN_IMPORTBANS_012 . "<br/><br/>";
  123. }
  124. if($failed > 0) {
  125. echo $LAN_IMPORTBANS_013 . $failed.$LAN_IMPORTBANS_014 . "<br/><br/>";
  126. }
  127. ?>
  128. </h5><?php
  129. echo $alreadyIDs;
  130. echo $failedIDs;
  131. }
  132. ?>
  133. <div class="tborder">
  134. <div id="tableHead">
  135. <div><b><?php echo $LAN_IMPORTBANS_002; ?></b></div>
  136. </div>
  137. <form action="index.php?page=importBans" method="POST" enctype="multipart/form-data">
  138. <table class="bordercolor" width="100%" cellspacing="1" cellpadding="5" border="0" style="margin-top: 1px;">
  139. <tr class="rowColor2">
  140. <th style="text-align: left;"><?php echo $LAN_IMPORTBANS_003; ?></th>
  141. <th style="text-align: left;"><?php echo $LAN_IMPORTBANS_004; ?></th>
  142. </tr>
  143. <tr class="rowColor1">
  144. <td><?php echo $LAN_IMPORTBANS_005; ?></td>
  145. <td><?php echo $LAN_IMPORTBANS_006; ?></td>
  146. </tr>
  147. <tr class="rowColor2">
  148. <td width="1%" nowrap><?php echo $LAN_IMPORTBANS_007; ?>
  149. <select name="reason">
  150. <?php
  151. if(count($banReasons > 0)) {
  152. for($i=0; $i<count($banReasons);$i++) {
  153. $reason = $banReasons[$i];
  154. ?><option value="<?php echo $reason->getId(); ?>"><?php echo $reason->getReason(); ?></option><?php
  155. }
  156. } else {
  157. ?><option value="-1"><?php echo $LAN_IMPORTBANS_008; ?></option><?php
  158. }
  159. ?>
  160. </select>
  161. </td>
  162. <td width="1%" nowrap><?php echo $LAN_IMPORTBANS_007; ?>
  163. <select name="reasonXML">
  164. <?php
  165. if(count($banReasons > 0)) {
  166. for($i=0; $i<count($banReasons);$i++) {
  167. $reason = $banReasons[$i];
  168. ?><option value="<?php echo $reason->getId(); ?>"><?php echo $reason->getReason(); ?></option><?php
  169. }
  170. } else {
  171. ?><option value="-1"><?php echo $LAN_IMPORTBANS_008; ?></option><?php
  172. }
  173. ?>
  174. </select>
  175. </td>
  176. </tr>
  177. <tr class="rowColor1">
  178. <td><input id="file" name="cfgfile" size="40" type="file" /></td>
  179. <td><input id="file" name="file" size="40" type="file" /></td>
  180. </tr>
  181. <tr class="rowColor2">
  182. <td><input type="submit" name="submitImport" value="<?php echo $LAN_IMPORTBANS_009; ?>"/></td>
  183. <td><input type="submit" name="submitXMLImport" value="<?php echo $LAN_IMPORTBANS_010; ?>"/></td>
  184. </tr>
  185. </table>
  186. </form>
  187. </div>
  188. <br/>
  189. <h5><?php echo $LAN_IMPORTBANS_011; ?></h5>
  190. <?php
  191. }
  192. ?>