Ejemplo n.º 1
0
function getStandardImage()
{
    //OCP\Response::setExpiresHeader('P10D');
    OCP\Response::enableCaching();
    OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
    exit;
}
Ejemplo n.º 2
0
 public static function getCalenderSources($parameters)
 {
     $base_url = OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=';
     foreach (OC_Contacts_Addressbook::all(OCP\USER::getUser()) as $addressbook) {
         $parameters['sources'][] = array('url' => $base_url . 'birthday_' . $addressbook['id'], 'backgroundColor' => '#cccccc', 'borderColor' => '#888', 'textColor' => 'black', 'cache' => true, 'editable' => false);
     }
 }
Ejemplo n.º 3
0
 public static function sendEmail($args)
 {
     $isEncrypted = OC_App::isEnabled('files_encryption');
     if (!$isEncrypted || isset($_POST['continue'])) {
         $continue = true;
     } else {
         $continue = false;
     }
     if (OC_User::userExists($_POST['user']) && $continue) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
             try {
                 OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             } catch (Exception $e) {
                 OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
             }
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
Ejemplo n.º 4
0
 /**
  * Check if the password is correct without logging in the user
  *
  * @param string $uid      The username
  * @param string $password The password
  *
  * @return true/false
  */
 public function checkPassword($uid, $password)
 {
     $uidEscaped = escapeshellarg($uid);
     $password = escapeshellarg($password);
     $result = array();
     $command = self::SMBCLIENT . ' //' . $this->host . '/dummy -U' . $uidEscaped . '%' . $password;
     $lastline = exec($command, $output, $retval);
     if ($retval === 127) {
         OCP\Util::writeLog('user_external', 'ERROR: smbclient executable missing', OCP\Util::ERROR);
         return false;
     } else {
         if (strpos($lastline, self::LOGINERROR) !== false) {
             //normal login error
             return false;
         } else {
             if (strpos($lastline, 'NT_STATUS_BAD_NETWORK_NAME') !== false) {
                 //login on minor error
                 goto login;
             } else {
                 if ($retval != 0) {
                     //some other error
                     OCP\Util::writeLog('user_external', 'ERROR: smbclient error: ' . trim($lastline), OCP\Util::ERROR);
                     return false;
                 } else {
                     login:
                     $this->storeUser($uid);
                     return $uid;
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
Archivo: imap.php Proyecto: kosli/apps
 /**
  * Check if the password is correct without logging in the user
  *
  * @param string $uid      The username
  * @param string $password The password
  *
  * @return true/false
  */
 public function checkPassword($uid, $password)
 {
     if (!function_exists('imap_open')) {
         OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR);
         return false;
     }
     // Check if we only want logins from ONE domain and strip the domain part from UID
     if ($this->domain != '') {
         $pieces = explode('@', $uid);
         if (count($pieces) == 1) {
             $username = $uid . "@" . $this->domain;
         } elseif (count($pieces) == 2 and $pieces[1] == $this->domain) {
             $username = $uid;
             $uid = $pieces[0];
         } else {
             return false;
         }
     } else {
         $username = $uid;
     }
     $mbox = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1);
     imap_errors();
     imap_alerts();
     if ($mbox !== FALSE) {
         imap_close($mbox);
         $uid = mb_strtolower($uid);
         $this->storeUser($uid);
         return $uid;
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     // 		if(count($calendars)==0 || !OCP\App::isEnabled('contacts')){
     // 			//return false;
     // 		}
     // NOTE: Does the following do anything
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '?id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
Ejemplo n.º 7
0
 public static function sendEmail($args)
 {
     if (OC_User::userExists($_POST['user'])) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
             OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             echo 'Mailsent';
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
Ejemplo n.º 8
0
 /**
  * @brief Gets the VCard as an OC_VObject
  * @returns The card or null if the card could not be parsed.
  */
 public static function getContactVCard($id)
 {
     $card = self::getContactObject($id);
     $vcard = OC_VObject::parse($card['carddata']);
     // Try to fix cards with missing 'N' field from pre ownCloud 4. Hot damn, this is ugly...
     if (!is_null($vcard) && !$vcard->__isset('N')) {
         $version = OCP\App::getAppVersion('contacts');
         if ($version >= 5) {
             OCP\Util::writeLog('contacts', 'OC_Contacts_App::getContactVCard. Deprecated check for missing N field', OCP\Util::DEBUG);
         }
         OCP\Util::writeLog('contacts', 'getContactVCard, Missing N field', OCP\Util::DEBUG);
         if ($vcard->__isset('FN')) {
             OCP\Util::writeLog('contacts', 'getContactVCard, found FN field: ' . $vcard->__get('FN'), OCP\Util::DEBUG);
             $n = implode(';', array_reverse(array_slice(explode(' ', $vcard->__get('FN')), 0, 2))) . ';;;';
             $vcard->setString('N', $n);
             OC_Contacts_VCard::edit($id, $vcard);
         } else {
             // Else just add an empty 'N' field :-P
             $vcard->setString('N', 'Unknown;Name;;;');
         }
     }
     if (!is_null($vcard) && !isset($vcard->REV)) {
         $rev = new DateTime('@' . $card['lastmodified']);
         $vcard->setString('REV', $rev->format(DateTime::W3C));
     }
     return $vcard;
 }
Ejemplo n.º 9
0
 public static function writePhoto($params)
 {
     $path = $params[OC_Filesystem::signal_param_path];
     if (self::isPhoto($path)) {
         OCP\Util::writeLog('gallery', 'updating thumbnail for ' . $path, OCP\Util::DEBUG);
         \OC\Pictures\ThumbnailsManager::getInstance()->getThumbnail($path);
     }
 }
Ejemplo n.º 10
0
 function __construct($source)
 {
     $this->path = $source;
     $this->zip = new ZipArchive();
     if ($this->zip->open($source, ZipArchive::CREATE)) {
     } else {
         OCP\Util::writeLog('files_archive', 'Error while opening archive ' . $source, OCP\Util::WARN);
     }
 }
Ejemplo n.º 11
0
 public static function apiConfig($parameters)
 {
     $xml['version'] = '1.7';
     $xml['website'] = 'ownCloud';
     $xml['host'] = OCP\Util::getServerHost();
     $xml['contact'] = '';
     $xml['ssl'] = 'false';
     return new OC_OCS_Result($xml);
 }
Ejemplo n.º 12
0
/**
 * Copyright (c) 2011 Marvin Thomas Rabe <*****@*****.**>
 * Copyright (c) 2011 Arthur Schiwon <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
function bookmarklet()
{
    $l = new OC_l10n('bookmarks');
    $blet = "javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=c(document.title),d=a.open('";
    $blet .= OCP\Util::linkToAbsolute('bookmarks', 'addBm.php');
    $blet .= "?output=popup&url='+c(b.location)+'&title='+e,'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=400px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300);})();";
    $help_msg = $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:');
    return '<div class="bkm_hint">' . $help_msg . '</div><br /><a class="button bookmarklet" href="' . $blet . '">' . $l->t('Add to ownCloud') . '</a>';
}
Ejemplo n.º 13
0
 function search($query)
 {
     $stmt = OCP\DB::prepare('SELECT * FROM `*PREFIX*gallery_albums` WHERE `uid_owner` = ? AND `album_name` LIKE ?');
     $result = $stmt->execute(array(OCP\USER::getUser(), '%' . $query . '%'));
     $results = array();
     while ($row = $result->fetchRow()) {
         $results[] = new OC_Search_Result($row['album_name'], '', OCP\Util::linkTo('gallery', 'index.php') . '?view=' . $row['album_name'], (string) $l->t('Galleries'));
     }
     return $results;
 }
Ejemplo n.º 14
0
 /**
  * Get an layer
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getlayer()
 {
     $layer = $this->params('layer') ? $this->params('layer') : null;
     if ($layer === "contacts") {
         if (\OCP\App::isEnabled('contacts')) {
         } else {
             OCP\Util::writeLog('maps', "App contacts missing for Maps", \OCP\Util::WARN);
         }
     }
 }
Ejemplo n.º 15
0
 public function checkPassword($uid, $password)
 {
     if (!phpCAS::forceAuthentication()) {
         return false;
     }
     $uid = phpCAS::getUser();
     if ($uid === false) {
         OCP\Util::writeLog('user_cas', 'phpCAS return no user !', OCP\Util::ERROR);
         return false;
     }
     return $uid;
 }
Ejemplo n.º 16
0
function debug($msg, $tracelevel = 0, $debuglevel = OCP\Util::DEBUG)
{
    if (PHP_VERSION >= "5.4") {
        $call = debug_backtrace(false, $tracelevel + 1);
    } else {
        $call = debug_backtrace(false);
    }
    $call = $call[$tracelevel];
    if ($debuglevel !== false) {
        OCP\Util::writeLog('contacts', $call['file'] . '. Line: ' . $call['line'] . ': ' . $msg, $debuglevel);
    }
}
Ejemplo n.º 17
0
 private function createUser($uid)
 {
     if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
         OCP\Util::writeLog('saml', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OCP\Util::DEBUG);
         return false;
     } else {
         $random_password = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(64);
         OCP\Util::writeLog('user_openam', 'Creating new user: ' . $uid, OCP\Util::DEBUG);
         OC_User::createUser($uid, $random_password);
         return $uid;
     }
 }
Ejemplo n.º 18
0
 public static function logout($parameters)
 {
     $samlBackend = new OC_USER_SAML();
     if ($samlBackend->auth->isAuthenticated()) {
         OCP\Util::writeLog('saml', 'Executing SAML logout', OCP\Util::DEBUG);
         unset($_COOKIE["SimpleSAMLAuthToken"]);
         setcookie('SimpleSAMLAuthToken', '', time() - 3600, \OC::$WEBROOT);
         setcookie('SimpleSAMLAuthToken', '', time() - 3600, \OC::$WEBROOT . '/');
         $samlBackend->auth->logout();
     }
     return true;
 }
Ejemplo n.º 19
0
function shutdown()
{
    $l = OC_L10N::get('news');
    $error = error_get_last();
    if ($error['type'] & (E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR)) {
        //all fatal errors
        if (strpos($error['message'], 'get_uri')) {
            //handle a fatal error caused by a SimplePie bug (https://github.com/simplepie/simplepie/issues/214)
            OCP\Util::writeLog('news', 'ajax/createfeed.php: Fatal error:' . $error['message'], OCP\Util::ERROR);
            exit;
        }
    }
}
Ejemplo n.º 20
0
 public function checkPassword($uid, $assertion)
 {
     if ($this->_isPersonaRequest) {
         $email = OCA\User_persona\Validator::Validate($assertion);
         if ($email) {
             return OCA\User_persona\Policy::apply($email, $uid);
         }
         //we've got incorrect assertion
         OCP\Util::writeLog('OC_USER_PERSONA', 'Validation failed. Incorrect Assertion.', OCP\Util::DEBUG);
         OCP\JSON::error(array('msg' => 'Incorrect Assertion'));
         exit;
     }
     return false;
 }
Ejemplo n.º 21
0
 function search($query)
 {
     $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
     if (count($calendars) == 0 || !OCP\App::isEnabled('calendar')) {
         //return false;
     }
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $user_timezone = OC_Calendar_App::getTimezone();
     $l = new OC_l10n('calendar');
     foreach ($calendars as $calendar) {
         $objects = OC_Calendar_Object::all($calendar['id']);
         foreach ($objects as $object) {
             if ($object['objecttype'] != 'VEVENT') {
                 continue;
             }
             if (substr_count(strtolower($object['summary']), strtolower($query)) > 0) {
                 $calendardata = OC_VObject::parse($object['calendardata']);
                 $vevent = $calendardata->VEVENT;
                 $dtstart = $vevent->DTSTART;
                 $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
                 $start_dt = $dtstart->getDateTime();
                 $start_dt->setTimezone(new DateTimeZone($user_timezone));
                 $end_dt = $dtend->getDateTime();
                 $end_dt->setTimezone(new DateTimeZone($user_timezone));
                 if ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE) {
                     $end_dt->modify('-1 sec');
                     if ($start_dt->format('d.m.Y') != $end_dt->format('d.m.Y')) {
                         $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y') . ' - ' . $end_dt->format('d.m.Y');
                     } else {
                         $info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y');
                     }
                 } else {
                     $info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i') . ' - ' . $end_dt->format('d.m.y H:i');
                 }
                 $link = OCP\Util::linkTo('calendar', 'index.php') . '?showevent=' . urlencode($object['id']);
                 $results[] = new OC_Search_Result($object['summary'], $info, $link, (string) $l->t('Cal.'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
Ejemplo n.º 22
0
 /**
  * Check if the password is correct without logging in the user
  *
  * @param string $uid      The username
  * @param string $password The password
  *
  * @return true/false
  */
 public function checkPassword($uid, $password)
 {
     if (false === array_search($this->protocol, stream_get_wrappers())) {
         OCP\Util::writeLog('user_external', 'ERROR: Stream wrapper not available: ' . $this->protocol, OCP\Util::ERROR);
         return false;
     }
     // opendir handles the as %-encoded string, but this is not true for usernames and passwords, encode them before passing them
     $url = sprintf('%s://%s:%s@%s/', $this->protocol, urlencode($uid), urlencode($password), $this->host);
     $result = @opendir($url);
     if (is_resource($result)) {
         $this->storeUser($uid);
         return $uid;
     } else {
         return false;
     }
 }
Ejemplo n.º 23
0
 private function updateQuota($dn)
 {
     $quota = null;
     if (!empty($this->ldapQuotaDefault)) {
         $quota = $this->ldapQuotaDefault;
     }
     if (!empty($this->ldapQuotaAttribute)) {
         $aQuota = OC_LDAP::readAttribute($dn, $this->ldapQuotaAttribute);
         if ($aQuota && count($aQuota) > 0) {
             $quota = $aQuota[0];
         }
     }
     if (!is_null($quota)) {
         OCP\Config::setUserValue(OC_LDAP::dn2username($dn), 'files', 'quota', OCP\Util::computerFileSize($quota));
     }
 }
 public static function changePassword($aParams)
 {
     if (isset($aParams['uid'], $aParams['password'])) {
         $sUser = $aParams['uid'];
         $sEmail = $sUser;
         $sPassword = $aParams['password'];
         $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
         $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
         if ('' !== $sUrl && '' !== $sPath) {
             OCP\Util::writeLog('rainloop', 'rainloop|login: Setting new RainLoop password for ' . $sEmail, OCP\Util::DEBUG);
             $sPassword = self::encodePassword($sPassword, md5($sEmail));
             return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword);
         }
     }
     return false;
 }
function display_sub_dirs($current_dir, $sub_dirs)
{
    $results = explore($current_dir, $sub_dirs, 1);
    foreach ($results as $r) {
        echo '<tr id = "row" data-file="' . $r[0] . '" data-type="dir">
				<td id = "thumbnail_container" width = "14%"><div id = "thumbs">';
        $is_dir = check_dir_exists($current_dir, $r[0]);
        $margin = 10;
        $img_id = 1;
        foreach ($r[1] as $thumbs) {
            $thumb_exists = false;
            $thumb_exists = check_thumb_exists($current_dir . $r[0] . '/' . $thumbs);
            $img_path = \OCP\Util::linkTo('reader', 'ajax/thumbnail.php') . '&filepath=' . urlencode($current_dir . $r[0] . '/' . rtrim($thumbs, 'pdf') . 'png');
            $counter = 3;
            for ($i = 1; $i <= $counter; $i++) {
                echo '<img id = "' . $current_dir . $r[0] . '/' . $thumbs . '" src = "' . $img_path . '" value = "' . $thumb_exists . '" style = "position:absolute;top:-55px;left:10px;margin-left:' . $margin . 'px; z-index:' . (50 - $margin) . ';"/>';
                $margin = $margin + 5;
                $img_id = $img_id + 1;
            }
        }
        echo '</div></td>';
        echo '<td class = "filename svg" width = "86%">
					<a class = "dirs" id = "' . $r[0] . '" href = "' . OCP\Util::linkTo('reader', 'index.php') . '&dir=' . $current_dir . $r[0] . '/' . '">
						<span class = "nametext">' . htmlspecialchars($r[0]) . '</span>
					</a>
					<div id = "more_info" style = "color:#666;margin-left:15px;margin-top:35px; vertical-align:bottom">';
        echo "Browse in for";
        echo '<br>';
        $dir_browse_results = explore($current_dir, array($r[0]), 5);
        foreach ($dir_browse_results as $browse_result) {
            foreach ($browse_result[1] as $each) {
                $each_sub_dir = explode("/", $each);
                if (count($each_sub_dir) > 1) {
                    foreach ($each_sub_dir as $element) {
                        echo '<span style = "color:#DDD;">>></span>' . $element;
                    }
                } else {
                    echo '<span style = "color:#DDD;"> >></span>' . $each;
                }
                echo '<br>';
            }
        }
        echo '</div> 
			</td>
		</tr>';
    }
}
Ejemplo n.º 26
0
 /**
  * @brief Check if the password is correct
  * @param $uid The username
  * @param $password The password
  * @returns true/false
  *
  * Check if the password is correct without logging in the user
  */
 public function checkPassword($uid, $password)
 {
     // Get identity from user and redirect browser to OpenID Server
     $openid = new SimpleOpenID();
     $openid->SetIdentity($uid);
     $openid->SetTrustRoot('http://' . OCP\Util::getServerHost());
     if ($openid->GetOpenIDServer()) {
         $openid->SetApprovedURL('http://' . OCP\Util::getServerHost() . OC::$WEBROOT);
         // Send Response from OpenID server to this script
         $openid->Redirect();
         // This will redirect user to OpenID Server
         exit;
     } else {
         return false;
     }
     exit;
 }
Ejemplo n.º 27
0
 /**
  * Check if the password is correct without logging in the user
  *
  * @param string $uid      The username
  * @param string $password The password
  *
  * @return true/false
  */
 public function checkPassword($uid, $password)
 {
     if (!function_exists('imap_open')) {
         OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR);
         return false;
     }
     $mbox = @imap_open($this->mailbox, $uid, $password, OP_HALFOPEN);
     imap_errors();
     imap_alerts();
     if ($mbox !== FALSE) {
         imap_close($mbox);
         $this->storeUser($uid);
         return $uid;
     } else {
         return false;
     }
 }
Ejemplo n.º 28
0
 public function stream_read($count)
 {
     //$count will always be 8192 https://bugs.php.net/bug.php?id=21641
     //This makes this function a lot simpler but will breake everything the moment it's fixed
     $this->writeCache = '';
     if ($count != 8192) {
         OCP\Util::writeLog('files_encryption', 'php bug 21641 no longer holds, decryption will not work', OCP\Util::FATAL);
         die;
     }
     $data = fread($this->source, 8192);
     if (strlen($data)) {
         $result = OC_Crypt::decrypt($data);
     } else {
         $result = '';
     }
     return $result;
 }
Ejemplo n.º 29
0
function curl_exec_follow($ch, &$maxredirect = null)
{
    $mr = $maxredirect === null ? 5 : intval($maxredirect);
    if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
        curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
    } else {
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        if ($mr > 0) {
            $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            $rch = curl_copy_handle($ch);
            curl_setopt($ch, CURLOPT_USERAGENT, "Owncloud Bookmark Crawl");
            curl_setopt($rch, CURLOPT_HEADER, true);
            curl_setopt($rch, CURLOPT_NOBODY, true);
            curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
            curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
            do {
                curl_setopt($rch, CURLOPT_URL, $newurl);
                $header = curl_exec($rch);
                if (curl_errno($rch)) {
                    $code = 0;
                } else {
                    $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
                    if ($code == 301 || $code == 302) {
                        preg_match('/Location:(.*?)\\n/', $header, $matches);
                        $newurl = trim(array_pop($matches));
                    } else {
                        $code = 0;
                    }
                }
            } while ($code && --$mr);
            curl_close($rch);
            if (!$mr) {
                if ($maxredirect === null) {
                    OCP\Util::writeLog('bookmark', 'Too many redirects. When following redirects, libcurl hit the maximum amount on bookmark', OCP\Util::ERROR);
                } else {
                    $maxredirect = 0;
                }
                return false;
            }
            curl_setopt($ch, CURLOPT_URL, $newurl);
        }
    }
    return curl_exec($ch);
}
Ejemplo n.º 30
0
 /**
  * Check if roundcube table exists in the current database.
  *
  * @return bool TRUE if table exists, FALSE if no table found.
  */
 public static function tableExists()
 {
     OCP\Util::writeLog('roundcube', 'OC_RoundCube_DB_Util.class.php: ' . 'Checking if roundcube table exists.', OCP\Util::DEBUG);
     // Try a select statement against the table
     // Run it in try/catch in case PDO is in ERRMODE_EXCEPTION.
     try {
         $sql = 'SELECT * FROM `*PREFIX*roundcube` LIMIT 1';
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_DB_Util.class.php: ' . 'Used SQL: ' . $sql, OCP\Util::DEBUG);
         $query = \OCP\DB::prepare($sql);
         $result = $query->execute();
     } catch (Exception $e) {
         // We got an exception == table not found
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_DB_Util.class.php: ' . 'Table roundcube does not exists. ' . $e, OCP\Util::DEBUG);
         return false;
     }
     OCP\Util::writeLog('roundcube', 'OC_RoundCube_DB_Util.class.php: ' . 'Table roundcube exists.', OCP\Util::DEBUG);
     return true;
 }