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]; }
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; }
function sys_credentials($mfolder, $mountpoint = "") { static $creds = array(); if ($mountpoint != "") { $mountpoint = sys_parse_folder($mountpoint); if (empty($mountpoint["mfolder"])) { return array(); } if ($mfolder == "") { $mfolder = $mountpoint["mfolder"]; } $creds[$mfolder] = array("server" => $mountpoint["mfolder"], "username" => $mountpoint["user"], "password" => $mountpoint["pass"], "port" => $mountpoint["port"], "ssl" => $mountpoint["ssl"], "options" => $mountpoint["options"]); return $mountpoint; } if (!isset($creds[$mfolder]) and isset($_SESSION["permission_sql_read"]) and $mountpoint == "" and $mfolder != "") { $mp = db_select_value("simple_sys_tree", "fmountpoint", array("id=@id@", $_SESSION["permission_sql_read"]), array("id" => $mfolder)); if (!empty($mp)) { sys_credentials($mfolder, $mp); } } if (!isset($creds[$mfolder])) { $creds[$mfolder] = array("server" => "", "username" => "", "password" => "", "port" => "", "ssl" => "", "options" => ""); } return $creds[$mfolder]; }
private static function _base_dn($mfolder) { $cid = "ldap_" . md5("basedn_" . $mfolder); if ($basedn = sys_cache_get($cid)) { return $basedn; } $creds = sys_credentials($mfolder); $basedn = $creds["options"]; if ($basedn == "") { if (!($ds = self::_connect($mfolder))) { return ""; } $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]; } } sys_cache_set($cid, $basedn, LDAP_LIST_CACHE); return $basedn; }
static function sendmail($id, $data, $unused, $table, $to_self = false) { if (isset($data["sendnow"]) and $data["sendnow"] == 0) { return ""; } $row = self::sendmail_getconn($_SESSION["username"], $data["efrom"]); if (USE_MAIL_FUNCTION or !empty($row["smtp"])) { if (!empty($row["smtp"])) { sys_credentials($data["folder"], "smtp:" . $row["smtp"] . "/"); } if (!empty($row["email"])) { $data["efrom"] = $row["email"]; } if (!empty($row["name"])) { $data["name"] = $row["name"]; } $result = lib_smtp::insert("", $data, $data["folder"], $to_self, USE_MAIL_FUNCTION, true); if (is_array($result)) { if ($table != "" and !strpos($table, "_nodb_")) { db_update($table, array("headers" => implode("\n", $result)), array("id=@id@"), array("id" => $id)); } $result = ""; } if (empty($result) and sys_strbegins($data["subject"], SMTP_NOTIFICATION)) { sys_notification(sprintf("{t}Notificaiton sent to: %s{/t}", $data["eto"])); } } else { $result = sprintf("{t}Mail identities{/t}: {t}SMTP not configured for %s{/t}", $_SESSION["username"]); } return $result; }
function __construct($folder, $view, $items = array(), $writeable = true) { // Mountpoint $folders = array($folder); if (!is_numeric($folder)) { $url = sys_parse_folder($folder); $type = "sys_nodb_" . $url["handler"]; $mfolder = $url["mfolder"]; sys_credentials($mfolder); } else { $row = db_select_first("simple_sys_tree", array("ftype", "folders"), "id=@id@", "", array("id" => $folder)); if (empty($row["ftype"])) { throw new Exception("{t}Folder not found.{/t}"); } $type = $row["ftype"]; if ($row["folders"] != "") { $folders = array(); foreach (explode("|", trim($row["folders"], "|")) as $val) { if (empty($val) or !db_get_right($val, $writeable ? "write" : "read", $view)) { continue; } $folders[] = $val; } } $mfolder = ""; } if (isset($_SESSION["disabled_modules"][$type])) { exit("{t}Module disabled.{/t}"); } $this->schema = db_get_schema(sys_find_module($type), $folder, $view); $view = sys_array_shift(array_keys($this->schema["views"])); $this->current_view =& $this->schema["views"][$view]; if (isset($this->current_view["SCHEMA"]) and $this->current_view["SCHEMA"] != "") { $this->schema = db_get_schema(sys_find_module($this->current_view["SCHEMA"]), "", $view); $view = sys_array_shift(array_keys($this->schema["views"])); $this->current_view =& $this->schema["views"][$view]; } $this->folder = $folder; $this->view = $view; $this->fields =& $this->schema["fields"]; $this->att =& $this->schema["att"]; $this->tname = $this->att["NAME"]; $this->where = $this->current_view["SQLWHERE"]; $this->handler = $this->current_view["SQL_HANDLER"]; $this->buttons = $this->current_view["buttons"]; $this->rowvalidates = $this->current_view["rowvalidates"]; $this->rowfilters = $this->current_view["rowfilters"]; $this->current_fields =& $this->current_view["fields"]; $this->notification = true; $this->vars = array("item" => $items, "folder" => $this->folder, "folders" => $folders, "mfolder" => $mfolder); $this->vars_noquote = array(); if (!empty($this->att["ENABLE_ASSET_RIGHTS"])) { if ($writeable) { $this->where[] = "@permission_sql_write_nq@"; } $this->vars_noquote["permission_sql_read_nq"] = $_SESSION["permission_sql_read"]; $this->vars_noquote["permission_sql_write_nq"] = $_SESSION["permission_sql_write"]; } if (is_array($this->where) and count($this->where) > 0) { foreach ($this->where as $key => $val) { $matches = array(); if (!preg_match_all("|@(.*?)@|i", $val, $matches, PREG_SET_ORDER)) { continue; } foreach ($matches as $match) { if (count($match) != 2) { continue; } $wkey = $match[1]; if (empty($this->vars[$wkey]) and empty($this->vars_noquote[$wkey])) { $this->where[$key] = "1=1"; } } } } }
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]; }