Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.88 KB | None | 0 0
  1. <?php
  2.  
  3. function open_logs($CONF_LOG) {
  4. return fopen($CONF_LOG, "a");
  5. }
  6.  
  7. function do_log($stdlog, $text_log) {
  8. fputs($stdlog, get_date() . " " . $text_log . "\n");
  9. }
  10.  
  11. function do_log_sql($stdlog, $text_log, $child) {
  12. $LINK = $GLOBALS["LINK"];
  13. if (!mysql_ping($LINK)) {
  14. $do_mysql_reconect = 1;
  15. fputs($stdlog, get_date() . " " . $text_log . "\n");
  16. fputs($stdlog, get_date() . " " . "Child " . $child . " MySQL Connect failed" . "\n");
  17. }
  18. else {
  19. fputs($stdlog, get_date() . " " . $text_log . "\n");
  20. }
  21. while ($do_mysql_reconect == 1) {
  22. $config_file = "../etc/config.xml";
  23. if (file_exists($config_file)) {
  24. $xml = simplexml_load_file($config_file);
  25. $CONF_MYSQL_HOST = (string)$xml->parameters->mysql->host;
  26. $CONF_MYSQL_USERNAME = (string)$xml->parameters->mysql->username;
  27. $CONF_MYSQL_PASSWORD = (string)$xml->parameters->mysql->password;
  28. $CONF_MYSQL_DBNAME = (string)$xml->parameters->mysql->dbname;
  29. }
  30. $GLOBALS["LINK"] = mysql_pconnect($CONF_MYSQL_HOST, $CONF_MYSQL_USERNAME, $CONF_MYSQL_PASSWORD);
  31. mysql_select_db($CONF_MYSQL_DBNAME, $LINK);
  32. mysql_query("SET NAMES koi8r", $LINK) || do_log_sql($stdlog, "#0000 " . mysql_error($GLOBALS["LINK"]), $child);
  33. mysql_query("SET NAMES koi8r", $LINK) || do_log_sql($stdlog, "#0000 " . mysql_error($GLOBALS["LINK"]), $child);
  34. mysql_query("SET CHARSET koi8r", $LINK) || do_log_sql($stdlog, "#0000 " . mysql_error($GLOBALS["LINK"]), $child);
  35. mysql_query("SET CHARSET koi8r", $LINK) || do_log_sql($stdlog, "#0000 " . mysql_error($GLOBALS["LINK"]), $child);
  36. if (mysql_ping($LINK)) {
  37. $do_mysql_reconect = 0;
  38. fputs($stdlog, get_date() . " " . "Child " . $child . " MySQL Connect restored" . "\n");
  39. }
  40. sleep(5);
  41. continue;
  42. }
  43. $return_var = false;
  44. return $return_var;
  45. }
  46.  
  47. function get_date() {
  48. $date_current = date("d.m.Y H:i:s");
  49. return $date_current;
  50. }
  51.  
  52. function billing_init_packets_pool($LINK, $stdlog, $child) {
  53. $packets = (array());
  54. $i = 0;
  55. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_PACKET_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#132 " . mysql_error($LINK), $child);
  56. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_PACKET_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#132 " . mysql_error($LINK), $child);
  57. while ($i < mysql_num_rows($result)) {
  58. $i++;
  59. $res = mysql_fetch_array($result);
  60. $packets[$i] = $res;
  61. continue;
  62. }
  63. mysql_free_result($result);
  64. return $packets;
  65. }
  66.  
  67. function billing_init_pools($LINK, $stdlog, $child) {
  68. $packets = (array());
  69. $i = 0;
  70. $result = mysql_query("SELECT poolid,usegw,poolmask,poolgw FROM " . BILL_IPPOOL . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#145 " . mysql_error($LINK), $child);
  71. $result = mysql_query("SELECT poolid,usegw,poolmask,poolgw FROM " . BILL_IPPOOL . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#145 " . mysql_error($LINK), $child);
  72. while ($i < mysql_num_rows($result)) {
  73. $i++;
  74. $res = mysql_fetch_array($result);
  75. $packets[$res["poolid"]] = $res;
  76. continue;
  77. }
  78. mysql_free_result($result);
  79. return $packets;
  80. }
  81.  
  82. function billing_init_packets($LINK, $stdlog, $child) {
  83. $packets = (array());
  84. $i = 0;
  85. $result = mysql_query("SELECT * FROM " . BILL_PACKET_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#1 " . mysql_error($LINK), $child);
  86. $result = mysql_query("SELECT * FROM " . BILL_PACKET_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#1 " . mysql_error($LINK), $child);
  87. while ($i < mysql_num_rows($result)) {
  88. $i++;
  89. $res = mysql_fetch_array($result);
  90. $packets[$res["gid"]] = $res;
  91. continue;
  92. }
  93. mysql_free_result($result);
  94. return $packets;
  95. }
  96.  
  97. function billing_init_sectors($LINK, $stdlog, $child) {
  98. $sectors = (array());
  99. $i = 0;
  100. $result = mysql_query("SELECT * FROM " . BILL_SECTORS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#157 " . mysql_error($LINK), $child);
  101. $result = mysql_query("SELECT * FROM " . BILL_SECTORS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#157 " . mysql_error($LINK), $child);
  102. while ($i < mysql_num_rows($result)) {
  103. $i++;
  104. $res = mysql_fetch_array($result);
  105. $sectors[$res["sectorid"]] = $res;
  106. continue;
  107. }
  108. mysql_free_result($result);
  109. return $sectors;
  110. }
  111.  
  112. function billing_init_switch($LINK, $stdlog, $child) {
  113. $switches = (array());
  114. $i = 0;
  115. $result = mysql_query("SELECT * FROM " . BILL_SWITCH_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#170 " . mysql_error($LINK), $child);
  116. $result = mysql_query("SELECT * FROM " . BILL_SWITCH_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#170 " . mysql_error($LINK), $child);
  117. while ($i < mysql_num_rows($result)) {
  118. $i++;
  119. $res = mysql_fetch_array($result);
  120. $switches[$res["swid"]] = $res;
  121. continue;
  122. }
  123. mysql_free_result($result);
  124. return $switches;
  125. }
  126.  
  127. function billing_init_nas($LINK, $stdlog, $child) {
  128. $sql_init_nas = "SELECT * FROM " . BILL_NAS_TABLE;
  129. $nases = (array());
  130. $i = 0;
  131. $result = mysql_query($sql_init_nas, $LINK) || do_log_sql($stdlog, "#2 " . mysql_error($LINK), $child);
  132. $result = mysql_query($sql_init_nas, $LINK) || do_log_sql($stdlog, "#2 " . mysql_error($LINK), $child);
  133. while ($i < mysql_num_rows($result)) {
  134. $i++;
  135. $res = mysql_fetch_array($result);
  136. $nases[$res["nasname"]] = $res;
  137. continue;
  138. }
  139. mysql_free_result($result);
  140. return $nases;
  141. }
  142.  
  143. function get_card_from_active_cards($LINK, $stdlog, $child, $password) {
  144. $SQL = "SELECT " . BILL_CARDS_ACTIVATE_CARD . ".cardactid," . BILL_CARDS_ACTIVATE_CARD . ".serieid," . BILL_CARDS_ACTIVATE_CARD . ".secret," . BILL_CARDS_ACTIVATE_CARD . ".status, " . BILL_CARDS_ACTIVATE_SERIE . ".serie," . BILL_CARDS_ACTIVATE_SERIE . ".serieid, " . BILL_CARDS_ACTIVATE_SERIE . ".gid," . BILL_CARDS_ACTIVATE_SERIE . ".deposit," . BILL_CARDS_ACTIVATE_SERIE . ".credit," . BILL_CARDS_ACTIVATE_SERIE . ".expired," . BILL_CARDS_ACTIVATE_SERIE . ".active FROM " . BILL_CARDS_ACTIVATE_CARD . "," . BILL_CARDS_ACTIVATE_SERIE . " WHERE " . BILL_CARDS_ACTIVATE_CARD . ".secret LIKE '" . $password . "' and " . BILL_CARDS_ACTIVATE_CARD . ".serieid=" . BILL_CARDS_ACTIVATE_SERIE . ".serieid";
  145. $res = mysql_fetch_array($result);
  146. mysql_free_result($result);
  147. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#70 " . mysql_error($LINK), $child);
  148. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#70 " . mysql_error($LINK), $child);
  149. return $res;
  150. }
  151.  
  152. function get_ip_from_pool_unknown($LINK, $stdlog, $system_options, $child) {
  153. $res = mysql_fetch_array($result);
  154. mysql_free_result($result);
  155. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL . " WHERE poolid = " . $system_options["accl_unk_ippololid"] . " ORDER BY RAND() LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#3 " . mysql_error($LINK), $child);
  156. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL . " WHERE poolid = " . $system_options["accl_unk_ippololid"] . " ORDER BY RAND() LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#3 " . mysql_error($LINK), $child);
  157. return $res;
  158. }
  159.  
  160. function get_ip_from_pool_bez_deneg($LINK, $stdlog, $system_options, $child) {
  161. $res = mysql_fetch_array($result);
  162. mysql_free_result($result);
  163. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL . " WHERE poolid = " . $system_options["dolgnik_ippololid"] . " ORDER BY RAND() LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#3 " . mysql_error($LINK), $child);
  164. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL . " WHERE poolid = " . $system_options["dolgnik_ippololid"] . " ORDER BY RAND() LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#3 " . mysql_error($LINK), $child);
  165. return $res;
  166. }
  167.  
  168. function check_if_dolg_ip_pool($LINK, $stdlog, $RAD_REQUEST, $system_options, $child) {
  169. $res = mysql_fetch_array($result);
  170. mysql_free_result($result);
  171. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL_USE . " WHERE poolid = " . $system_options["dolgnik_ippololid"] . " AND poolip='" . $RAD_REQUEST["Framed-IP-Address"] . "' ", $LINK) || do_log_sql($stdlog, "#38 " . mysql_error($LINK), $child);
  172. $result = mysql_query("SELECT * FROM " . BILL_IPPOOL_POOL_USE . " WHERE poolid = " . $system_options["dolgnik_ippololid"] . " AND poolip='" . $RAD_REQUEST["Framed-IP-Address"] . "' ", $LINK) || do_log_sql($stdlog, "#38 " . mysql_error($LINK), $child);
  173. if ($res != false) {
  174. $res = true;
  175. }
  176. return $res;
  177. }
  178.  
  179. function get_ip_from_pool($LINK, $stdlog, $gid, $system_options, $child, $packets_pool) {
  180. $tmp = 0;
  181. $subquerry = "";
  182. foreach ($packets_pool as $key => $value) {
  183. if ($value["gid"] == $gid) {
  184. if ($tmp == 0) {
  185. $subquerry = $value["poolid"];
  186. $tmp = 1;
  187. }
  188. else {
  189. $subquerry .= "," . $value["poolid"];
  190. }
  191. }
  192. continue;
  193. }
  194. $querry = "SELECT poolip,poolid\n\tFROM " . BILL_IPPOOL_POOL . ",\n\t(SELECT FLOOR(MAX(" . BILL_IPPOOL_POOL . ".id) * RAND()) AS randId FROM " . BILL_IPPOOL_POOL . ") AS someRandId\n\tWHERE " . BILL_IPPOOL_POOL . ".id = someRandId.randId AND " . BILL_IPPOOL_POOL . ".poolid IN (" . $subquerry . ")";
  195. $res = mysql_fetch_array($result);
  196. mysql_free_result($result);
  197. $result = mysql_query($querry, $LINK) || do_log_sql($stdlog, "#3dddddd " . mysql_error($LINK), $child);
  198. $result = mysql_query($querry, $LINK) || do_log_sql($stdlog, "#3dddddd " . mysql_error($LINK), $child);
  199. return $res;
  200. }
  201.  
  202. function billing_init_price_floors($LINK, $stdlog, $child) {
  203. $i = 0;
  204. $result = mysql_query("SELECT gid, floor FROM " . BILL_PRICES_TABLE . " WHERE 1 GROUP BY gid, floor ORDER BY gid ", $LINK) || do_log_sql($stdlog, "#4 " . mysql_error($LINK), $child);
  205. $result = mysql_query("SELECT gid, floor FROM " . BILL_PRICES_TABLE . " WHERE 1 GROUP BY gid, floor ORDER BY gid ", $LINK) || do_log_sql($stdlog, "#4 " . mysql_error($LINK), $child);
  206. while ($i < mysql_num_rows($result)) {
  207. $i++;
  208. $res = mysql_fetch_array($result);
  209. $price_floors[$res["gid"]] = $res;
  210. continue;
  211. }
  212. mysql_free_result($result);
  213. return $price_floors;
  214. }
  215.  
  216. function billing_init_prices($LINK, $stdlog, $child) {
  217. $i = 0;
  218. $result = mysql_query("SELECT * FROM " . BILL_PRICES_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#5 " . mysql_error($LINK), $child);
  219. $result = mysql_query("SELECT * FROM " . BILL_PRICES_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#5 " . mysql_error($LINK), $child);
  220. while ($i < mysql_num_rows($result)) {
  221. $i++;
  222. $res = mysql_fetch_array($result);
  223. $key = $res["gid"] . $res["week_day"] . $res["floor"];
  224. $price_diff[$key] = $res;
  225. continue;
  226. }
  227. mysql_free_result($result);
  228. return $price_diff;
  229. }
  230.  
  231. function billing_init_system_options($LINK, $stdlog, $child) {
  232. $options = (array());
  233. $i = 0;
  234. $result = mysql_query("SELECT * FROM " . BILL_SYSTEM_OPTIONS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#6EDF " . mysql_error($LINK), $child);
  235. $result = mysql_query("SELECT * FROM " . BILL_SYSTEM_OPTIONS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#6EDF " . mysql_error($LINK), $child);
  236. while ($i < mysql_num_rows($result)) {
  237. $i++;
  238. $res = mysql_fetch_array($result);
  239. $options[$res["key"]] = $res["value"];
  240. continue;
  241. }
  242. mysql_free_result($result);
  243. return $options;
  244. }
  245.  
  246. function billing_init_sysopts($LINK, $stdlog, $child) {
  247. $res = mysql_fetch_array($result);
  248. mysql_free_result($result);
  249. $result = mysql_query("SELECT * FROM " . BILL_SYSPOTS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#6 " . mysql_error($LINK), $child);
  250. $result = mysql_query("SELECT * FROM " . BILL_SYSPOTS_TABLE . " WHERE 1 ", $LINK) || do_log_sql($stdlog, "#6 " . mysql_error($LINK), $child);
  251. return $res;
  252. }
  253.  
  254. function billing_init_version($LINK, $stdlog, $child) {
  255. $version = "2.8.16";
  256. $res = mysql_fetch_array($result);
  257. mysql_free_result($result);
  258. $version = $res["version"];
  259. $result = mysql_query("SELECT get_version() as version; ", $LINK) || do_log_sql($stdlog, "#335 " . mysql_error($LINK), $child);
  260. $result = mysql_query("SELECT get_version() as version; ", $LINK) || do_log_sql($stdlog, "#335 " . mysql_error($LINK), $child);
  261. return $version;
  262. }
  263.  
  264. function billing_init_count($LINK, $stdlog, $child) {
  265. $count = 0;
  266. $res = mysql_fetch_array($result);
  267. mysql_free_result($result);
  268. $count = $count + $res["count"];
  269. $res = mysql_fetch_array($result);
  270. mysql_free_result($result);
  271. $count = $count + $res["count"];
  272. $res["count"] = $count;
  273. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_AUTH_TABLE . " ", $LINK) || do_log_sql($stdlog, "#40 " . mysql_error($LINK), $child);
  274. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_AUTH_TABLE . " ", $LINK) || do_log_sql($stdlog, "#40 " . mysql_error($LINK), $child);
  275. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_USERFREEZE_TABLE . " ", $LINK) || do_log_sql($stdlog, "#40 " . mysql_error($LINK), $child);
  276. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_USERFREEZE_TABLE . " ", $LINK) || do_log_sql($stdlog, "#40 " . mysql_error($LINK), $child);
  277. return $res;
  278. }
  279.  
  280. function user_coa($RAD_REQUEST, $system_options, $nases) {
  281. $NAS_TYPE = $nases[$RAD_REQUEST["NAS-IP-Address"]]["nastype"];
  282. $SNMP_RW = $nases[$RAD_REQUEST["NAS-IP-Address"]]["secret"];
  283. $INPUT_PORT = $nases[$RAD_REQUEST["NAS-IP-Address"]]["impruport"];
  284. if (strlen($RAD_REQUEST["User-Name"]) == 17) {
  285. $user = $RAD_REQUEST["User-Name"];
  286. }
  287. else {
  288. $user = $RAD_REQUEST["Called-Station-Id"];
  289. }
  290. if ($NAS_TYPE == "accelipoe") {
  291. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=" . $user . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  292. }
  293. if (isset($command)) {
  294. exec($command);
  295. }
  296. }
  297.  
  298. function user_kill($RAD_REQUEST, $system_options, $nases) {
  299. $NAS_TYPE = $nases[$RAD_REQUEST["NAS-IP-Address"]]["nastype"];
  300. $SNMP_RW = $nases[$RAD_REQUEST["NAS-IP-Address"]]["secret"];
  301. $INPUT_PORT = $nases[$RAD_REQUEST["NAS-IP-Address"]]["impruport"];
  302. if ($NAS_TYPE == "cisco") {
  303. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=\\\"" . $RAD_REQUEST["User-Name"] . "\\\",Cisco-AVPair=\\\"subscriber:command=account-logoff\\\",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " coa " . $SNMP_RW . " &>/dev/null 2>&1 ";
  304. }
  305. if ($NAS_TYPE == "finger") {
  306. $command = $system_options["sudo"] . " " . $system_options["CLRLINE_PORTSLAVE"] . " reset:" . $SNMP_RW . ":S" . $RAD_REQUEST["NAS-Port"] . "\\@" . $RAD_REQUEST["NAS-IP-Address"] . " &>/dev/null 2>&1 ";
  307. }
  308. if ($NAS_TYPE == "pppd") {
  309. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"NAS-Port=" . $RAD_REQUEST["NAS-Port"] . ",User-Name=" . $RAD_REQUEST["User-Name"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  310. }
  311. if ($NAS_TYPE == "accelppp") {
  312. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"NAS-Port=" . $RAD_REQUEST["NAS-Port"] . ",User-Name=" . $RAD_REQUEST["User-Name"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  313. }
  314. if ($NAS_TYPE == "se100") {
  315. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=" . $RAD_REQUEST["User-Name"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  316. }
  317. if ($NAS_TYPE == "junnoip") {
  318. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"Acct-Session-Id=" . $RAD_REQUEST["Acct-Session-Id"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  319. }
  320. if ($NAS_TYPE == "junip") {
  321. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"Acct-Session-Id=" . $RAD_REQUEST["Acct-Session-Id"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  322. }
  323. if (strlen($RAD_REQUEST["User-Name"]) == 17) {
  324. $user = $RAD_REQUEST["User-Name"];
  325. }
  326. else {
  327. $user = $RAD_REQUEST["Framed-IP-Address"];
  328. }
  329. if ($NAS_TYPE == "accelipoe") {
  330. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"NAS-Port=" . $RAD_REQUEST["NAS-Port"] . ",User-Name=" . $user . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  331. }
  332. if ($NAS_TYPE == "mikrotik") {
  333. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=" . $RAD_REQUEST["User-Name"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  334. }
  335. if ($NAS_TYPE == "MPD5") {
  336. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"Acct-Session-Id=" . $RAD_REQUEST["Acct-Session-Id"] . ",User-Name=" . $RAD_REQUEST["User-Name"] . ",NAS-IP-Address=" . $RAD_REQUEST["NAS-IP-Address"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  337. }
  338. if ($NAS_TYPE == "lisg") {
  339. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=" . $RAD_REQUEST["User-Name"] . ",NAS-IP-Address=" . $RAD_REQUEST["NAS-IP-Address"] . ",NAS-Port=" . $RAD_REQUEST["NAS-Port"] . ",NAS-Identifier=" . $RAD_REQUEST["NAS-Identifier"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  340. }
  341. if ($NAS_TYPE == "HotSpot") {
  342. $command = $system_options["sudo"] . " " . $system_options["ECHO"] . " \"User-Name=" . $RAD_REQUEST["User-Name"] . ",Framed-IP-Address=" . $RAD_REQUEST["Framed-IP-Address"] . "\" | " . $system_options["exec_radclient"] . " -r 1 " . $RAD_REQUEST["NAS-IP-Address"] . ":" . $INPUT_PORT . " disconnect " . $SNMP_RW . " &>/dev/null 2>&1 ";
  343. }
  344. if (isset($command)) {
  345. exec($command);
  346. }
  347. }
  348.  
  349. function get_old_session_data($LINK, $stdlog, $acctsessionid, $user_name, $nasipaddress, $child) {
  350. $res = mysql_fetch_array($result);
  351. mysql_free_result($result);
  352. $result = mysql_query("SELECT acctinputoctets,acctoutputoctets,acctsessiontime FROM " . BILL_ACCT_TABLE . " WHERE username = '" . $user_name . "' AND acctsessionid = '" . $acctsessionid . "' and nasipaddress = '" . $nasipaddress . "' ", $LINK) || do_log_sql($stdlog, "#7 " . mysql_error($LINK), $child);
  353. $result = mysql_query("SELECT acctinputoctets,acctoutputoctets,acctsessiontime FROM " . BILL_ACCT_TABLE . " WHERE username = '" . $user_name . "' AND acctsessionid = '" . $acctsessionid . "' and nasipaddress = '" . $nasipaddress . "' ", $LINK) || do_log_sql($stdlog, "#7 " . mysql_error($LINK), $child);
  354. return $res;
  355. }
  356.  
  357. function do_update_mac_by_dhcp($LINK, $stdlog, $uid, $child, $user_proper, $new_mac) {
  358. $ts = time();
  359. $gid = $user_proper["gid"];
  360. $stuffid = 0;
  361. $logtypeid = 1;
  362. $ip_remote = "";
  363. $oldvalue = $user_proper["local_mac"];
  364. $newvalue = $new_mac;
  365. $valuename = "local_mac";
  366. $SQL = "INSERT INTO " . BILL_LOG_TABLE . " (logid ,stuffid ,date ,logtypeid ,uid ,gid ,ip,valuename ,oldvalue ,newvalue) VALUES (NULL," . $stuffid . ", FROM_UNIXTIME(" . $ts . ")," . $logtypeid . "," . $uid . "," . $gid . ",'" . $ip_remote . "','" . $valuename . "','" . $oldvalue . "','" . $newvalue . "')";
  367. $SQL = "UPDATE " . BILL_AUTH_TABLE . " SET local_mac=\"" . $new_mac . "\" where uid=" . $uid;
  368. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#505 " . mysql_error($LINK), $child);
  369. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#505 " . mysql_error($LINK), $child);
  370. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#508 " . mysql_error($LINK), $child);
  371. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#508 " . mysql_error($LINK), $child);
  372. }
  373.  
  374. function do_fixed_one_day_abonplata_by_uid($LINK, $stdlog, $uid, $child, $packets, $gid, $user_proper) {
  375. $ts = time();
  376. $SQL = "INSERT INTO " . BILL_PLATEGI_STAT_TABLE . " (`plategid` ,`uid` ,`date` ,`who` ,`bughtypeid` ,`before_billing` ,`summa` ,`comment` ) VALUES (NULL , " . $uid . ", FROM_UNIXTIME(" . $ts . "), NULL , '2', '" . $user_proper["deposit"] . "', '" . $packets[$gid]["fixed_cost"] . "', NULL );";
  377. $SQL = "UPDATE " . BILL_AUTH_TABLE . " SET deposit=deposit-" . $packets[$gid]["fixed_cost"] . " where uid=" . $uid;
  378. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#517 " . mysql_error($LINK), $child);
  379. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#517 " . mysql_error($LINK), $child);
  380. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#520 " . mysql_error($LINK), $child);
  381. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#520 " . mysql_error($LINK), $child);
  382. }
  383.  
  384. function get_switch_options_by_swid($LINK, $stdlog, $swid, $child) {
  385. $res = mysql_fetch_array($result);
  386. mysql_free_result($result);
  387. $result = mysql_query("SELECT swid, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,strict_dhcp_mode, mac, swunit, swmodule,use_circut_template,circut_template,use_unit_find,use_module_find FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE swid='" . $swid . "' ", $LINK) || do_log_sql($stdlog, "#525 " . mysql_error($LINK), $child);
  388. $result = mysql_query("SELECT swid, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,strict_dhcp_mode, mac, swunit, swmodule,use_circut_template,circut_template,use_unit_find,use_module_find FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE swid='" . $swid . "' ", $LINK) || do_log_sql($stdlog, "#525 " . mysql_error($LINK), $child);
  389. return $res;
  390. }
  391.  
  392. function get_switch_options_by_qnq($LINK, $stdlog, $qnq, $child) {
  393. $res = mysql_fetch_array($result);
  394. mysql_free_result($result);
  395. $result = mysql_query("SELECT swid, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,strict_dhcp_mode, swunit, swmodule,use_circut_template,circut_template,use_unit_find,use_module_find FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE qnq='" . $qnq . "' ", $LINK) || do_log_sql($stdlog, "#437 " . mysql_error($LINK), $child);
  396. $result = mysql_query("SELECT swid, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,strict_dhcp_mode, swunit, swmodule,use_circut_template,circut_template,use_unit_find,use_module_find FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE qnq='" . $qnq . "' ", $LINK) || do_log_sql($stdlog, "#437 " . mysql_error($LINK), $child);
  397. return $res;
  398. }
  399.  
  400. function get_ip_from_segment_lease_by_mac_ip($LINK, $stdlog, $sectorid, $mac, $ip, $child) {
  401. $res = mysql_fetch_array($result);
  402. mysql_free_result($result);
  403. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE mac like '" . $mac . "' AND IP like '" . $ip . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#460 " . mysql_error($LINK), $child);
  404. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE mac like '" . $mac . "' AND IP like '" . $ip . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#460 " . mysql_error($LINK), $child);
  405. return $res;
  406. }
  407.  
  408. function get_ip_from_segment_lease_by_ip($LINK, $stdlog, $sectorid, $ip, $child) {
  409. $res = mysql_fetch_array($result);
  410. mysql_free_result($result);
  411. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE ip like '" . $ip . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#482 " . mysql_error($LINK), $child);
  412. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE ip like '" . $ip . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#482 " . mysql_error($LINK), $child);
  413. return $res;
  414. }
  415.  
  416. function get_ip_from_segment_lease($LINK, $stdlog, $sectorid, $mac, $child) {
  417. $res = mysql_fetch_array($result);
  418. mysql_free_result($result);
  419. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE mac like '" . $mac . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#481 " . mysql_error($LINK), $child);
  420. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE mac like '" . $mac . "' LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#481 " . mysql_error($LINK), $child);
  421. if (empty($res)) {
  422. $res = mysql_fetch_array($result);
  423. mysql_free_result($result);
  424. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE sectorid='" . $sectorid . "' AND used=0 LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#487 " . mysql_error($LINK), $child);
  425. $result = mysql_query("SELECT ip,ip2long,sectorid,expired FROM " . BILL_SECTORS_LEASE_TABLE . " WHERE sectorid='" . $sectorid . "' AND used=0 LIMIT 1 ", $LINK) || do_log_sql($stdlog, "#487 " . mysql_error($LINK), $child);
  426. }
  427. return $res;
  428. }
  429.  
  430. function set_ip_in_use_by_segment_lease($LINK, $stdlog, $sectorid, $ip2long, $ip, $mac, $child, $system_options) {
  431. if (isset($system_options["default_lease_time"])) {
  432. if (!is_numeric($system_options["default_lease_time"])) {
  433. $system_options["default_lease_time"] = 3600;
  434. }
  435. else {
  436. if ($system_options["default_lease_time"] < 600) {
  437. $system_options["default_lease_time"] = 3600;
  438. }
  439. }
  440. }
  441. else {
  442. $system_options["default_lease_time"] = 3600;
  443. }
  444. $querry = "UPDATE " . BILL_SECTORS_LEASE_TABLE . " SET `used` = '1',\n`mac` = '" . $mac . "',expired='" . $system_options["default_lease_time"] . "' WHERE `ip2long` = " . $ip2long . " AND `ip` = '" . $ip . "' AND `sectorid` = " . $sectorid . " ;";
  445. mysql_query($querry, $LINK) || do_log_sql($stdlog, "#484 " . mysql_error($LINK), $child);
  446. mysql_query($querry, $LINK) || do_log_sql($stdlog, "#484 " . mysql_error($LINK), $child);
  447. }
  448.  
  449. function get_segment_options_by_vlan($LINK, $stdlog, $vlanid, $child) {
  450. $res = mysql_fetch_array($result);
  451. mysql_free_result($result);
  452. $result = mysql_query("SELECT * FROM " . BILL_SECTORS_TABLE . " WHERE vlanid='" . $vlanid . "' ", $LINK) || do_log_sql($stdlog, "#475 " . mysql_error($LINK), $child);
  453. $result = mysql_query("SELECT * FROM " . BILL_SECTORS_TABLE . " WHERE vlanid='" . $vlanid . "' ", $LINK) || do_log_sql($stdlog, "#475 " . mysql_error($LINK), $child);
  454. return $res;
  455. }
  456.  
  457. function get_switch_options_by_mac($LINK, $stdlog, $switch_mac, $child) {
  458. $res = mysql_fetch_array($result);
  459. mysql_free_result($result);
  460. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' ", $LINK) || do_log_sql($stdlog, "#690 " . mysql_error($LINK), $child);
  461. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' ", $LINK) || do_log_sql($stdlog, "#690 " . mysql_error($LINK), $child);
  462. return $res;
  463. }
  464.  
  465. function get_switch_options_by_mac_all($LINK, $stdlog, $switch_mac, $child) {
  466. $switches = (array());
  467. $i = 0;
  468. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' ", $LINK) || do_log_sql($stdlog, "#710 " . mysql_error($LINK), $child);
  469. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' ", $LINK) || do_log_sql($stdlog, "#710 " . mysql_error($LINK), $child);
  470. while ($i < mysql_num_rows($result)) {
  471. $i++;
  472. $res = mysql_fetch_array($result);
  473. $switches[$i] = $res;
  474. continue;
  475. }
  476. mysql_free_result($result);
  477. return $switches;
  478. }
  479.  
  480. function get_switch_options_by_mac_unit($LINK, $stdlog, $switch_mac, $swunit, $child) {
  481. $res = mysql_fetch_array($result);
  482. mysql_free_result($result);
  483. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' AND swunit = " . $swunit, $LINK) || do_log_sql($stdlog, "#736 " . mysql_error($LINK), $child);
  484. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' AND swunit = " . $swunit, $LINK) || do_log_sql($stdlog, "#736 " . mysql_error($LINK), $child);
  485. return $res;
  486. }
  487.  
  488. function get_switch_options_by_mac_module($LINK, $stdlog, $switch_mac, $swmodule, $child) {
  489. $res = mysql_fetch_array($result);
  490. mysql_free_result($result);
  491. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' AND swmodule = " . $swmodule, $LINK) || do_log_sql($stdlog, "#757 " . mysql_error($LINK), $child);
  492. $result = mysql_query("SELECT swid, swunit, swmodule, do_check_switch_port, do_mac_autoreg_by_radius, do_ip_unnumbered,use_circut_template,circut_template,use_unit_find,use_module_find,strict_dhcp_mode FROM " . BILL_SWITCH_TABLE . " NATURAL JOIN " . BILL_SWITCH_TYPE_TABLE . " WHERE mac like '" . $switch_mac . "' AND swmodule = " . $swmodule, $LINK) || do_log_sql($stdlog, "#757 " . mysql_error($LINK), $child);
  493. return $res;
  494. }
  495.  
  496. function get_user_proper_by_swid_port_mac($LINK, $stdlog, $swid, $switchport, $mac, $child) {
  497. $res = mysql_fetch_array($result);
  498. mysql_free_result($result);
  499. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid = '" . $swid . "' AND switchport = '" . $switchport . "' AND local_mac = '" . $mac . "';", $LINK) || do_log_sql($stdlog, "#2345624 " . mysql_error($LINK), $child);
  500. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid = '" . $swid . "' AND switchport = '" . $switchport . "' AND local_mac = '" . $mac . "';", $LINK) || do_log_sql($stdlog, "#2345624 " . mysql_error($LINK), $child);
  501. return $res;
  502. }
  503.  
  504. function get_DHCP_circuit_remote_ids($RAD_REQUEST, $LINK, $stdlog, $child) {
  505. $DHCP_Relay_Circuit_Id = $RAD_REQUEST["DHCP-Relay-Circuit-Id"];
  506. $DHCP_Relay_Remote_Id = $RAD_REQUEST["DHCP-Relay-Remote-Id"];
  507. $client_code = "";
  508. $client_length = "";
  509. $client_unit = "";
  510. $client_module = "";
  511. $client_port = "0";
  512. $client_vlan = "0";
  513. $switch_circuit_id = "";
  514. $switch_mac = "";
  515. $swid_by_mac = "";
  516. $use_circut_template = 0;
  517. $swid_by_mac_arr = (array());
  518. if ($DHCP_Relay_Remote_Id == "") {
  519. $tmp_var = explode("x", $DHCP_Relay_Circuit_Id);
  520. if (isset($tmp_var[1])) {
  521. $switch_circuit_id = substr($tmp_var[1], 0, 2);
  522. $client_vlan = hexdec(substr($tmp_var[1], 4, 4));
  523. $client_port = hexdec(substr($tmp_var[1], 2, 2));
  524. }
  525. unset(${$tmp_var});
  526. unset(${$tmp_var});
  527. }
  528. else {
  529. $tmp_var = explode("x", $DHCP_Relay_Remote_Id);
  530. if (isset($tmp_var[1])) {
  531. if (strlen($tmp_var[1]) == 12) {
  532. $switch_mac = substr($tmp_var[1], 0, 2) . ":" . substr($tmp_var[1], 2, 2) . ":" . substr($tmp_var[1], 4, 2) . ":" . substr($tmp_var[1], 6, 2) . ":" . substr($tmp_var[1], 8, 2) . ":" . substr($tmp_var[1], 10, 2);
  533. }
  534. if (strlen($tmp_var[1]) == 16) {
  535. $switch_mac = substr($tmp_var[1], 4, 2) . ":" . substr($tmp_var[1], 6, 2) . ":" . substr($tmp_var[1], 8, 2) . ":" . substr($tmp_var[1], 10, 2) . ":" . substr($tmp_var[1], 12, 2) . ":" . substr($tmp_var[1], 14, 2);
  536. }
  537. if ($switch_mac == "") {
  538. $switch_mac = $tmp_var[1];
  539. }
  540. }
  541. $switch_mac = trim(strtoupper($switch_mac));
  542. unset(${$tmp_var});
  543. unset(${$tmp_var});
  544. $swid_by_mac_arr = get_switch_options_by_mac_all($LINK, $stdlog, $switch_mac, $child);
  545. if (count($swid_by_mac_arr) == 1) {
  546. $swid_by_mac = $swid_by_mac_arr[0];
  547. $use_circut_template = $swid_by_mac["use_circut_template"];
  548. }
  549. else {
  550. if (0 < count($swid_by_mac_arr)) {
  551. $swid_by_mac = $swid_by_mac_arr[0];
  552. $use_circut_template = $swid_by_mac_arr[0]["use_circut_template"];
  553. }
  554. }
  555. if ($use_circut_template == 0) {
  556. $tmp_var = explode("x", $DHCP_Relay_Circuit_Id);
  557. if (isset($tmp_var[1])) {
  558. if (strlen($DHCP_Relay_Circuit_Id) == 10) {
  559. $switch_circuit_id = substr($tmp_var[1], 0, 4);
  560. if ($switch_circuit_id == "0000") {
  561. $client_port = hexdec(substr($tmp_var[1], 4, 4));
  562. }
  563. else {
  564. $client_vlan = hexdec(substr($tmp_var[1], 0, 4));
  565. $client_port = hexdec(substr($tmp_var[1], 6, 2));
  566. }
  567. }
  568. if (strlen($DHCP_Relay_Circuit_Id) == 14) {
  569. $switch_circuit_id = substr($tmp_var[1], 0, 4);
  570. $client_vlan = hexdec(substr($tmp_var[1], 4, 4));
  571. $client_port = hexdec(substr($tmp_var[1], 8, 4));
  572. }
  573. }
  574. }
  575. else {
  576. $template_arr = explode(",", $swid_by_mac["circut_template"]);
  577. $circuitid = $DHCP_Relay_Circuit_Id;
  578. foreach ($template_arr as $key => $value) {
  579. $tmp_val1 = explode("=", $value);
  580. if (isset($tmp_val1[1])) {
  581. $tag_code = $tmp_val1[0];
  582. $tag_len = $tmp_val1[1];
  583. switch ($tag_code) {
  584. case "C": {
  585. $client_code = substr($circuitid, 0, $tag_len);
  586. $client_code = hexdec($client_code);
  587. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  588. break;
  589. }
  590. case "L": {
  591. $client_length = substr($circuitid, 0, $tag_len);
  592. $client_length = hexdec($client_length);
  593. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  594. break;
  595. }
  596. case "U": {
  597. $client_unit = substr($circuitid, 0, $tag_len);
  598. $client_unit = hexdec($client_unit);
  599. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  600. break;
  601. }
  602. case "M": {
  603. $client_module = substr($circuitid, 0, $tag_len);
  604. $client_module = hexdec($client_module);
  605. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  606. break;
  607. }
  608. case "V": {
  609. $client_vlan = substr($circuitid, 0, $tag_len);
  610. $client_vlan = hexdec($client_vlan);
  611. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  612. break;
  613. }
  614. case "CP": {
  615. $client_port = substr($circuitid, 0, $tag_len);
  616. $client_port = hexdec($client_port);
  617. $client_port = $client_port + 1;
  618. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  619. break;
  620. }
  621. case "P": {
  622. $client_port = substr($circuitid, 0, $tag_len);
  623. $client_port = hexdec($client_port);
  624. $circuitid = substr($circuitid, $tag_len, strlen($circuitid) - $tag_len);
  625. break;
  626. }
  627. }
  628. }
  629. continue;
  630. }
  631. }
  632. unset(${$tmp_var});
  633. unset(${$tmp_var});
  634. }
  635. if (1 < count($swid_by_mac_arr)) {
  636. if ($swid_by_mac["use_unit_find"] == 1 && $swid_by_mac["use_module_find"] == 1) {
  637. if ($client_unit != "" && $client_module != "") {
  638. if (is_numeric($client_module) && is_numeric($client_unit)) {
  639. foreach ($swid_by_mac_arr as $key => $value) {
  640. if ($value["swunit"] == $client_unit && $value["swmodule"] == $client_module) {
  641. $swid_by_mac = $swid_by_mac_arr[$key];
  642. }
  643. continue;
  644. }
  645. }
  646. }
  647. }
  648. else {
  649. if ($swid_by_mac["use_unit_find"] == 1) {
  650. if ($client_unit != "") {
  651. if (is_numeric($client_unit)) {
  652. foreach ($swid_by_mac_arr as $key => $value) {
  653. if ($value["swunit"] == $client_unit) {
  654. $swid_by_mac = $swid_by_mac_arr[$key];
  655. }
  656. continue;
  657. }
  658. }
  659. }
  660. }
  661. if ($swid_by_mac["use_module_find"] == 1) {
  662. if ($client_module != "") {
  663. if (is_numeric($client_module)) {
  664. foreach ($swid_by_mac_arr as $key => $value) {
  665. if ($value["swmodule"] == $client_module) {
  666. $swid_by_mac = $swid_by_mac_arr[$key];
  667. }
  668. continue;
  669. }
  670. }
  671. }
  672. }
  673. }
  674. }
  675. $result = (array("client_module" => $client_module, "client_unit" => $client_unit, "client_port" => $client_port, "client_vlan" => $client_vlan, "switch_circuit_id" => $switch_circuit_id, "switch_mac" => $switch_mac, "DHCP_Relay_Circuit_Id" => $DHCP_Relay_Circuit_Id, "DHCP_Relay_Remote_Id" => $DHCP_Relay_Remote_Id, "swid_by_mac" => $swid_by_mac));
  676. unset(${$client_port});
  677. unset(${$client_port});
  678. unset(${$client_vlan});
  679. unset(${$client_vlan});
  680. unset(${$client_module});
  681. unset(${$client_module});
  682. unset(${$client_unit});
  683. unset(${$client_unit});
  684. unset(${$switch_circuit_id});
  685. unset(${$switch_circuit_id});
  686. unset(${$switch_mac});
  687. unset(${$switch_mac});
  688. unset(${$DHCP_Relay_Circuit_Id});
  689. unset(${$DHCP_Relay_Circuit_Id});
  690. unset(${$DHCP_Relay_Remote_Id});
  691. unset(${$DHCP_Relay_Remote_Id});
  692. unset(${$swid_by_mac});
  693. unset(${$swid_by_mac});
  694. unset(${$swid_by_mac_arr});
  695. unset(${$swid_by_mac_arr});
  696. return $result;
  697. }
  698.  
  699. function fill_rad_reply($user_proper, $switches, $sectors, $system_options, &$RAD_REPLY, &$RAD_REQUEST) {
  700. $local_ip = $user_proper["local_ip"];
  701. $sectorid = $user_proper["sectorid"];
  702. $user_installed = $user_proper["user_installed"];
  703. $vlan = $sectors[$sectorid]["vlanid"];
  704. $mask = $sectors[$sectorid]["mask"];
  705. $dns_serv = $sectors[$sectorid]["dns_serv"];
  706. $dns_serv2 = $sectors[$sectorid]["dns_serv2"];
  707. $wins_serv = $sectors[$sectorid]["wins_serv"];
  708. $netbios_dd_serv = $sectors[$sectorid]["wins_serv"];
  709. $routers = $sectors[$sectorid]["routers"];
  710. $time_serv = $sectors[$sectorid]["time_serv"];
  711. $static_routes = $sectors[$sectorid]["static_routes"];
  712. $classless_route = $sectors[$sectorid]["classless_route"];
  713. if (isset($RAD_REQUEST["DHCP-Client-IP-Address"])) {
  714. $RAD_REPLY["DHCP-Client-IP-Address"] = $RAD_REQUEST["DHCP-Client-IP-Address"];
  715. }
  716. $RAD_REPLY["DHCP-Your-IP-Address"] = $local_ip;
  717. $RAD_REPLY["DHCP-Subnet-Mask"] = $mask;
  718. if (trim($classless_route) != "") {
  719. $tmp = preg_split("/\\,/", $classless_route);
  720. $tmp_str = "";
  721. foreach ($tmp as $key => $value) {
  722. $tmp_str2 = dechex($value);
  723. if (strlen($tmp_str2) == 1) {
  724. $tmp_str2 = "0" . $tmp_str2;
  725. }
  726. $tmp_str .= $tmp_str2;
  727. continue;
  728. }
  729. $tmp_str = strtoupper($tmp_str);
  730. $RAD_REPLY["DHCP-Classless-Static-Route"] = "0x" . $tmp_str;
  731. $RAD_REPLY["DHCP-MS-Static-Routes"] = "0x" . $tmp_str;
  732. unset(${$tmp});
  733. unset(${$tmp});
  734. unset(${$tmp_str2});
  735. unset(${$tmp_str2});
  736. unset(${$tmp_str});
  737. unset(${$tmp_str});
  738. }
  739. if (trim($routers) != "") {
  740. $RAD_REPLY["DHCP-Router-Address"] = $routers;
  741. }
  742. if (trim($dns_serv) != "" && trim($dns_serv2) != "") {
  743. $RAD_REPLY["DHCP-Domain-Name-Server"] = (array($dns_serv, $dns_serv2));
  744. }
  745. else {
  746. if (trim($dns_serv) != "") {
  747. $RAD_REPLY["DHCP-Domain-Name-Server"] = (array($dns_serv));
  748. }
  749. if (trim($dns_serv2) != "") {
  750. $RAD_REPLY["DHCP-Domain-Name-Server"] = (array($dns_serv2));
  751. }
  752. }
  753. if (trim($time_serv) != "") {
  754. $RAD_REPLY["DHCP-NTP-Servers"] = $time_serv;
  755. $RAD_REPLY["DHCP-Time-Server"] = $time_serv;
  756. }
  757. if (trim($wins_serv) != "") {
  758. $RAD_REPLY["DHCP-NETBIOS-Name-Servers"] = $wins_serv;
  759. $RAD_REPLY["DHCP-NETBIOS-Node-Type"] = "8";
  760. }
  761. if (trim($system_options["DHCP_PARAM_DOMAIN"] != "")) {
  762. $RAD_REPLY["DHCP-Domain-Name"] = $system_options["DHCP_PARAM_DOMAIN"];
  763. }
  764. $RAD_REPLY["DHCP-IP-Address-Lease-Time"] = $system_options["default_lease_time"];
  765. }
  766.  
  767. function get_user_proper_by_swid_port($LINK, $stdlog, $swid, $switchport, $child) {
  768. $res = mysql_fetch_array($result);
  769. mysql_free_result($result);
  770. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid = '" . $swid . "' AND switchport = '" . $switchport . "';", $LINK) || do_log_sql($stdlog, "##2345625 " . mysql_error($LINK), $child);
  771. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid = '" . $swid . "' AND switchport = '" . $switchport . "';", $LINK) || do_log_sql($stdlog, "##2345625 " . mysql_error($LINK), $child);
  772. return $res;
  773. }
  774.  
  775. function get_switch_port_by_parent_swid_and_vlan($LINK, $stdlog, $parent_swid, $client_vlan, $child) {
  776. $res = mysql_fetch_array($result);
  777. mysql_free_result($result);
  778. $result = mysql_query("SELECT `swid`, `port` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = '" . $client_vlan . "' AND `swid` IN (SELECT `swid` FROM `" . BILL_SWITCH_TABLE . "` WHERE `parent_swid` = '" . $parent_swid . "');", $LINK) || do_log_sql($stdlog, "#2345626 " . mysql_error($LINK), $child);
  779. $result = mysql_query("SELECT `swid`, `port` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = '" . $client_vlan . "' AND `swid` IN (SELECT `swid` FROM `" . BILL_SWITCH_TABLE . "` WHERE `parent_swid` = '" . $parent_swid . "');", $LINK) || do_log_sql($stdlog, "#2345626 " . mysql_error($LINK), $child);
  780. return $res;
  781. }
  782.  
  783. function get_user_proper_by_vlan_for_accel_qnqunnumbered($LINK, $stdlog, $vlan, $qnq, $child) {
  784. $SQL_Query = "SELECT `swid`,`port` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = " . $vlan . " and `swid` IN (SELECT swid FROM " . BILL_SWITCH_TABLE . " WHERE qnq=" . $qnq . ");";
  785. $switch_port_pair = mysql_fetch_array($result);
  786. mysql_free_result($result);
  787. $result = mysql_query($SQL_Query, $LINK) || do_log_sql($stdlog, "#switch by qnq " . mysql_error($LINK), $child);
  788. $result = mysql_query($SQL_Query, $LINK) || do_log_sql($stdlog, "#switch by qnq " . mysql_error($LINK), $child);
  789. if (!empty($switch_port_pair)) {
  790. $res = mysql_fetch_array($result);
  791. mysql_free_result($result);
  792. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid=" . $switch_port_pair["swid"] . " and switchport =" . $switch_port_pair["port"] . "; ", $LINK) || do_log_sql($stdlog, "#8433s4 " . mysql_error($LINK), $child);
  793. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid=" . $switch_port_pair["swid"] . " and switchport =" . $switch_port_pair["port"] . "; ", $LINK) || do_log_sql($stdlog, "#8433s4 " . mysql_error($LINK), $child);
  794. return $res;
  795. }
  796. else {
  797. return array();
  798. }
  799. }
  800.  
  801. function get_user_proper_by_vlan_for_accel_unnumbered($LINK, $stdlog, $vlan, $child) {
  802. $switch_port_pair = mysql_fetch_array($result);
  803. mysql_free_result($result);
  804. $result = mysql_query("SELECT `swid`, `port` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = " . $vlan . ";", $LINK) || do_log_sql($stdlog, "#switch by vlan " . mysql_error($LINK), $child);
  805. $result = mysql_query("SELECT `swid`, `port` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = " . $vlan . ";", $LINK) || do_log_sql($stdlog, "#switch by vlan " . mysql_error($LINK), $child);
  806. if (!empty($switch_port_pair)) {
  807. $res = mysql_fetch_array($result);
  808. mysql_free_result($result);
  809. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid=" . $switch_port_pair["swid"] . " and switchport =" . $switch_port_pair["port"] . " ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  810. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid=" . $switch_port_pair["swid"] . " and switchport =" . $switch_port_pair["port"] . " ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  811. return $res;
  812. }
  813. else {
  814. return array();
  815. }
  816. }
  817.  
  818. function get_abonplata_by_uid_fixed_pays($LINK, $stdlog, $uid, $child) {
  819. $month = date("m");
  820. $years = date("Y");
  821. $current_day = date("d");
  822. $SQL = "SELECT count(plategid) as count FROM " . BILL_PLATEGI_STAT_TABLE . " WHERE bughtypeid=2 and uid=" . $uid . " AND `date` BETWEEN '" . $years . "-" . $month . "-" . $current_day . " 00:00:00' AND '" . $years . "-" . $month . "-" . $current_day . " 23:59:59'";
  823. $res = mysql_fetch_array($result);
  824. mysql_free_result($result);
  825. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#80 " . mysql_error($LINK), $child);
  826. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#80 " . mysql_error($LINK), $child);
  827. return $res["count"];
  828. }
  829.  
  830. function get_sum_all_by_uid($LINK, $stdlog, $uid, $child) {
  831. $month = date("m");
  832. $years = date("Y");
  833. $last_day = date("t");
  834. $res = mysql_fetch_array($result);
  835. mysql_free_result($result);
  836. $return = $res["acctinputoctets"] + $res["acctoutputoctets"];
  837. $result = mysql_query("SELECT SUM(acctinputoctets)/1048576 as acctinputoctets, SUM(acctoutputoctets)/1048576 as acctoutputoctets FROM " . BILL_ACCT_TABLE . " WHERE uid=" . $uid . " AND `acctstarttime` BETWEEN '" . $years . "-" . $month . "-01 00:00:00' AND '" . $years . "-" . $month . "-" . $last_day . " 23:59:59'", $LINK) || do_log_sql($stdlog, "#80 " . mysql_error($LINK), $child);
  838. $result = mysql_query("SELECT SUM(acctinputoctets)/1048576 as acctinputoctets, SUM(acctoutputoctets)/1048576 as acctoutputoctets FROM " . BILL_ACCT_TABLE . " WHERE uid=" . $uid . " AND `acctstarttime` BETWEEN '" . $years . "-" . $month . "-01 00:00:00' AND '" . $years . "-" . $month . "-" . $last_day . " 23:59:59'", $LINK) || do_log_sql($stdlog, "#80 " . mysql_error($LINK), $child);
  839. return $return;
  840. }
  841.  
  842. function get_sum_by_uid($LINK, $stdlog, $uid, $child) {
  843. $month = date("m");
  844. $years = date("Y");
  845. $last_day = date("t");
  846. $SQL = "SELECT SUM(acctinputoctets)/1048576 as acctinputoctets, SUM(acctoutputoctets)/1048576 as acctoutputoctets FROM " . BILL_ACCT_TABLE . " WHERE uid=" . $uid . " AND `acctstarttime` BETWEEN '" . $years . "-" . $month . "-01 00:00:00' AND '" . $years . "-" . $month . "-" . $last_day . " 23:59:59'";
  847. $res = mysql_fetch_array($result);
  848. mysql_free_result($result);
  849. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#8 " . mysql_error($LINK), $child);
  850. $result = mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#8 " . mysql_error($LINK), $child);
  851. return $res;
  852. }
  853.  
  854. function get_price_diff_limit($price_floors, $gid, $traf_sum) {
  855. $limits = 0;
  856. $limit_old = 0;
  857. foreach ($price_floors as $key => $value) {
  858. if ($limit_old < $price_floors[$key][1] && $price_floors[$key][1] < $traf_sum && $gid == $key) {
  859. $limit_old = $limits;
  860. list(, $limits) = $price_floors[$key];
  861. }
  862. continue;
  863. }
  864. return $limits;
  865. }
  866.  
  867. function do_billing_minus($LINK, $stdlog, $acctsessionid, $user_name, $nasipaddress, $uid, $billing_minus_current, $child) {
  868. mysql_query("UPDATE " . BILL_AUTH_TABLE . " SET deposit = deposit - " . $billing_minus_current . " WHERE uid = " . $uid . "", $LINK) || do_log_sql($stdlog, "#9 " . mysql_error($LINK), $child);
  869. mysql_query("UPDATE " . BILL_AUTH_TABLE . " SET deposit = deposit - " . $billing_minus_current . " WHERE uid = " . $uid . "", $LINK) || do_log_sql($stdlog, "#9 " . mysql_error($LINK), $child);
  870. mysql_query("UPDATE " . BILL_ACCT_TABLE . " SET billing_minus = billing_minus + " . $billing_minus_current . " WHERE acctsessionid='" . $acctsessionid . "' and username='" . $user_name . "' and nasipaddress='" . $nasipaddress . "' and uid=" . $uid . "", $LINK) || do_log_sql($stdlog, "#10 " . mysql_error($LINK), $child);
  871. mysql_query("UPDATE " . BILL_ACCT_TABLE . " SET billing_minus = billing_minus + " . $billing_minus_current . " WHERE acctsessionid='" . $acctsessionid . "' and username='" . $user_name . "' and nasipaddress='" . $nasipaddress . "' and uid=" . $uid . "", $LINK) || do_log_sql($stdlog, "#10 " . mysql_error($LINK), $child);
  872. }
  873.  
  874. function do_postauth_log($LINK, $stdlog, $RAD_REQUEST, $RAD_CHECK, $packettypeid, $replymessageid, $nasid, $uid, $child) {
  875. if (isset($RAD_REQUEST["User-Password"])) {
  876. $Clear_text_password = $RAD_REQUEST["User-Password"];
  877. }
  878. else {
  879. if (!isset($RAD_CHECK["Cleartext-Password"])) {
  880. $Clear_text_password = "";
  881. }
  882. else {
  883. $Clear_text_password = $RAD_CHECK["Cleartext-Password"];
  884. }
  885. }
  886. if (!is_numeric($uid)) {
  887. $uid = 0;
  888. }
  889. if (isset($RAD_REQUEST["NAS-Port"])) {
  890. if (!is_numeric($RAD_REQUEST["NAS-Port"])) {
  891. $RAD_REQUEST["NAS-Port"] = 0;
  892. }
  893. }
  894. else {
  895. $RAD_REQUEST["NAS-Port"] = 0;
  896. }
  897. if ($nasid == "") {
  898. $nasid = 0;
  899. }
  900. $SQL = "call do_post_auth(" . $uid . ",'" . $RAD_REQUEST["User-Name"] . "','" . $Clear_text_password . "'," . $packettypeid . "," . $replymessageid . "," . $nasid . ",'" . $RAD_REQUEST["NAS-Port"] . "','" . $RAD_REQUEST["Calling-Station-Id"] . "');";
  901. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#Do log Post Auth " . mysql_error($LINK), $child);
  902. mysql_query($SQL, $LINK) || do_log_sql($stdlog, "#Do log Post Auth " . mysql_error($LINK), $child);
  903. }
  904.  
  905. function get_user_proper_by_login($LINK, $stdlog, $login, $child) {
  906. $res = mysql_fetch_array($result);
  907. mysql_free_result($result);
  908. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1225 " . mysql_error($LINK), $child);
  909. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1225 " . mysql_error($LINK), $child);
  910. return $res;
  911. }
  912.  
  913. function get_user_proper_by_login_freeze($LINK, $stdlog, $login, $child) {
  914. $res = mysql_fetch_array($result);
  915. mysql_free_result($result);
  916. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#12434 " . mysql_error($LINK), $child);
  917. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#12434 " . mysql_error($LINK), $child);
  918. return $res;
  919. }
  920.  
  921. function get_user_proper_by_login_otkl($LINK, $stdlog, $login, $child) {
  922. $res = mysql_fetch_array($result);
  923. mysql_free_result($result);
  924. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1243 " . mysql_error($LINK), $child);
  925. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1243 " . mysql_error($LINK), $child);
  926. return $res;
  927. }
  928.  
  929. function get_user_proper_by_login_del($LINK, $stdlog, $login, $child) {
  930. $res = mysql_fetch_array($result);
  931. mysql_free_result($result);
  932. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1253 " . mysql_error($LINK), $child);
  933. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE user='" . $login . "' ", $LINK) || do_log_sql($stdlog, "#1253 " . mysql_error($LINK), $child);
  934. return $res;
  935. }
  936.  
  937. function get_user_proper_by_password($LINK, $stdlog, $pass, $child) {
  938. $res = mysql_fetch_array($result);
  939. mysql_free_result($result);
  940. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE password='" . $pass . "' ", $LINK) || do_log_sql($stdlog, "#1263 " . mysql_error($LINK), $child);
  941. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE password='" . $pass . "' ", $LINK) || do_log_sql($stdlog, "#1263 " . mysql_error($LINK), $child);
  942. return $res;
  943. }
  944.  
  945. function get_user_proper_by_ip($LINK, $stdlog, $ip, $child) {
  946. $res = mysql_fetch_array($result);
  947. mysql_free_result($result);
  948. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1272 " . mysql_error($LINK), $child);
  949. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1272 " . mysql_error($LINK), $child);
  950. return $res;
  951. }
  952.  
  953. function get_user_proper_by_ip_freeze($LINK, $stdlog, $ip, $child) {
  954. $res = mysql_fetch_array($result);
  955. mysql_free_result($result);
  956. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1286 " . mysql_error($LINK), $child);
  957. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1286 " . mysql_error($LINK), $child);
  958. return $res;
  959. }
  960.  
  961. function get_user_proper_by_ip_otkl($LINK, $stdlog, $ip, $child) {
  962. $res = mysql_fetch_array($result);
  963. mysql_free_result($result);
  964. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1290 " . mysql_error($LINK), $child);
  965. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1290 " . mysql_error($LINK), $child);
  966. return $res;
  967. }
  968.  
  969. function get_user_proper_by_ip_del($LINK, $stdlog, $ip, $child) {
  970. $res = mysql_fetch_array($result);
  971. mysql_free_result($result);
  972. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1301 " . mysql_error($LINK), $child);
  973. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE local_ip='" . $ip . "' ", $LINK) || do_log_sql($stdlog, "#1301 " . mysql_error($LINK), $child);
  974. return $res;
  975. }
  976.  
  977. function do_last_connection($LINK, $stdlog, $uid, $child) {
  978. if (is_numeric($uid)) {
  979. mysql_free_result($result);
  980. $result = mysql_query("CALL last_connection(" . $uid . "); ", $LINK) || do_log_sql($stdlog, "#1320 " . mysql_error($LINK), $child);
  981. $result = mysql_query("CALL last_connection(" . $uid . "); ", $LINK) || do_log_sql($stdlog, "#1320 " . mysql_error($LINK), $child);
  982. }
  983. }
  984.  
  985. function get_user_proper_by_switch_port_groupe_del($LINK, $stdlog, $swid, $port, $child) {
  986. $res = mysql_fetch_array($result);
  987. mysql_free_result($result);
  988. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  989. $result = mysql_query("SELECT * FROM " . BILL_USERDEL_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  990. return $res;
  991. }
  992.  
  993. function get_user_proper_by_switch_port_groupe_otkl($LINK, $stdlog, $swid, $port, $child) {
  994. $res = mysql_fetch_array($result);
  995. mysql_free_result($result);
  996. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  997. $result = mysql_query("SELECT * FROM " . BILL_USERBLOCK_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  998. return $res;
  999. }
  1000.  
  1001. function get_user_proper_by_switch_port_groupe_freeze($LINK, $stdlog, $swid, $port, $child) {
  1002. $res = mysql_fetch_array($result);
  1003. mysql_free_result($result);
  1004. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  1005. $result = mysql_query("SELECT * FROM " . BILL_USERFREEZE_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  1006. return $res;
  1007. }
  1008.  
  1009. function get_user_proper_by_switch_port($LINK, $stdlog, $swid, $port, $child) {
  1010. $res = mysql_fetch_array($result);
  1011. mysql_free_result($result);
  1012. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  1013. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE swid='" . $swid . "' and switchport ='" . $port . "' ", $LINK) || do_log_sql($stdlog, "#844 " . mysql_error($LINK), $child);
  1014. return $res;
  1015. }
  1016.  
  1017. function check_mac_in_segment_not_uid($LINK, $stdlog, $mac, $uid, $sectorid, $child) {
  1018. $res = mysql_fetch_array($result);
  1019. mysql_free_result($result);
  1020. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_AUTH_TABLE . " WHERE local_mac='" . $mac . "' and sectorid = " . $sectorid . " and uid!=" . $uid . "", $LINK) || do_log_sql($stdlog, "#2345629 " . mysql_error($LINK), $child);
  1021. $result = mysql_query("SELECT count(uid) as count FROM " . BILL_AUTH_TABLE . " WHERE local_mac='" . $mac . "' and sectorid = " . $sectorid . " and uid!=" . $uid . "", $LINK) || do_log_sql($stdlog, "#2345629 " . mysql_error($LINK), $child);
  1022. return $res["count"];
  1023. }
  1024.  
  1025. function get_user_proper_by_mac_for_switch($LINK, $stdlog, $mac, $swid, $child) {
  1026. $res = mysql_fetch_array($result);
  1027. mysql_free_result($result);
  1028. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE local_mac='" . $mac . "' and sectorid in (select sectorid from " . BILL_SWITCH_VLAN_TABLE . " where swid = " . $swid . ")", $LINK) || do_log_sql($stdlog, "#2345630 " . mysql_error($LINK), $child);
  1029. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE local_mac='" . $mac . "' and sectorid in (select sectorid from " . BILL_SWITCH_VLAN_TABLE . " where swid = " . $swid . ")", $LINK) || do_log_sql($stdlog, "#2345630 " . mysql_error($LINK), $child);
  1030. return $res;
  1031. }
  1032.  
  1033. function get_user_proper_by_mac_hs($LINK, $stdlog, $mac, $child) {
  1034. $res = mysql_fetch_array($result);
  1035. mysql_free_result($result);
  1036. $result = mysql_query("SELECT * FROM " . BILL_hotspot_free_users_TABLE . " WHERE local_mac='" . $mac . "' ", $LINK) || do_log_sql($stdlog, "#2345631 " . mysql_error($LINK), $child);
  1037. $result = mysql_query("SELECT * FROM " . BILL_hotspot_free_users_TABLE . " WHERE local_mac='" . $mac . "' ", $LINK) || do_log_sql($stdlog, "#2345631 " . mysql_error($LINK), $child);
  1038. return $res;
  1039. }
  1040.  
  1041. function get_user_proper_by_vlan_port($LINK, $stdlog, $client_vlan, $client_port, $child) {
  1042. $res = mysql_fetch_array($result);
  1043. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE `switchport` = '" . $client_port . "' AND `swid` IN (SELECT `swid` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = '" . $client_vlan . "' AND `port` = '" . $client_port . "');", $LINK) || do_log_sql($stdlog, "#1432423f2 " . mysql_error($LINK), $child);
  1044. $result = mysql_query("SELECT * FROM " . BILL_AUTH_TABLE . " WHERE `switchport` = '" . $client_port . "' AND `swid` IN (SELECT `swid` FROM `" . BILL_SWITCH_IP_UNNUMBERED_TABLE . "` WHERE `vlan` = '" . $client_vlan . "' AND `port` = '" . $client_port . "');", $LINK) || do_log_sql($stdlog, "#1432423f2 " . mysql_error($LINK), $child);
  1045. return $res;
  1046. }
  1047.  
  1048. function get_basic_users_list_by_mac($LINK, $stdlog, $mac, $child) {
  1049. $mac = strtoupper($mac);
  1050. $mac = trim($mac);
  1051. ....................................
  1052. ...........
  1053. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement