Source of file api.userside.php
Size: 66,007 Bytes - Last Modified: 2024-04-27T15:26:05+03:00
/tmp/current_snapshot/api/libs/api.userside.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783 | <?php /** * Userside integration API * https://www.userside.eu */ class UserSideApi { const API_VER = '1.5'; const API_DATE = '06.10.2017'; /** * Stores system alter config as key=>value * * @var array */ protected $altCfg = array(); /** * Contains all of available tariffs data as tariffname=>data * * @var array */ protected $allTariffs = array(); /** * Contains all of available tariff speeds as tariffname=>data (speeddown/speedup keys) * * @var array */ protected $allTariffSpeeds = array(); /** * Contains all tariffs periods as tariffname=>period (month/day) * * @var array */ protected $allTariffPeriods = array(); /** * Contains available cities as cityid=>data * * @var array */ protected $allCities = array(); /** * Contains available streets array as streetid=>data * * @var array */ protected $allStreets = array(); /** * Contains all available builds array as buildid=>builddata * * @var array */ protected $allBuilds = array(); /** * Contains available custom fields types as id=>name * * @var array */ protected $allCfTypes = array(); /** * Contains available custom fields data as login+cftypeid=>data * * @var array */ protected $allCfData = array(); /** * Contains data of all available Internet users as login=>data * * @var array */ protected $allUserData = array(); /** * Contains available tag types as id=>name * * @var array */ protected $allTagTypes = array(); /** * Contains supported methods list * * @var array */ protected $supportedMethods = array(); /** * Contains supported methods for change_user_data request * * @var array */ protected $supportedChangeMethods = array(); /** * Contains supported user states to change * * @var array */ protected $supportedChageUserState = array(); /** * Contains localised error notices * * @var array */ protected $errorNotices = array(); /** * Default streets type. May be configurable in future * * @var string */ protected $defaultStreetType = ''; /** * Default city type. May be configurable in future * * @var string */ protected $defaultCityType = ''; /** * Contains build passports data as buildid=>data * * @var array */ protected $buildPassports = array(); /** * Contains list of available virtual services as id=>data * * @var array */ protected $vServices = array(); /** * Contains virtual services to user tags mappings as tagid=>serviceid * * @var array */ protected $serviceTagMappings = array(); /** * Contains available device types as id=>name * * @var array */ protected $allDeviceTypes = array(); /** * Contains available devices models as id=>modeldata * * @var array */ protected $allSwitchModels = array(); /** * Contains available devices directory as id=>devicedata * * @var array */ protected $allSwitches = array(); /** * Debug mode flag * * @var bool */ protected $debugMode = false; /** * Creates new instance of basic UserSide API */ public function __construct() { $this->loadAlter(); $this->setOptions(); $this->loadTariffs(); $this->loadTariffSpeeds(); $this->loadTariffPeriods(); $this->loadCities(); $this->loadStreets(); $this->loadBuilds(); $this->loadCF(); $this->loadUsers(); $this->loadTagTypes(); $this->loadBuildPassports(); $this->loadVservices(); $this->loadSwitchModels(); $this->loadSwitchesAll(); } /** * Loads system alter config into private property for further usage * * @global object $ubillingConfig * * @return void */ protected function loadAlter() { global $ubillingConfig; $this->altCfg = $ubillingConfig->getAlter(); } /** * Sets object default properties * * @return void */ protected function setOptions() { $this->defaultStreetType = __('st.'); $this->defaultCityType = __('ct.'); $this->supportedMethods = array( 'get_supported_method_list' => __('Returns supported methods list'), 'get_api_information' => __('Returns UserSide API version'), 'get_tariff_list' => __('Returns available tariffs'), 'get_city_list' => __('Returns available cities data'), 'get_street_list' => __('Returns available streets data'), 'get_house_list' => __('Returns available builds data'), 'get_user_additional_data_type_list' => __('Returns user profile custom fields data'), 'get_user_state_list' => __('Returns users state data'), 'get_user_group_list' => __('Returns user tags list'), 'get_system_information' => __('Returns system information'), 'get_user_list' => __('Returns available users data'), 'get_user_tags' => __('Returns available users tags'), 'get_services_list' => __('Returns available user services'), 'get_user_history' => __('Returns user financial operations history'), 'get_user_messages' => __('Previous user tickets'), 'change_user_data' => __('Do some changes with user data'), 'get_supported_change_user_data_list' => __('Returns list of supported change user data methods'), 'get_supported_change_user_state' => __('Returns list of supported change user states'), 'get_supported_change_user_tariff' => __('Returns list of supported change user tariffs'), 'get_device_type' => __('Returns device type'), 'get_device_model' => __('Returns device model'), 'get_device_list' => __('Returns devices list'), 'get_connect_list' => __('Get device connection list') ); $this->supportedChangeMethods = array( 'balance_operation' => __('User balance operations'), 'balance_correct_operation' => __('User balance operations'), 'name' => __('User name operations'), 'comment' => __('User notes operations'), 'tariff' => __('User tariff operations'), 'state' => __('User state operations'), ); $this->supportedChageUserState = array( 'frozen' => __('Frozen user'), 'unfrozen' => __('Not frozen user'), 'down' => __('User down'), 'notdown' => __('User not down'), 'ao' => __('User AlwaysOnline'), 'notao' => __('User not AlwaysOnline') ); $this->allDeviceTypes = array( 1 => 'switch', 2 => 'radio', 3 => 'olt', 4 => 'onu', 5 => 'other' ); $this->errorNotices = array( 'EX_NO_PARAMS' => __('No request parameters set'), 'EX_USER_NOT_EXISTS' => __('No such user available'), 'EX_PARAM_MISSED' => __('Important parameter missed'), 'EX_METHOD_NOT_SUPPORTED' => __('Method not supported'), 'EX_BAD_MONEY_FORMAT' => __('Wrong format of money sum'), 'EX_WRONG_TARIFF' => __('Wrong tariff name') ); } /** * Loads all existing Internet users from database * * @return void */ protected function loadUsers() { $all = zb_UserGetAllStargazerData(); if (!empty($all)) { foreach ($all as $io => $each) { $this->allUserData[$each['login']] = $each; } } } /** * Loads existing tariffs from database into protected property for further usage * * @return void */ protected function loadTariffs() { $query = "SELECT * from `tariffs`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allTariffs[$each['name']] = $each; } } } /** * Loads existing tariff speeds from database into protected property for further usage * * @return void */ protected function loadTariffSpeeds() { $query = "SELECT * from `speeds`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allTariffSpeeds[$each['tariff']] = $each; } } } /** * Loads existing tariff periods from database into protected property for further usage * * @return void */ protected function loadTariffPeriods() { $this->allTariffPeriods = zb_TariffGetPeriodsAll(); } /** * Loads existing cities from database * * @return void */ protected function loadCities() { $query = "SELECT * from `city`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allCities[$each['id']] = $each; } } } /** * Loads existing builds from database * * @return void */ protected function loadBuilds() { $query = "SELECT * from `build`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allBuilds[$each['id']] = $each; } } } /** * Loads existing streets from database * * @return void */ protected function loadStreets() { $query = "SELECT * from `street`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allStreets[$each['id']] = $each; } } } /** * Loads existing custom fields data from database * * @return void */ protected function loadCF() { //getting CF types $query = "SELECT * from `cftypes`"; $allCfTypes = simple_queryall($query); if (!empty($allCfTypes)) { foreach ($allCfTypes as $io => $eachTypeData) { $this->allCfTypes[$eachTypeData['id']] = $eachTypeData['name']; } //getting users assigned CF content $query = "SELECT * from `cfitems`"; $allCfData = simple_queryall($query); $i = 0; if (!empty($allCfData)) { foreach ($allCfData as $io => $each) { if (!empty($each['content'])) { $this->allCfData[$each['login']][$i]['id'] = $each['typeid']; $this->allCfData[$each['login']][$i]['value'] = $each['content']; } $i++; } } } } /** * Returns all users registration dates as login=>date * * @return array */ protected function getUserRegData() { $result = array(); $query = "SELECT * from `userreg`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['login']] = $each['date']; } } return ($result); } /** * Loads existing tag types from database * * @return void */ protected function loadTagTypes() { $query = "SELECT * from `tagtypes`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allTagTypes[$each['id']] = $each['tagname']; } } } /** * Preloads available build passports for further usage * * @return void */ protected function loadBuildPassports() { if ($this->altCfg['BUILD_EXTENDED']) { $query = "SELECT * from `buildpassport`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->buildPassports[$each['buildid']] = $each; } } } } /** * Loads array of available virtual services * * @return void */ protected function loadVservices() { $query = "SELECT * from `vservices`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->vServices[$each['id']] = $each; $this->serviceTagMappings[$each['tagid']] = $each['id']; } } } /** * Loads available devices models from database * * @return void */ protected function loadSwitchModels() { $all = zb_SwitchModelsGetAll(); if (!empty($all)) { foreach ($all as $io => $each) { $this->allSwitchModels[$each['id']] = $each; } } } /** * Loads existing devices directory from database * * @return void */ protected function loadSwitchesAll() { $all = zb_SwitchesGetAll(); if (!empty($all)) { foreach ($all as $io => $each) { $this->allSwitches[$each['id']] = $each; } } } /** * Renders API reply as JSON string * * @param array $data * * @rerutn void */ protected function renderReply($data) { $result = 'undefined'; if (!$this->debugMode) { header('Content-Type: application/json'); if (!empty($data)) { $result = json_encode($data); } die($result); } else { debarr($data); } } /** * Returns array of all of existing tariffs data * * @param bool $brief - brief tariffs listing only with names * * @return array */ protected function getTariffsData($brief = false) { $result = array(); if (!empty($this->allTariffs)) { foreach ($this->allTariffs as $tariffName => $tariffData) { if (!$brief) { $result[$tariffName]['id'] = $tariffName; $result[$tariffName]['name'] = $tariffName; $result[$tariffName]['payment'] = $tariffData['Fee']; $result[$tariffName]['payment_interval'] = ($this->allTariffPeriods[$tariffName] == 'month') ? 30 : 1; $downspeed = (isset($this->allTariffSpeeds[$tariffName]['speeddown'])) ? $this->allTariffSpeeds[$tariffName]['speeddown'] : 0; $upspeed = (isset($this->allTariffSpeeds[$tariffName]['speedup'])) ? $this->allTariffSpeeds[$tariffName]['speedup'] : 0; $result[$tariffName]['speed'] = array( 'up' => $upspeed, 'down' => $downspeed, ); $result[$tariffName]['traffic'] = ($tariffData['Free']) ? $tariffData['Free'] : -1; $result[$tariffName]['service_type'] = 0; } else { $result[$tariffName]['id'] = $tariffName; $result[$tariffName]['name'] = $tariffName; } } } return ($result); } /** * Returns city data array * * @return array */ protected function getCitiesData() { $result = array(); if (!empty($this->allCities)) { foreach ($this->allCities as $cityId => $cityData) { $result[$cityId]['id'] = $cityId; $result[$cityId]['name'] = $cityData['cityname']; $result[$cityId]['type_name'] = $this->defaultCityType; } } return ($result); } /** * Returns streets data array * * @return array */ protected function getStreetsData() { $result = array(); if (!empty($this->allStreets)) { foreach ($this->allStreets as $streetId => $streetData) { $result[$streetId]['id'] = $streetId; $result[$streetId]['city_id'] = $streetData['cityid']; $result[$streetId]['name'] = $streetData['streetname']; $result[$streetId]['type_name'] = $this->defaultStreetType; $result[$streetId]['full_name'] = $this->defaultStreetType . ' ' . $streetData['streetname']; } } return ($result); } /** * Returns streets data array * * @return array */ protected function getBuildsData() { $result = array(); if (!empty($this->allBuilds)) { foreach ($this->allBuilds as $buildId => $buildData) { $result[$buildId]['id'] = $buildId; $streetId = $buildData['streetid']; $streetName = @$this->allStreets[$streetId]['streetname']; $result[$buildId]['city_district_id'] = ''; $result[$buildId]['street_id'] = $buildData['streetid']; $result[$buildId]['full_name'] = $streetName . ' ' . $buildData['buildnum']; $result[$buildId]['postcode'] = ''; if (isset($this->buildPassports[$buildId])) { $result[$buildId]['floor'] = $this->buildPassports[$buildId]['floors']; $result[$buildId]['entrance'] = $this->buildPassports[$buildId]['entrances']; } else { $result[$buildId]['floor'] = ''; $result[$buildId]['entrance'] = ''; } if (ispos($buildData['buildnum'], '/')) { $buildExpl = explode('/', $buildData['buildnum']); @$buildNumber = vf($buildExpl[0], 3); @$blockLetter = $buildExpl[1]; } else { $buildNumber = vf($buildData['buildnum'], 3); $blockLetter = preg_replace('/\P{L}+/u', '', $buildData['buildnum']); $blockLetter = trim($blockLetter); } $result[$buildId]['number'] = $buildNumber; $result[$buildId]['block'] = $blockLetter; $result[$buildId]['coordinates'] = $buildData['geo']; } } return ($result); } /** * Returns customfield types data * * @return array */ protected function getCFTypesData() { $result = array(); if (!empty($this->allCfTypes)) { foreach ($this->allCfTypes as $cftypeId => $eachCftypeName) { $result[$cftypeId]['id'] = $cftypeId; $result[$cftypeId]['name'] = $eachCftypeName; } } return ($result); } /** * Returns users states data * * @return array */ protected function getUsersStateList() { $result = array(); $result[5]['id'] = 5; $result[5]['name'] = __('Active'); $result[5]['functional'] = 'work'; $result[1]['id'] = 1; $result[1]['name'] = __('Debt'); $result[1]['functional'] = 'nomoney'; $result[2]['id'] = 2; $result[2]['name'] = __('User passive'); $result[2]['functional'] = 'pause'; $result[3]['id'] = 3; $result[3]['name'] = __('User down'); $result[3]['functional'] = 'disable'; $result[4]['id'] = 4; $result[4]['name'] = __('No tariff'); $result[4]['functional'] = 'new'; return ($result); } /** * Returns available tag types data * * @return array */ protected function getTagTypesList() { $result = array(); /* Правда твоя - теплый асфальт */ if (!empty($this->allTagTypes)) { foreach ($this->allTagTypes as $tagId => $eachTagName) { $result[$tagId]['id'] = $tagId; $result[$tagId]['name'] = $eachTagName; } } return ($result); } /** * Returns available methods array * * @return array */ protected function getMethodsList() { $result = array(); if (!empty($this->supportedMethods)) { foreach ($this->supportedMethods as $io => $each) { $result[$io]['comment'] = $each; } } return ($result); } /** * Returns available change methods list * * @return array */ protected function getChangeMethodsList() { $result = array(); if (!empty($this->supportedChangeMethods)) { foreach ($this->supportedChangeMethods as $io => $each) { $result[$io]['comment'] = $each; } } return ($result); } /** * Returns supported change user state options * * @return array */ protected function getChangeStateMethodsList() { $result = array(); if (!empty($this->supportedChageUserState)) { foreach ($this->supportedChageUserState as $io => $each) { $result[$io] = $each; } } return ($result); } /** * Returns available devices types * * @return array */ protected function getDeviceTypesList() { $result = $this->allDeviceTypes; return ($result); } /** * Returns available device models * * @return array */ protected function getDeviceModels() { $result = array(); if (!empty($this->allSwitchModels)) { foreach ($this->allSwitchModels as $io => $each) { $result[$each['id']]['id'] = $each['id']; $result[$each['id']]['type_id'] = ''; //empty now, because model don't know anything about this $result[$each['id']]['name'] = $each['modelname']; $result[$each['id']]['iface_count'] = $each['ports']; } } return ($result); } /** * Returns list of available devices in database * * @param string $types * * @return array */ protected function getDevicesList($types = '') { $result = array(); if (!empty($this->allSwitches)) { $typesFilter = array(); //ids of device types for result rendering $switchCemetery = zb_SwitchesGetAllDeathTime(); //getting currently dead switches list if (!empty($types)) { //filters preprocessing $filtersTmp = explode(',', $types); if (!empty($filtersTmp)) { foreach ($filtersTmp as $ia => $eachFilter) { $tidTmp = array_search($eachFilter, $this->allDeviceTypes); if ($tidTmp) { $typesFilter[$tidTmp] = $this->allDeviceTypes[$tidTmp]; } } } } foreach ($this->allSwitches as $io => $each) { //setting device type $deviceType = $this->getDeviceType($each['id']); //applying filters if required if (empty($typesFilter)) { $filteredFlag = true; } else { if (isset($typesFilter[$deviceType])) { $filteredFlag = true; } else { $filteredFlag = false; } } $switchIp = $each['ip']; if (isset($switchCemetery[$switchIp])) { $lastActivityTime = $switchCemetery[$switchIp]; } else { $lastActivityTime = curdatetime(); } $switchMac = (check_mac_format($each['swid'])) ? $each['swid'] : ''; if ($filteredFlag) { $result[$each['id']]['id'] = $each['id']; $result[$each['id']]['type_id'] = $deviceType; $result[$each['id']]['model_id'] = $each['modelid']; $result[$each['id']]['ip'] = $each['ip']; $result[$each['id']]['mac'] = $switchMac; //requires SWITCHES_EXTENDED option enabled. $result[$each['id']]['house_id'] = ''; //no normal topology points at this moment $result[$each['id']]['entrance'] = ''; $result[$each['id']]['floor'] = ''; $result[$each['id']]['node_id'] = ''; $result[$each['id']]['location'] = $each['location']; $result[$each['id']]['geo'] = $each['geo']; $result[$each['id']]['comment'] = $each['desc']; $result[$each['id']]['date_activity'] = $lastActivityTime; $result[$each['id']]['date_create'] = ''; $result[$each['id']]['snmp_version'] = '2c'; $result[$each['id']]['snmp_port'] = '161'; $result[$each['id']]['snmp_read_community'] = $each['snmp']; $result[$each['id']]['software_version'] = ''; } } } return ($result); } /** * Returns device type id * * @param int $deviceId * * @return int */ protected function getDeviceType($deviceId) { //switch by default $result = 1; if (isset($this->allSwitches[$deviceId])) { if (ispos($this->allSwitches[$deviceId]['desc'], 'OLT')) { $result = 3; } if ((ispos($this->allSwitches[$deviceId]['desc'], 'MTSIGMON')) OR ( ispos($this->allSwitches[$deviceId]['desc'], 'AP')) OR ( ispos($this->allSwitches[$deviceId]['desc'], 'ssid:'))) { $result = 2; } } return ($result); } /** * Returns array of devices connection topology * * @return array */ protected function getDeviceConnectionsList() { $result = array(); if (!empty($this->allSwitches)) { foreach ($this->allSwitches as $io => $each) { //setting device type $deviceType = $this->getDeviceType($each['id']); // We dont know anyting about is. Like John Snow, yeah. $uplinkPort = 1; //detecting, have device uplinks or not? if (!empty($each['parentid'])) { //uplinks description $result[$this->allDeviceTypes[$deviceType]][$each['id']][1][$uplinkPort][] = array( 'type' => $this->allDeviceTypes[$this->getDeviceType($each['parentid'])], 'id' => $each['parentid'], 'direction' => 1, 'interface' => $uplinkPort); //downlinks description $result[$this->allDeviceTypes[$this->getDeviceType($each['parentid'])]][$each['parentid']][1][$uplinkPort][] = array( 'type' => $this->allDeviceTypes[$deviceType], 'id' => $each['id'], 'direction' => 1, 'interface' => 2 ); } } } return ($result); } /** * Returns Userside API information * * @return array */ protected function getApiInformation() { $result = array(); $result['version'] = self::API_VER; $result['date'] = self::API_DATE; return ($result); } /** * Returns server system information * * @return array */ protected function getSystemInformation() { $result = array(); $curdate = curdatetime(); $operatingSystem = shell_exec('uname'); $billingVersion = file_get_contents('RELEASE'); $result['date'] = $curdate; $result['os'] = trim($operatingSystem); $result['billing']['name'] = 'Ubilling'; $result['billing']['version'] = trim($billingVersion); return ($result); } /** * Returns array of all tagtypes set to users * * @return array */ protected function getAllUsersTags() { $result = array(); $query = "SELECT * from `tags`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['login']][] = $each['tagid']; } } return ($result); } /** * Returns array of all available PaymentIDs * * @return array */ protected function getAllUserPaymentIds() { $result = array(); if ($this->altCfg['OPENPAYZ_SUPPORT']) { if ($this->altCfg['OPENPAYZ_REALID']) { $query = "SELECT * from `op_customers`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['realid']] = $each['virtualid']; } } } else { if (!empty($this->allUserData)) { foreach (@$this->allUserData as $io => $each) { $result[$each['login']] = ip2int($each['IP']); } } } } return ($result); } /** * Returns array of all available login=>apt bindings * * @return array */ protected function getAllAddressList() { $result = array(); $query = "SELECT * from `address`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['login']] = $each['aptid']; } } return ($result); } /** * Returns array of all available apartments data as id=>data * * @return array */ protected function getAllAptList() { $result = array(); $query = "SELECT * from `apt`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['id']] = $each; } } return ($result); } /** * Returns array of all nethosts data as ip=>data * * @return array */ protected function getNethostsData() { $result = array(); $query = "SELECT * from `nethosts`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['ip']] = $each; } } return ($result); } /** * Returns data of available multinet networks as netid=>data * * @return array */ protected function getNetworksData() { $result = array(); $query = "SELECT * from `networks`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $result[$each['id']] = $each; } } return ($result); } /** * Returns all users support tickets * * @return array */ protected function getUsersMessages() { $result = array(); $query = "SELECT * from `ticketing` ORDER BY `id` ASC;"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { if (($each['from'] != 'NULL') AND ( empty($each['replyid']))) { //original ticket body $result[$each['id']]['id'] = $each['id']; $result[$each['id']]['user_id'] = $each['from']; $result[$each['id']]['msg_date'] = $each['date']; $result[$each['id']]['subject'] = __('Ticket') . ' ' . $each['date']; $result[$each['id']]['text'] = $each['text']; } else { //thats replies for a ticket if ((isset($result[$each['replyid']]))) { $replyAuthor = (!empty($each['admin'])) ? $each['admin'] : $each['from']; $result[$each['replyid']]['text'] .= PHP_EOL . '=========' . PHP_EOL; $result[$each['replyid']]['text'] .= PHP_EOL . __('Message') . ' ' . $each['date'] . ' (' . $replyAuthor . ')'; $result[$each['replyid']]['text'] .= ': ' . PHP_EOL . $each['text'] . PHP_EOL; } } } } return ($result); } /** * Returns existing users full info * * @param string $customerId * * @return array */ protected function getUsersList($customerId = '') { $result = array(); $allRealNames = zb_UserGetAllRealnames(); $allContracts = zb_UserGetAllContracts(); $allUserTags = $this->getAllUsersTags(); $allUserNotes = zb_UserGetAllNotes(); $allPaymentIds = $this->getAllUserPaymentIds(); $allAddresBindings = $this->getAllAddressList(); $allAptData = $this->getAllAptList(); $allPhones = zb_UserGetAllPhoneData(); $allEmails = zb_UserGetAllEmails(); $allNethosts = $this->getNethostsData(); $allNetworks = $this->getNetworksData(); $allRegData = $this->getUserRegData(); $scanData = array(); $hiddenDeadUsers = array(); if (@$this->altCfg['DEAD_HIDE'] AND @ $this->altCfg['DEAD_HIDE_USERSIDE']) { $deadTagId = @$this->altCfg['DEAD_TAGID']; if (!empty($deadTagId)) { if (!empty($allUserTags)) { foreach ($allUserTags as $dTagLogin => $dTagData) { if (!empty($dTagData)) { foreach ($dTagData as $dTagIndex => $dTagId) { if ($dTagId == $deadTagId) { $hiddenDeadUsers[$dTagLogin] = $dTagId; } } } } } } } if (!empty($allContracts)) { $allContracts = array_flip($allContracts); } $contractDates = new ContractDates(); $allContractDates = $contractDates->getAllDatesBasic(); //just one user if (!empty($customerId)) { if (isset($this->allUserData[$customerId])) { $scanData[$customerId] = $this->allUserData[$customerId]; } else { $scanData = array(); } } else { $scanData = $this->allUserData; } if (!empty($scanData)) { foreach ($scanData as $userLogin => $userData) { if (!isset($hiddenDeadUsers[$userLogin])) { $result[$userLogin]['id'] = $userLogin; $result[$userLogin]['login'] = $userLogin; $result[$userLogin]['full_name'] = @$allRealNames[$userLogin]; $result[$userLogin]['flag_corporate'] = 0; if ($userData['TariffChange']) { $curMonth = date('n'); $curYear = date('Y'); $firstDayNextMonth = ($curMonth == 12) ? mktime(0, 0, 0, 0, 0, $curYear + 1) : mktime(0, 0, 0, $curMonth + 1, 1); $firstDayNextMonth = date("Y-m-d", $firstDayNextMonth); } else { $firstDayNextMonth = ''; } $result[$userLogin]['tariff']['current'][0]['id'] = $userData['Tariff']; if ($firstDayNextMonth) { $result[$userLogin]['tariff']['current'][0]['date_finish'] = $firstDayNextMonth; } if ($userData['TariffChange']) { $result[$userLogin]['tariff']['new'][0]['id'] = $userData['TariffChange']; $result[$userLogin]['tariff']['new'][0]['date_start'] = $firstDayNextMonth; } $userContract = @$allContracts[$userLogin]; if ($userContract) { $result[$userLogin]['agreement'][0]['number'] = $userContract; $contractDate = @$allContractDates[$userContract]; if ($contractDate) { $result[$userLogin]['agreement'][0]['date'] = $contractDate; } } $result[$userLogin]['account_number'] = @$allPaymentIds[$userLogin]; // yep, this is something like Payment ID if (isset($allUserTags[$userLogin])) { foreach ($allUserTags[$userLogin] as $tagIo => $eachTagid) { $result[$userLogin]['group'][$eachTagid] = $eachTagid; } } $userNotes = @$allUserNotes[$userLogin]; if ($userNotes) { $result[$userLogin]['comment'] = $userNotes; } $result[$userLogin]['balance'] = $userData['Cash']; $result[$userLogin]['credit'] = $userData['Credit']; $userState = 5; // work if ($userData['Cash'] < '-' . $userData['Credit']) { $userState = 1; //nomoney } if ($userData['Passive'] == 1) { $userState = 2; // pause } if ($userData['Down'] == 1) { $userState = 3; // disable } if ($userData['Tariff'] == '*_NO_TARIFF_*') { $userState = 4; // new } $result[$userLogin]['state_id'] = $userState; if (isset($allRegData[$userLogin])) { $result[$userLogin]['date_create'] = $allRegData[$userLogin]; $result[$userLogin]['date_connect'] = $allRegData[$userLogin]; } else { $result[$userLogin]['date_create'] = ''; $result[$userLogin]['date_connect'] = ''; } if ($this->altCfg['DN_FULLHOSTSCAN']) { $dnFilePath = DATA_PATH . 'dn/' . $userLogin; if (file_exists($dnFilePath)) { $actTimestamp = filemtime($dnFilePath); $result[$userLogin]['date_activity'] = date("Y-m-d H:i:s", $actTimestamp); } else { $result[$userLogin]['date_activity'] = ''; } } else { $result[$userLogin]['date_activity'] = date("Y-m-d H:i:s", $userData['LastActivityTime']); } $result[$userLogin]['traffic']['month']['up'] = $userData['U0']; $result[$userLogin]['traffic']['month']['down'] = $userData['D0']; $result[$userLogin]['discount'] = 0; // TODO: to many discount models at this time $userApartmentId = @$allAddresBindings[$userLogin]; if ($userApartmentId) { $aptData = $allAptData[$userApartmentId]; $result[$userLogin]['address'][0]['type'] = 'connect'; $result[$userLogin]['address'][0]['house_id'] = $aptData['buildid']; $result[$userLogin]['address'][0]['apartment']['id'] = $userApartmentId; $result[$userLogin]['address'][0]['apartment']['full_name'] = $aptData['apt']; $result[$userLogin]['address'][0]['apartment']['number'] = vf($aptData['apt'], 3); if ($aptData['entrance']) { $result[$userLogin]['address'][0]['entrance'] = $aptData['entrance']; } if ($aptData['floor']) { $result[$userLogin]['address'][0]['floor'] = $aptData['floor']; } } $userPhoneData = @$allPhones[$userLogin]; if (!empty($userPhoneData)) { if (isset($userPhoneData['phone'])) { $result[$userLogin]['phone'][0]['number'] = $userPhoneData['phone']; $result[$userLogin]['phone'][0]['flag_main'] = 0; } if (isset($userPhoneData['mobile'])) { $result[$userLogin]['phone'][1]['number'] = $userPhoneData['mobile']; $result[$userLogin]['phone'][1]['flag_main'] = 1; } } $userEmail = @$allEmails[$userLogin]; if ($userEmail) { $result[$userLogin]['email'][0]['address'] = $userEmail; $result[$userLogin]['email'][0]['flag_main'] = 1; } $userIp = $userData['IP']; $userIp = ip2int($userIp); $result[$userLogin]['ip_mac'][0]['ip'] = $userIp; $nethostsData = @$allNethosts[$userData['IP']]; if (!empty($nethostsData)) { $subnetId = $nethostsData['netid']; $userMac = $nethostsData['mac']; $userMac = str_replace(':', '', $userMac); $userMac = strtolower($userMac); // mac lowercased withot delimiters $result[$userLogin]['ip_mac'][0]['mac'] = $userMac; $result[$userLogin]['ip_mac'][0]['ip_net'] = @$allNetworks[$subnetId]['desc']; } if (isset($allUserTags[$userLogin])) { foreach ($allUserTags[$userLogin] as $tagIo => $eachTagid) { $result[$userLogin]['tag'][$eachTagid]['id'] = $eachTagid; $result[$userLogin]['tag'][$eachTagid]['date_add'] = ''; } } if (isset($allUserTags[$userLogin])) { $srvCount = 0; foreach ($allUserTags[$userLogin] as $tagIo => $eachTagid) { if (isset($this->serviceTagMappings[$eachTagid])) { $serviceId = $this->serviceTagMappings[$eachTagid]; if (isset($result[$userLogin]['service'][$serviceId])) { $srvCount++; } else { $srvCount = 0; } $result[$userLogin]['service'][$serviceId][$srvCount]['cost'] = $this->vServices[$serviceId]['price']; $result[$userLogin]['service'][$serviceId][$srvCount]['date_add'] = ''; $result[$userLogin]['service'][$serviceId][$srvCount]['comment'] = ''; } } } if (isset($this->allCfData[$userLogin])) { $result[$userLogin]['additional_data'] = $this->allCfData[$userLogin]; } $result[$userLogin]['password'] = $userData['Password']; } } } return ($result); } /** * Returns array of available tags * * @return array */ protected function getUserTags() { $result = array(); if (!empty($this->allTagTypes)) { foreach ($this->allTagTypes as $tagId => $tagName) { $result[$tagId]['id'] = $tagId; $result[$tagId]['name'] = $tagName; } } return ($result); } /** * Returns list of available services * * @return array */ protected function getServicesList() { $result = array(); if (!empty($this->vServices)) { foreach ($this->vServices as $serviceId => $serviceData) { $result[$serviceId]['id'] = $serviceId; $result[$serviceId]['name'] = $this->allTagTypes[$serviceData['tagid']]; $result[$serviceId]['cost'] = $serviceData['price']; } } return ($result); } /** * Returns users finance operations history * * @param string $customerId * * @return array */ protected function getUserFinanceHistory($customerId) { $result = array(); if (isset($this->allUserData[$customerId])) { $allServices = zb_VservicesGetAllNamesLabeled(); $fundsFlow = new FundsFlow(); $allfees = $fundsFlow->getFees($customerId); $allpayments = $fundsFlow->getPayments($customerId); $allcorrectings = $fundsFlow->getPaymentsCorr($customerId); $allOps = $allfees + $allpayments + $allcorrectings; $allOps = $fundsFlow->transformArray($allOps); $i = 0; if (!empty($allOps)) { foreach ($allOps as $io => $each) { // print_r($each); $result[] = array( 'id' => $i, 'date' => $each['date'], 'type' => 'financial', 'name' => __($each['operation']), 'data' => json_encode(array( 'amount' => $each['summ'], 'from' => $each['from'], 'to' => $each['to'], 'operator_name' => $each['admin'] )), 'comment' => zb_TranslatePaymentNote($each['note'], $allServices) ); $i++; } } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $customerId); } return ($result); } /** * Catches and preprocess change_user_data request params * * @return array */ protected function catchChangeParams() { $result = array(); /** * There is a house in New Orleans * They call the Rising Sun * And it's been the ruin of many a poor boy * And God, I know I'm one */ if (wf_CheckGet(array('customer_id'))) { $result['customerid'] = $_GET['customer_id']; } if (wf_CheckGet(array('type'))) { $result['type'] = vf($_GET['type']); } if (wf_CheckGet(array('value'))) { $result['value'] = $_GET['value']; } if (wf_CheckGet(array('comment'))) { $result['comment'] = $_GET['comment']; } return ($result); } /** * Do some user finance data changes * * @param array $changeParams * * @return array */ protected function changeUserFinance($changeParams) { $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { if (zb_checkMoney($changeParams['value'])) { $paymentNotes = (isset($changeParams['comment'])) ? $changeParams['comment'] : ''; $cashTypeId = 1; //like default if (isset($this->altCfg['USERSIDE_CASHTYPE'])) { if (!empty($this->altCfg['USERSIDE_CASHTYPE'])) { $cashTypeId = $this->altCfg['USERSIDE_CASHTYPE']; } } zb_CashAdd($changeParams['customerid'], $changeParams['value'], 'add', $cashTypeId, $paymentNotes); $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_BAD_MONEY_FORMAT'] . ': ' . $changeParams['value']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Do some user finance data correct * * @param array $changeParams * * @return array */ protected function changeUserFinanceCorrect($changeParams) { $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { if (zb_checkMoney($changeParams['value'])) { $paymentNotes = (isset($changeParams['comment'])) ? $changeParams['comment'] : ''; $cashTypeId = 1; //like default if (isset($this->altCfg['USERSIDE_CASHTYPE'])) { if (!empty($this->altCfg['USERSIDE_CASHTYPE'])) { $cashTypeId = $this->altCfg['USERSIDE_CASHTYPE']; } } zb_CashAdd($changeParams['customerid'], $changeParams['value'], 'correct', $cashTypeId, $paymentNotes); $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_BAD_MONEY_FORMAT'] . ': ' . $changeParams['value']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Changes user RealName * * @param array $changeParams * * @return array */ protected function changeUserRealName($changeParams) { $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { zb_UserChangeRealName($changeParams['customerid'], $changeParams['value']); $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Changes user notes * * @param array $changeParams * * @return array */ protected function changeUserNotes($changeParams) { $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { zb_UserDeleteNotes($changeParams['customerid']); zb_UserCreateNotes($changeParams['customerid'], $changeParams['value']); $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Changes user tariff * * @param array $changeParams * * @return array */ protected function changeUserTariff($changeParams) { $result = array(); global $billing; if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { if (isset($this->allTariffs[$changeParams['value']])) { $newTariff = $changeParams['value']; $billing->settariff($changeParams['customerid'], $newTariff); log_register('CHANGE Tariff (' . $changeParams['customerid'] . ') ON `' . $newTariff . '`'); if ($this->altCfg['TARIFFCHGRESET']) { $billing->resetuser($changeParams['customerid']); log_register('RESET User (' . $changeParams['customerid'] . ')'); } $result = array('result' => 'ok'); } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_WRONG_TARIFF'] . ': ' . $changeParams['value']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Changes user basic state * * @global object $billing * @param array $changeParams * * @return array */ protected function changeUserState($changeParams) { global $billing; $result = array(); if (isset($changeParams['customerid'])) { if (isset($this->allUserData[$changeParams['customerid']])) { if (isset($changeParams['value'])) { $newState = $changeParams['value']; if (isset($this->supportedChageUserState[$newState])) { switch ($newState) { case 'frozen': $billing->setpassive($changeParams['customerid'], 1); log_register('CHANGE Passive (' . $changeParams['customerid'] . ') ON 1'); $result = array('result' => 'ok'); break; case 'unfrozen': $billing->setpassive($changeParams['customerid'], 0); log_register('CHANGE Passive (' . $changeParams['customerid'] . ') ON 0'); $result = array('result' => 'ok'); break; case 'down': $billing->setdown($changeParams['customerid'], 1); log_register('CHANGE Down (' . $changeParams['customerid'] . ') ON 1'); $result = array('result' => 'ok'); break; case 'notdown': $billing->setdown($changeParams['customerid'], 0); log_register('CHANGE Down (' . $changeParams['customerid'] . ') ON 0'); $result = array('result' => 'ok'); break; case 'ao': $billing->setao($changeParams['customerid'], 1); log_register('CHANGE AlwaysOnline (' . $changeParams['customerid'] . ') ON 1'); $result = array('result' => 'ok'); break; case 'notao': $billing->setao($changeParams['customerid'], 0); log_register('CHANGE AlwaysOnline (' . $changeParams['customerid'] . ') ON 0'); $result = array('result' => 'ok'); break; } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_METHOD_NOT_SUPPORTED'] . ': ' . $newState); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': value'); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_USER_NOT_EXISTS'] . ': ' . $changeParams['customerid']); } } else { $result = array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id'); } return ($result); } /** * Listens API requests and renders replies for it * * @return void */ public function catchRequest() { if (wf_CheckGet(array('request'))) { $request = $_GET['request']; $customerId = (wf_CheckGet(array('customer_id'))) ? mysql_real_escape_string($_GET['customer_id']) : ''; if (isset($this->supportedMethods[$request])) { switch ($request) { case 'get_tariff_list': $this->renderReply($this->getTariffsData()); break; case 'get_city_list': $this->renderReply($this->getCitiesData()); break; case 'get_street_list': $this->renderReply($this->getStreetsData()); break; case 'get_house_list': $this->renderReply($this->getBuildsData()); break; case 'get_user_additional_data_type_list': $this->renderReply($this->getCFTypesData()); break; case 'get_user_state_list': $this->renderReply($this->getUsersStateList()); break; case 'get_supported_method_list': $this->renderReply($this->getMethodsList()); break; case 'get_api_information': $this->renderReply($this->getApiInformation()); break; case 'get_user_group_list': $this->renderReply($this->getTagTypesList()); break; case 'get_system_information': $this->renderReply($this->getSystemInformation()); break; case 'get_user_list': if (empty($customerId)) { $this->renderReply($this->getUsersList()); } else { $this->renderReply($this->getUsersList($customerId)); } break; case 'get_user_messages': $this->renderReply($this->getUsersMessages()); break; case 'get_user_history': if (!empty($customerId)) { $this->renderReply($this->getUserFinanceHistory($customerId)); } else { $this->renderReply(array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': customer_id')); } break; case 'get_user_tags': $this->renderReply($this->getUserTags()); break; case 'get_services_list': $this->renderReply($this->getServicesList()); break; case 'get_supported_change_user_data_list': $this->renderReply($this->getChangeMethodsList()); break; case 'get_supported_change_user_state': $this->renderReply($this->getChangeStateMethodsList()); break; case 'get_supported_change_user_tariff': $this->renderReply($this->getTariffsData(true)); break; case 'get_device_type': $this->renderReply($this->getDeviceTypesList()); break; case 'get_device_model': $this->renderReply($this->getDeviceModels()); break; case 'get_device_list': $devTypeFilters = (wf_CheckGet(array('device_type'))) ? $_GET['device_type'] : ''; $this->renderReply($this->getDevicesList($devTypeFilters)); break; case 'get_connect_list': $this->renderReply($this->getDeviceConnectionsList()); break; case 'change_user_data': $changeParams = $this->catchChangeParams(); if (!empty($changeParams)) { if (isset($changeParams['type'])) { $changeOperationType = $changeParams['type']; if (isset($this->supportedChangeMethods[$changeOperationType])) { switch ($changeOperationType) { case 'balance_operation': $this->renderReply($this->changeUserFinance($changeParams)); break; case 'balance_correct_operation': $this->renderReply($this->changeUserFinanceCorrect($changeParams)); break; case 'name': $this->renderReply($this->changeUserRealName($changeParams)); break; case 'comment': $this->renderReply($this->changeUserNotes($changeParams)); break; case 'tariff': $this->renderReply($this->changeUserTariff($changeParams)); break; case 'state': $this->renderReply($this->changeUserState($changeParams)); break; } } else { $this->renderReply(array('result' => 'error', 'error' => $this->errorNotices['EX_METHOD_NOT_SUPPORTED'] . ': ' . $changeOperationType)); } } else { $this->renderReply(array('result' => 'error', 'error' => $this->errorNotices['EX_PARAM_MISSED'] . ': type')); } } else { $this->renderReply(array('result' => 'error', 'error' => $this->errorNotices['EX_NO_PARAMS'])); } } } else { header('HTTP/1.1 400 Unknown Action"', true, 400); die('Unknown Action'); } } else { header('HTTP/1.1 400 Undefined request', true, 400); die('Undefined request'); } } } ?> |