Beispiel #1
0
 /**
  * Login into pyLoad
  *
  * @param string $username Username
  * @param string $password Password
  * @return string Session ID
  * @throws \Exception
  */
 public function login($username, $password)
 {
     if (!is_null(PyLoad::getInstance()->getSession())) {
         return PyLoad::getInstance()->getSession();
     }
     $curl_opts[CURLOPT_POST] = true;
     $curl_opts[CURLOPT_POSTFIELDS] = array('username' => $username, 'password' => $password);
     $curl_opts[CURLOPT_HTTPHEADER] = array('Content-Type: multipart/form-data');
     $session = CURL::exec('login', $curl_opts);
     $session = str_replace('"', '', $session);
     PyLoad::getInstance()->setSession($session);
     return $session;
 }
Beispiel #2
0
 private static function curl($url, array $opts = array())
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, PyLoad::getBaseURL() . $url);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_NOBODY, false);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
     curl_setopt_array($ch, $opts);
     if (!($resp = curl_exec($ch))) {
         throw new \Exception(curl_error($ch));
     }
     curl_close($ch);
     return $resp;
 }
Beispiel #3
0
 /**
  * Check that user is authenticated
  *
  * @throws \Exception
  */
 protected function checkAuthentication()
 {
     if (is_null(PyLoad::getInstance()->getSession())) {
         throw new \Exception('You must be authenticated to access this URL');
     }
 }