public function update(RESTRequest $request) { $put = $request->getPut(); if (empty($put)) { throw new RESTCommandException('HTTP PUT data is empty'); } $allowed_to_update_fields = array_fill_keys(array('sub_ch', 'additional_services_on'), true); $data = array_intersect_key($put, $allowed_to_update_fields); $stb_data = array_intersect_key($put, array('additional_services_on' => true)); if (empty($data)) { throw new RESTCommandException('Update data is empty'); } unset($data['additional_services_on']); if (!empty($stb_data)) { //$stb = Stb::getInstance(); //$stb->setParam('additional_services_on', intval($stb_data['additional_services_on'])); $uids = $request->getConvertedIdentifiers(); foreach ($uids as $uid) { Stb::setAdditionServicesById($uid, intval($stb_data['additional_services_on'])); } } //var_dump($stb_data); if (!empty($data)) { $list = ItvSubscription::updateByUids($request->getConvertedIdentifiers(), $data); if (empty($list)) { return false; } } return $this->formatList(ItvSubscription::getByUids($request->getConvertedIdentifiers())); }
public function update(RESTRequest $request) { $stb_list = $request->getConvertedIdentifiers(); if (empty($stb_list)) { throw new RESTCommandException('Empty stb list'); } /*if (count($stb_list) != 1){ throw new RESTCommandException('Only one identifier allowed'); }*/ $uids = $stb_list; $data = $request->getPut(); if (empty($data)) { throw new RESTCommandException('HTTP PUT data is empty'); } if (!key_exists('disabled', $data) && !key_exists('restricted', $data)) { throw new RESTCommandException('Update data is empty'); } if (key_exists('disabled', $data)) { foreach ($uids as $uid) { Stb::setDisabledModulesByUid($uid, $data['disabled']); } } if (key_exists('restricted', $data)) { foreach ($uids as $uid) { Stb::setRestrictedModulesByUid($uid, $data['restricted']); } } return array('disabled' => Stb::getDisabledModulesByUid($uids[0]), 'restricted' => Stb::getRestrictedModulesByUid($uids[0])); }
public function update(RESTRequest $request) { $put = $request->getPut(); if (empty($put)) { throw new RESTCommandException('HTTP PUT data is empty'); } if (empty($put['action'])) { throw new RESTCommandException('Action param is empty'); } $identifiers = $request->getIdentifiers(); if (empty($identifiers)) { throw new RESTCommandException('Empty identifiers'); } if ($put['action'] == 'started') { foreach ($identifiers as $identifier) { $this->manager->setStarted(intval($identifier)); } return true; } elseif ($put['action'] == 'ended') { foreach ($identifiers as $identifier) { $this->manager->setEnded(intval($identifier)); } return true; } else { throw new RESTCommandException('Action is wrong'); } }
public function get(RESTRequest $request) { $ids = $request->getIdentifiers(); if (empty($ids[0])) { throw new ErrorException('Empty token'); } return Itv::checkTemporaryLink($ids[0]); }
public function create(RESTRequest $request) { $media_name = $request->getData('media_name'); if (empty($media_name)) { throw new ErrorException('Empty media_name'); } return $this->manager->startMD5Sum($media_name); }
/** * Delete recording task * * @param RESTRequest $request * @return bool * @throws ErrorException */ public function delete(RESTRequest $request) { $ch_ids = $request->getIdentifiers(); if (empty($ch_ids[0])) { throw new ErrorException('Empty ch_id'); } return $this->manager->stop($ch_ids[0]); }
public function get(RESTRequest $request) { $identifiers = $request->getIdentifiers(); if (!empty($identifiers[0])) { $plan_id = (int) $identifiers[0]; } else { $plan_id = null; } $result = Tariff::getDetailedPlanInfo($plan_id); return $result; }
/** * @throws RESTCommandResolverException * @param RESTRequest $request * @return RESTCommand */ public function getCommand(RESTRequest $request) { $resource = implode("", array_map(function ($part) { return ucfirst($part); }, explode('_', $request->getResource()))); $class = 'RESTCommand' . ucfirst($resource); if (!class_exists($class)) { throw new RESTCommandResolverException('Resource "' . $resource . '" does not exist'); } return new $class(); }
private function setManager(RESTRequest $request) { $type = $request->getData('type'); if (empty($type)) { $type = empty($_GET['type']) ? 'itv' : $_GET['type']; } $base_class = ucfirst($type); if (class_exists($base_class)) { $this->manager = $base_class::getInstance(); } }
public function update(RESTRequest $request) { $stb_list = $request->getConvertedIdentifiers(); if (empty($stb_list)) { throw new RESTCommandException('Empty stb list'); } foreach ($stb_list as $uid) { Mysql::getInstance()->update('users', array('access_token' => strtoupper(md5(microtime(1) . uniqid()))), array('id' => $uid)); Mysql::getInstance()->update('access_tokens', array('token' => 'invalid_' . md5(microtime(1) . uniqid()), 'refresh_token' => 'invalid_' . md5(microtime(1) . uniqid())), array('uid' => $uid)); } return true; }
public function create(RESTRequest $request) { $media_name = $request->getData('media_name'); $media_id = $request->getData('media_id'); if (empty($media_name)) { throw new ErrorException('Empty media_name'); } if (empty($media_id)) { throw new ErrorException('Empty media_id'); } return $this->manager->createLink($media_name, $media_id); }
public function update(RESTRequest $request) { $ids = $request->getIdentifiers(); if (empty($ids[0]) || intval($ids[0]) == 0) { throw new ErrorException('Empty channel id'); } $data = $request->getData(); if (key_exists('start_time', $data)) { $this->manager->updateStartTime(intval($ids[0]), $data['start_time']); } if (key_exists('end_time', $data)) { $this->manager->updateEndTime(intval($ids[0]), $data['end_time']); } return true; }
/** * @throws RESTCommandResolverException * @param RESTRequest $request * @return RESTCommand */ public function getCommand(RESTRequest $request) { //For php >= 5.3.0 /*$resource = implode(array_map(function($part){ return ucfirst($part); },explode('_', $request->getResource())));*/ $resource = ''; foreach (explode('_', $request->getResource()) as $part) { $resource .= ucfirst($part); } $class = 'RESTCommand' . ucfirst($resource); if (!class_exists($class)) { throw new RESTCommandResolverException('Resource "' . $class . '" does not exist'); } return new $class(); }
public function send() { if (!empty($this->request) && strpos($this->request->getAccept(), 'text/channel-monitoring-id-url') !== false) { if (is_array($this->body['results'])) { $channels = array_filter($this->body['results'], function ($channel) { return $channel['enable_monitoring']; }); //$channels = $this->body['results']; if (preg_match("/items=(\\d+)-(\\d*)/", $this->request->getAccept(), $match)) { $start = $match[1]; $end = empty($match[2]) ? count($channels) : $match[2]; $channels = array_slice($channels, $start - 1, $end - $start + 1); //var_dump($start, $end, $channels); } elseif (preg_match("/part=(\\d+)\\/(\\d+)/", $this->request->getAccept(), $match)) { $length = count($channels); $start = round((intval($match[1]) - 1) * ($length / intval($match[2]))); $end = round(intval($match[1]) * ($length / intval($match[2]))); $channels = array_slice($channels, $start, $end - $start); //var_dump($length, $start, $end); } $body = array_reduce($channels, function ($prev, $curr) { return $prev . $curr['id'] . ' ' . $curr['url'] . (isset($curr['type']) ? ' ' . $curr['type'] : '') . ' ' . str_replace(' ', '_', $curr["ch_name"]) . ' ' . ((int) $curr["status"] == 1 ? "up" : "down") . "\n"; }, ''); header("Content-Type: text/plain"); echo $body; } return; } header("Content-Type: " . $this->content_type); $this->setOutput(); $response = json_encode($this->body); echo $response; ob_end_flush(); if (!Config::getSafe('enable_api_log', true)) { return; } $logger = new Logger(); $logger->setPrefix("api_"); // format: ip - login - [date] method "query" - "data" response_bytes; $logger->access(sprintf("%s - %s - [%s] %s \"%s\" - \"%s\" %d\n", empty($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_REAL_IP'], @$_SERVER['PHP_AUTH_USER'], date("r"), $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], empty($this->request) ? 'no resource' : http_build_query($this->request->getData()), strlen($response))); if (!empty($this->body['error'])) { // format: ip - login - [date] method "query" - "data": error message; $logger->error(sprintf("%s - %s - [%s] %s \"%s\" - \"%s\": %s\n", empty($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_REAL_IP'], @$_SERVER['PHP_AUTH_USER'], date("r"), $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], empty($this->request) ? 'no resource' : http_build_query($this->request->getData()), $this->body['error'])); } }
public static function handleRequest() { $result = null; $response = new RESTResponse(); try { $request = new RESTRequest(); if ($request->getAction() != 'get' || !in_array($request->getResource(), array('vclub', 'karaoke'))) { self::checkAccess($request->getAccessToken()); } $cmd_r = new RESTCommandResolver(); $cmd = $cmd_r->getCommand($request); $result = $cmd->execute($request); } catch (Exception $e) { $response->setError($e->getMessage()); } $response->setBody($result); $response->send(); }
public function update(RESTRequest $request) { $put = $request->getPut(); if (empty($put)) { throw new RESTCommandException('HTTP PUT data is empty'); } $allowed_to_update_fields = array_fill_keys(array('monitoring_status'), true); $data = array_intersect_key($put, $allowed_to_update_fields); if (empty($data)) { throw new RESTCommandException('Update data is empty'); } $ids = $request->getIdentifiers(); if (empty($ids)) { throw new RESTCommandException('Empty channel id'); } $channel_id = intval($ids[0]); return Mysql::getInstance()->update('itv', $data, array('id' => $channel_id)); }
public function create(RESTRequest $request) { $stb_list = $request->getConvertedIdentifiers(); if (empty($stb_list)) { throw new RESTCommandException('Empty stb list'); } $msg = $request->getData("msg"); if (empty($msg)) { throw new RESTCommandException('Empty msg'); } $event = new SysEvent(); $ttl = (int) $request->getData("ttl"); if (!empty($ttl)) { $event->setTtl($ttl); } $auto_hide_timeout = (int) $request->getData('auto_hide_timeout'); if ($auto_hide_timeout) { $event->setAutoHideTimeout($auto_hide_timeout); } $event->setUserListById($stb_list); $event->sendMsg($msg); return true; }
public function create(RESTRequest $request) { $data = $request->getData(); if (empty($data)) { throw new RESTCommandException('HTTP POST data is empty'); } $allowed_to_update_fields = array_fill_keys(array('mac', 'login', 'password', 'status', 'additional_services_on', 'ls', 'end_date', 'account_balance'), true); $data = array_intersect_key($data, $allowed_to_update_fields); if (empty($data)) { throw new RESTCommandException('Insert data is empty'); } if (isset($data['end_date'])) { $data['expire_billing_date'] = $data['end_date']; unset($data['end_date']); } if (!empty($data['mac'])) { $mac = Middleware::normalizeMac($data['mac']); if (!$mac) { throw new RESTCommandException('Not valid mac address'); } $data['mac'] = $mac; } if (empty($data['mac']) && (empty($data['login']) || empty($data['password']))) { throw new RESTCommandException('Login and password required'); } try { $uid = Stb::create($data); } catch (Exception $e) { throw new RESTCommandException($e->getMessage()); } $stb_list = $this->manager->getByUids(array($uid)); $stb_list = $this->formatList($stb_list); if (count($stb_list) == 1) { return $stb_list[0]; } return $stb_list; }
/** * Sending get method to http * * @param string $url * @param string $data * @param string $header * @param string $headers_only * @return Object */ private function doPost($url, $data = null, $header = array(), $headers_only = false) { return RESTRequest::post($url, $data, $header, $headers_only); }
public static function delete($url, array $headers = array(), $headers_only = false, array $curl_options = array()) { //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); $ch = RESTRequest::factory($curl_options); $ch->set_opt(CURLOPT_URL, $url)->set_opt(CURLOPT_RETURNTRANSFER, true)->set_opt(CURLOPT_NOBODY, $headers_only)->set_opt(CURLOPT_CUSTOMREQUEST, 'DELETE'); //Set any additional headers if (!empty($headers)) { $ch->set_opt(CURLOPT_HTTPHEADER, $headers); } $result['content'] = $ch->exec(); $result['http_code'] = self::$http_code; return new RESTResponse($result); }
function routeRequest() { $req = new RESTRequest(); $req->setUrl($_SERVER['REQUEST_URI']); $req->setMethod($_SERVER['REQUEST_METHOD']); if (preg_match('%\\/cmb-xr-crawler\\/api\\/records%', $req->getUrl())) { (new RecordsController($req))->process(); } else { if (preg_match('%\\/cmb-xr-crawler\\/api\\/currency%', $req->getUrl())) { (new CurrencyController($req))->process(); } else { RESTUtil::sendResponse(404); } } }
public function delete(RESTRequest $request) { $identifiers = $request->getIdentifiers(); if (count($identifiers) == 0) { throw new RESTCommandException('Identifier required'); } $users_ids = $this->getUsersIdsFromIdentifiers($identifiers); if (count($identifiers) == 1 && count($users_ids) == 0) { throw new RESTCommandException('Account not found'); } if (count($identifiers) > 1) { throw new RESTCommandException('Only one identifier allowed'); } $result = true; foreach ($users_ids as $user_id) { $user = User::getInstance($user_id); $result = $user->delete() && $result; User::clear(); } return $result; }
public function delete(RESTRequest $request) { $identifiers = $request->getIdentifiers(); if (!empty($identifiers[0]) && strlen($identifiers[0]) >= 12) { $users_ids = Stb::getUidByMacs($identifiers); } else { $users_ids = Stb::getUidByAccountNumber($identifiers); } if (count($identifiers) == 1 && count($users_ids) == 0) { throw new RESTCommandException('Account not found'); } if (count($identifiers) > 1) { throw new RESTCommandException('Only one identifier allowed'); } $result = true; foreach ($users_ids as $user_id) { $user = User::getInstance($user_id); $info = $user->getAccountInfo(); $subscribe = $user->updateOptionalPackageSubscription(array('subscribe' => array(), 'unsubscribe' => $info['subscribed'])); $result = $result && $subscribe; User::clear(); } return $result; }
public function create(RESTRequest $request) { $stb_list = $request->getConvertedIdentifiers(); $identifiers = $request->getIdentifiers(); if (empty($stb_list) && !empty($identifiers)) { throw new RESTCommandException('STB not found'); } $event = new SysEvent(); if (empty($identifiers)) { $event->setUserListByMac('all'); } else { $event->setUserListById($stb_list); } if ($request->getData('ttl')) { $event->setTtl($request->getData('ttl')); } switch ($request->getData('event')) { case 'send_msg': if ($request->getData('need_reboot')) { $event->sendMsgAndReboot($request->getData('msg')); } else { $event->sendMsg($request->getData('msg')); } if ($request->getData('auto_hide_timeout')) { $event->setAutoHideTimeout($request->getData('auto_hide_timeout')); } break; case 'send_msg_with_video': $event->sendMsgWithVideo($request->getData('msg'), $request->getData('video')); break; case 'reboot': $event->sendReboot(); break; case 'reload_portal': $event->sendReloadPortal(); break; case 'update_channels': $event->sendUpdateChannels(); break; case 'play_channel': $event->sendPlayChannel($request->getData('channel')); break; case 'play_radio_channel': $event->sendPlayRadioChannel($request->getData('channel')); break; case 'update_image': $event->sendUpdateImage(); break; case 'cut_off': $event->sendCutOff(); break; case 'show_menu': $event->sendShowMenu(); break; default: return false; } return true; }
public static function useMacIdentifiers() { return self::$use_mac_identifiers = true; }