示例#1
0
 /**
  * Connects to the HCP instance
  * 
  */
 private function connect()
 {
     $data = $this->checkAuthFile();
     $options = $this->options;
     $options['url'] = $this->url;
     foreach ($data->cookie as $cookie) {
         $options['headers'][] = 'Cookie: ' . $cookie;
     }
     $req = new Request($options);
     $this->content_type = $req->getHeader('content-type');
     $this->contents = $req->getContents();
 }
示例#2
0
 /**
  * Generate the auth cookie 
  * 
  * @return mixed
  */
 private function generateAuthCookie()
 {
     $req = new Request($this->getOptions($this->url));
     $cookieHana = $req->getHeader('set-cookie');
     $location = $req->getHeader('location');
     $req2 = new Request($this->getOptions($location));
     $cookieAccounts = $req2->getHeader('set-cookie');
     $contents = $req2->getContents();
     $dom = new DOMDocument();
     @$dom->loadHTML($contents);
     $action = $dom->getElementsByTagName('form')->item(0)->getAttribute('action');
     $inputs = $dom->getElementsByTagName('input');
     $form = array();
     foreach ($inputs as $input) {
         switch ($input->getAttribute('name')) {
             case 'j_username':
                 $value = $this->auth_options['username'];
                 break;
             case 'j_password':
                 $value = $this->auth_options['password'];
                 break;
             default:
                 $value = $input->getAttribute('value');
                 break;
         }
         $form[$input->getAttribute('name')] = $value;
     }
     $loginurl = $form['targetUrl'] . $action;
     $options = $this->getOptions($loginurl);
     $options['form'] = $form;
     foreach ($cookieAccounts as $cookie) {
         $options['headers'][] = 'Cookie: ' . $cookie;
     }
     $post_req = new Request($options, 'POST');
     $cookieAccounts = $post_req->getHeader('set-cookie');
     // Now we call the initial site
     $dom = new DOMDocument();
     @$dom->loadHTML($post_req->getContents());
     $messages = $dom->getElementById('globalMessages');
     if ($messages == '') {
         // Read the Form Action + Method
         $action = $dom->getElementsByTagName('form')->item(0)->getAttribute('action');
         $inputs = $dom->getElementsByTagName('input');
         $form = array();
         foreach ($inputs as $input) {
             $form[$input->getAttribute('name')] = $input->getAttribute('value');
         }
         $options = $this->getOptions($action);
         $options['form'] = $form;
         foreach ($cookieHana as $cookie) {
             $options['headers'][] = 'Cookie: ' . $cookie;
         }
         $post_req2 = new Request($options, 'POST');
         $this->cookie = $post_req2->getHeader('set-cookie');
     } else {
         return;
     }
 }