index.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. set_time_limit(0);
  3. if (cfr('ROOT')) {
  4. function web_UserGenForm() {
  5. $alltariffs_raw = zb_TariffsGetAll();
  6. $alltariffs = array();
  7. if (!empty($alltariffs_raw)) {
  8. foreach ($alltariffs_raw as $it => $eachtariff) {
  9. $alltariffs[$eachtariff['name']] = $eachtariff['name'];
  10. }
  11. }
  12. $inputs = wf_TextInput('gencount', __('Count of users to generate'), '', true);
  13. $inputs .= wf_Selector('gentariff', $alltariffs, __('Existing tariff for this users'), '', true);
  14. $inputs .= multinet_service_selector() . ' ' . __('Service for new users') . wf_tag('br');
  15. $inputs .= wf_CheckInput('fastsqlgen', __('Generate MySQL dump to restore via backups module'), true, false);
  16. $inputs .= wf_Submit(__('Go!'));
  17. $result = wf_Form("", "POST", $inputs, 'glamour');
  18. show_window(__('Sample user generator'), $result);
  19. }
  20. web_UserGenForm();
  21. if (ubRouting::checkPost('gencount')) {
  22. $altCfg = $ubillingConfig->getAlter();
  23. $neednum = ubRouting::post('gencount', 'int');
  24. $lastBuild = simple_query("SELECT * from `build` ORDER BY `id` DESC LIMIT 1");
  25. $lastBuildId = $lastBuild['id'];
  26. $serviceID = ubRouting::post('serviceselect', 'int');
  27. $netID = multinet_get_service_networkid($serviceID);
  28. $tariff = ubRouting::post('gentariff', 'mres');
  29. if (!ubRouting::checkPost('fastsqlgen')) {
  30. //normal user generation via standard stargazer API
  31. for ($i = 1; $i <= $neednum; $i++) {
  32. $randomLogin = 'gen_' . zb_rand_string(10);
  33. $randomPassword = zb_PasswordGenerate($altCfg['PASSWORD_GENERATION_LENGHT']);
  34. $randomName = zb_GenerateRandomName();
  35. $randomPhone = rand(111111, 999999);
  36. $randomMobile = '380' . rand(1111111, 9999999);
  37. $randomMac = '14:' . '88' . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99);
  38. $randomApt = $i;
  39. $randomIp = multinet_get_next_freeip('nethosts', 'ip', $netID);
  40. $randomFloor = rand(1, 9);
  41. $randomEntrance = rand(1, 4);
  42. //registering subroutine
  43. $billing->createuser($randomLogin);
  44. $billing->setpassword($randomLogin, $randomPassword);
  45. $billing->setip($randomLogin, $randomIp);
  46. zb_AddressCreateApartment($lastBuildId, $randomEntrance, $randomFloor, $randomApt);
  47. zb_AddressCreateAddress($randomLogin, zb_AddressGetLastid());
  48. multinet_add_host($netID, $randomIp);
  49. zb_UserCreateRealName($randomLogin, $randomName);
  50. zb_UserCreatePhone($randomLogin, $randomPhone, $randomMobile);
  51. zb_UserCreateContract($randomLogin, '');
  52. zb_UserCreateEmail($randomLogin, '');
  53. zb_UserCreateSpeedOverride($randomLogin, 0);
  54. multinet_change_mac($randomIp, $randomMac);
  55. multinet_rebuild_all_handlers();
  56. $billing->settariff($randomLogin, $tariff);
  57. $billing->setao($randomLogin, '1');
  58. $billing->setdstat($randomLogin, '1');
  59. zb_UserRegisterLog($randomLogin);
  60. log_register("SAMPLE GENERATION OF (" . $randomLogin . ") DONE");
  61. }
  62. } else {
  63. //generating MySQL dump
  64. $dumpName = 'content/backups/sql/generated_' . date("Y-m-d_H_i_s") . '.sql';
  65. $dumpData = '';
  66. $newAptId = @zb_AddressGetLastid();
  67. if (empty($newAptId)) {
  68. $newAptId = 0;
  69. }
  70. $allFreeIps = multinet_get_all_free_ip('nethosts', 'ip', $netID);
  71. $admin = whoami();
  72. $usedMacs = array();
  73. if (sizeof($allFreeIps) >= $neednum) {
  74. for ($i = 1; $i <= $neednum; $i++) {
  75. $newAptId++;
  76. $randomLogin = 'gen_' . zb_rand_string(16);
  77. $randomPassword = zb_PasswordGenerate($altCfg['PASSWORD_GENERATION_LENGHT']);
  78. $randomName = zb_GenerateRandomName();
  79. $randomName = ubRouting::filters($randomName, 'mres');
  80. $randomPhone = rand(111111, 999999);
  81. $randomMobile = '380' . rand(1111111, 9999999);
  82. $randomMac = '14:' . '88' . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99);
  83. if (isset($usedMacs[$randomMac])) {
  84. while (isset($usedMacs[$randomMac])) {
  85. $randomMac = '14:' . '88' . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99);
  86. }
  87. }
  88. $usedMacs[$randomMac] = 1; //mark as used
  89. $randomApt = $i;
  90. $randomCash = rand(0, 500);
  91. $randomFloor = rand(1, 9);
  92. $randomEntrance = rand(1, 4);
  93. $nextFreeIpIndex = array_keys($allFreeIps);
  94. $randomIp = $allFreeIps[$nextFreeIpIndex[0]];
  95. unset($allFreeIps[$nextFreeIpIndex[0]]);
  96. //user profile creation
  97. $dumpData .= "-- " . $randomLogin . PHP_EOL;
  98. $dumpData .= "INSERT INTO `users` (`login`,`Password`,`Passive`,`Down`,`DisabledDetailStat`,`AlwaysOnline`,`Tariff`,`Address`,`Phone`,`Email`,`Note`,`RealName`,`StgGroup`,`Credit`,`TariffChange`,`Userdata0`,`Userdata1`,`Userdata2`,`Userdata3`,`Userdata4`,`Userdata5`,`Userdata6`,`Userdata7`,`Userdata8`,`Userdata9`,`CreditExpire`,`IP`,`D0`,`U0`,`D1`,`U1`,`D2`,`U2`,`D3`,`U3`,`D4`,`U4`,`D5`,`U5`, `D6`, `U6`,`D7`, `U7`, `D8`,`U8`,`D9`,`U9`,`Cash`,`FreeMb`,`LastCashAdd`,`LastCashAddTime`,`PassiveTime`,`LastActivityTime`,`NAS`)VALUES ('" . $randomLogin . "','" . $randomPassword . "','0','0','1','1','" . $tariff . "','','','','','','','0','', '','','','', '', '', '', '','', '', '0','" . $randomIp . "','0','0','0','0','0', '0','0','0', '0','0','0','0','0', '0','0','0', '0', '0', '0', '0', '" . $randomCash . "','0','0', '0','0', '0','');" . PHP_EOL;
  99. //apartment creation
  100. $dumpData .= "INSERT INTO `apt` (`id`,`buildid`,`entrance`,`floor`,`apt`) VALUES (NULL,'" . $lastBuildId . "','" . $randomEntrance . "','" . $randomFloor . "','" . $randomApt . "');" . PHP_EOL;
  101. //apt=>address binding
  102. $dumpData .= "INSERT INTO `address` (`id`,`login`,`aptid`) VALUES (NULL, '" . $randomLogin . "','" . $newAptId . "');" . PHP_EOL;
  103. //new multinet host creation
  104. $dumpData .= "INSERT INTO `nethosts` (`id` ,`ip` ,`mac` ,`netid` ,`option`) VALUES (NULL , '" . $randomIp . "', '" . $randomMac . "', '" . $netID . "', '');" . PHP_EOL;
  105. //users real name creation
  106. $dumpData .= "INSERT INTO `realname` (`id`,`login`,`realname`) VALUES (NULL, '" . $randomLogin . "','" . $randomName . "');" . PHP_EOL;
  107. //phone data here
  108. $dumpData .= "INSERT INTO `phones` (`id`,`login`,`phone`,`mobile`) VALUES (NULL, '" . $randomLogin . "','" . $randomPhone . "','" . $randomMobile . "');" . PHP_EOL;
  109. //empty contract, email, sped overrides here
  110. $dumpData .= "INSERT INTO `contracts` (`id`,`login`,`contract`) VALUES (NULL, '" . $randomLogin . "','');" . PHP_EOL;
  111. $dumpData .= "INSERT INTO `emails` (`id`,`login`,`email`) VALUES (NULL, '" . $randomLogin . "','');" . PHP_EOL;
  112. $dumpData .= "INSERT INTO `userspeeds` (`id` ,`login` ,`speed`) VALUES (NULL , '" . $randomLogin . "', '0');" . PHP_EOL;
  113. //user register log
  114. $dumpData .= "INSERT INTO `userreg` (`id` ,`date` ,`admin` ,`login` ,`address`) VALUES (NULL , '" . curdatetime() . "', '" . $admin . "', '" . $randomLogin . "', 'someaddress " . $randomApt . "');" . PHP_EOL;
  115. $dumpData .= PHP_EOL;
  116. }
  117. //saving dump
  118. file_put_contents($dumpName, $dumpData);
  119. show_success($dumpName . ' ' . __('Saved'));
  120. //debarr($dumpData);
  121. } else {
  122. show_error(__('No free IPs enough in selected service'));
  123. }
  124. }
  125. }
  126. } else {
  127. show_error(__('Permission denied'));
  128. }