123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- <?php
- /**
- *
- * @param string $login
- *
- * @return void
- */
- function billing_createuser($login) {
- setVal($login, "add");
- }
- /**
- * Creates new stargazer user
- *
- * @param string $login
- *
- * @return void
- */
- function billing_deleteuser($login) {
- setVal($login, "del");
- }
- /**
- * Sets user credit limit
- *
- * @param string $login
- * @param float $credit
- *
- * @return void
- */
- function billing_setcredit($login, $credit) {
- setVal($login, "credit", $credit);
- }
- /**
- * Sets user credit limit expire date
- *
- * @param string $login
- * @param string $creditexpire
- *
- * @return void
- */
- function billing_setcreditexpire($login, $creditexpire) {
- $creditexpire = strtotime($creditexpire);
- setVal($login, "CreditExpire", $creditexpire);
- }
- /**
- * Sets user IP address
- *
- * @param string $login
- * @param string $ip
- *
- * @return void
- */
- function billing_setip($login, $ip) {
- setVal($login, "ip", $ip);
- }
- /**
- * Changes user password
- *
- * @param string $login
- * @param string $password
- *
- * @return void
- */
- function billing_setpassword($login, $password) {
- setVal($login, "password", $password);
- }
- /**
- * Changes user tariff
- *
- * @param string $login
- * @param string $tariff
- *
- * @return void
- */
- function billing_settariff($login, $tariff) {
- setVal($login, "tariff", $tariff, "now");
- }
- /**
- * Changes user tariff from next month
- *
- * @param string $login
- * @param string $tariff
- *
- * @return void
- */
- function billing_settariffnm($login, $tariff) {
- setVal($login, "tariff", $tariff, "delayed");
- }
- /**
- * Pushes some money summ to user account
- *
- * @param string $login
- * @param float $cash
- *
- * @return void
- */
- function billing_addcash($login, $cash) {
- setVal($login, "cash", $cash, "add");
- }
- /**
- * Changes user AlwaysOnline flag state
- *
- * @param string $login
- * @param int $state
- *
- * @return void
- */
- function billing_setao($login, $state) {
- setVal($login, "aonline", $state);
- }
- /**
- * Sets user Cash parameter to some summ value
- *
- * @param string $login
- * @param float $cash
- *
- * @return void
- */
- function billing_setcash($login, $cash) {
- setVal($login, "cash", $cash, "set");
- }
- /**
- * Changes user detailed stats flag state
- *
- * @param string $login
- * @param int $state
- *
- * @return void
- */
- function billing_setdstat($login, $state) {
- setVal($login, "disabledetailstat", $state);
- }
- /**
- * Changes user Down flag state
- *
- * @param string $login
- * @param int $state
- *
- * @return void
- */
- function billing_setdown($login, $state) {
- setVal($login, "down", $state);
- }
- /**
- * Performs sequential call of OnDisconnect and OnConnect init scripts.
- *
- * @global object $billing_config
- * @param string $login
- *
- * @return void
- */
- function billing_resetuser($login) {
- global $billing_config;
- //rscriptd reset hotfix
- if ($billing_config['RESET_AO']) {
- billing_setao($login, 0);
- billing_setao($login, 1);
- } else {
- billing_setdown($login, 1);
- billing_setdown($login, 0);
- }
- }
- /**
- * Changes user Passive (aka Frozen) flag state
- *
- * @param string $login
- * @param int $state
- *
- * @return void
- */
- function billing_setpassive($login, $state) {
- setVal($login, "passive", $state);
- }
- /**
- * Creates new Stargazer tariff
- *
- * @param string $tariff
- *
- * @return void
- */
- function billing_createtariff($tariff) {
- setVal(@$login, "addtariff", $tariff);
- }
- /**
- * Deletes some Stargazer tariff
- *
- * @param string $tariff
- *
- * @return void
- */
- function billing_deletetariff($tariff) {
- setVal(@$login, "deltariff", $tariff);
- }
- /**
- * Returns array of all available Stargazer tariffs with all tariff data
- *
- * @return array
- */
- function billing_getalltariffs() {
- return simple_queryall("SELECT * from `tariffs` ORDER BY `name`");
- }
- /**
- * Returns array of some existing tariff data
- *
- * @param string $name
- *
- * @return array
- */
- function billing_gettariff($name) {
- return simple_query("SELECT * from `tariffs` where `name` = '$name'");
- }
- /**
- * Changes some existing Stargazer tariff parameters
- *
- * @param string $tariff
- * @param array $options
- *
- * @return void
- */
- function billing_edittariff($tariff, $options) {
- $dhour = $options ['dhour'];
- $dmin = $options ['dmin'];
- $nhour = $options ['nhour'];
- $nmin = $options ['nmin'];
- $PriceDay = $options ['PriceDay'];
- $PriceNight = $options ['PriceNight'];
- $Fee = $options ['Fee'];
- $Free = $options ['Free'];
- $PassiveCost = $options ['PassiveCost'];
- $TraffType = $options ['TraffType'];
- if (isset($options['Period'])) {
- $period = $options['Period'];
- } else {
- $period = '';
- }
- $dirs = getAllDirs();
- $string = "<SetTariff name=\"$tariff\">";
- $string .= "<Fee value=\"$Fee\"/>";
- $string .= "<Free value=\"$Free\"/>";
- $string .= "<PassiveCost value=\"$PassiveCost\"/>";
- $string .= "<TraffType value=\"$TraffType\"/>";
- if (!empty($period)) {
- $string .= "<period value=\"" . $period . "\"/>";
- }
- foreach ($dirs as $dir) {
- $key = $dir['rulenumber'];
- $string .= "<Time$key value=\"$dhour[$key]:$dmin[$key]-$nhour[$key]:$nmin[$key]\"/>";
- }
- $PriceDayA = '';
- $PriceDayB = '';
- $PriceNightA = '';
- $PriceNightB = '';
- $SinglePrice = '';
- $NoDiscount = '';
- $Threshold = '';
- $dayATmp = array();
- $dayBTmp = array();
- $nightATmp = array();
- $nightBTmp = array();
- // A-a-a-a-a-a-a!
- // https://stg.net.ua/doc/ch11.html
- // A-A-A-A-A-A!!!1
- for ($i = 0; $i <= 9; $i++) {
- if (isset($PriceDay[$i])) {
- if (strpos($PriceDay[$i], '/') !== false) {
- $prices = explode('/', $PriceDay[$i]);
- if (sizeof($prices) == 2) {
- $dayATmp[$i] = $prices[0];
- $dayBTmp[$i] = $prices[1];
- } else {
- debarr(sizeof($prices));
- $dayATmp[$i] = 0;
- $dayBTmp[$i] = 0;
- }
- } else {
- $dayATmp[$i] = $PriceDay[$i];
- $dayBTmp[$i] = $PriceDay[$i];
- }
- } else {
- $dayATmp[$i] = 0;
- $dayBTmp[$i] = 0;
- }
- if (isset($PriceNight[$i])) {
- if (strpos($PriceNight[$i], '/') !== false) {
- $prices = explode('/', $PriceNight[$i]);
- if (sizeof($prices) == 2) {
- $nightATmp[$i] = $prices[0];
- $nightBTmp[$i] = $prices[1];
- } else {
- $nightATmp[$i] = 0;
- $nightBTmp[$i] = 0;
- }
- } else {
- $nightATmp[$i] = $PriceNight[$i];
- $nightBTmp[$i] = $PriceNight[$i];
- }
- } else {
- $nightATmp[$i] = 0;
- $nightBTmp[$i] = 0;
- }
- }
- for ($i = 0; $i <= 9; $i++) {
- $delimiter = ($i < 9) ? '/' : '';
- if (isset($options['NoDiscount'][$i])) {
- $NoDiscount .= '1' . $delimiter;
- } else {
- $NoDiscount .= '0' . $delimiter;
- }
- if (isset($options['SinglePrice'][$i])) {
- $SinglePrice .= '1' . $delimiter;
- } else {
- $SinglePrice .= '0' . $delimiter;
- }
- if (isset($options['Threshold'][$i])) {
- $Threshold .= $options['Threshold'][$i] . $delimiter;
- } else {
- $Threshold .= '0' . $delimiter;
- }
- $PriceDayA .= $dayATmp[$i] . $delimiter;
- $PriceDayB .= $dayBTmp[$i] . $delimiter;
- $PriceNightA .= $nightATmp[$i] . $delimiter;
- $PriceNightB .= $nightBTmp[$i] . $delimiter;
- }
- $string .= "<PriceDayA value=\"$PriceDayA\"/>";
- $string .= "<PriceDayB value=\"$PriceDayB\"/>";
- $string .= "<PriceNightA value=\"$PriceNightA\"/>";
- $string .= "<PriceNightB value=\"$PriceNightB\"/>";
- $string .= "<SinglePrice value=\"$SinglePrice\"/>";
- $string .= "<NoDiscount value=\"$NoDiscount\"/>";
- $string .= "<Threshold value=\"$Threshold\"/>";
- $string .= "</SetTariff>";
- executor($string);
- }
- /**
- * Returns array of all available traffic classes
- *
- * @return array
- */
- function getAllDirs() {
- return simple_queryall("SELECT * from `directions` ORDER BY `rulenumber`");
- }
- /**
- * Performs sgconf_xml call with some XML formatted request
- *
- * @global object $billing_config
- * @param string $attr
- *
- * @param bool $debug
- *
- * @return void
- */
- function executor($attr, $debug = false) {
- global $billing_config;
- $cmd = $billing_config['SGCONFXML'] . ' -s ' . $billing_config['STG_HOST'] . ' -p ' . $billing_config['STG_PORT'] . ' -a ' . $billing_config['STG_LOGIN'] . ' -w ' . $billing_config['STG_PASSWD'] . ' -r \'' . $attr . '\'';
- if ($debug) {
- print(htmlspecialchars($cmd) . "\n<br>");
- print(shell_exec($cmd));
- die();
- } else {
- shell_exec($cmd);
- }
- }
- /**
- * Performs call of executor with some request data
- *
- * @param string $login
- * @param string $type
- * @param string $value
- * @param string $subtype
- *
- * @return void
- */
- function setVal($login, $type, $value = false, $subtype = false) {
- $maintype = 'SetUser';
- $maintype = ($type == 'add') ? 'AddUser' : $maintype;
- $maintype = ($type == 'del') ? 'DelUser' : $maintype;
- $maintype = ($type == 'addtariff') ? 'AddTariff' : $maintype;
- $maintype = ($type == 'deltariff') ? 'DelTariff' : $maintype;
- $string = "<$maintype><login value=\"$login\" />";
- switch ($type) {
- case (preg_match('#cash|\btariff\b#i', $type) ? $type : !$type) :
- $val = $subtype;
- break;
- case 'del':
- $val = 'login';
- break;
- case (preg_match('#addtariff|deltariff#Uis', $type) ? $type : !$type):
- $val = 'name';
- break;
- default :
- $val = 'value';
- break;
- }
- if ($type != 'add') {
- $string .= "<$type $val=\"$value\" />";
- }
- $string .= "</$maintype>";
- $string = ($type == 'del') ? "<$maintype $val=\"$login\" />" : $string;
- $string = ($type == 'addtariff' || $type == 'deltariff') ? "<$type $val=\"$value\" />" : $string;
- executor($string, false);
- }
|