Exemple #1
0
 public function request($method, $url = '', $body = null, $headers = array())
 {
     $headers['user-agent'] = Constants::DAV_USER_AGENT;
     $sLog = "REQUEST: " . $method;
     if ($url != '') {
         $sLog = $sLog . " " . $url;
     }
     if ($body != null) {
         $sLog = $sLog . "\r\nBody:\r\n" . $body;
     }
     \CApi::Log($sLog, \ELogLevel::Full, 'dav-');
     \CApi::LogObject($headers, \ELogLevel::Full, 'dav-');
     $response = array();
     try {
         $response = parent::request($method, $url, $body, $headers);
     } catch (\Sabre\DAV\Exception $ex) {
         \CApi::LogObject($ex->getMessage(), \ELogLevel::Full, 'dav-');
         throw $ex;
     }
     $sLog = "RESPONSE: " . $method;
     if (!empty($response['body'])) {
         $sLog = $sLog . "\r\nBody:\r\n" . $response['body'];
     }
     \CApi::Log($sLog, \ELogLevel::Full, 'dav-');
     if (!empty($response['headers'])) {
         \CApi::LogObject($response['headers'], \ELogLevel::Full, 'dav-');
     }
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function createDir($path, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $response = $this->client->request('MKCOL', $location);
     if ($response['statusCode'] !== 201) {
         return false;
     }
     return compact('path') + ['type' => 'dir'];
 }
Exemple #3
0
 /**
  * @param string $method
  * @param string $path
  * @param integer $expected
  */
 private function simpleResponse($method, $path, $body, $expected)
 {
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->request($method, $this->encodePath($path), $body);
         return $response['statusCode'] == $expected;
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * request method of server webdav
  *
  * @param string $method
  * @param string $path
  * @param integer $expected status code
  * @return boolean request successful
  */
 private function simpleResponse($_method, $_path, $_body, $_expected)
 {
     $path = $this->cleanPath($_path);
     try {
         $response = $this->client->request($_method, $this->encodePath($path), $_body);
         return $response['statusCode'] == $_expected;
     } catch (Exception $e) {
         error_log($e->getMessage());
         return false;
     }
 }
Exemple #5
0
/**
 * @param \Sabre\DAV\Client $client
 * @param $uploadUrl
 * @return mixed
 */
function request($client, $method, $uploadUrl, $data = null, $headers = [])
{
    echo "{$method} {$uploadUrl} ... ";
    $t0 = microtime(true);
    $result = $client->request($method, $uploadUrl, $data, $headers);
    $t1 = microtime(true);
    echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL;
    if (!in_array($result['statusCode'], [200, 201])) {
        echo $result['body'] . PHP_EOL;
    }
    return $result;
}
Exemple #6
0
 /**
  * @param string $method
  * @param string $path
  * @param integer $expected
  */
 private function simpleResponse($method, $path, $body, $expected)
 {
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->request($method, $this->encodePath($path), $body);
         return $response['statusCode'] == $expected;
     } catch (\Exception $e) {
         // TODO: log for now, but in the future need to wrap/rethrow exception
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Exemple #7
0
 /**
  * @param string $method
  * @param string $path
  * @param integer $expected
  */
 private function simpleResponse($method, $path, $body, $expected)
 {
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->request($method, $this->encodePath($path), $body);
         return $response['statusCode'] == $expected;
     } catch (Exception\NotFound $e) {
         if ($method === 'DELETE') {
             return false;
         }
         $this->convertException($e);
     } catch (\Exception $e) {
         $this->convertException($e);
     }
     return false;
 }
Exemple #8
0
 /**
  * @param string $method
  * @param string $path
  * @param string|resource|null $body
  * @param int $expected
  * @return bool
  * @throws StorageInvalidException
  * @throws StorageNotAvailableException
  */
 private function simpleResponse($method, $path, $body, $expected)
 {
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->request($method, $this->encodePath($path), $body);
         return $response['statusCode'] == $expected;
     } catch (ClientHttpException $e) {
         if ($e->getHttpStatus() === 404 && $method === 'DELETE') {
             $this->statCache->clear($path . '/');
             $this->statCache->set($path, false);
             return false;
         }
         $this->convertException($e);
     } catch (\Exception $e) {
         $this->convertException($e);
     }
     return false;
 }
$method = filter_input(INPUT_GET, "method");
if (empty($method)) {
    $method = "calDAV";
}
if ($method == "cardDAV") {
    $firstresponse = $client->propfind('/remote.php/carddav/addressbooks/' . $settings["userName"], array('{DAV:}displayname'), 1);
    foreach ($firstresponse as $addressbook => $value) {
        if (empty($value)) {
            continue;
        }
        $response = $client->propfind($addressbook, array('{DAV:}displayname'), 1);
        foreach ($response as $vcardUrl => $value) {
            if ($vcardUrl == $addressbook) {
                continue;
            }
            $vcardresponse = $client->request('GET', $vcardUrl);
            $vcard = VObject\Reader::read($vcardresponse["body"]);
            $name = (string) $vcard->FN;
            $bday_raw = explode("-", (string) $vcard->BDAY);
            if (!empty($bday_raw[0])) {
                $bdays[$name] = mktime(0, 0, 0, $bday_raw[1], $bday_raw[2], $bday_raw[0]) * 1000;
            }
        }
    }
    $bdays["dummy"] = (time() + 86520) * 1000;
    $bdays["dummy2"] = (time() + 120) * 1000;
    $bdays["dummy3"] = (time() - 86200) * 1000;
    $json = "{";
    $first = true;
    foreach ($bdays as $key => $value) {
        if ($first) {
Exemple #10
0
 public function getRepo()
 {
     if (file_exists($this->git_dir)) {
         $this->recursiveRemoveDirectory($this->git_dir);
     }
     $repo = Gitonomy\Git\Admin::cloneTo($this->git_dir, $this->git_url, false);
     $tags = $repo->getReferences()->getTags();
     /**
      * If no tags, use master
      */
     if (empty($tags)) {
         $commitHash = $repo->getReferences()->getBranch('master')->getCommitHash();
     } else {
         rsort($tags);
         $commitHash = $tags[0]->getCommitHash();
     }
     if ($commitHash === $this->info["last_commit"]) {
         // No need of update
         return true;
     }
     $sql = \Lobby\DB::getDBH()->prepare("UPDATE `git_cache` SET `last_commit` = ? WHERE `git_url` = ?");
     $sql->execute(array($commitHash, $this->git_url));
     $this->recursiveRemoveDirectory($this->git_dir . "/.git");
     /**
      * Get screenshots
      */
     $manifest = json_decode(file_get_contents($this->git_dir . "/manifest.json"), true);
     // Manifest file is invalid
     if (!is_array($manifest)) {
         return false;
     }
     if (isset($manifest["version"])) {
         $latestVersion = $manifest["version"];
     } else {
         return false;
     }
     if (isset($manifest->screenshots)) {
         $screenshots = array();
         foreach ($manifest["screenshots"] as $img) {
             $url = parse_url($img);
             if ($url["host"] === "i.imgur.com") {
                 $path = $url["path"];
                 // $path has slash at beginning
                 $headers = @get_headers("http://i.imgur.com{$path}", 1);
                 if ($headers[0] === "HTTP/1.1 200 OK") {
                     $screenshots[] = "//i.imgur.com{$path}";
                 }
             }
         }
         if (empty($screenshots)) {
             unset($screenshots);
         }
     }
     if (exec("cd {$this->git_dir};zip -r '{$this->git_dir}/app.zip' ./ -1 -q;") !== false) {
         $logo = true;
         if (file_exists($this->git_dir . "/src/image/logo.svg")) {
             $this->convertLogoToPNG();
         } else {
             if (file_exists($this->git_dir . "/src/image/logo.png")) {
                 copy($this->git_dir . "/src/image/logo.png", $this->git_dir . "/logo.png");
             } else {
                 $logo = false;
             }
         }
         $webdavPass = getenv("SKY_WEBDAV_PASS");
         $settings = array('baseUri' => "https://sky-phpgeek.rhcloud.com/remote.php/webdav/Apps/{$this->id}/", 'userName' => 'lobby-apps', 'password' => $webdavPass);
         $client = new Client($settings);
         /**
          * Create folder
          */
         $client->request('MKCOL');
         /**
          * Upload files
          */
         $client->request('PUT', "{$this->id}.zip", file_get_contents($this->git_dir . "/app.zip"));
         if ($logo) {
             $client->request('PUT', "logo.png", file_get_contents($this->git_dir . "/logo.png"));
         }
         $request = \Requests::post("https://sky-phpgeek.rhcloud.com/ocs/v1.php/apps/files_sharing/api/v1/shares?format=json", array("Content-Type" => "application/x-www-form-urlencoded"), array("path" => "Apps/{$this->id}", "shareType" => "3"), array("auth" => array("lobby-apps", $webdavPass)));
         $response = json_decode($request->body);
         $this->cloud_id = $response->ocs->data->token;
         $extraColumnData = array("short_description" => $manifest["short_description"]);
         if (isset($latestVersion)) {
             $extraColumnData["version"] = $latestVersion;
         }
         if (isset($screenshots)) {
             $extraColumnData["screenshots"] = implode("\n", $screenshots);
         }
         if (isset($manifest["require"]) && is_array($manifest["require"])) {
             $extraColumnData["requires"] = json_encode($manifest["require"]);
         }
         /**
          * Update Cloud ID and download file size
          */
         $appInfoUpdate = array(":cloudID" => $this->cloud_id, ":downloadSize" => filesize($this->git_dir . "/app.zip"), ":appID" => $this->id);
         $extraColumns = "";
         if (!empty($extraColumnData)) {
             foreach ($extraColumnData as $k => $v) {
                 $extraColumns .= ", {$k} = :{$k}";
                 $appInfoUpdate[":{$k}"] = $v;
             }
         }
         $sql = \Lobby\DB::getDBH()->prepare("UPDATE `apps` SET `cloud_id` = :cloudID, `download_size` = :downloadSize, `updated` = NOW() {$extraColumns} WHERE `id` = :appID");
         $sql->execute($appInfoUpdate);
         $this->recursiveRemoveDirectory($this->git_dir);
         return true;
     }
     return false;
 }
Exemple #11
0
 /**
  * @param string $url
  * @param string $sharedSecret
  * @param string $resourcePath
  * @return array
  */
 protected function download($url, $sharedSecret, $resourcePath)
 {
     $settings = ['baseUri' => $url, 'userName' => 'system', 'password' => $sharedSecret];
     $client = new Client($settings);
     $client->setThrowExceptions(true);
     $response = $client->request('GET', $resourcePath);
     return $response;
 }
Exemple #12
0
<?php

require 'SabreDAV/vendor/autoload.php';
require 'credentials.php';
use Sabre\DAV\Client;
// Parameters
$serie = $_GET["s"];
$chapter = str_pad($_GET["c"], 4, "0", STR_PAD_LEFT);
$nextPage = str_pad(intval($_GET["p"]) + 1, 2, "0", STR_PAD_LEFT);
// Complete filename
$filename = '/' . $serie . '/' . $chapter . '/' . $chapter . '-' . $nextPage . '.jpg';
// Set credentials
$settings = getCredentials($serie, $chapter);
$client = new Client($settings);
$response = $client->request('GET', $filename);
$statusCode = $response["statusCode"];
if ($statusCode != 200) {
    // We try the next chapter
    $chapter = intval($chapter) + 1;
    $nextPage = 1;
}
$url = 'read.php?s=' . $serie . '&c=' . intval($chapter) . '&p=' . intval($nextPage);
echo $url;