コード例 #1
0
ファイル: ocsclient.php プロジェクト: hjimmy/owncloud
 /**
  * @brief Get the content of an OCS url call.
  * @returns string of the response
  * This function calls an OCS server and returns the response. It also sets a sane timeout
  */
 private static function getOCSresponse($url)
 {
     $data = \OC_Util::getUrlContent($url);
     return $data;
 }
コード例 #2
0
 /**
  * @param array $data
  * @return array
  * @throws Exception
  */
 public static function downloadApp($data = array())
 {
     $l = \OC::$server->getL10N('lib');
     if (!isset($data['source'])) {
         throw new \Exception($l->t("No source specified when installing app"));
     }
     //download the file if necessary
     if ($data['source'] == 'http') {
         $pathInfo = pathinfo($data['href']);
         $path = OC_Helper::tmpFile('.' . $pathInfo['extension']);
         if (!isset($data['href'])) {
             throw new \Exception($l->t("No href specified when installing app from http"));
         }
         file_put_contents($path, \OC_Util::getUrlContent($data['href']));
     } else {
         if (!isset($data['path'])) {
             throw new \Exception($l->t("No path specified when installing app from local file"));
         }
         $path = $data['path'];
     }
     //detect the archive type
     $mime = OC_Helper::getMimeType($path);
     if ($mime !== 'application/zip' && $mime !== 'application/x-gzip') {
         throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
     }
     //extract the archive in a temporary folder
     $extractDir = OC_Helper::tmpFolder();
     OC_Helper::rmdirr($extractDir);
     mkdir($extractDir);
     if ($archive = OC_Archive::open($path)) {
         $archive->extract($extractDir);
     } else {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("Failed to open archive when installing app"));
     }
     return array($extractDir, $path);
 }
コード例 #3
0
 public static function getURLMetadata($url)
 {
     //allow only http(s) and (s)ftp
     $protocols = '/^[hs]{0,1}[tf]{0,1}tp[s]{0,1}\\:\\/\\//i';
     //if not (allowed) protocol is given, assume http
     if (preg_match($protocols, $url) == 0) {
         $url = 'http://' . $url;
     }
     $metadata['url'] = $url;
     $page = OC_Util::getUrlContent($url);
     if ($page) {
         if (preg_match("/<title>(.*)<\\/title>/sUi", $page, $match) !== false) {
             if (isset($match[1])) {
                 $metadata['title'] = html_entity_decode($match[1], ENT_QUOTES, 'UTF-8');
                 //Not the best solution but....
                 $metadata['title'] = str_replace('&trade;', chr(153), $metadata['title']);
                 $metadata['title'] = str_replace('&dash;', '‐', $metadata['title']);
                 $metadata['title'] = str_replace('&ndash;', '–', $metadata['title']);
             }
         }
     }
     return $metadata;
 }
コード例 #4
0
    \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
    exit;
}
$token = $_POST['token'];
$remote = $_POST['remote'];
$owner = $_POST['owner'];
$name = $_POST['name'];
$password = $_POST['password'];
// Check for invalid name
if (!\OCP\Util::isValidFileName($name)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.'))));
    exit;
}
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getUserSession()->getUser()->getUID());
// check for ssl cert
if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
    exit;
} else {
    $mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true);
    /**
     * @var \OCA\Files_Sharing\External\Storage $storage
     */
    $storage = $mount->getStorage();
    try {
        // check if storage exists
        $storage->checkStorageAvailability();
    } catch (\OCP\Files\StorageInvalidException $e) {
        // note: checkStorageAvailability will already remove the invalid share
        \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
        \OCP\JSON::error(array('data' => array('message' => $l->t('Could not authenticate to remote share, password might be wrong'))));
コード例 #5
0
ファイル: api.php プロジェクト: hjimmy/owncloud
 /**
  * Gets the content of an URL by using CURL or a fallback if it is not
  * installed
  * @param string $url the url that should be fetched
  * @return string the content of the webpage
  */
 public function getUrlContent($url)
 {
     return \OC_Util::getUrlContent($url);
 }