handlers.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. function __call($method, $params = null, $debug = false) {
  3. global $billing_config;
  4. $request = xmlrpc_encode_request('stargazer.' . $method, $params, array('escaping' => 'markup', 'encoding' => 'utf-8'));
  5. $context = stream_context_create(
  6. array('http' => array(
  7. 'method' => 'POST',
  8. 'header' => 'Content-Type: text/xml',
  9. 'content' => $request)));
  10. $file = file_get_contents('http://' . $billing_config['STG_HOST'] . ':' . $billing_config['XMLRPC_PORT'] . '/RPC2', false, $context);
  11. $response = xmlrpc_decode($file);
  12. if (is_array($response) && xmlrpc_is_fault($response)) {
  13. trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
  14. }
  15. if ($debug) {
  16. echo( print_r($response) );
  17. }
  18. return $response;
  19. }
  20. function executor($method, $array) {
  21. global $billing_config;
  22. $data = __call('login', array($billing_config['STG_LOGIN'], $billing_config['STG_PASSWD']));
  23. if (isset($data['cookie'])) {
  24. array_unshift($array, $data['cookie']);
  25. __call($method, $array);
  26. }
  27. __call('logout', array($data['cookie']));
  28. }
  29. function billing_createuser($login) {
  30. executor('add_user', array($login));
  31. }
  32. function billing_addcash($login, $cash) {
  33. executor('add_user_cash', array($login, (float) $cash, "add $cash cash"));
  34. }
  35. function billing_deleteuser($login) {
  36. executor('del_user', array($login));
  37. }
  38. function billing_setip($login, $ip) {
  39. executor('chg_user', array($login, array('ips' => $ip)));
  40. }
  41. function billing_setpassword($login, $password) {
  42. executor('chg_user', array($login, array('password' => $password)));
  43. }
  44. function billing_settariff($login, $tariff) {
  45. executor('chg_user_tariff', array($login, $tariff, false, 'change tariff'));
  46. }
  47. function billing_settariffnm($login, $tariff) {
  48. executor('chg_user_tariff', array($login, $tariff, true, 'change tariff'));
  49. }
  50. function billing_setao($login, $state) {
  51. $state = ($state === 1) ? TRUE : FALSE;
  52. executor('chg_user', array($login, array('aonline' => $state)));
  53. }
  54. function billing_setcash($login, $cash) {
  55. executor('set_user_cash', array($login, (float) $cash, "set $cash cash"));
  56. }
  57. function billing_setdstat($login, $state) {
  58. $state = ($state === 1) ? TRUE : FALSE;
  59. executor('chg_user', array($login, array('disableddetailstat' => $state)));
  60. }
  61. function billing_setdown($login, $state) {
  62. $state = ($state === 1) ? TRUE : FALSE;
  63. executor('chg_user', array($login, array('down' => $state)));
  64. }
  65. function billing_resetuser($login) {
  66. global $billing_config;
  67. //rscriptd reset hotfix
  68. if ($billing_config['RESET_AO']) {
  69. billing_setao($login, 0);
  70. billing_setao($login, 1);
  71. } else {
  72. billing_setdown($login, 1);
  73. billing_setdown($login, 0);
  74. }
  75. }
  76. function billing_setpassive($login, $state) {
  77. $state = ($state === 1) ? TRUE : FALSE;
  78. executor('chg_user', array($login, array('passive' => $state)));
  79. }
  80. function billing_createtariff($tariff) {
  81. executor('add_tariff', array($tariff));
  82. }
  83. function billing_deletetariff($tariff) {
  84. executor('del_tariff', array($tariff));
  85. }
  86. function billing_getalltariffs() {
  87. return simple_queryall("SELECT * from `tariffs` ORDER BY `name`");
  88. }
  89. function billing_gettariff($name) {
  90. return simple_query("SELECT * from `tariffs` where `name` = '$name'");
  91. }
  92. function billing_setcredit($login, $credit) {
  93. executor('chg_user', array($login, array('credit' => $credit)));
  94. }
  95. function billing_edittariff($tariff, $options) {
  96. $dhour = $options ['dhour'];
  97. $dmin = $options ['dmin'];
  98. $nhour = $options ['nhour'];
  99. $nmin = $options ['nmin'];
  100. $PriceDay = $options ['PriceDay'];
  101. $PriceNight = $options ['PriceNight'];
  102. $Fee = (double) $options ['Fee'];
  103. $Free = (double) $options ['Free'];
  104. $PassiveCost = (double) $options ['PassiveCost'];
  105. $Threshold = $options ['Threshold'];
  106. $SinglePrice = $options ['SinglePrice'];
  107. $NoDiscount = $options ['NoDiscount'];
  108. switch ($options ['TraffType']) {
  109. case 'up':
  110. $TraffType = 0;
  111. break;
  112. case 'down':
  113. $TraffType = 1;
  114. break;
  115. case 'up+down':
  116. $TraffType = 2;
  117. break;
  118. case 'max':
  119. $TraffType = 3;
  120. break;
  121. default:
  122. $TraffType = 2;
  123. break;
  124. }
  125. for ($i = 0; $i < 10; ++$i) {
  126. $arr = @explode('/', $PriceDay[$i]);
  127. if ($arr [0] && $arr [1]) {
  128. $PriceDayAa = $arr [0];
  129. $PriceDayBb = $arr [1];
  130. } else {
  131. $PriceDayAa = @$PriceDay[$i];
  132. $PriceDayBb = @$PriceDay[$i];
  133. }
  134. $PriceDayAc [$i] = $PriceDayAa;
  135. $PriceDayBc [$i] = $PriceDayBb;
  136. $arr1 = @explode('/', $PriceNight[$i]);
  137. if ($arr1 [0] && $arr1 [1]) {
  138. $PriceNightAa = $arr1 [0];
  139. $PriceNightBb = $arr1 [1];
  140. } else {
  141. $PriceNightAa = @$PriceNight[$i];
  142. $PriceNightBb = @$PriceNight[$i];
  143. }
  144. $PriceNightAc [$i] = $PriceNightAa;
  145. $PriceNightBc [$i] = $PriceNightBb;
  146. $array[$i] = @array('hday' => (int) $dhour[$i], 'mday' => (int) $dmin[$i], 'hnight' => (int) $nhour[$i], 'mnight' => (int) $nmin[$i], 'pricedaya' => (double) $PriceDayAc [$i], 'pricedayb' => (double) $PriceDayBc[$i], 'pricenighta' => (double) $PriceNightAc [$i], 'pricenightb' => (double) $PriceNightBc [$i], 'threshold' => (int) $Threshold[$i], 'singleprice' => (boolean) $SinglePrice[$i], 'nodiscount' => (boolean) $NoDiscount[$i]);
  147. }
  148. executor('chg_tariff', array($tariff,
  149. array('fee' => $Fee, 'freemb' => $Free, 'passivecost' => $PassiveCost, 'traffType' => $TraffType,
  150. 'dirprices' => $array
  151. ))
  152. );
  153. }
  154. function getAllDirs() {
  155. return simple_queryall("SELECT * from `directions` ORDER BY `rulenumber`");
  156. }
  157. ?>