Ejemplo n.º 1
0
 /**
  * Create a contact group with the given name
  *
  * @param string The group name
  * @return mixed False on error, array with record props in success
  */
 public function create_group($name)
 {
     $cuid = $this->find_free_uid();
     $uri = "{$cuid}.vcf";
     $save_data = array('name' => $name, 'kind' => 'group', 'cuid' => $cuid);
     $vcf = $this->create_vcard_from_save_data($save_data);
     if (!$vcf) {
         return false;
     }
     $vcfstr = $vcf->serialize();
     if (!($etag = $this->put_record_to_carddav($uri, $vcfstr))) {
         return false;
     }
     $url = carddav_common::concaturl($this->config['url'], $uri);
     $url = preg_replace(';https?://[^/]+;', '', $url);
     if (!($dbid = $this->dbstore_group($etag, $url, $vcfstr, $save_data))) {
         return false;
     }
     return array('id' => $dbid, 'name' => $name);
 }
Ejemplo n.º 2
0
 function cd_save($args)
 {
     $this->add_texts('localization/', false);
     if ($args['section'] != 'cd_preferences') {
         return;
     }
     $prefs = carddav_common::get_adminsettings();
     if (isset($prefs['_GLOBAL']['hide_preferences']) && $prefs['_GLOBAL']['hide_preferences'] === TRUE) {
         return;
     }
     // update existing in DB
     $abooks = carddav_backend::get_dbrecord($_SESSION['user_id'], 'id,presetname', 'addressbooks', false, 'user_id');
     foreach ($abooks as $abook) {
         $abookid = $abook['id'];
         if (isset($_POST[$abookid . "_cd_delete"])) {
             self::delete_abook($abookid);
         } else {
             $newset = array('name' => get_input_value($abookid . "_cd_name", RCUBE_INPUT_POST), 'username' => get_input_value($abookid . "_cd_username", RCUBE_INPUT_POST, true), 'url' => get_input_value($abookid . "_cd_url", RCUBE_INPUT_POST), 'active' => isset($_POST[$abookid . '_cd_active']) ? 1 : 0, 'refresh_time' => get_input_value($abookid . "_cd_refresh_time", RCUBE_INPUT_POST));
             // only set the password if the user entered a new one
             $password = get_input_value($abookid . "_cd_password", RCUBE_INPUT_POST, true);
             if (strlen($password) > 0) {
                 $newset['password'] = $password;
             }
             // remove admin only settings
             foreach ($newset as $pref => $value) {
                 if (self::no_override($pref, $abook, $prefs)) {
                     unset($newset[$pref]);
                 }
             }
             self::update_abook($abookid, $newset);
         }
     }
     // add a new address book?
     $new = get_input_value('new_cd_name', RCUBE_INPUT_POST);
     if ((!array_key_exists('_GLOBAL', $prefs) || !$prefs['_GLOBAL']['fixed']) && strlen($new) > 0) {
         $srv = get_input_value('new_cd_url', RCUBE_INPUT_POST);
         $usr = get_input_value('new_cd_username', RCUBE_INPUT_POST, true);
         $pass = get_input_value('new_cd_password', RCUBE_INPUT_POST, true);
         $pass = self::$helper->encrypt_password($pass);
         $abname = get_input_value('new_cd_name', RCUBE_INPUT_POST);
         $discovery = new carddav_discovery();
         $srvs = $discovery->find_addressbooks($srv, $usr, $pass);
         if (is_array($srvs) && count($srvs) > 0) {
             foreach ($srvs as $srv) {
                 self::$helper->debug("ADDING ABOOK " . print_r($srv, true));
                 $this_abname = $abname;
                 if ($srv['name']) {
                     $this_abname .= ' (' . $srv['name'] . ')';
                 }
                 self::insert_abook(array('name' => $this_abname, 'username' => $usr, 'password' => $pass, 'url' => $srv['href'], 'refresh_time' => get_input_value('new_cd_refresh_time', RCUBE_INPUT_POST)));
             }
         } else {
             $args['abort'] = true;
             $args['message'] = $abname . ': ' . $this->gettext('cd_err_noabfound');
         }
     }
     return $args;
 }
