Exemple #1
0
 /**
  * Uploads a file to the wiki API.
  *
  * @param   array    $array  Array of details to be used in the upload
  * @return  array            Unserialized php output from the wiki API
  */
 public function upload($array)
 {
     $array['action'] = 'upload';
     $array['format'] = 'php';
     // Construct multipart body: https://www.mediawiki.org/wiki/API:Upload#Sample_Raw_Upload
     $boundary = '---Wikimate-' . md5(microtime());
     $body = '';
     foreach ($array as $fieldName => $fieldData) {
         $body .= "--{$boundary}\r\n";
         $body .= 'Content-Disposition: form-data; name="' . $fieldName . '"';
         // Process the (binary) file
         if ($fieldName == 'file') {
             $body .= '; filename="' . $array['filename'] . '"' . "\r\n";
             $body .= "Content-Type: application/octet-stream; charset=UTF-8\r\n";
             $body .= "Content-Transfer-Encoding: binary\r\n";
             // Process text parameters
         } else {
             $body .= "\r\n";
             $body .= "Content-Type: text/plain; charset=UTF-8\r\n";
             $body .= "Content-Transfer-Encoding: 8bit\r\n";
         }
         $body .= "\r\n{$fieldData}\r\n";
     }
     $body .= "--{$boundary}--\r\n";
     // Construct multipart headers
     $headers = array('Content-Type' => "multipart/form-data; boundary={$boundary}", 'Content-Length' => strlen($body));
     $apiResult = $this->session->post($this->api, $headers, $body);
     return unserialize($apiResult->body);
 }
Exemple #2
0
 /**
  * Perfoms a delete query to the wiki api
  * @param array $array array of details to be passed in the query
  * @return array unserialized php output from the wiki
  */
 public function delete($array)
 {
     $headers = array('Content-Type' => "application/x-www-form-urlencoded");
     $array['action'] = 'delete';
     $array['format'] = 'php';
     $apiResult = $this->session->post($this->api, $headers, $array);
     return unserialize($apiResult);
 }
Exemple #3
0
 public static function logInAsUser(\Requests_Session $session, $username, $password)
 {
     $loginPostData = ['log' => $username, 'pwd' => $password, 'rememberme' => 'forever', 'wp-submit' => 'Log+In'];
     $loginURL = \Wordfence\ExKit\Endpoint::loginURL();
     $r = $session->post($loginURL, [], $loginPostData);
     if ($r->url == $loginURL) {
         \Wordfence\ExKit\Cli::write('[-] Authentication failed', 'yellow', null);
         exit(\Wordfence\ExKit\ExitCodes::EXIT_CODE_FAILED_PRECONDITION);
     }
 }
Exemple #4
0
 public function testBasicPOST()
 {
     $session_headers = array('X-Requests-Session' => 'BasicPOST', 'X-Requests-Request' => 'notset');
     $session = new Requests_Session(httpbin('/'), $session_headers);
     $response = $session->post('/post', array('X-Requests-Request' => 'POST'), array('postdata' => 'exists'));
     $response->throw_for_status(false);
     $this->assertEquals(200, $response->status_code);
     $data = json_decode($response->body, true);
     $this->assertArrayHasKey('X-Requests-Session', $data['headers']);
     $this->assertEquals('BasicPOST', $data['headers']['X-Requests-Session']);
     $this->assertArrayHasKey('X-Requests-Request', $data['headers']);
     $this->assertEquals('POST', $data['headers']['X-Requests-Request']);
 }
Exemple #5
0
 /**
  * Разрешаем доступ приложению
  *
  * @param $url
  * @return \Requests_Response
  */
 private function post_confirm($url)
 {
     $v = explode('?', $url);
     return $this->session->post('?' . $v[1]);
 }