Ejemplo n.º 1
0
 private static function _get_data($file)
 {
     if ($data = sys_cache_get("bookmarks_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     if (!($data = @file_get_contents($file))) {
         sys_warning("{t}The url doesn't exist.{/t} (" . $file . ")");
         return array();
     }
     preg_match_all("!(?:<h3.*?>(.*?)</h3>|<dd>(.*?)\n|<a href=\"(.*?)\".*?(?:add_date=\"(.*?)\".*?>|>)(.*?)</a>)!msi", $data, $matches);
     $category = "";
     $rows = array();
     if (is_array($matches) and count($matches) == 6) {
         for ($i = 0; $i < count($matches[0]); $i++) {
             $url = "";
             $name = "";
             $created = 0;
             $desc = "";
             if (!empty($matches[1][$i])) {
                 $category = modify::unquote($matches[1][$i]);
             }
             if (!empty($matches[2][$i + 1])) {
                 $desc = modify::unquote($matches[2][$i + 1]);
             }
             if (!empty($matches[3][$i])) {
                 $url = $matches[3][$i];
             }
             if (!empty($matches[4][$i])) {
                 $created = $matches[4][$i];
             }
             if (!empty($matches[5][$i])) {
                 $name = modify::unquote($matches[5][$i]);
             }
             if ($name != "" or $url != "") {
                 $rows[] = array("category" => $category, "bookmarkname" => $name, "description" => $desc, "url" => $url, "created" => $created);
             }
         }
     }
     sys_cache_set("bookmarks_" . sha1($file), $rows, BOOKMARKS_CACHE);
     return $rows;
 }
Ejemplo n.º 2
0
 static function count($path, $where, $vars, $mfolder)
 {
     if (sys_allowedpath($path) != "") {
         return 0;
     }
     $files = 0;
     if ($handle = @opendir($path)) {
         while (false !== ($file = readdir($handle))) {
             if ($file == '.' or $file == '..' or is_dir($path . $file) or modify::getfileext($file) == "meta") {
                 continue;
             }
             $files++;
         }
         closedir($handle);
     } else {
         sys_warning("{t}Access denied.{/t}");
     }
     return $files;
 }
Ejemplo n.º 3
0
 private static function _parse($file)
 {
     if ($data = sys_cache_get("vcard_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     if (!($data = @file_get_contents($file))) {
         sys_warning("{t}The url doesn't exist.{/t} (" . $file . ")");
         return array();
     }
     if (!class_exists("Contact_Vcard_Parse", false)) {
         require "lib/vcard/Contact_Vcard_Parse.php";
     }
     $parse = new Contact_Vcard_Parse();
     $rows = array();
     if ($data = $parse->fromText($data)) {
         foreach ($data as $item) {
             $row = array();
             foreach ($item as $key => $values) {
                 $key = strtolower($key);
                 $row[$key] = array();
                 foreach ($values as $value) {
                     foreach ($value["value"] as $value2) {
                         if ($value2[0]) {
                             $row[$key][] = trim($value2[0]);
                         }
                     }
                 }
             }
             $rows[] = $row;
         }
     } else {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, ""));
         return array();
     }
     sys_cache_set("vcard_" . sha1($file), $rows, VCARD_CACHE);
     return $rows;
 }
