private function fetch() { $response = $this->httpClient->get($this->path, $this->parameters, $this->headers); $this->getPagination($response); $elements = json_decode($response->getBody()); return $elements; }
/** * make the call to the API * * @param Request * @return Response */ public function send($request) { try { # if it was successful, return the response return $this->client->send($request)->json(); } catch (\GuzzleHttp\Exception\ClientException $e) { # if it was unsuccessful then return the error that was thrown return $e->getResponse(); } }
public function it_should_throw_a_bad_request_exception_when_the_response_is_a_400() { $productJson = '{ "sku": "sku1" }'; $stream = Stream::factory('{"code":400,"message":"You must specify at least one valid identifier."}'); $mock = new Mock([new response(400, [], $stream)]); $client = new client(); $client->getemitter()->attach($mock); $this->beConstructedWith($client, $this->getDefaultConfigArray()); $this->shouldThrow('Flubit\\BadRequestException')->during('post', ['product', $productJson]); }
public function content() { $data = $this->input['data']; $content_client_relation = $data['content_client_relation']; $content_relation = $data['content_relation']; $content = $data['content']; if (!$content_client_relation || !$content_relation || !$content) { $this->errorOutput('NO_DATA'); } $bundle_id = $content['bundle_id']; $module_id = $content['module_id']; $struct_id = $content['struct_id']; //content process $syn_content = $this->syn_obj->get_content_in_site($content['id'], $content['site_id']); $update_contentarr = $content; unset($update_contentarr['id']); if ($syn_content) { //struct_table update process $this->struct($bundle_id, $module_id, $struct_id, $data, 'update', $syn_content['expand_id']); unset($update_contentarr['syn_cid'], $update_contentarr['expand_id'], $update_contentarr['plan_set_id'], $update_contentarr['bundle_id'], $update_contentarr['module_id'], $update_contentarr['struct_id'], $update_contentarr['content_fromid']); $this->obj->update('content', ' id=' . $syn_content['id'], $update_contentarr); $content_id = $syn_content['id']; } else { //struct_table insert process $update_contentarr['expand_id'] = $this->struct($bundle_id, $module_id, $struct_id, $data); $update_contentarr['syn_cid'] = $content['id']; $content_id = $this->obj->insert('content', $update_contentarr); } //content_relation process $syn_content_relation = $this->syn_obj->get_content_relation_by_columnid($content_id, $content_relation['column_id']); $update_content_relationarr = $content_relation; unset($update_content_relationarr['id']); if ($syn_content_relation) { unset($update_content_relationarr['syn_rid'], $update_content_relationarr['content_id'], $update_content_relationarr['order_id'], $update_contentarr['bundle_id'], $update_contentarr['module_id'], $update_contentarr['struct_id']); $this->obj->update('content_relation', ' id=' . $syn_content_relation['id'], $update_content_relationarr); $content_relation_id = $syn_content_relation['id']; } else { $update_content_relationarr['syn_rid'] = $content_relation['id']; $update_content_relationarr['content_id'] = $content_id; $content_relation_id = $this->obj->insert('content_relation', $update_content_relationarr); $this->obj->update('content_relation', ' id=' . $content_relation_id, array('order_id' => $content_relation_id)); //add content_client_relation //get client include CUR_CONF_PATH . 'lib/client.class.php'; $client_obj = new client(); $client_typearr = $client_obj->get_all_client(); foreach ($client_typearr as $kct => $vct) { $content_client_data['client_type'] = $vct['id']; $content_client_data['relation_id'] = $content_relation_id; $this->obj->insert('content_client_relation', $content_client_data); } } }
/** * @Description : 获取发布库内容 * @Author : dong(dong@hoge.cn) * @Category : publishcontent * @Date : 2014-2-14 * @LastUpdateDate : 2014-2-14 * @Copyright : hogesoft * @Param : site_id(站点id);column_id(栏目id,多个逗号隔开);client_type(终端id); * @Return : json */ public function show() { $site_id = $column_id = ''; $content_data = array(); $id = urldecode($this->input['_id']); $app = urldecode($this->input['con_app']) == 'all' ? '' : urldecode($this->input['con_app']); //查询出站点下模块的内容 //$offset = $this->input['offset'] ? intval(urldecode($this->input['offset'])) : 0; $page = $this->input['page'] ? intval(urldecode($this->input['page'])) : 1; $count = $this->input['offset'] ? intval(urldecode($this->input['offset'])) : 20; $offset = $count * ($page - 1); $content_data = $this->obj->get_content_allinfo($this->get_condition(), $offset, $count, $this->other_field); if ($content_data['col_id_str']) { $col_parent = $this->column->get_col_parents($content_data['col_id_str']); $column_datas = $this->column->get_column_by_id(' id,name,site_id,column_dir,relate_dir,fid,childdomain,father_domain,custom_content_dir,col_con_maketype ', $content_data['col_id_str'], 'id'); } if ($content_data['site_id_arr']) { $site_datas = $this->column->get_site(' id,site_name,weburl,sub_weburl,custom_content_dir ', ' AND id in(' . implode(',', $content_data['site_id_arr']) . ')', 'id'); } unset($content_data['col_id_str']); unset($content_data['site_id_arr']); foreach ($content_data as $k => $v) { $content_data[$k]['state'] = $v['status']; if ($v['outlink']) { $content_data[$k]['content_url'] = stripos($v['outlink'], 'http') === 0 ? $v['outlink'] : 'http://' . $v['outlink']; } else { $v['column_id'] = $v['use_maincolumn'] ? $v['main_column_id'] : $v['column_id']; $content_data[$k]['content_url'] = mk_content_url($site_datas[$v['site_id']], $column_datas[$v['column_id']], $v); } } //取出应用模块 $appdata = $this->obj->get_app(); $appchilddata = $this->obj->get_app_child($app); //取出所有客户端 include_once CUR_CONF_PATH . 'lib/client.class.php'; $client_obj = new client(); $client = $client_obj->get_all_client('*', '', 'id'); $sql = "SELECT COUNT(*) AS total" . $this->other_field . " FROM " . DB_PREFIX . "content_client_relation cr LEFT JOIN " . DB_PREFIX . "content_relation r ON cr.relation_id=r.id WHERE 1 " . $this->get_condition(); $pagearr = $this->db->query_first($sql); $pagearr['offset'] = $count; $pagearr['count'] = $count; $pagearr['total_page'] = ceil($pagearr['total'] / $count); $pagearr['current_page'] = floor($offset / $count) + 1; $alldata['content_data'] = $content_data; $alldata['col_parent'] = $col_parent; $alldata['app_data'] = $appdata; $alldata['appchild_data'] = $appchilddata; $alldata['client'] = $client; $alldata['page'] = $pagearr; $this->addItem($alldata); $this->output(); }
function get_num_rows(client $client, $table_name) { //TODO: check client's cookie (setting) not to do all these selects if (false) { return ""; } $query = "select count(*) from " . $table_name . ";"; $res = odbc_exec($client->get_connection(), $query); if ($res === false) { return "unknown"; } else { return format_num_rows(odbc_result($res, 1)); } }
/** * @param array $request * @param array $response * * @dataProvider requestsApi */ public function testApi($request, $response) { foreach ($request as $key => $value) { if (is_null($value)) { unset($request[$key]); } } $this->client->request('GET', $this->client->generate('oro_api_get_search'), $request); $result = $this->client->getResponse(); ToolsAPI::assertJsonResponse($result, 200); $result = json_decode($result->getContent(), true); //compare result $this->assertEqualsResponse($response, $result); }
public function add() { $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => ''); $errors = $form; if ($_POST) { $post = new Validation($_POST); $post->pre_filter('trim', true); $post->add_rules('buildings_id', 'required', 'digit'); $post->add_rules('name', 'required'); $post->add_rules('index', 'required'); $post->add_rules('img_uri', 'required'); $post->add_rules('active', 'required'); if ($post->validate()) { // check for invilid $form = arr::overwrite($form, $post->as_array()); $people = new Person_Model(); $result = $people->save($this->input->get('person'), $person_id); } else { $form = arr::overwrite($form, $post->as_array()); client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations'))); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $building = new Building_Model(); $buildings_list = $building->select_list(); $this->template->title = 'Seating::Spaces::Add'; $this->template->content = new View('pages/spaces_add'); $this->template->content->form = $form; $this->template->content->buildings_list = $buildings_list; }
public static function createNote($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } if ($pack->media) { $pack->media->auth = $pack->auth; $pack->media->game_id = $pack->game_id; $pack->media_id = media::createMedia($pack->media)->data->media_id; } $game = games::getGame($pack); $pack->note_id = dbconnection::queryInsert("INSERT INTO notes (" . "game_id," . "user_id," . (isset($pack->name) ? "name," : "") . (isset($pack->description) ? "description," : "") . (isset($pack->media_id) ? "media_id," : "") . "published," . "created" . ") VALUES (" . "'" . $pack->game_id . "'," . "'" . $pack->auth->user_id . "'," . (isset($pack->name) ? "'" . addslashes($pack->name) . "'," : "") . (isset($pack->description) ? "'" . addslashes($pack->description) . "'," : "") . (isset($pack->media_id) ? "'" . addslashes($pack->media_id) . "'," : "") . ($game->data->moderated ? "'PENDING'" : "'AUTO'") . "," . "CURRENT_TIMESTAMP" . ")"); if ($pack->trigger) { $scene_id = dbconnection::queryObject("SELECT * FROM user_game_scenes WHERE user_id = '{$pack->auth->user_id}' AND game_id = '{$pack->game_id}'")->scene_id; if (!$scene_id) { $scene_id = $game->data->intro_scene_id; } $instance_id = dbconnection::queryInsert("INSERT INTO instances (game_id, object_id, object_type, created) VALUES ('{$pack->game_id}', '{$pack->note_id}', 'NOTE', CURRENT_TIMESTAMP)"); $trigger_id = dbconnection::queryInsert("INSERT INTO triggers (game_id, instance_id, scene_id, type, latitude, longitude, infinite_distance, created) VALUES ( '{$pack->game_id}', '{$instance_id}', '{$scene_id}', 'LOCATION', '{$pack->trigger->latitude}', '{$pack->trigger->longitude}', '1', CURRENT_TIMESTAMP);"); } //allow for 'tag_id' in API, but really just use object_tags if ($pack->tag_id) { dbconnection::queryInsert("INSERT INTO object_tags (game_id, object_type, object_id, tag_id, created) VALUES ('{$pack->game_id}', 'NOTE', '{$pack->note_id}', '{$pack->tag_id}', CURRENT_TIMESTAMP)"); } client::logPlayerCreatedNote($pack); games::bumpGameVersion($pack); return notes::getNote($pack); }
/** * 通过调用信任登陆相关用户接口生成用户info * * @param string $code * @return string */ public function generateUserInfo() { $args = ['access_token' => $this->getAccessToken()]; $msg = client::get($this->getUrl('userinfo'), ['query' => $args])->json(); if ($msg['error']) { throw new \LogicException("error :" . $msg['error_code'] . "msg :" . $msg['error']); } return $this->convertStandardUserInfo($msg); }
function show_filter() { global $TPL; global $defaults; $_FORM = client::load_form_data($defaults); $arr = client::load_client_filter($_FORM); is_array($arr) and $TPL = array_merge($TPL, $arr); include_template("templates/clientListFilterS.tpl"); }
public function generateUserInfo() { $args = ['access_token' => $this->getAccessToken(), 'oauth_consumer_key' => $this->getAppKey(), 'openid' => $this->getOpenId()]; $msg = client::get($this->getUrl('userinfo'), ['query' => $args])->json(); if ($msg['ret'] !== 0) { throw new \LogicException(app::get('sysuser')->_('参数错误!')); } return $this->convertStandardUserInfo($msg); }
function addOrder() { if ($_POST['cl_id'] < 0) { $client = new client(); $client->addClient(); $client->existClient(); } $ord_cl_id = $_POST['cl_id']; $ord_bike = $_POST['ord_bike']; //$ord_start_job = strtotime($_POST['ord_date_start']); $ord_start_job = $_POST['ord_date_start']; $ord_internal_note = $_POST['ord_internal_note']; $query = "INSERT INTO `order`(`ord_cl_id`,`ord_bike`,`ord_start_job`,`ord_internal_note`) \n\t\t\t\t\t\t\tVALUES ('{$ord_cl_id}','{$ord_bike}', STR_TO_DATE('{$ord_start_job}','%d.%m.%Y'),'{$ord_internal_note}')"; $database = new database(); $database->dbQuery($query); //return $query; return $_POST['cl_id']; }
/** * * Get the coordinates for a query * * @param string $query * @return array * @throws \Exception */ public function getCoordinatesForQuery($query) { if ($query == '') { return false; } $request = $this->client->get('http://maps.googleapis.com/maps/api/geocode/json'); $request->getQuery()->set('address', $query)->set('sensor', 'false'); $response = $request->send(); if ($response->getStatusCode() != 200) { throw new \Exception('could not connect to googleapis.com/maps/api'); } $fullResponse = $response->json(); if (count($fullResponse['results'])) { $geocoderResult = ['lat' => $fullResponse['results'][0]['geometry']['location']['lat'], 'lng' => $fullResponse['results'][0]['geometry']['location']['lng'], 'accuracy' => $fullResponse['results'][0]['geometry']['location_type']]; } else { $geocoderResult = ['lat' => 0, 'lng' => 0, 'accuracy' => self::RESULT_NOT_FOUND]; } return $geocoderResult; }
public static function createNoteComment($pack) { $pack->auth->permission = "read_write"; if (!users::authenticateUser($pack->auth)) { return new return_package(6, NULL, "Failed Authentication"); } $pack->note_comment_id = dbconnection::queryInsert("INSERT INTO note_comments (" . "game_id," . "note_id," . "user_id," . (isset($pack->name) ? "name," : "") . (isset($pack->description) ? "description," : "") . "created" . ") VALUES (" . "'" . $pack->game_id . "'," . "'" . $pack->note_id . "'," . "'" . $pack->auth->user_id . "'," . (isset($pack->name) ? "'" . addslashes($pack->name) . "'," : "") . (isset($pack->description) ? "'" . addslashes($pack->description) . "'," : "") . "CURRENT_TIMESTAMP" . ")"); client::logPlayerCreatedComment($pack); games::bumpGameVersion($pack); return note_comments::getNoteComment($pack); }
static function find($search_id) { $found_client = null; $clients = client::getAll(); foreach (clients as $client) { $id = $client->getId(); if ($id == $search_id) { $found_client = $client; } } return $found_client; }
/** * 通过调用信任登陆accesstoken接口生成access token * * @param string $code * @return string */ public function generateAccessToken($code) { $args = ['client_id' => $this->getAppKey(), 'client_secret' => $this->getAppSecret(), 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $this->getCallbackUrl()]; try { $msg = client::post($this->getUrl('token'), ['body' => $args])->json(); } catch (ClientException $e) { $msg = $e->getResponse()->json(); throw new \LogicException("error :" . $msg['error'] . "msg :" . $msg['error_description']); } $this->taobaoUserInfo = ['taobao_user_id' => $msg['taobao_user_id'], 'taobao_user_nick' => $msg['taobao_user_nick']]; return $msg['access_token']; }
static function download($ver) { $url = 'http://sitecake.com/dl/upgrade/sitecake-' . $ver . '-upgrade.zip'; $resp = client::get($url); if ($resp->isSuccess()) { $file = TEMP_DIR . '/' . 'sitecake-' . $ver . '-upgrade.zip'; io::file_put_contents($file, $resp->getBody()); return $file; } else { return array('status' => -1, 'errorMessage' => 'Unable to download upgrade from ' . $url); } }
/** * 保存非法字符攻击日志 */ private static function save_attack_log($type, $val) { $cfg = App::get_config(); if ($cfg['SYS_ATTACK_LOG']) { if (SYS_DOMAIN) { $_SERVER['REQUEST_URI'] = str_replace('/' . SYS_DOMAIN, '', $_SERVER['REQUEST_URI']); } $data = array('url' => isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : $_SERVER['REQUEST_URI'], 'ip' => client::get_user_ip(), 'uid' => get_cookie('member_id'), 'time' => time(), 'type' => $type, 'val' => $val, 'user' => $_SERVER['HTTP_USER_AGENT']); $dir = APP_ROOT . 'cache' . DIRECTORY_SEPARATOR . 'attack' . DIRECTORY_SEPARATOR; $file = $dir . date('Ymd') . '.log'; if (!is_dir($dir)) { mkdir($dir, 0777); } $body = file_exists($file) ? file_get_contents($file) : null; if ($body) { $fdata = explode(PHP_EOL, $body); $idata = 0; foreach ($fdata as $v) { if (empty($v)) { continue; } $t = unserialize($v); if ($data['ip'] == $t['ip']) { $idata++; } //若Ip出现10次以上,直接禁止不再保存提醒 //相同地址在20秒内都含有非法字符,直接禁止不再保存提醒 if ($idata >= 10 || $data['time'] - $t['time'] < 20 && $data['user'] == $t['user'] && $data['ip'] == $t['ip'] && $data['url'] == $t['url']) { if ($cfg['SYS_ILLEGAL_CHAR']) { App::display_error(lang('app-10') . '<pre>' . htmlspecialchars(self::strip_slashes($val)) . '</pre>', 1); } unset($cfg); return false; } } unset($fadta); } $body = serialize($data) . PHP_EOL . $body; file_put_contents($file, $body, LOCK_EX); if ($data['ip'] && $cfg['SYS_ATTACK_MAIL'] && check::is_email($cfg['SITE_SYSMAIL'])) { //发送邮件至管理员 mail::set($cfg); $body = '------------------------------------------------------------------------------------------<br>' . 'SITE: ' . SITE_URL . '<br>URL: ' . $data['url'] . '<br>TYPE: ' . $data['type'] . '<br>VALUE: ' . $data['val'] . '<br>IP: ' . $data['ip'] . '<br>TIME: ' . date(TIME_FORMAT, $data['time']) . '<br>USER: '******'user'] . '<br>------------------------------------------------------------------------------------------<br>' . lang('a-cfg-6') . '<br>'; mail::sendmail($cfg['SITE_SYSMAIL'], lang('a-cfg-5') . '-' . $cfg['SITE_NAME'], $body); } } if ($cfg['SYS_ILLEGAL_CHAR']) { App::display_error(lang('app-10') . '<pre>' . htmlspecialchars(self::strip_slashes($val)) . '</pre>', 1); } unset($cfg); }
public function action_delete($delete_id) { if (!$delete_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('buildings'); } $building = ORM::factory('building')->find($delete_id); if ($building->id) { $building->delete($delete_id); client::messageSend('The Building "' . HTML::chars($building->name) . '" was removed', E_USER_NOTICE); } else { client::messageSend("Building not found", E_USER_WARNING); } $this->request->redirect('admin/buildings'); }
public function action_delete($delete_id) { if (!$delete_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('markers'); } $marker = ORM::factory('marker')->find($delete_id); if ($marker->id) { $marker->delete($delete_id); client::messageSend('The Marker "' . HTML::chars($marker->email) . '" was removed', E_USER_NOTICE); } else { client::messageSend("Marker not found", E_USER_WARNING); } $this->request->redirect('admin/markers'); }
function get_report(client $client, $table_name, $show, $rownum) { if ($table_name == null) { return "Bad table name."; } //TODO check table_name is one word //compile query $colnames = odbc_exec($client->get_connection(), "SELECT column_name, data_type, data_length FROM ALL_TAB_COLUMNS WHERE table_name = '" . strtoupper($table_name) . "';"); if ($colnames === false) { return "Unable to get table fields."; } $query = "SELECT "; $i = 0; while (odbc_fetch_row($colnames)) { if (isset($show) && isset($show[$i]) && $show[$i] == true) { if ($query != "SELECT ") { $query .= ", "; } $query .= odbc_result($colnames, 1); } $i += 1; } $query .= " FROM " . $table_name . " WHERE rownum <= ?;"; //prepare statement $statement = odbc_prepare($client->get_connection(), $query); if ($statement === false) { return $query . "\n\n" . get_odbc_error(); } $items = array(); $items[] = (int) $rownum; $result = odbc_execute($statement, $items); if ($result === false) { return $query . "\n\n" . get_odbc_error(); } return $statement; }
public function action_delete($delete_id) { if (!$delete_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('sites'); } $site = ORM::factory('site')->find($delete_id); if ($site->id) { $site->delete($delete_id); client::messageSend('The Site "' . HTML::chars($site->name) . '" was removed', E_USER_NOTICE); } else { client::messageSend("Site not found", E_USER_WARNING); } $this->request->redirect('admin/sites'); }
/** * 登录验证 * @param $username * @param $password * @return boolean */ public function check_login($username, $password) { $row = $this->where('username=?', $username)->select(false); if ($row) { if (md5(md5($password) . $row['salt'] . md5($password)) != $row['password']) { return false; } $ip = client::get_user_ip(); if (empty($row['loginip']) || $row['loginip'] != $ip) { $update = array('lastloginip' => $row['loginip'], 'lastlogintime' => (int) $row['logintime'], 'loginip' => $ip, 'logintime' => time()); $this->update($update, 'userid=' . $row['userid']); } return $row; } return false; }
function changeSuperAdminPass() { if ($this->nname === 'superadmin') { $oldpass = getAdminDbPass(); $newp = client::createDbPass($this->realpass); $return = lfile_put_contents("__path_super_pass", $newp); if (!$return) { log_log("admin_error", "Admin pass change failed {$last_error}"); throw new lxException("could_not_change_superadmin_pass", ''); } $return = $sql->setPassword($newp); if ($return) { $return = lfile_put_contents("__path_super_pass", $oldpass); log_log("admin_error", "mysqladmin Failed . {$out}"); throw new lxException("could_not_change_superadmin_pass", ''); } } }
function create_mysql_db($type, $opt, $admin_pass) { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $db = $sgbl->__var_dbf; if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) { print "Need db Root User and password --db-rootuser, --db-rootpassword \n"; exit; } if ($sgbl->__var_database_type === 'mysql') { // TODO: REPLACE MYSQL_CONNECT // TUT TUT naughty programmer... We are creating the db now XD $req = mysqli_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']); } else { if ($sgbl->__var_database_type === 'mssql') { $req = mssql_connect("localhost,{$sgbl->__var_mssqlport}"); } else { $req = new PDO("sqlite:{$db}"); } } if (!$req) { print "Could not Connect to Database on localhost using root user: "******"\n"; } //$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql"); $dp = randomString(9); $dbadminpass = client::createDbPass($dp); $dbname = $sgbl->__var_dbf; $pguser = $sgbl->__var_admin_user; if ($sgbl->__var_database_type === 'mysql') { @mysqli_query($req, "CREATE DATABASE {$dbname}"); mysqli_query($req, "GRANT ALL ON {$dbname}.* TO '{$pguser}'@'localhost' IDENTIFIED BY '{$dbadminpass}';"); } else { if ($sgbl->__var_database_type === 'mssql') { mssql_query("create database {$dbname};"); mssql_query("use master "); mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';"); mssql_query("use {$dbname} "); mssql_query("grant all to {$pguser}"); } else { } } lfile_put_contents("__path_admin_pass", $dbadminpass); lxfile_generic_chown("__path_admin_pass", "lxlabs"); }
function create_mysql_db($type, $opt, $admin_pass) { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) { print "Need db Root User and password --db-rootuser, --db-rootpassword \n"; exit; } if ($sgbl->__var_database_type === 'mysql') { $req = mysql_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']); } else { if ($sgbl->__var_database_type === 'mssql') { $req = mssql_connect("localhost,{$sgbl->__var_mssqlport}"); } else { $req = new PDO("sqlite:{$sgbl->__var_dbf}"); } } if (!$req) { print "Could not Connect to Database on localhost using root user\n"; } //$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql"); $dp = randomString(9); $dbadminpass = client::createDbPass($dp); $dbname = $sgbl->__var_dbf; $pguser = $sgbl->__var_admin_user; if ($sgbl->__var_database_type === 'mysql') { @mysql_query("create database {$dbname}"); mysql_query("grant all on {$dbname}.* to '{$pguser}'@'localhost' identified by '{$dbadminpass}';"); } else { if ($sgbl->__var_database_type === 'mssql') { mssql_query("create database {$dbname};"); mssql_query("use master "); mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';"); mssql_query("use {$dbname} "); mssql_query("grant all to {$pguser}"); } else { } } lfile_put_contents("__path_admin_pass", $dbadminpass); lxfile_generic_chown("__path_admin_pass", "lxlabs"); }
/** * 上传文件到七牛,内部使用 * * @param $upToken 上传凭证 * @param $key 上传文件名 * @param $filePath 上传文件的路径 * @param $params 自定义变量,规格参考 * http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar * @param $mime 上传数据的mimeType * @param $checkCrc 是否校验crc32 * * @return array 包含已上传文件的信息,类似: * [ * "hash" => "<Hash string>", * "key" => "<Key string>" * ] */ public static function putFile($upToken, $key, $filePath, $config, $params, $mime, $checkCrc) { $fields = array('token' => $upToken, 'file' => self::createFile($filePath, $mime)); if ($key !== null) { $fields['key'] = $key; } if ($checkCrc) { $fields['crc32'] = Qiniu\crc32_file($filePath); } if ($params) { foreach ($params as $k => $v) { $fields[$k] = $v; } } $fields['key'] = $key; $headers = array('Content-Type' => 'multipart/form-data'); $response = client::post($config->getUpHost(), $fields, $headers); if (!$response->ok()) { return array(null, new Error($config->getUpHost(), $response)); } return array($response->json(), null); }
public static function putFile($upToken, $key, $filePath, $params, $mime, $checkCrc) { $fields = array('token' => $upToken, 'file' => self::createFile($filePath, $mime)); if ($key === null) { $fname = 'filename'; } else { $fname = $key; $fields['key'] = $key; } if ($checkCrc) { $fields['crc32'] = (new Functions())->crc32_file($filePath); } if ($params) { foreach ($params as $k => $v) { $fields[$k] = $v; } } $headers = array('Content-Type' => 'multipart/form-data'); $response = client::post(Config::$defaultHost, $fields, $headers); if (!$response->ok()) { return array(null, new Error(Config::$defaultHost, $response)); } return array($response->json(), null); }
<?php /** * ==================================== * FileName: client.php * Description: 测试 * * Author: EricZhang * Date Time: 3/27/16 11:10 AM * ==================================== */ include_once "./singleton.php"; class client { public static function main() { $instance = Singleton::getInstance(); $instance->test(); } } client::main();