Ejemplo n.º 3
0
 public static function get_adminsettings()
 {
     if (is_array(self::$admin_settings)) {
         return self::$admin_settings;
     }
     $rcmail = rcmail::get_instance();
     $prefs = array();
     $configfile = dirname(__FILE__) . "/config.inc.php";
     if (file_exists($configfile)) {
         require "{$configfile}";
     }
     self::$admin_settings = $prefs;
     if (is_array($prefs['_GLOBAL'])) {
         $scheme = $prefs['_GLOBAL']['pwstore_scheme'];
         if (preg_match("/^(plain|base64|encrypted|des_key)\$/", $scheme)) {
             self::$pwstore_scheme = $scheme;
         }
     }
     return $prefs;
 }
Ejemplo n.º 4
0
    private function retrieve_addressbooks($path, $cdfopen_cfg, $recurse = false)
    {
        $baseurl = $cdfopen_cfg['url'];
        $url = carddav_common::concaturl($baseurl, $path);
        $depth = $recurse ? 1 : 0;
        self::$helper->debug("SEARCHING {$url} (Depth: " . $depth . ")");
        // check if the given URL points to an addressbook
        $opts = array('method' => "PROPFIND", 'header' => array("Depth: " . $depth, 'Content-Type: application/xml; charset="utf-8"'), 'content' => <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav"><D:prop>
\t<D:current-user-principal/>
    <D:resourcetype />
    <D:displayname />
\t<C:addressbook-home-set/>
</D:prop></D:propfind>
EOF
);
        $reply = self::$helper->cdfopen($url, $opts, $cdfopen_cfg);
        $xml = self::$helper->checkAndParseXML($reply);
        if ($xml === false) {
            return false;
        }
        $aBooks = array();
        // Check if we found addressbooks at the URL
        $xpresult = $xml->xpath('//RCMCD:response[descendant::RCMCD:resourcetype/RCMCC:addressbook]');
        foreach ($xpresult as $ab) {
            self::$helper->registerNamespaces($ab);
            $aBook = array();
            list($aBook['href']) = $ab->xpath('child::RCMCD:href');
            list($aBook['name']) = $ab->xpath('descendant::RCMCD:displayname');
            $aBook['href'] = (string) $aBook['href'];
            $aBook['name'] = (string) $aBook['name'];
            if (strlen($aBook['href']) > 0) {
                $aBook['href'] = carddav_common::concaturl($baseurl, $aBook['href']);
                self::$helper->debug("found abook: " . $aBook['name'] . " at " . $aBook['href']);
                $aBooks[] = $aBook;
            }
        }
        // found -> done
        if (count($aBooks) > 0) {
            return $aBooks;
        }
        if ($recurse === false) {
            // Check some additional URLs:
            $additional_urls = array();
            // (1) original URL
            $additional_urls[] = $url;
            // (2) see if the server told us the addressbook home location
            $abookhome = $xml->xpath('//RCMCC:addressbook-home-set/RCMCD:href');
            if (count($abookhome) != 0) {
                self::$helper->debug("addressbook home: " . $abookhome[0]);
                $additional_urls[] = $abookhome[0];
            }
            // (3) see if we got a principal URL
            $princurl = $xml->xpath('//RCMCD:current-user-principal/RCMCD:href');
            if (count($princurl) != 0) {
                self::$helper->debug("principal URL: " . $princurl[0]);
                $additional_urls[] = $princurl[0];
            }
            foreach ($additional_urls as $other_url) {
                self::$helper->debug("Searching additional URL: {$other_url}");
                if (strlen($other_url) <= 0) {
                    continue;
                }
                // if the server returned a full URL, adjust the base url
                if (preg_match(';^[^/]+://[^/]+;', $other_url, $match)) {
                    $cdfopen_cfg['url'] = $match[0];
                } else {
                    // restore original baseurl, may have changed in prev URL check
                    $cdfopen_cfg['url'] = $baseurl;
                }
                $aBooks = $this->retrieve_addressbooks($other_url, $cdfopen_cfg, $other_url != $princurl[0]);
                // found -> done
                if (!($aBooks === false) && count($aBooks) > 0) {
                    return $aBooks;
                }
            }
        }
        // (4) there is no more we can do -> fail
        self::$helper->debug("no principal URL found");
        return false;
    }