Ejemplo n.º 4
0
 private static function _parse($file)
 {
     if ($data = sys_cache_get("rss_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     if (!($data = @file_get_contents($file))) {
         sys_warning("{t}The url doesn't exist.{/t} (" . $file . ")");
         return array();
     }
     if (strpos(strtolower(substr($data, 0, 100)), "<?xml") === false) {
         // find RSS in website
         if (preg_match("/rss[^>]+?href=\"(.*?)\"/i", $data, $match)) {
             $file = $match[1];
             if (!($data = @file_get_contents($file))) {
                 sys_warning("{t}The url doesn't exist.{/t} (" . $file . ")");
                 return array();
             }
         }
     }
     try {
         $xml = @new SimpleXMLElement($data);
     } catch (Exception $e) {
         sys_warning("{t}Error{/t}: " . $file . " " . $e->getMessage());
         return array();
     }
     if (!is_object($xml)) {
         return array();
     }
     if (isset($xml->channel)) {
         $item0 = $xml->channel;
         $item0->subtitle = (string) $xml->channel->description;
         if (isset($xml->channel->item)) {
             $items = $xml->channel->item;
         } else {
             $items = $xml->item;
         }
     } else {
         $item0 = $xml;
         $items = $xml->entry;
     }
     $rows = array(array("title" => (string) $item0->title, "content" => (string) $item0->subtitle, "link" => self::_get_link($item0->link), "order" => 0));
     $i = 0;
     foreach ($items as $item) {
         if (isset($item->description)) {
             $item->summary = (string) $item->description;
         }
         $rows[] = array("title" => (string) $item->title, "content" => (string) $item->summary, "link" => self::_get_link($item->link), "order" => ++$i);
     }
     sys_cache_set("rss_" . sha1($file), $rows, RSS_CACHE);
     return $rows;
 }
Ejemplo n.º 5
0
 private static function _import_delete($folder, $id, $tname, $module)
 {
     $where = array("folder=@folder@");
     if ($id[0] == "_") {
         $where[] = "id=@id@";
     } else {
         $where[] = "syncid=@id@";
     }
     $row_id = db_select_value($tname, "id", $where, array("id" => trim($id, "_"), "folder" => $folder));
     if (!empty($row_id)) {
         $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash"));
         if (empty($trash)) {
             sys_warning("{t}Error{/t}: {t}Trash folder not found.{/t}");
             return;
         }
         $id = folders::create(sys_date("{t}m/d/Y{/t}"), "blank", "", $trash, true);
         $id2 = folders::create($module, str_replace("simple_", "", $tname), "", $id, true);
         $data = array("folder" => $id2, "history" => sprintf("{t}Item deleted by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
         db_update($tname, $data, array("id=@id@"), array("id" => $row_id));
         db_update_treesize($tname, $folder);
         db_search_delete($tname, $row_id, $folder);
         sys_log_stat("deleted_records", 1);
     }
 }
Ejemplo n.º 6
0
 private static function _get_auth($mfolder, $match = true)
 {
     $cid = "gdocs_" . $mfolder;
     static $conn = array();
     if ($auth = sys_cache_get($cid)) {
         return $auth;
     }
     $creds = sys_credentials($mfolder);
     $url_auth = "https://www.google.com/accounts/ClientLogin?Email=" . urlencode($creds["username"]) . "&Passwd=" . urlencode($creds["password"]) . "&accountType=HOSTED_OR_GOOGLE&source=SimpleGroupware&service=writely";
     $http_response_header = array();
     $response = @file_get_contents($url_auth);
     preg_match("/^Auth=(.+)/m", $response, $match);
     $auth = "";
     if (!empty($match[1])) {
         $auth = "GData-Version: 3.0\r\nAuthorization: GoogleLogin auth=" . trim($match[1]) . "\r\n";
         sys_cache_set($cid, $auth, GDOCS_CACHE);
     } else {
         if (!isset($conn[$cid])) {
             sys_warning(sprintf("{t}Connection error: %s [%s]{/t}", $http_response_header[0], "Google Docs"));
         }
     }
     $conn[$cid] = true;
     return $auth;
 }
Ejemplo n.º 7
0
 private static function _connect($mfolder)
 {
     static $cache = array();
     if (empty($cache[$mfolder])) {
         $creds = sys_credentials($mfolder);
         if ($creds["server"] == "") {
             return false;
         }
         if (!$creds["port"]) {
             $creds["port"] = 110;
         }
         if ($creds["ssl"] and !extension_loaded("openssl")) {
             sys_warning(sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "OpenSSL"));
             return false;
         }
         $pop3 = new Net_POP3();
         if (PEAR::isError($result = $pop3->connect($creds["ssl"] ? $creds["ssl"] . "://" . $creds["server"] : $creds["server"], $creds["port"]))) {
             sys_warning(sprintf("{t}Connection error: %s [%s]{/t}", $result->getMessage(), "POP3"));
             return false;
         }
         if (PEAR::isError($ret = $pop3->login($creds["username"], $creds["password"], "USER"))) {
             sys_warning(sprintf("{t}Pop3-error: %s{/t}", $ret->getMessage()));
             return false;
         }
         $cache[$mfolder] = $pop3;
     }
     return $cache[$mfolder];
 }
Ejemplo n.º 8
0
function sys_parse_csv($file)
{
    if ($data = sys_cache_get("csv_" . sha1($file))) {
        return $data;
    }
    if (sys_allowedpath(dirname($file)) != "") {
        return array();
    }
    $rows = array();
    if ($handle = fopen($file, "r")) {
        if (strpos($file, "iso")) {
            $iso = true;
        } else {
            $iso = false;
        }
        while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
            if ($iso) {
                foreach (array_keys($data) as $key) {
                    $data[$key] = utf8_encode($data[$key]);
                }
            }
            $rows[] = $data;
        }
        fclose($handle);
    } else {
        sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, ""));
        return array();
    }
    sys_cache_set("csv_" . sha1($file), $rows, CSV_CACHE);
    return $rows;
}
Ejemplo n.º 9
0
 static function process_login($username, $password = "")
 {
     $id = session_id();
     if (!APC_SESSION and $id and (empty($_SESSION["username"]) or $_SESSION["username"] != $username)) {
         $row = db_select_first("simple_sys_session", array("id", "data", "expiry"), "username=@username@", "lastmodified desc", array("username" => $username));
         if (!empty($row["id"])) {
             $_SESSION = array();
             session_decode(rawurldecode($row["data"]));
             if ($row["expiry"] < NOW) {
                 db_delete("simple_sys_session", array("id=@id@"), array("id" => $row["id"]));
             }
         }
         if (!db_count("simple_sys_session", array("id=@id@"), array("id" => $id))) {
             db_insert("simple_sys_session", array("expiry" => NOW + LOGIN_TIMEOUT, "id" => $id));
         }
     }
     $_SESSION["username"] = $username;
     if ($password != "") {
         $_SESSION["password"] = sys_encrypt($password, $id);
     }
     if (!isset($_SESSION["history"])) {
         $_SESSION["history"] = array();
     }
     $_SESSION["groups"] = array();
     $_SESSION["folder_states"] = array();
     $base = dirname($_SERVER["SCRIPT_FILENAME"]) . "/";
     if (sys_is_super_admin($_SESSION["username"])) {
         $_SESSION["ALLOWED_PATH"] = array($base . SIMPLE_STORE . "/home/", $base . SIMPLE_CACHE . "/debug/", $base . SIMPLE_STORE . "/trash/", $base . SIMPLE_CACHE . "/preview/", $base . SIMPLE_STORE . "/backup/");
     } else {
         $_SESSION["ALLOWED_PATH"] = array($base . SIMPLE_STORE . "/home/" . $_SESSION["username"] . "/", $base . SIMPLE_CACHE . "/preview/");
     }
     foreach (explode(",", SIMPLE_IMPORT) as $folder) {
         if ($folder == "" or !is_dir($folder)) {
             continue;
         }
         if ($folder[0] != "/" and !strpos($folder, ":")) {
             $folder = $base . $folder;
         }
         $_SESSION["ALLOWED_PATH"][] = rtrim(str_replace("\\", "/", $folder), "/") . "/";
     }
     // TODO2 put in extra function and configure it with setup to fetch groups from somewhere else
     if (sys_is_super_admin($_SESSION["username"])) {
         $_SESSION["permission_sql"] = "1=1";
         $_SESSION["permission_sql_exception"] = "1=0";
         $_SESSION["disabled_modules"] = array();
     } else {
         $_SESSION["permission_sql"] = sql_regexp("r@right@_users", array($username, "anonymous"));
         $_SESSION["permission_sql_exception"] = "(rexception_users!='' and " . sql_regexp("rexception_users", array($username, "anonymous"), "|@view@:@right@:%s|") . ")";
         $_SESSION["disabled_modules"] = array_flip(explode("|", DISABLED_MODULES));
         $rows = db_select("simple_sys_groups", "groupname", array("activated=1", "members like @username_sql@"), "", "", array("username_sql" => "%|" . $username . "|%"));
         if (is_array($rows) and count($rows) > 0) {
             foreach ($rows as $val) {
                 $_SESSION["groups"][] = $val["groupname"];
             }
             $_SESSION["permission_sql"] = "(" . $_SESSION["permission_sql"] . " or " . sql_regexp("r@right@_groups", $_SESSION["groups"]) . ")";
             $_SESSION["permission_sql_exception"] = "(" . $_SESSION["permission_sql_exception"] . " or (rexception_groups!='' and " . sql_regexp("rexception_groups", $_SESSION["groups"], "|@view@:@right@:%s|") . "))";
         }
     }
     $_SESSION["permission_sql_read"] = str_replace("@right@", "read", $_SESSION["permission_sql"]);
     $_SESSION["permission_sql_write"] = str_replace("@right@", "write", $_SESSION["permission_sql"]);
     $_SESSION["ip"] = _login_get_remoteaddr();
     $_SESSION["tickets"] = array("templates" => array("dbselect", "simple_templates", array("tplcontent", "tplname"), array("tplname like @search@"), "tplname asc"));
     $_SESSION["treevisible"] = true;
     $row = db_select_first("simple_sys_users", "*", "username=@username@", "", array("username" => $username));
     if (!empty($row["cal_day_begin"])) {
         $_SESSION["day_begin"] = sys_date("G", $row["cal_day_begin"] - 1) * 3600;
         $_SESSION["day_end"] = sys_date("G", $row["cal_day_end"]) * 3600;
     } else {
         $_SESSION["day_begin"] = 25200;
         // 7:00 = 7*3600
         $_SESSION["day_end"] = 64800;
         // 18:00 = 18*3600
     }
     if (!empty($row["enabled_modules"])) {
         $row["enabled_modules"] = array_flip(explode("|", trim($row["enabled_modules"], "|")));
         $_SESSION["disabled_modules"] = array_diff_key($_SESSION["disabled_modules"], $row["enabled_modules"]);
     }
     if (!empty($row["timezone"])) {
         $_SESSION["timezone"] = $row["timezone"];
     } else {
         $_SESSION["timezone"] = "";
     }
     if (!empty($row["theme"])) {
         $_SESSION["theme"] = $row["theme"];
     } else {
         $_SESSION["theme"] = "core";
     }
     if (!empty($row["home_folder"])) {
         $_SESSION["home_folder"] = "index.php?folder=" . rawurlencode($row["home_folder"]);
     } else {
         if (sys_is_super_admin($username)) {
             $anchor = "system";
         } else {
             $anchor = "home_" . $username;
         }
         $_SESSION["home_folder"] = "index.php?folder=^" . $anchor;
     }
     if ($id or isset($_REQUEST["login"])) {
         sys_log_stat("logins", 1);
         sys_log_message_log("login", sprintf("{t}login %s from %s with %s{/t}", $_SESSION["username"], $_SESSION["ip"], sys::$browser));
     }
     trigger::login();
     if (!empty($row["pwdexpires"]) and $row["pwdexpires"] < NOW) {
         sys_warning(sprintf("{t}Password expired. (password of %s has expired){/t}", $username));
         self::_redirect("index.php?view=changepwd&find=asset|simple_sys_users|1|username="******"username"]);
     } else {
         if (!empty($_REQUEST["page"])) {
             if (CMS_REAL_URL) {
                 self::_redirect(CMS_REAL_URL . $_REQUEST["page"]);
             }
             self::_redirect("cms.php/" . $_REQUEST["page"]);
         } else {
             if (!empty($_REQUEST["redirect"])) {
                 self::_redirect($_SESSION["home_folder"]);
             }
         }
     }
 }
