consumption.inc.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <?php
  2. // -------------------------------------------------------------------------------
  3. // | net2ftp: a web based FTP client |
  4. // | Copyright (c) 2003-2013 by David Gartner |
  5. // | |
  6. // | This program is free software; you can redistribute it and/or |
  7. // | modify it under the terms of the GNU General Public License |
  8. // | as published by the Free Software Foundation; either version 2 |
  9. // | of the License, or (at your option) any later version. |
  10. // | |
  11. // -------------------------------------------------------------------------------
  12. /*
  13. The consumption of server and network resources is logged per client IP
  14. address, and per target FTP server. The 2 database tables which contain
  15. the logs are:
  16. net2ftp_log_consumption_ipaddress: date, ipaddress, datatransfer, executiontime
  17. net2ftp_log_consumption_ftpserver: date, ftpserver, datatransfer, executiontime
  18. The database is read at the beginning of the script, and updated at the end
  19. of the script. There are 6 global variables:
  20. These variables
  21. $consumption_ipaddress_datatransfer,
  22. $consumption_ipaddress_executiontime,
  23. $consumption_ftpserver_datatransfer,
  24. $consumption_ftpserver_executiontime;
  25. contain the data transfer volume, script execution time and number of FTP
  26. servers that were accessed. They are inititialized at the beginning of the
  27. script and updated each time data is read/written from/to the FTP server.
  28. The variable
  29. $consumption_datatransfer_changeflag;
  30. is initialized as 0 and changed to 1 if data was transferred.
  31. This is to avoid having to run an SQL query if no data was transferred, e.g. when
  32. logging in, browsing the FTP server, when confirming an action or even for some
  33. actions like delete or chmod.
  34. The variable
  35. $consumption_database_updated;
  36. is initialized as 0 and changed to 1 when the database is updated with the consumption
  37. in putConsumption(). This is to avoid updating the database twice. The putConsumption()
  38. function is called from index.php and from shutdown() in filesystem.inc.php. On Windows
  39. the shutdown() function is called after *every* script execution.
  40. */
  41. // **************************************************************************************
  42. // **************************************************************************************
  43. // ** **
  44. // ** **
  45. function getConsumption() {
  46. // --------------
  47. // This function reads the consumption from the database.
  48. // It is run at the beginning of the script.
  49. // --------------
  50. // -------------------------------------------------------------------------
  51. // Global variables
  52. // -------------------------------------------------------------------------
  53. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  54. // -------------------------------------------------------------------------
  55. // Initial checks
  56. // -------------------------------------------------------------------------
  57. // Verify if a database is used, and if consumption checking is turned on. If not: don't continue.
  58. if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_consumption"] != "yes") { return true; }
  59. // When user is not logged in, the FTP server is not set
  60. if ($net2ftp_globals["ftpserver"] == "") { return true; }
  61. // If the REMOTE_ADDR is not filled in, then there is a problem (IP spoofing), so return an error
  62. if ($net2ftp_globals["REMOTE_ADDR"] == "") {
  63. setErrorVars(false, __("Unable to determine your IP address."), debug_backtrace(), __FILE__, __LINE__);
  64. return false;
  65. }
  66. // Add slashes to variables which are used in a SQL query, and which are
  67. // potentially unsafe (supplied by the user).
  68. // $date is calculated in this function
  69. // $time is calculated in this function
  70. $REMOTE_ADDR_safe = addslashes($net2ftp_globals["REMOTE_ADDR"]);
  71. $net2ftp_ftpserver_safe = addslashes($net2ftp_globals["ftpserver"]);
  72. // ----------------------------------------------
  73. // Do not log accesses, errors and consumption while the logs are being rotated
  74. // ----------------------------------------------
  75. $logStatus = getLogStatus();
  76. if ($net2ftp_result["success"] == false) { return false; }
  77. if ($logStatus != 0) { return true; }
  78. // -------------------------------------------------------------------------
  79. // Set the change flags to the initial value
  80. // -------------------------------------------------------------------------
  81. $net2ftp_globals["consumption_datatransfer_changeflag"] = 0;
  82. $net2ftp_globals["consumption_database_updated"] = 0;
  83. // -------------------------------------------------------------------------
  84. // Get date
  85. // -------------------------------------------------------------------------
  86. $date = date("Y-m-d");
  87. // -------------------------------------------------------------------------
  88. // Connect
  89. // -------------------------------------------------------------------------
  90. $mydb = connect2db();
  91. if ($net2ftp_result["success"] == false) { return false; }
  92. // -------------------------------------------------------------------------
  93. // Get consumed data volume and execution time by the current IP address
  94. // -------------------------------------------------------------------------
  95. $sqlquery1 = "SELECT datatransfer, executiontime FROM net2ftp_log_consumption_ipaddress WHERE date = '$date' AND ipaddress = '$REMOTE_ADDR_safe';";
  96. $result1 = mysql_query("$sqlquery1") or die("Unable to execute SQL SELECT query (getConsumption > sqlquery1) <br /> $sqlquery1");
  97. $nrofrows1 = mysql_num_rows($result1);
  98. if ($nrofrows1 == 0) {
  99. $net2ftp_globals["consumption_ipaddress_datatransfer"] = 0;
  100. $net2ftp_globals["consumption_ipaddress_executiontime"] = 0;
  101. }
  102. elseif ($nrofrows1 == 1) {
  103. $resultRow1 = mysql_fetch_row($result1);
  104. $net2ftp_globals["consumption_ipaddress_datatransfer"] = $resultRow1[0];
  105. $net2ftp_globals["consumption_ipaddress_executiontime"] = $resultRow1[1];
  106. }
  107. else {
  108. setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress contains duplicate rows."), debug_backtrace(), __FILE__, __LINE__);
  109. return false;
  110. }
  111. // -------------------------------------------------------------------------
  112. // Get consumed data volume and execution time to the current FTP server
  113. // -------------------------------------------------------------------------
  114. $sqlquery2 = "SELECT datatransfer, executiontime FROM net2ftp_log_consumption_ftpserver WHERE date = '$date' AND ftpserver = '$net2ftp_ftpserver_safe';";
  115. $result2 = mysql_query("$sqlquery2") or die("Unable to execute SQL SELECT query (getConsumption > sqlquery2) <br /> $sqlquery2");
  116. $nrofrows2 = mysql_num_rows($result2);
  117. if ($nrofrows2 == 0) {
  118. $net2ftp_globals["consumption_ftpserver_datatransfer"] = 0;
  119. $net2ftp_globals["consumption_ftpserver_executiontime"] = 0;
  120. }
  121. elseif ($nrofrows2 == 1) {
  122. $resultRow2 = mysql_fetch_row($result2);
  123. $net2ftp_globals["consumption_ftpserver_datatransfer"] = $resultRow2[0];
  124. $net2ftp_globals["consumption_ftpserver_executiontime"] = $resultRow2[1];
  125. }
  126. else {
  127. setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver contains duplicate rows."), debug_backtrace(), __FILE__, __LINE__);
  128. return false;
  129. }
  130. // Return true
  131. return true;
  132. } // End getConsumption
  133. // ** **
  134. // ** **
  135. // **************************************************************************************
  136. // **************************************************************************************
  137. // **************************************************************************************
  138. // **************************************************************************************
  139. // ** **
  140. // ** **
  141. function putConsumption() {
  142. // --------------
  143. // This function writes the consumption to the database.
  144. // It is run at the end of the script.
  145. // --------------
  146. // -------------------------------------------------------------------------
  147. // Global variables
  148. // -------------------------------------------------------------------------
  149. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  150. // -------------------------------------------------------------------------
  151. // Initial checks
  152. // -------------------------------------------------------------------------
  153. // Verify if a database is used, and if consumption checking is turned on. If not: don't continue.
  154. if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_consumption"] != "yes") { return true; }
  155. // When user is not logged in, the FTP server is not set
  156. if ($net2ftp_globals["ftpserver"] == "") { return true; }
  157. // If the REMOTE_ADDR is not filled in, then there is a problem (IP spoofing), so return an error
  158. if ($net2ftp_globals["REMOTE_ADDR"] == "") {
  159. setErrorVars(false, __("Unable to determine your IP address."), debug_backtrace(), __FILE__, __LINE__);
  160. return false;
  161. }
  162. // If the database has already been updated, don't do it a second time.
  163. // This is to avoid updating the database twice. The putConsumption() function
  164. // is called from index.php and from shutdown() in filesystem.inc.php. On Windows
  165. // the shutdown() function is called after *every* script execution.
  166. if ($net2ftp_globals["consumption_database_updated"] == 1) { return true; }
  167. // Add slashes to variables which are used in a SQL query, and which are
  168. // potentially unsafe (supplied by the user).
  169. // $date is calculated in this function
  170. // $time is calculated in this function
  171. $REMOTE_ADDR_safe = addslashes($net2ftp_globals["REMOTE_ADDR"]);
  172. $net2ftp_ftpserver_safe = addslashes($net2ftp_globals["ftpserver"]);
  173. // ----------------------------------------------
  174. // Do not log accesses, errors and consumption while the logs are being rotated
  175. // ----------------------------------------------
  176. $logStatus = getLogStatus();
  177. if ($net2ftp_result["success"] == false) { return false; }
  178. if ($logStatus != 0) { return true; }
  179. // -------------------------------------------------------------------------
  180. // Check the input
  181. // -------------------------------------------------------------------------
  182. // if (preg_match("/^[0-9]+$/", $net2ftp_globals["consumption_ipaddress_datatransfer) == FALSE) {
  183. // setErrorVars(false, __("The variable <b>consumption_ipaddress_datatransfer</b> is not numeric."), debug_backtrace(), __FILE__, __LINE__);
  184. // return false;
  185. // }
  186. // -------------------------------------------------------------------------
  187. // Connect
  188. // -------------------------------------------------------------------------
  189. $mydb = connect2db();
  190. if ($net2ftp_result["success"] == false) { return false; }
  191. // -------------------------------------------------------------------------
  192. // Get date
  193. // -------------------------------------------------------------------------
  194. $date = date("Y-m-d");
  195. // -------------------------------------------------------------------------
  196. // Put consumed data volume and execution time by the current IP address
  197. // -------------------------------------------------------------------------
  198. $sqlquery1 = "SELECT * FROM net2ftp_log_consumption_ipaddress WHERE date = '$date' AND ipaddress = '$REMOTE_ADDR_safe';";
  199. $result1 = mysql_query("$sqlquery1");
  200. $nrofrows1 = mysql_num_rows($result1);
  201. if ($nrofrows1 == 1) {
  202. $sqlquery2 = "UPDATE net2ftp_log_consumption_ipaddress SET datatransfer = '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "' WHERE date = '$date' AND ipaddress = '$REMOTE_ADDR_safe';";
  203. $result2 = mysql_query("$sqlquery2");
  204. $nrofrows2 = mysql_affected_rows($mydb);
  205. // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same,
  206. // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0
  207. // and the executiontime is the same as in the table.)
  208. // if ($nrofrows2 != 1) {
  209. // setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  210. // return false;
  211. // }
  212. }
  213. elseif ($nrofrows1 == 0) {
  214. $sqlquery3 = "INSERT INTO net2ftp_log_consumption_ipaddress VALUES('$date', '$REMOTE_ADDR_safe', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "');";
  215. $result3 = mysql_query("$sqlquery3");
  216. $nrofrows3 = mysql_affected_rows($mydb);
  217. if ($nrofrows3 != 1) {
  218. setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  219. return false;
  220. }
  221. }
  222. else {
  223. setErrorVars(false, __("Table net2ftp_log_consumption_ipaddress contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__);
  224. return false;
  225. }
  226. // MySQL > 4.1.0
  227. // $sqlquery1 = "INSERT INTO net2ftp_log_consumption_ipaddress VALUES('$date', '$REMOTE_ADDR_safe', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "') ON DUPLICATE KEY UPDATE datatransfer = '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "';";
  228. // -------------------------------------------------------------------------
  229. // Put consumed data volume and execution time to the current FTP server
  230. // -------------------------------------------------------------------------
  231. $sqlquery4 = "SELECT * FROM net2ftp_log_consumption_ftpserver WHERE date = '$date' AND ftpserver = '$net2ftp_ftpserver_safe';";
  232. $result4 = mysql_query("$sqlquery4");
  233. $nrofrows4 = mysql_num_rows($result4);
  234. if ($nrofrows4 == 1) {
  235. $sqlquery5 = "UPDATE net2ftp_log_consumption_ftpserver SET datatransfer = '" . $net2ftp_globals["consumption_ftpserver_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_ftpserver_executiontime"]) . "' WHERE date = '$date' AND ftpserver = '$net2ftp_ftpserver_safe';";
  236. $result5 = mysql_query("$sqlquery5");
  237. $nrofrows5 = mysql_affected_rows($mydb);
  238. // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same,
  239. // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0
  240. // and the executiontime is the same as in the table.)
  241. // if ($nrofrows5 != 1) {
  242. // setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  243. // return false;
  244. // }
  245. }
  246. elseif ($nrofrows4 == 0) {
  247. $sqlquery6 = "INSERT INTO net2ftp_log_consumption_ftpserver VALUES('$date', '$net2ftp_ftpserver_safe', '" . $net2ftp_globals["consumption_ftpserver_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ftpserver_executiontime"]) . "');";
  248. $result6 = mysql_query("$sqlquery6");
  249. $nrofrows6 = mysql_affected_rows($mydb);
  250. if ($nrofrows6 != 1) {
  251. setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  252. return false;
  253. }
  254. }
  255. else {
  256. setErrorVars(false, __("Table net2ftp_log_consumption_ftpserver contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__);
  257. return false;
  258. }
  259. // -------------------------------------------------------------------------
  260. // Update the net2ftp_log_access record with the consumed data volume and execution time
  261. // -------------------------------------------------------------------------
  262. $sqlquery7 = "SELECT * FROM net2ftp_log_access WHERE id = '" . $net2ftp_globals["log_access_id"] . "';";
  263. $result7 = mysql_query("$sqlquery7");
  264. $nrofrows7 = mysql_num_rows($result7);
  265. if ($nrofrows7 == 1) {
  266. $sqlquery8 = "UPDATE net2ftp_log_access SET datatransfer = '" . $net2ftp_globals["consumption_datatransfer"] . "', executiontime = '" . round($net2ftp_globals["consumption_executiontime"]) . "' WHERE id = '" . $net2ftp_globals["log_access_id"] . "'";
  267. $result8 = mysql_query("$sqlquery8");
  268. $nrofrows8 = mysql_affected_rows($mydb);
  269. // Don't check on the UPDATE nr of rows, because when the values in the variables and in the table are the same,
  270. // the $nrofrows2 is set to 0. (This happens on the Browse screen, when the loading is fast: the datatransfer is 0
  271. // and the executiontime is the same as in the table.)
  272. // if ($nrofrows8 != 1) {
  273. // setErrorVars(false, __("Table net2ftp_log_access could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  274. // return false;
  275. // }
  276. }
  277. elseif ($nrofrows7 == 0) {
  278. $sqlquery9 = "INSERT INTO net2ftp_log_access VALUES('$date', '$REMOTE_ADDR_safe', '" . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "', '" . round($net2ftp_globals["consumption_ipaddress_executiontime"]) . "');";
  279. $result9 = mysql_query("$sqlquery9");
  280. $nrofrows9 = mysql_affected_rows($mydb);
  281. if ($nrofrows9 != 1) {
  282. setErrorVars(false, __("Table net2ftp_log_access could not be updated."), debug_backtrace(), __FILE__, __LINE__);
  283. return false;
  284. }
  285. }
  286. else {
  287. setErrorVars(false, __("Table net2ftp_log_access contains duplicate entries."), debug_backtrace(), __FILE__, __LINE__);
  288. return false;
  289. }
  290. // -------------------------------------------------------------------------
  291. // If all 3 tables have been updated, set the flag to 1
  292. // -------------------------------------------------------------------------
  293. $net2ftp_globals["consumption_database_updated"] = 1;
  294. // Return true
  295. return true;
  296. } // End putConsumption
  297. // ** **
  298. // ** **
  299. // **************************************************************************************
  300. // **************************************************************************************
  301. // **************************************************************************************
  302. // **************************************************************************************
  303. // ** **
  304. // ** **
  305. function addConsumption($data, $time) {
  306. // --------------
  307. // This function adds the $data and $time given in the argument of the function
  308. // to the global variables
  309. // --------------
  310. // -------------------------------------------------------------------------
  311. // Global variables
  312. // -------------------------------------------------------------------------
  313. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  314. // -------------------------------------------------------------------------
  315. // Initial checks
  316. // -------------------------------------------------------------------------
  317. // Verify if a database is used, and if consumption checking is turned on. If not: don't continue.
  318. if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_consumption"] != "yes") { return true; }
  319. // Initialize variables if needed
  320. if (isset($net2ftp_globals["consumption_datatransfer"]) == false) { $net2ftp_globals["consumption_datatransfer"] = 0; }
  321. if (isset($net2ftp_globals["consumption_executiontime"]) == false) { $net2ftp_globals["consumption_executiontime"] = 0; }
  322. if (isset($net2ftp_globals["consumption_ipaddress_datatransfer"]) == false) { $net2ftp_globals["consumption_ipaddress_datatransfer"] = 0; }
  323. if (isset($net2ftp_globals["consumption_ipaddress_executiontime"]) == false) { $net2ftp_globals["consumption_ipaddress_executiontime"] = 0; }
  324. if (isset($net2ftp_globals["consumption_ftpserver_datatransfer"]) == false) { $net2ftp_globals["consumption_ftpserver_datatransfer"] = 0; }
  325. if (isset($net2ftp_globals["consumption_ftpserver_executiontime"]) == false) { $net2ftp_globals["consumption_ftpserver_executiontime"] = 0; }
  326. // -------------------------------------------------------------------------
  327. // Add the consumption to the global variables
  328. // -------------------------------------------------------------------------
  329. if ($data != "" && $data > 0) {
  330. $net2ftp_globals["consumption_datatransfer_changeflag"] = 1;
  331. $net2ftp_globals["consumption_datatransfer"] = $net2ftp_globals["consumption_datatransfer"] + $data;
  332. $net2ftp_globals["consumption_ipaddress_datatransfer"] = $net2ftp_globals["consumption_ipaddress_datatransfer"] + $data;
  333. $net2ftp_globals["consumption_ftpserver_datatransfer"] = $net2ftp_globals["consumption_ftpserver_datatransfer"] + $data;
  334. }
  335. if ($time != "" && $time > 0) {
  336. $net2ftp_globals["consumption_executiontime"] = $net2ftp_globals["consumption_executiontime"] + $time;
  337. $net2ftp_globals["consumption_ipaddress_executiontime"] = $net2ftp_globals["consumption_ipaddress_executiontime"] + $time;
  338. $net2ftp_globals["consumption_ftpserver_executiontime"] = $net2ftp_globals["consumption_ftpserver_executiontime"] + $time;
  339. }
  340. // Return true
  341. return true;
  342. } // End addConsumption
  343. // ** **
  344. // ** **
  345. // **************************************************************************************
  346. // **************************************************************************************
  347. // **************************************************************************************
  348. // **************************************************************************************
  349. // ** **
  350. // ** **
  351. function printConsumption() {
  352. // --------------
  353. // This function prints the global consumption variables.
  354. // It is only used for debugging.
  355. // --------------
  356. // -------------------------------------------------------------------------
  357. // Global variables
  358. // -------------------------------------------------------------------------
  359. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  360. // -------------------------------------------------------------------------
  361. // Print the variables
  362. // -------------------------------------------------------------------------
  363. echo "FTP server: " . $net2ftp_globals["ftpserver"] . "<br />\n";
  364. echo "Remote address: " . $net2ftp_globals["REMOTE_ADDR"] . "<br />\n";
  365. echo "consumption_datatransfer: " . $net2ftp_globals["consumption_datatransfer"] . "<br />\n";
  366. echo "consumption_executiontime: " . $net2ftp_globals["consumption_executiontime"] . "<br />\n";
  367. echo "consumption_ipaddress_datatransfer: " . $net2ftp_globals["consumption_ipaddress_datatransfer"] . "<br />\n";
  368. echo "consumption_ipaddress_executiontime: " . $net2ftp_globals["consumption_ipaddress_executiontime"] . "<br />\n";
  369. echo "consumption_ftpserver_datatransfer: " . $net2ftp_globals["consumption_ftpserver_datatransfer"] . "<br />\n";
  370. echo "consumption_ftpserver_executiontime: " . $net2ftp_globals["consumption_ftpserver_executiontime"] . "<br />\n";
  371. echo "consumption_datatransfer_changeflag: " . $net2ftp_globals["consumption_datatransfer_changeflag"] . "<br />\n";
  372. echo "consumption_ipaddress_executiontime: " . $net2ftp_globals["consumption_ipaddress_executiontime"] . "<br />\n";
  373. } // End printConsumption()
  374. // ** **
  375. // ** **
  376. // **************************************************************************************
  377. // **************************************************************************************
  378. // **************************************************************************************
  379. // **************************************************************************************
  380. // ** **
  381. // ** **
  382. function checkConsumption() {
  383. // --------------
  384. // This function checks the consumption and returns an error message if
  385. // the limit has been reached.
  386. // It returns true if all is OK, false if the limit has been reached.
  387. // --------------
  388. // -------------------------------------------------------------------------
  389. // Global variables
  390. // -------------------------------------------------------------------------
  391. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  392. // -------------------------------------------------------------------------
  393. // Initial checks
  394. // -------------------------------------------------------------------------
  395. // Verify if a database is used, and if consumption checking is turned on. If not: don't continue.
  396. if ($net2ftp_settings["use_database"] != "yes" || $net2ftp_settings["check_consumption"] != "yes") { return true; }
  397. // -------------------------------------------------------------------------
  398. // Check if the limit has been reached
  399. // -------------------------------------------------------------------------
  400. if ($net2ftp_globals["consumption_ipaddress_datatransfer"] > $net2ftp_settings["max_consumption_ipaddress_datatransfer"]) { return false; }
  401. if ($net2ftp_globals["consumption_ipaddress_executiontime"] > $net2ftp_settings["max_consumption_ipaddress_executiontime"]) { return false; }
  402. if ($net2ftp_globals["consumption_ftpserver_datatransfer"] > $net2ftp_settings["max_consumption_ftpserver_datatransfer"]) { return false; }
  403. if ($net2ftp_globals["consumption_ftpserver_executiontime"] > $net2ftp_settings["max_consumption_ftpserver_executiontime"]) { return false; }
  404. return true;
  405. } // End checkConsumption()
  406. // ** **
  407. // ** **
  408. // **************************************************************************************
  409. // **************************************************************************************
  410. ?>