/var/www/doncode.com.ua/www/controllers
NameSizeModeActions
class.admin.php165050644editdlrm
class.api.php234480644editdlrm
class.archive.php20420644editdlrm
class.arm.php25040644editdlrm
class.dcccatalog.php52020644editdlrm
class.dcclist.php57550644editdlrm
class.dccsupport.php6430644editdlrm
class.dmp_platforms.php21880644editdlrm
class.docs.php14850644editdlrm
class.doncode_users.php27640644editdlrm
class.driver.php2390644editdlrm
class.error.php4910644editdlrm
class.exchange.php51510644editdlrm
class.files.php39350644editdlrm
class.index.php10450644editdlrm
class.login.php67080644editdlrm
class.mobile_users.php28280644editdlrm
class.news.php26000644editdlrm
class.orders.php27180644editdlrm
class.settings.php19550644editdlrm
class.support.php82360644editdlrm
class.user.php126690644editdlrm
class.users.php26330644editdlrm
Edit: /var/www/doncode.com.ua/www/controllers/class.api.php (23448B)
errors[0] = 'OK'; $this->errors[1] = 'Unknown error occured'; $this->errors[2] = 'Application is disabled. Enable your application'; $this->errors[3] = 'Unknown method passed'; $this->errors[4] = 'Incorrect signature'; $this->errors[5] = 'User authorization failed'; $this->errors[6] = 'Invalid request'; $this->errors[7] = 'Invalid request'; $this->errors[8] = 'User not authorized'; $this->method_no_autorized[0] = 'ping'; $this->method_no_autorized[1] = 'callback'; $this->method_no_autorized[2] = 'login'; $this->method_no_autorized[3] = 'register'; $this->method_no_autorized[4] = 'phone'; $this->method_no_autorized[5] = 'detect_server'; $this->method_no_autorized[6] = 'detect_city'; $this->method_no_autorized[7] = 'new_drivers_list'; $this->method_no_autorized[8] = 'get_countries'; $this->method_no_autorized[9] = 'get_regions'; $this->method_no_autorized[10] = 'get_cities'; $this->method_no_autorized[11] = 'get_colors'; $this->method_no_autorized[12] = 'get_marks'; $this->method_no_autorized[13] = 'get_models'; $this->method_no_autorized[14] = 'detect_servers'; $this->method_no_autorized[15] = 'detect_server_by_driver_code'; $this->method_no_autorized[16] = 'create_driver_code'; $this->method_no_autorized[17] = 'get_driver_code'; //$this->method_no_autorized[15] = 'get_servers_by_city'; } public function index($url = 0){ //print_r($url);exit; if (isset($url[2])) {//если есть параметр метода $key = $value = array(); for($i=1, $count=count($url);$i<$count;$i++){ if($i%2==0){ $value[] = $url[$i]; }else{ $key[] = $url[$i]; } } if(count($key)!=count($value)){ $this->error(6); return false; } $param = array_combine($key,$value); $sig = isset($param['sig'])?$param['sig']:0; $method = isset($param['method'])?$param['method']:0; $api_id = isset($param['api_id'])?$param['api_id']:0; $client_key = isset($param['client_key'])?$param['client_key']:0; $ip = $_SERVER['REMOTE_ADDR']; unset($param['sig']); ksort($param); //print_r($param);exit; $query = ''; foreach($param as $k => $v){ $query.=$k.'='.$v; } //echo $query;exit; list($user_id, $apikey, $detect) = $this->model->getApiKey($api_id); if($apikey==null)$this->error(2,$param); //echo $apikey;exit; //$apikey = e270b9a4510e46e5d21c763fe5dca4e2 (Android DEV) $test_sig = md5($query.$apikey); if($test_sig!=$sig){ $this->error(4,$param); } // Авторизация клиента по ключу //$res = db_fetch(db_query("SELECT * FROM `sms_activation` WHERE `client_key`='$client_key' AND `activated`='1'")); //if(isset($res[0])){ //$res[0]['client_id'] = 1; $client_id = $this->model->getUserIdByClientKey($client_key); $param['client_id'] = $client_id; if($client_id>0){ $client_authorized = true; //$client_id = $res[0]['client_id']; }else{ $client_authorized = false; } if(!$client_authorized){ if (!in_array($method, $this->method_no_autorized)) { $this->error(8); return false; } } $json['response']['client_authorized'] = $client_authorized; $this->model->logKeyAccess($api_id,$method,$ip); $param['user_id'] = $client_id; unset($param['method']); unset($param['random']); if (method_exists($this, $method)) { // Подмена метода detect_server[s] если выключено определение по координатам --->>>> if($detect==0&&$method=='detect_server'){ $method = 'list_server'; } if($detect==0&&$method=='detect_servers'){ $method = 'list_servers'; } // <<<<---- $this->{$method}( $param ); //загружаем методs с передаными параметрами }else{ $this->error(3,$param); return false; } } else { $this->error(6); } } public function error($error=0,$param=0){ $json['error'] = $error; $json['error_msg'] = $this->errors[$error]; $json['request'] = $param; echo $this->model->json_encode__($json); exit; } // ====================== FUNCTIONS ========================= // public function ping($param=0){ $json['error'] = 0; $json['response']['method'] = 'pong'; echo $this->model->json_encode__($json); return false; } public function dcc_api($gid, $cmd, $param=array()){ global $conf; $random = rand(10000,1000000); $dcc = $this->model->getDCC($gid); if($dcc==null){ return null; } //echo $gid; $key = $dcc['key']; $client_key = '123'; $sig = md5("client_key=".$client_key."method=".$cmd."random=".$random.$key); $url = "http://".$dcc['host'].':'.$dcc['port']."/api/method/".$cmd."/client_key/".$client_key."/random/".$random."/sig/".$sig; $myCurl = curl_init(); curl_setopt_array($myCurl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query($param) )); $response = curl_exec($myCurl); curl_close($myCurl); return $response; } public function callback($param=0){ $phone = isset($_POST['phone'])?$_POST['phone']:null; if($phone==null)$this->error(6); $this->loadModel('user',true); $user = $this->getCollection('user')->getUserByPhone($phone); if($user==null)$this->error(100); $user_id = $user['id']; $city_id = $user['city_id']; $call_id = isset($_POST['call_id'])?$_POST['call_id']:0; $chin = isset($_POST['chin'])?$_POST['chin']:0; $chout = isset($_POST['chout'])?$_POST['chout']:0; $from_gid = isset($_POST['from_gid'])?intval($_POST['from_gid']):0; $to_gid = isset($_POST['to_gid'])?intval($_POST['to_gid']):0; $gid = $this->model->callback_by_city_id($city_id); $response_array = array(); if($gid>0){ $to_gid = $gid; //$data['host'] = $dcc['host'].':'.$dcc['port']; $data['phone'] = $phone; $data['call_id'] = $call_id; $data['chin'] = $chin; $data['chout'] = $chout; $data['user_id'] = $user_id; $data['city_id'] = $city_id; $data['from_gid'] = $from_gid; $data['to_gid'] = $to_gid; $response = $this->dcc_api($gid,'callback',$data); $response_array = json_decode($response,true); } $callback_id = $this->model->addCallback($phone,$call_id,$chin,$chout,$user_id,$city_id,$from_gid,$to_gid); $json['error'] = 0; $json['response']['method'] = 'callback'; $jout['callback_id'] = $callback_id; $jout['city_id'] = $city_id; $jout['gid'] = $to_gid; $jout['result'] = $response_array['error']; //$jout['response'] = $response_array; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function add_account($param=0){ $jout = array(); $user_id = isset($_POST['user_id'])?$_POST['user_id']:null; $gid = isset($_POST['gid'])?$_POST['gid']:null; if($user_id==null)$this->error(6); if($gid==null)$this->error(6); if($user_id==0)$this->error(6); if($gid==0)$this->error(6); $account_id = $this->model->add_account($user_id,$gid); if($account_id>0){ $dcc = $this->model->getDCC($gid); $jout['taxi_name'] = $dcc['taxi_name']; $jout['country'] = $dcc['country']; $jout['city'] = $dcc['city']; $jout['account_id'] = $account_id; $json['error'] = 0; $json['error_msg'] = 'OK'; }else{ $json['error'] = 100; $json['error_msg'] = 'Add account error!'; } $json['response']['method'] = 'add_account'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function del_account($param=0){ $jout = array(); $id = isset($_POST['id'])?$_POST['id']:null; if($id==null)$this->error(6); if($id==0)$this->error(6); $account_id = $this->model->del_account($id); if($account_id>0){ $jout['account_id'] = $account_id; $json['error'] = 0; $json['error_msg'] = 'OK'; }else{ $json['error'] = 100; $json['error_msg'] = 'Del account error!'; } $json['response']['method'] = 'del_account'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function new_drivers_list($param=0){ $gid = isset($_POST['gid'])?$_POST['gid']:null; if($gid==null)$this->error(6); if($gid>0){ $drivers = $this->model->new_drivers_list($gid); $jout['drivers'] = $drivers; $json['response']['method'] = 'new_drivers_list'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); }else{ $this->error(100); } } public function activate_new_driver($param=0){ $gid = isset($_POST['gid'])?$_POST['gid']:null; $ch = isset($_POST['ch'])?$_POST['ch']:null; $poz = isset($_POST['poz'])?$_POST['poz']:null; $remote_car_id = isset($_POST['car_id'])?$_POST['car_id']:null; $openpass = isset($_POST['openpass'])?$_POST['openpass']:null; if($gid==null)$this->error(6); if($gid>0){ $json['response']['method'] = 'activate_new_driver'; $res = $this->model->activate_new_driver($gid,$param['client_id'],$remote_car_id,$ch,$poz,$openpass); if($res>0){ $json['response']['result'] = 'OK'; }else{ $this->error(101); } echo $this->model->json_encode__($json); }else{ $this->error(100); } } public function get_countries($param=0){ $countries = $this->model->get_countries(); $jout['countries'] = $countries; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_countries'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_regions($param=0){ $id_country = isset($_POST['country_id'])?$_POST['country_id']:null; if($id_country==null)$this->error(6); $regions = $this->model->get_regions($id_country); $jout['regions'] = $regions; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_regions'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_cities($param=0){ $id_region = isset($_POST['region_id'])?$_POST['region_id']:null; if($id_region==null)$this->error(6); $cities = $this->model->get_cities($id_region); $jout['cities'] = $cities; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_cities'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_colors($param=0){ $colors = $this->model->get_colors(); $jout['colors'] = $colors; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_colors'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_marks($param=0){ $marks = $this->model->get_marks(); $jout['marks'] = $marks; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_marks'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_models($param=0){ $mark_id = isset($_POST['mark_id'])?$_POST['mark_id']:null; if($mark_id==null)$this->error(6); $models = $this->model->get_models($mark_id); $jout['models'] = $models; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_models'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function get_servers_by_city($param=0){ $id_city = isset($_POST['city_id'])?$_POST['city_id']:null; if($id_city==null)$this->error(6); $servers = $this->model->get_servers_by_city($id_city); $jout['servers'] = $servers; $json['error'] = 0; $json['error_msg'] = 'OK'; $json['response']['method'] = 'get_servers_by_city'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); } public function register($param=0){ $jout = array(); $login = isset($_POST['login'])?$_POST['login']:null; $pass = isset($_POST['pass'])?$_POST['pass']:null; if($login==null)$this->error(6); if($pass==null)$this->error(6); $login = '+'.preg_replace("/[^0-9]/","",$_POST['login']); if (strlen($login)<12||strlen($login)>13){ $this->error(6); } $user = $this->model->register($login,$pass); if($user['id']>0){ $accounts = $this->model->getDriverAccounts($user['id']); $jout['accounts'] = $accounts; $jout['id'] = $user['id']; $jout['FIO'] = $user['FIO']; $jout['email'] = $user['email']; $jout['email_confirmed'] = $user['email_confirmed']; $jout['balance'] = $user['balance']; $jout['datereg'] = $user['datereg']; $jout['lastvisit'] = $user['lastvisit']; $jout['country_id'] = $user['country_id']; $jout['region_id'] = $user['region_id']; $jout['city_id'] = $user['city_id']; $jout['rate'] = $user['rate']; $jout['lang'] = $user['lang']; $json['error'] = 0; $json['error_msg'] = 'OK'; }else{ $json['error'] = 100; $json['error_msg'] = 'User already exists'; } $jout['login'] = $login; $json['response']['method'] = 'register'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function login($param=0){ $jout = array(); $login = isset($_POST['login'])?$_POST['login']:null; $pass = isset($_POST['pass'])?$_POST['pass']:null; if($login==null)$this->error(6); if($pass==null)$this->error(6); $login = '+'.preg_replace("/[^0-9]/","",$_POST['login']); if (strlen($login)<12||strlen($login)>13){ $this->error(6); } $user = $this->model->login($login,$pass); if($user['id']>0){ $accounts = $this->model->getDriverAccounts($user['id']); $jout['accounts'] = $accounts; $jout['id'] = $user['id']; $jout['FIO'] = $user['FIO']; $jout['email'] = $user['email']; $jout['email_confirmed'] = $user['email_confirmed']; $jout['balance'] = $user['balance']; $jout['datereg'] = $user['datereg']; $jout['lastvisit'] = $user['lastvisit']; $jout['country_id'] = $user['country_id']; $jout['region_id'] = $user['region_id']; $jout['city_id'] = $user['city_id']; $jout['rate'] = $user['rate']; $jout['lang'] = $user['lang']; $jout['key'] = $user['key']; $json['error'] = 0; $json['error_msg'] = 'OK'; }else{ $json['error'] = 100; $json['error_msg'] = 'User not found or password incorrect'; } $jout['login'] = $login; $json['response']['method'] = 'login'; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function phone($param=0){ $phone = isset($_POST['phone'])?$_POST['phone']:null; if($phone==null)$this->error(6); $this->loadModel('user',true); $user = $this->getCollection('user')->getUserByPhone($phone); if($user==null)$this->error(100); $user_id = $user['id']; $city_id = $user['city_id']; $json['error'] = 0; $json['response']['method'] = 'phone'; $jout['city_id'] = $city_id; $json['response']['result'] = $jout; echo $this->model->json_encode__($json); return false; } public function search($param=0){ if(!isset($_REQUEST['q'])){ $this->errors[100] = 'Not found'; $this->errors[101] = 'No request'; $this->error(101); } $callback = isset($_POST['json_callback'])? '&json_callback='.$_POST['json_callback']:''; $query = '?format=json'; $query .= isset($_POST['viewbox'])? '&viewbox='.$_POST['viewbox']:''; $query .= isset($_POST['bounded'])? '&bounded='.$_POST['bounded']:''; $query .= isset($_POST['addressdetails'])? '&addressdetails='.$_POST['addressdetails']:'&addressdetails=1'; $query .= isset($_POST['polygon_geojson'])? '&polygon_geojson='.$_POST['polygon_geojson']:''; $query .= isset($_POST['polygon_kml'])? '&polygon_kml='.$_POST['polygon_kml']:''; $query .= isset($_POST['polygon_svg'])? '&polygon_svg='.$_POST['polygon_svg']:''; $query .= isset($_POST['polygon_text'])? '&polygon_text='.$_POST['polygon_text']:''; $query .= isset($_POST['limit'])? '&limit='.$_POST['limit']:''; $query .= isset($_POST['accept-language'])? '&accept-language='.$_POST['accept-language']:''; $query .= isset($_REQUEST['q'])? '&q='.urlencode($_REQUEST['q']):'q='; //$query .= '&format=json'; $body = file_get_contents(HOST_NOMI.$query); $json['error'] = 0; //$json['query'] = HOST_NOMI.$query; //$json['body'] = $body; $jout = json_decode($body,true); if(is_array($jout)) foreach($jout as $k => $v){ unset($jout[$k]['place_id']); unset($jout[$k]['licence']); unset($jout[$k]['osm_id']); } $json['response']['result'] = $jout; $json['response']['method'] = 'search'; //echo $this->model->json_encode__($json); if(isset($callback)) echo $callback.'('.json_encode($json,JSON_UNESCAPED_UNICODE).')'; else echo json_encode($json,JSON_UNESCAPED_UNICODE); return false; } public function detect_city($param=0){ $la = isset($_POST['la'])?$_POST['la']:0; $lo = isset($_POST['lo'])?$_POST['lo']:0; //$la = 49.040422; //$lo = 37.551769; if(!$la>0||!$lo>0){ $this->error(6); } $arr = $this->model->detect_city($la,$lo); if($arr!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_city'; $json['response']['city'] = $arr; }else{ $this->errors[100] = 'Not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; } public function list_server($param=0){ if(!$param['api_id']>0){ $this->error(6); } $arr = $this->model->list_server($param['api_id']); if($arr!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_server'; $json['response']['method_redirect'] = 'list_server'; $json['response']['server'] = $arr; }else{ $this->errors[100] = 'Server not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; } public function list_servers($param=0){ if(!$param['api_id']>0){ $this->error(6); } $arr = $this->model->list_servers($param['api_id']); if($arr!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_servers'; $json['response']['method_redirect'] = 'list_servers'; $json['response']['servers'] = $arr; }else{ $this->errors[100] = 'Server not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; } public function detect_server($param=0){ $la = isset($_POST['la'])?$_POST['la']:0; $lo = isset($_POST['lo'])?$_POST['lo']:0; //$la = 49.040422; //$lo = 37.551769; if(!$la>0||!$lo>0){ $this->error(6); } $arr = $this->model->detect_server($la,$lo); if($arr!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_server'; $json['response']['server'] = $arr; }else{ $this->errors[100] = 'Server not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; } public function detect_servers($param=0){ $la = isset($_POST['la'])?$_POST['la']:0; $lo = isset($_POST['lo'])?$_POST['lo']:0; //$la = 49.040422; //$lo = 37.551769; if(!$la>0||!$lo>0){ $this->error(6); } $arr = $this->model->detect_servers($la,$lo); if($arr!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_servers'; $json['response']['servers'] = $arr; }else{ $this->errors[100] = 'Server not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; } public function order_create($param=0){ $json['error'] = 0; $this->loadModel('user',true); session::set('id_user',$param['user_id']); $city_id = isset($_POST['city_id'])?$_POST['city_id']:0; session::set('city_id',$city_id); $this->getCollection('user')->addorder(true); $order_id = $this->getCollection('user')->create_order(true); $json['response']['method'] = 'order_create'; $json['response']['order_id'] = $order_id; echo $this->model->json_encode__($json); return false; } public function detect_server_by_driver_code($param=0){ $code = isset($_POST['driver_code']) ? intval($_POST['driver_code']) : 0; if($code > 0){ $res = $this->model->detect_server_by_driver_code($code); if($res!=null){ $json['error'] = 0; $json['response']['method'] = 'detect_server'; $json['response']['server'] = $res; }else{ $this->errors[100] = 'Server not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; }else{ $this->error(6); } } public function get_driver_code($param=0){ $driver_client_key = isset($_POST['driver_client_key']) ? $_POST['driver_client_key'] : null; if($driver_client_key != null){ $arr = $this->model->get_driver_code($driver_client_key); if(is_array($arr) && count($arr) > 0){ $json['error'] = 0; $json['response']['method'] = 'get_driver_code'; $json['response']['key_code'] = $arr[0]['key_code']; }else{ $this->errors[100] = 'Driver code not found'; $this->error(100); } echo $this->model->json_encode__($json); return false; }else{ $this->error(6); } } public function create_driver_code($param=0){ $driver_client_key = isset($_POST['driver_client_key']) ? $_POST['driver_client_key'] : null; if($driver_client_key != null){ $res = $this->model->create_driver_code($driver_client_key, $param['client_key']); if($res > 0){ $json['error'] = 0; $json['response']['method'] = 'create_driver_code'; $json['response']['key_code'] = $res; }else if ($res == -1){ $this->errors[100] = 'Driver code update error'; $this->error(100); }else if ($res == -2){ $this->errors[101] = 'Driver code insert error'; $this->error(101); } echo $this->model->json_encode__($json); return false; } else{ $this->error(6); } } }