Ejemplo n.º 10
0
 private static function _parse($file)
 {
     if ($data = sys_cache_get("ldif_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     $rows = array();
     $i = 0;
     if ($handle = fopen($file, "r")) {
         while (!feof($handle)) {
             $data = utf8_encode(trim(fgets($handle, 8192)));
             if ($data != "" and $pos = strpos($data, ":")) {
                 $data_key = strtolower(substr($data, 0, $pos));
                 $data_val = substr($data, $pos + 1);
                 if ($data_val != "" and $data_val[0] == ":") {
                     $data_val = base64_decode(trim(substr($data_val, 1)));
                 }
                 if ($data_key == "" or $data_val == "") {
                     continue;
                 }
                 $rows[$i][$data_key] = trim($data_val);
             } else {
                 if ($data == "") {
                     $i++;
                 }
             }
         }
         fclose($handle);
     } else {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, ""));
         return array();
     }
     sys_cache_set("ldif_" . sha1($file), $rows, LDIF_CACHE);
     return $rows;
 }
Ejemplo n.º 11
0
 private static function _parse($file)
 {
     if ($data = sys_cache_get("icalendar_" . sha1($file))) {
         return $data;
     }
     if ($message = sys_allowedpath(dirname($file))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, $message));
         return array();
     }
     $rows = array();
     if (!($handle = fopen($file, "rb"))) {
         sys_warning(sprintf("{t}Cannot read the file %s. %s{/t}", $file, ""));
         return array();
     }
     $i = 0;
     $evopen = false;
     $lines = array();
     while (!feof($handle)) {
         $line = fgets($handle, 10000);
         $line = str_replace(array("\r", "\n", "\\n"), array("", "", "\n"), $line);
         if ($line == "") {
             continue;
         }
         if ($line[0] == " ") {
             $lines[count($lines) - 1] .= substr($line, 1);
         } else {
             $lines[] = $line;
         }
     }
     fclose($handle);
     foreach ($lines as $line) {
         $line = trim($line);
         switch ($line) {
             case "BEGIN:VEVENT":
                 $i++;
                 $evopen = true;
                 $rows[$i] = array("subject" => "", "begin" => 0, "ending" => 0, "created" => 0, "duration" => 0, "lastmodified" => 0, "allday" => "0", "location" => "", "description" => "", "organizer" => array(), "participants_ext" => array(), "category" => "", "priority" => "3", "recurrence" => "", "repeatinterval" => 1, "repeatcount" => "0", "repeatuntil" => 0, "repeatexcludes" => array());
                 break;
             case "BEGIN:VALARM":
                 $evopen = false;
                 break;
             case "END:VEVENT":
                 $evopen = false;
                 $begin = sys_getdate($rows[$i]["begin"]);
                 $end = sys_getdate($rows[$i]["ending"]);
                 if ($rows[$i]["lastmodified"] == 0) {
                     $rows[$i]["lastmodified"] = $rows[$i]["created"];
                 }
                 if ($begin["hours"] == 0 and $end["hours"] == 0 and $begin["minutes"] == 0 and $end["minutes"] == 0) {
                     if ($rows[$i]["begin"] == $rows[$i]["ending"]) {
                         $rows[$i]["ending"] += 86399;
                     } else {
                         $rows[$i]["ending"]--;
                     }
                     $rows[$i]["allday"] = "1";
                 }
                 foreach ($rows[$i] as $key => $item) {
                     if (is_array($item)) {
                         $rows[$i][$key] = self::_array_flat($item);
                     }
                 }
                 if ($rows[$i]["ending"] != "" and $rows[$i]["begin"] != "") {
                     $rows[$i]["duration"] = $rows[$i]["ending"] - $rows[$i]["begin"];
                 }
                 $rows[$i] = array_merge($rows[$i], trigger::calcappointment("", $rows[$i], null, ""));
                 // $rows[$i]["begin_str"] = date("D d-m-y H:i:s",$rows[$i]["begin"]);
                 // $rows[$i]["end_str"] = date("D d-m-y H:i:s",$rows[$i]["ending"]);
                 break;
             default:
                 if (!$evopen) {
                     break;
                 }
                 $pos = strpos($line, ":");
                 $first = substr($line, 0, $pos);
                 $value_str = str_replace(array("\\,", "\\n", "\\N"), array(",", "\n", "\n"), substr($line, $pos + 1));
                 if ($pos2 = strpos($first, ";")) {
                     $kval = substr($first, 0, $pos2);
                 } else {
                     $kval = $first;
                 }
                 switch ($kval) {
                     case "SUMMARY":
                         $rows[$i]["subject"] = $value_str;
                         break;
                     case "DESCRIPTION":
                         $rows[$i]["description"] = $value_str;
                         break;
                     case "LOCATION":
                         $rows[$i]["location"] = $value_str;
                         break;
                     case "CLASS":
                         if ($rows[$i]["category"] != "" and $value_str != "") {
                             $rows[$i]["category"] .= ",";
                         }
                         $rows[$i]["category"] .= ucfirst(strtolower($value_str));
                         break;
                     case "CATEGORIES":
                         if ($rows[$i]["category"] != "") {
                             $rows[$i]["category"] .= ",";
                         }
                         $rows[$i]["category"] .= $value_str;
                         break;
                     case "UID":
                         $rows[$i]["id"] = $value_str;
                         break;
                     case "SEQUENCE":
                         $rows[$i]["sequence"] = $value_str;
                         break;
                     case "DTSTART":
                         $rows[$i]["begin"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DTEND":
                         $rows[$i]["ending"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "LAST-MODIFIED":
                         $rows[$i]["lastmodified"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DTSTAMP":
                         $rows[$i]["created"] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "DURATION":
                         if (!preg_match("/PT?([0-9]{1,2}W)?([0-9]{1,2}D)?([0-9]{1,2}H)?([0-9]{1,2}M)?/", $value_str, $match)) {
                             break;
                         }
                         $match = array_merge($match, array(0, 0, 0, 0));
                         $rows[$i]["ending"] = $rows[$i]["begin"] + str_replace("W", "", $match[1]) * 604800 + str_replace("D", "", $match[2]) * 86400 + str_replace("H", "", $match[3]) * 3600 + str_replace("M", "", $match[4]) * 60;
                         break;
                     case "RRULE":
                         $value = explode(";", $value_str);
                         foreach ($value as $val) {
                             $val = explode("=", $val);
                             switch ($val[0]) {
                                 case "FREQ":
                                     switch ($val[1]) {
                                         case "YEARLY":
                                             $rows[$i]["recurrence"] = "years";
                                             break;
                                         case "MONTHLY":
                                             $rows[$i]["recurrence"] = "months";
                                             break;
                                         case "WEEKLY":
                                             $rows[$i]["recurrence"] = "weeks";
                                             break;
                                         case "DAILY":
                                             $rows[$i]["recurrence"] = "days";
                                             break;
                                     }
                                     break;
                                 case "INTERVAL":
                                     $rows[$i]["repeatinterval"] = $val[1];
                                     break;
                                 case "COUNT":
                                     $rows[$i]["repeatcount"] = $val[1];
                                     break;
                                 case "UNTIL":
                                     $rows[$i]["repeatuntil"] = modify::ical_datetime_to_int($val[1]);
                                     break;
                             }
                         }
                         break;
                     case "EXDATE":
                         $rows[$i]["repeatexcludes"][] = modify::ical_datetime_to_int($value_str);
                         break;
                     case "ORGANIZER":
                         $value = explode(";", $value_str);
                         $key = explode(";", $first);
                         if (isset($value[1])) {
                             $value[0] = $value[1];
                         }
                         if (isset($key[1])) {
                             $value[0] = str_replace(array("CN=", "\""), "", $key[1]) . " (" . str_replace(array("MAILTO:", "mailto:"), "", $value[0]) . ")";
                         }
                         $rows[$i]["organizer"][] = $value[0];
                         break;
                     case "ATTENDEE":
                         $value = explode(";", $value_str);
                         $key = explode(";", $first);
                         if (isset($value[1])) {
                             $value[0] = $value[1];
                         }
                         $value[0] = str_replace(array("MAILTO:", "mailto:"), "", $value[0]);
                         if (isset($key[1]) and strpos($key[1], "CN=") !== false) {
                             $value[0] = str_replace(array("CN=", "\""), "", $key[1]) . " (" . $value[0] . ")";
                         }
                         $rows[$i]["participants_ext"][] = $value[0];
                         break;
                     default:
                         // echo $line."<br>\n";
                         break;
                 }
                 break;
         }
     }
     sys_cache_set("icalendar_" . sha1($file), $rows, ICALENDAR_CACHE);
     return $rows;
 }
Ejemplo n.º 12
0
 private static function _connect($mfolder)
 {
     static $cache = array();
     if (empty($cache[$mfolder])) {
         $creds = sys_credentials($mfolder);
         if ($creds["server"] == "") {
             return false;
         }
         $basedn = $creds["options"];
         if (!$creds["port"]) {
             $creds["port"] = 389;
         }
         if ($creds["ssl"] and !extension_loaded("openssl")) {
             sys_warning(sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "OpenSSL"));
             return false;
         }
         if (!function_exists("ldap_connect")) {
             sys_warning(sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "LDAP"));
             return false;
         }
         if (!($ds = ldap_connect($creds["server"]))) {
             sys_die(sprintf("{t}LDAP connection to host %s failed.{/t}", $creds["server"]));
         }
         ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
         ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
         if (!@ldap_bind($ds, $creds["username"], $creds["password"])) {
             if (!@ldap_bind($ds)) {
                 sys_warning("{t}LDAP anonymous connection failed.{/t}");
                 return false;
             }
             if ($basedn == "") {
                 $result_id = @ldap_read($ds, "", "(objectclass=*)", array("namingContexts"));
                 $attrs = ldap_get_attributes($ds, ldap_first_entry($ds, $result_id));
                 if (isset($attrs["namingContexts"]) and is_array($attrs["namingContexts"])) {
                     $basedn = $attrs["namingContexts"][0];
                 }
             }
             $creds["username"] = preg_replace("/[\\\\*()#!|&=<>~ ]/", "", $creds["username"]);
             $res = ldap_search($ds, $basedn, "uid=" . $creds["username"]);
             if (ldap_count_entries($ds, $res) == 1) {
                 $dn = ldap_get_dn($ds, ldap_first_entry($ds, $res));
                 if (@ldap_bind($ds, $dn, $creds["password"])) {
                     sys_warning(sprintf("{t}Login failed from %s.{/t} (ldap) (%s)\n{t}(for active directory username must be: username@domain){/t}", _login_get_remoteaddr(), ldap_error($ds)));
                     return false;
                 }
             }
         }
         $cache[$mfolder] = $ds;
     }
     return $cache[$mfolder];
 }
