handlers.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * base stargazer handlers as add_cash routines using sgconf via shellscripts
  4. */
  5. /* *
  6. * execute sgconf command
  7. * @param string $command parameters for sgconf
  8. *
  9. * @return void
  10. */
  11. function executor($command, $debug = false) {
  12. $globconf = parse_ini_file('config/billing.ini');
  13. $SGCONF = $globconf['SGCONF'];
  14. $STG_HOST = $globconf['STG_HOST'];
  15. $STG_PORT = $globconf['STG_PORT'];
  16. $STG_LOGIN = $globconf['STG_LOGIN'];
  17. $STG_PASSWD = $globconf['STG_PASSWD'];
  18. $configurator = $SGCONF . ' set -s ' . $STG_HOST . ' -p ' . $STG_PORT . ' -a' . $STG_LOGIN . ' -w' . $STG_PASSWD . ' ' . $command;
  19. if ($debug) {
  20. print($configurator . "\n");
  21. print(shell_exec($configurator));
  22. } else {
  23. shell_exec($configurator);
  24. }
  25. }
  26. /**
  27. * Create stargazer user
  28. * @param string $login login to register
  29. *
  30. * @return void
  31. */
  32. function billing_createuser($login) {
  33. executor('-u' . $login . ' -n');
  34. }
  35. /**
  36. * Delete stargazer user
  37. * @param string $login login to delete
  38. *
  39. * @return void
  40. */
  41. function billing_deleteuser($login) {
  42. executor('-u' . $login . ' -l');
  43. }
  44. /**
  45. * Add cash to stargazer user
  46. *
  47. * @param string $login stargazer user login
  48. * @param string $cash cash float value
  49. *
  50. * @return void
  51. */
  52. function billing_addcash($login, $cash) {
  53. executor('-u' . $login . ' -c ' . $cash);
  54. }
  55. /**
  56. * Set user credit
  57. * @param string $login stargazer user login
  58. * @param string $credit cash float value
  59. *
  60. * @return void
  61. */
  62. function billing_setcredit($login, $credit) {
  63. executor('-u' . $login . ' -r ' . $credit);
  64. }
  65. /**
  66. * Set user credit expiration date
  67. * @param string $login stargazer user login
  68. * @param string $creditexpire creditexpire date value
  69. *
  70. * @return void
  71. */
  72. function billing_setcreditexpire($login, $creditexpire) {
  73. executor('-u' . $login . ' -E ' . $creditexpire);
  74. }
  75. /**
  76. * Set user down, then up
  77. * @param string $login stargazer user login
  78. *
  79. * @return void
  80. */
  81. function billing_resetuser($login) {
  82. executor('-u' . $login . ' -d 1');
  83. //sleep(3);
  84. executor('-u' . $login . ' -d 0');
  85. }
  86. /**
  87. * Set user AlwaysOnline
  88. * @param string $login stargazer user login
  89. * @param string $state always online - 1 or 0
  90. *
  91. * @return void
  92. */
  93. function billing_setao($login, $state) {
  94. executor('-u' . $login . ' --always-online ' . $state);
  95. }
  96. /**
  97. * Set cash to stargazer user
  98. * @param string $login stargazer user login
  99. * @param string $cash cash float value
  100. *
  101. * @return void
  102. */
  103. function billing_setcash($login, $cash) {
  104. executor('-u' . $login . ' -v ' . $cash);
  105. }
  106. /**
  107. * Set user DisableDstats
  108. * @param string $login stargazer user login
  109. * @param string $state disabledstats - 1 or 0
  110. *
  111. * @return void
  112. */
  113. function billing_setdstat($login, $state) {
  114. executor('-u' . $login . ' --disable-stat ' . $state);
  115. }
  116. /**
  117. * Set IP to stargazer user
  118. * @param string $login stargazer user login
  119. * @param string $ip ip value
  120. *
  121. * @return void
  122. */
  123. function billing_setip($login, $ip) {
  124. executor('-u' . $login . ' -I ' . $ip);
  125. }
  126. /**
  127. * Set password to stargazer user
  128. * @param string $login stargazer user login
  129. * @param string $password password string
  130. *
  131. * @return void
  132. */
  133. function billing_setpassword($login, $password) {
  134. executor('-u' . $login . ' -o ' . $password);
  135. ;
  136. }
  137. /**
  138. * Set tariff to stargazer user right now
  139. * @param string $login stargazer user login
  140. * @param string $tariff tariff name string
  141. *
  142. * @return void
  143. */
  144. function billing_settariff($login, $tariff) {
  145. executor('-u' . $login . ' -t ' . $tariff);
  146. }
  147. /**
  148. * Set tariff to stargazer user next month (native)
  149. * @param string $login stargazer user login
  150. * @param string $tariff tariff name string
  151. *
  152. * @return void
  153. */
  154. function billing_settariffnm($login, $tariff) {
  155. executor('-u' . $login . ' -t ' . $tariff . ':delayed');
  156. }
  157. /**
  158. * Set user Down
  159. * @param string $login stargazer user login
  160. * @param string $state Down state - 1 or 0
  161. *
  162. * @return void
  163. */
  164. function billing_setdown($login, $state) {
  165. executor('-u' . $login . ' -d ' . $state);
  166. }
  167. /**
  168. * Set user Passive
  169. * @param string $login stargazer user login
  170. * @param string $state Passive state - 1 or 0
  171. *
  172. * @return void
  173. */
  174. function billing_setpassive($login, $state) {
  175. executor('-u' . $login . ' -i ' . $state);
  176. }
  177. /**
  178. * Billing hadlers which is not supported in sgconf layer
  179. */
  180. function billing_edittariff($tariff, $options) {
  181. die('Sorry, this feature is not available in sgconf');
  182. }
  183. function billing_deletetariff($tariff) {
  184. die('Sorry, this feature is not available in sgconf');
  185. }
  186. function billing_createtariff($tariff) {
  187. die('Sorry, this feature is not available in sgconf');
  188. }
  189. function getAllDirs() {
  190. return simple_queryall("SELECT * from `directions` ORDER BY `rulenumber`");
  191. }
  192. function billing_getalltariffs() {
  193. return simple_queryall("SELECT * from `tariffs` ORDER BY `name`");
  194. }
  195. function billing_gettariff($name) {
  196. return simple_query("SELECT * from `tariffs` where `name` = '$name'");
  197. }
  198. ?>