Ejemplo n.º 13
0
 private static function _get_ntlm($mfolder)
 {
     static $cache = array();
     if (empty($cache[$mfolder])) {
         if (!function_exists("java_require")) {
             if (!isset($cache[$mfolder])) {
                 sys_warning(sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "PHP/Java Bridge"));
             }
             $cache[$mfolder] = false;
         } else {
             java_require("jcifs-1.3.8_tb.jar");
             $conf = new JavaClass("jcifs.Config");
             $conf->setProperty("jcifs.smb.client.responseTimeout", "5000");
             $conf->setProperty("jcifs.resolveOrder", "LMHOSTS,DNS");
             $conf->setProperty("jcifs.smb.client.soTimeout", "120000");
             // TODO2 option for hidden shares
             $creds = sys_credentials($mfolder);
             $creds["domain"] = "";
             if ($creds["options"] != "") {
                 $options = explode(",", $creds["options"]);
                 foreach ($options as $option) {
                     $option = trim($option);
                     if (sys_strbegins($option, "domain=")) {
                         $creds["domain"] = substr($option, 7);
                     }
                 }
             }
             $cache[$mfolder] = new Java("jcifs.smb.NtlmPasswordAuthentication", $creds["domain"], $creds["username"], $creds["password"]);
         }
     }
     return $cache[$mfolder];
 }