Exemplo n.º 1
0
 static function languages()
 {
     $langs = array();
     foreach (scandir("lang") as $file) {
         if (sys_strbegins($file, "master") or !strpos($file, ".lang")) {
             continue;
         }
         $match = array();
         preg_match("|\\*\\* !_Language\n(.*?)\n|", file_get_contents("lang/" . $file, false, null, -1, 1024), $match);
         $lang = str_replace(".lang", "", $file);
         $langs[$lang] = !empty($match[1]) ? $match[1] : "unknown (" . $file . ")";
     }
     asort($langs);
     return $langs;
 }
Exemplo n.º 2
0
 static function url($url)
 {
     if (strlen($url) > 6 and (preg_match("!^(http|www)[\\S]+!i", $url) or sys_strbegins($url, "index.php?") or $url == "about:blank")) {
         return "";
     }
     return "{t}Please enter a valid url.{/t}";
 }
Exemplo n.º 3
0
 public static function createedit($id, $data, $unused, $table)
 {
     if (!defined("SYNC4J") or !SYNC4J) {
         return "";
     }
     $module = str_replace("simple_", "", $table);
     $anchor = db_select_value("simple_sys_tree", "anchor", "id=@id@", array("id" => $data["folder"]));
     if (empty($id) or empty($anchor) or !sys_strbegins($anchor, $module . "_")) {
         return "";
     }
     $username = substr($anchor, strlen($module) + 1);
     $error = "";
     switch ($table) {
         case "simple_notes":
             $row = db_select_first("fnbl_simple_notes_exp", "*", "id=@id@", "", array("id" => $id));
             if (!empty($row["id"])) {
                 self::_create_item("fnbl_pim_note", $row, "simple_notes", $id, $username);
             }
             break;
         case "simple_tasks":
             $row = db_select_first("fnbl_simple_tasks_exp", "*", "id=@id@", "", array("id" => $id));
             if (!empty($row["id"])) {
                 self::_create_item("fnbl_pim_calendar", $row, "simple_tasks", $id, $username);
             }
             break;
         case "simple_calendar":
             $row = db_select_first("fnbl_simple_calendar_exp", "*", "id=@id@", "", array("id" => $id));
             if (!empty($row["id"])) {
                 db_delete("fnbl_pim_calendar_exception", array("calendar=@id@"), array("id" => $row["syncid"]));
                 self::_create_item("fnbl_pim_calendar", $row, "simple_calendar", $id, $username);
                 if (!empty($row["rec_exceptions"])) {
                     $exceptions = explode("|", trim($row["rec_exceptions"], "|"));
                     if (count($exceptions) > 0) {
                         foreach ($exceptions as $exception) {
                             $data = array("calendar" => $row["syncid"], "occurrence_date" => date("Y-m-d H:i:s", $exception));
                             db_insert("fnbl_pim_calendar_exception", $data, array("no_defaults" => 1));
                         }
                     }
                 }
             }
             break;
         case "simple_contacts":
             $row = db_select_first("simple_contacts", "*", "id=@id@", "", array("id" => $id));
             $company = db_select_first("simple_companies", "*", "companyname=@company@", "", array("company" => $row["company"]));
             if (!empty($row["id"])) {
                 $row2 = db_select_first("fnbl_simple_contacts_exp", "*", "id=@id@", "", array("id" => $id));
                 self::_create_item("fnbl_pim_contact", $row2, "simple_contacts", $id, $username);
                 db_delete("fnbl_pim_address", array("contact=@syncid@"), array("syncid" => $row["syncid"]));
                 if (!empty($row["street"])) {
                     $data = array("contact" => $row["syncid"], "type" => 1, "street" => $row["street"], "city" => $row["city"], "state" => $row["state"], "postal_code" => $row["zipcode"], "country" => $row["country"]);
                     db_insert("fnbl_pim_address", $data, array("no_defaults" => 1));
                 }
                 if (!empty($company["street"])) {
                     $data = array("contact" => $row["syncid"], "type" => 2, "street" => $company["street"], "city" => $company["city"], "state" => $company["state"], "postal_code" => $company["zipcode"], "country" => $company["country"]);
                     db_insert("fnbl_pim_address", $data, array("no_defaults" => 1));
                 }
                 /**
                  * @see https://core.forge.funambol.org/source/browse/core/branches/v10/modules/foundation/foundation-core/src/main/java/com/funambol/foundation/items/dao/PIMContactDAO.java?view=markup
                  * @see http://code.google.com/p/syncby/source/browse/trunk/SyncSources/funambol/fnbl_pim_contact_item.txt
                  */
                 $items = array(1 => $row["phoneprivate"], 2 => $row["faxprivate"], 3 => $row["mobile"], 4 => $row["email"], 6 => $row["homepage"], 7 => @$company["homepage"], 8 => $row["skype"], 10 => $row["phone"], 11 => $row["fax"], 12 => @$company["phone"], 14 => $row["pager"], 16 => $row["emailprivate"]);
                 foreach ($items as $key => $item) {
                     db_delete("fnbl_pim_contact_item", array("contact=@syncid@", "type=@type@"), array("syncid" => $row["syncid"], "type" => $key));
                     if (empty($item)) {
                         continue;
                     }
                     db_insert("fnbl_pim_contact_item", array("contact" => $row["syncid"], "type" => $key, "value" => $item), array("no_defaults" => 1));
                 }
             }
             break;
     }
     return $error;
 }
Exemplo n.º 4
0
 static function rebuild_schema($rebuild_search = false)
 {
     if ($rebuild_search) {
         self::_out(sprintf("{t}Processing %s ...{/t}", "schema, search index"));
     } else {
         self::_out(sprintf("{t}Processing %s ...{/t}", "schema"));
     }
     if (sgsml_parser::table_exists("simple_sys_search") and $rebuild_search) {
         db_delete("simple_sys_search", array(), array());
     }
     $files = array();
     $folders = array("modules/schema/", "modules/schema_sys/", SIMPLE_EXT . "/modules/schema/", SIMPLE_EXT . "/modules/schema_sys/", SIMPLE_CUSTOM . "/modules/schema/", SIMPLE_CUSTOM . "/modules/schema_sys/");
     foreach ($folders as $folder) {
         if (!is_dir($folder)) {
             continue;
         }
         foreach (scandir($folder) as $file) {
             if (!strpos($file, ".xml")) {
                 continue;
             }
             $files[$file] = $folder . $file;
         }
     }
     @set_time_limit(60 * count($files));
     foreach ($files as $file) {
         self::_out(basename($file) . " ", false);
         $schema = db_get_schema($file, "", "", false);
         sys::$db_queries = array();
         // reduce memory usage
         if (!$rebuild_search or sys_strbegins(basename($file), "nodb_") or empty($schema["views"]["display"])) {
             continue;
         }
         if (!empty($schema["att"]["SQL_HANDLER"]) or !empty($schema["att"]["NO_SEARCH_INDEX"])) {
             continue;
         }
         $table = $schema["att"]["NAME"];
         $fields = $schema["fields"];
         $rows = db_select($table, array("id", "folder"), array(), "", "");
         if (!is_array($rows) or count($rows) == 0) {
             continue;
         }
         self::_out("... ", false);
         foreach ($rows as $row) {
             if (folder_in_trash($row["folder"])) {
                 continue;
             }
             db_search_update($table, $row["id"], $fields);
         }
     }
     self::_out("<br>", false);
 }
Exemplo n.º 5
0
 static function update($path, $data, $where, $vars, $mfolder)
 {
     if (empty($vars["id"])) {
         return "";
     }
     if (!empty($data["filedata"])) {
         $source = $data["filedata"];
     } else {
         $source = $vars["id"];
     }
     if (!empty($vars["folder_source"])) {
         return self::_move_file($vars["id"], $vars["folder_source"], $path, $mfolder);
     }
     $drop = array("filedata", "folder", "lastmodified", "handler", "mfolder", "dsize");
     $meta = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     $content = "<?xml version='1.0' encoding='UTF-8'?>" . "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:docs='http://schemas.google.com/docs/2007'>" . "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/docs/2007#document'/>" . "<title>" . q(modify::basename($source)) . "</title>" . "<docs:description>" . q($meta) . "</docs:description></entry>";
     if (file_exists($source) and sys_strbegins($source, SIMPLE_CACHE . "/upload/")) {
         $url = "https://docs.google.com/feeds/upload/create-session/default/private/full/" . $vars["id"] . "?convert=false";
         $header = "X-Upload-Content-Type: application/octet-stream\r\n";
         $context = self::_get_context_action($mfolder, "PUT", $content, $header);
         $http_response_header = array();
         $response = file_get_contents($url, false, $context);
         preg_match("/Location: (.+)/m", implode("\n", $http_response_header), $match);
         if (!strpos($http_response_header[0], "200") or empty($match[1])) {
             return "{t}Error{/t} [update] " . implode("\n", $http_response_header) . "\n" . $response;
         }
         $header = "PUT " . $match[1] . " HTTP/1.0\r\n";
         $header .= "Host: docs.google.com\r\n";
         $header .= "Content-Length: " . filesize($source) . "\r\n\r\n";
         $errorNumber = 0;
         $errorString = "";
         $fp = fsockopen("ssl://docs.google.com", "443", $errorNumber, $errorString, 5);
         $fin = fopen($source, "rb");
         if (is_resource($fp) and is_resource($fin)) {
             fwrite($fp, $header);
             while (!feof($fin)) {
                 fwrite($fp, fread($fin, 8192));
             }
             $resp = "";
             while (!feof($fp)) {
                 $resp .= fread($fp, 8192);
             }
             fclose($fp);
             fclose($fin);
             if (!sys_strbegins($resp, "HTTP/1.0 200")) {
                 return "{t}Error{/t} [update2] " . $resp;
             }
         } else {
             return "{t}Error{/t} [update3] " . $errorString . " " . $errorNumber;
         }
     } else {
         $url = "https://docs.google.com/feeds/default/private/full/" . $vars["id"] . "?convert=false";
         $context = self::_get_context_action($mfolder, "PUT", $content);
         $http_response_header = array();
         $response = file_get_contents($url, false, $context);
         if (!strpos($http_response_header[0], "200")) {
             return "{t}Error{/t} [update4] " . $http_response_header . "\n" . $response;
         }
     }
     sys_cache_remove("gdocs_xml_" . md5(serialize(sys_credentials($mfolder)) . $path));
     return "";
 }
Exemplo n.º 6
0
 static function table_add_column($schema_name, $field_name, $ftype, $default)
 {
     if (sql_query(sprintf("ALTER TABLE %s ADD %s %s", $schema_name, $field_name, $ftype))) {
         if ($default != "" and !sys_strbegins($default, "|#")) {
             $default = sys_correct_quote($default);
             if (!sql_query(sprintf("update %s set %s=%s", $schema_name, $field_name, $default))) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 function createSimpleHandler($channelName, $recursive = false)
 {
     if (!is_string($channelName)) {
         $errno = null;
         $errstr = null;
         // tb
         $peer = @fsockopen("127.0.0.1", $channelName, $errno, $errstr, 5);
     } else {
         $type = $channelName[0];
         if ($type == '@' || $type == '/') {
             if ($type == '@') {
                 $channelName[0] = "";
             }
             $peer = pfsockopen("unix://{$channelName}", null, $errno, $errstr, 10);
         } else {
             list($host, $channelName) = explode(":", $channelName);
             $peer = pfsockopen($host, $channelName, $errno, $errstr, 10);
         }
     }
     if (!$peer) {
         // tb
         if (!$recursive) {
             $cmd = "java -jar JavaBridge.jar INET_LOCAL:9676 3 ../../" . SIMPLE_CACHE . "/debug/java_bridge.log";
             if (strpos(PHP_OS, "WIN") === false) {
                 $cmd .= " &";
             } else {
                 $cmd = "start /B " . $cmd;
             }
             chdir("tools/java_bridge/");
             $result = exec($cmd);
             chdir("../../");
             if (sys_strbegins($result, "@")) {
                 return $this->createSimpleHandler($channelName, true);
             }
         }
         throw new java_RuntimeException("[1] Could not connect to the context server {$channelName}. Error message: {$errstr} ({$errno})\n");
     }
     stream_set_timeout($peer, -1);
     $handler = new java_SocketHandler($this, new java_SocketChannel($peer, $this));
     $compatibility = $this->client->RUNTIME["PARSER"] == "NATIVE" ? chr(0103) : ($compatibility = chr(0100));
     $this->client->RUNTIME["COMPATIBILITY"] = $compatibility;
     if (is_int(JAVA_LOG_LEVEL)) {
         $compatibility |= 128 | (7 & JAVA_LOG_LEVEL) << 2;
     }
     $this->write("{$compatibility}");
     $this->serverName = "127.0.0.1:{$channelName}";
     return $handler;
 }
Exemplo n.º 8
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     $cid = "pop3_" . md5(serialize(sys_credentials($mfolder)));
     $datas = self::_get_datas($mfolder, $cid);
     if (!isset($datas[0])) {
         return array();
     }
     $rows = array();
     foreach ($datas[0] as $key => $data) {
         $msg_id = $datas[1][$key]["msg_id"];
         $msg_uid = $datas[1][$key]["uidl"];
         $structure = array();
         $row = array();
         $row_id = "pop3_fields_" . md5(implode("_", $fields) . $msg_uid);
         if (!($row = sys_cache_get($row_id))) {
             if (!($pop3 = self::_connect($mfolder)) or !$pop3) {
                 return array();
             }
             foreach ($fields as $field) {
                 switch ($field) {
                     case "id":
                         $row[$field] = $path . "/?" . md5($msg_uid);
                         break;
                     case "folder":
                         $row[$field] = $path;
                         break;
                     case "searchcontent":
                         $row[$field] = $data["subject"] . " " . $data["from"];
                         break;
                     case "subject":
                         $row[$field] = !empty($data["subject"]) ? $data["subject"] : "- {t}Empty{/t} -";
                         break;
                     case "efrom":
                         $row[$field] = isset($data["from"]) ? $data["from"] : "";
                         break;
                     case "eto":
                         $row[$field] = isset($data["to"]) ? $data["to"] : "";
                         break;
                     case "cc":
                         $row[$field] = isset($data["cc"]) ? $data["cc"] : "";
                         break;
                     case "receipt":
                         $row[$field] = !empty($data["disposition-notification-to"]) ? "1" : "0";
                         break;
                     case "created":
                     case "lastmodified":
                         $row[$field] = isset($data["date"]) ? strtotime($data["date"]) : "0";
                         break;
                     case "lastmodifiedby":
                         $row[$field] = "";
                         break;
                     case "dsize":
                     case "size":
                         $row[$field] = $datas[1][$key]["size"];
                         break;
                     case "headers":
                         $row[$field] = "";
                         foreach ($data as $data_key => $data_item) {
                             $row[$field] .= ucfirst($data_key) . ": " . (is_array($data_item) ? implode("\n  ", $data_item) : $data_item) . "\n";
                         }
                         break;
                     case "message_html":
                     case "message":
                         if ($field == "message_html") {
                             $html = true;
                         } else {
                             $html = false;
                         }
                         $row[$field] = "";
                         if (empty($structure)) {
                             $input = $pop3->getMsg($msg_id);
                             $decode = new Mail_mimeDecode($input);
                             $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid);
                             $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true);
                             file_put_contents($raw_file, $input);
                         }
                         $file_index = -1;
                         foreach ($structure as $skey => $item) {
                             $is_attachment = self::_is_attachment($item);
                             if ($is_attachment) {
                                 $file_index++;
                             }
                             $content = "";
                             if (sys_strbegins($item["contenttype"], "multipart") and $skey != 0) {
                                 if (isset($item["header"]["subject"])) {
                                     $content = self::_drawheader($item["header"]);
                                     if (!sys_contains($item["charset"], "utf")) {
                                         $content = modify::utf8_encode($content, $item["charset"]);
                                     }
                                     if ($html) {
                                         $content .= modify::nl2br(q(trim($content)), false, true);
                                     }
                                 }
                             } else {
                                 if (!$is_attachment and $item["size"] > 0 and strpos($item["contenttype"], "text/") !== false) {
                                     $data_body = $item["body"];
                                     if (!strpos("#" . $item["charset"], "utf")) {
                                         $data_body = modify::utf8_encode($data_body, $item["charset"]);
                                     }
                                     if ($html) {
                                         if ($content != "") {
                                             $content .= "<hr>";
                                         }
                                         if ($item["contenttype"] != "text/html") {
                                             $data_body = modify::nl2br(q(trim($data_body)), false, true);
                                             if ($item["contenttype"] != "text/plain") {
                                                 $content .= "<b>[" . $item["contenttype"] . "]</b><br>";
                                             }
                                         }
                                         $item["level"] = substr_count($item["id"], ".");
                                         $content .= "<div style='margin-left:" . $item["level"] * 20 . "px;'><code>" . $data_body . "</code></div>";
                                     } else {
                                         if ($content != "") {
                                             $content .= "\n";
                                         }
                                         if ($item["contenttype"] == "text/html") {
                                             $data_body = modify::htmlmessage($data_body);
                                         } else {
                                             if ($item["contenttype"] != "text/plain") {
                                                 $content .= "[" . $item["contenttype"] . "]\n";
                                             }
                                         }
                                         $content .= trim($data_body) . "\n";
                                     }
                                 } else {
                                     if (strpos($item["contenttype"], "image/") !== false and !empty($item["cid"])) {
                                         $url = "download.php?folder=@folder@&view=attachment_show&field=attachment&item[]=@id@&subitem=" . $file_index;
                                         $row[$field] = str_replace("cid:" . $item["cid"], $url, $row[$field]);
                                     }
                                 }
                             }
                             if ($row[$field] != "" and $content != "") {
                                 if ($html) {
                                     $row[$field] .= "<hr><br>";
                                 } else {
                                     $row[$field] .= "\n----\n\n";
                                 }
                             }
                             $row[$field] .= $content;
                         }
                         break;
                     case "attachment":
                         $row[$field] = "";
                         if (empty($structure)) {
                             $input = $pop3->getMsg($msg_id);
                             $decode = new Mail_mimeDecode($input);
                             $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid);
                             $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true);
                             file_put_contents($raw_file, $input);
                         }
                         $files = array();
                         foreach ($structure as $item) {
                             if ($item["disposition"] == "attachment") {
                                 $files[] = sys_cache_get_file("pop3", $msg_uid, "--" . $item["name"]);
                             }
                         }
                         $files[] = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt");
                         if (count($files) > 0) {
                             $row[$field] = "|" . implode("|", $files) . "|";
                         }
                         break;
                 }
             }
             sys_cache_set($row_id, $row, POP3_MAIL_CACHE);
         }
         $row["_msg_id"] = $msg_id;
         $row["seen"] = file_exists(sys_cache_get_file("pop3", md5($msg_uid), "seen_" . $mfolder)) ? "1" : "";
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     return sys_select($rows, $order, $limit, $fields);
 }
Exemplo n.º 9
0
 private static function _copy($ccp, $folder, $sgsml, $delete)
 {
     $tname = $sgsml->tname;
     $vars = array("handler" => $ccp["handler"], "sqlvarsnoquote" => $ccp["vars_noquote"], "custom_name" => $ccp["custom_name"], "default_sql" => $ccp["default_sql"]);
     $rows = db_select($ccp["tname"], $ccp["data_fields"], $ccp["where"], "", "", array("item" => $ccp["items"], "folder" => $ccp["folder"], "folders" => $ccp["folders"]), $vars);
     if (is_array($rows) and count($rows) < count($ccp["items"])) {
         exit("{t}Item(s) not found or access denied.{/t}");
     }
     foreach (self::_get_mappings("->") as $mapping) {
         if (!strpos($mapping[1], "=")) {
             continue;
         }
         $mapping[1] = explode(".", $mapping[1]);
         if ("simple_" . $mapping[0] == $ccp["tname"] and "simple_" . $mapping[1][0] == $tname) {
             $sgsml->patch_fields(array_slice($mapping[1], 1));
         }
     }
     $mappings = array();
     foreach (self::_get_mappings("|") as $mapping) {
         if (strpos($mapping[0], "->")) {
             continue;
         }
         $mapping1 = explode(".", $mapping[0]);
         $mapping2 = explode(".", $mapping[1]);
         $key = "simple_" . $mapping1[0] . ".simple_" . $mapping2[0];
         $mappings[$key][$mapping2[1]] = $mapping1[1];
         $key = "simple_" . $mapping2[0] . ".simple_" . $mapping1[0];
         $mappings[$key][$mapping1[1]] = $mapping2[1];
     }
     $default_values = folder_get_default_values($folder);
     $messages = array();
     foreach ($rows as $row) {
         if (empty($row["folder"]) or !db_get_right($row["folder"], "read")) {
             continue;
         }
         if (isset($mappings[$ccp["tname"] . "." . $tname])) {
             foreach ($mappings[$ccp["tname"] . "." . $tname] as $to => $from) {
                 $row[$to] = $row[$from];
             }
         }
         $row = array_merge($row, $default_values);
         foreach (array_keys($row) as $key) {
             if (!isset($sgsml->fields[$key])) {
                 unset($row[$key]);
                 continue;
             }
             $field = $sgsml->fields[$key];
             if ((isset($field["KEY"]) or isset($field["IS_UNIQUE"])) and !empty($row[$key]) and !isset($field["READONLYIN"])) {
                 $val = $row[$key];
                 $step = 1;
                 while ($step < 100 and validate::itemexists($tname, array($key => $val), -1) != "") {
                     $step++;
                     $val = $row[$key] . "_" . $step;
                 }
                 $row[$key] = $val;
             }
             if (isset($field["RESTORE"])) {
                 $row[$key] = self::_restore_value($row, $key, $field["RESTORE"]);
             }
         }
         $id = $row["id"];
         $row["id"] = -1;
         $row["folder"] = $folder;
         if (isset($row["syncid"])) {
             $row["syncid"] = "";
         }
         $newfiles = array();
         if (is_array($ccp["file_fields"]) and count($ccp["file_fields"]) > 0) {
             foreach ($ccp["file_fields"] as $file_field) {
                 if (!empty($row[$file_field])) {
                     $data_files = explode("|", trim($row[$file_field], "|"));
                     $row[$file_field] = array();
                     foreach ($data_files as $file) {
                         if (!file_exists($file)) {
                             continue;
                         }
                         $target = self::_paste_item_copyfile($file, $row["id"], $tname);
                         $row[$file_field][] = $target;
                         $newfiles[] = $target;
                     }
                     $row[$file_field] = implode("|", $row[$file_field]);
                 }
             }
         }
         if (!empty($sgsml->att["DISABLE_TRIGGER_CCP"])) {
             unset($sgsml->att["TRIGGER_NEW"]);
         }
         $result = $sgsml->insert($row);
         if (!is_numeric($result)) {
             if (is_array($result) and count($result) > 0) {
                 $message = "{t}Error pasting asset{/t}:";
                 foreach ($result as $field => $errors) {
                     foreach ($errors as $error) {
                         $message .= "\n" . $error[0] . ": " . $error[1];
                     }
                 }
             } else {
                 $message = $result;
             }
             $messages[] = $message;
         } else {
             if ($delete) {
                 asset::delete_items($ccp["folder"], "display", array($id), $ccp["delete_mode"]);
             }
             sys_log_stat("copied_records", 1);
         }
         foreach ($newfiles as $file) {
             if (sys_strbegins($file, SIMPLE_CACHE . "/upload/")) {
                 @unlink($file);
             }
         }
     }
     return $messages;
 }
Exemplo n.º 10
0
function sys_can_lock($file)
{
    if (sys_strbegins($file, SIMPLE_STORE . "/") and file_exists($file) and !file_exists($file . ".lck")) {
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 private function _save(array &$data, $id = -1)
 {
     $insert = ($id > 0 or !is_numeric($id)) ? false : true;
     if (count($data) == 0) {
         return array();
     }
     if (!empty($this->att["DEFAULT_SQL"]) and $this->att["DEFAULT_SQL"] == "no_select") {
         return self::_error("{t}Module{/t}", "{t}Access denied.{/t}");
     }
     if (!empty($data["folder"])) {
         // check permissions
         if (!db_get_right($data["folder"], "write", $this->view)) {
             return self::_error("{t}Folder{/t}", "{t}Access denied.{/t}", "folder");
         }
         $this->folder = $data["folder"];
     } else {
         $data["folder"] = $this->folder;
     }
     // fill data array
     list($rdata, $data_row, $error) = $this->_complete_data($data, $id);
     if ($error) {
         return $error;
     }
     // validate
     if ($result = $this->_validate($rdata, $id)) {
         return $result;
     }
     if ($insert) {
         $id = sql_genID($this->tname) * 100;
         $sql_data = array("id" => $id, "dsize" => 0, "history" => sprintf("{t}Item created by %s at %s{/t}\n", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
     } else {
         $sql_data = array("dsize" => 0, "history" => sprintf("{t}Item edited (%s) by %s at %s{/t}\n", "@fields@", $_SESSION["username"], sys_date("{t}m/d/y g:i:s a{/t}")));
     }
     // count sizes, move files to store, delete old files
     foreach ($this->current_fields as $field_name => $field) {
         if ($field["SIMPLE_TYPE"] == "id") {
             continue;
         }
         if ($field["SIMPLE_TYPE"] == "files" and !empty($rdata[$field_name])) {
             foreach ($rdata[$field_name] as $val) {
                 if (file_exists($val)) {
                     $sql_data["dsize"] += filesize($val);
                 }
             }
             // TODO 2 store handler?
             if (!empty($data_row[$field_name])) {
                 $data_old = explode("|", trim($data_row[$field_name], "|"));
                 foreach ($data_old as $filekey => $file) {
                     if (in_array($file, $rdata[$field_name])) {
                         continue;
                     }
                     if (ARCHIVE_DELETED_FILES and file_exists($file)) {
                         $i = 1;
                         $m = "";
                         $trash_name = SIMPLE_STORE . "/trash/" . $this->folder . "_" . $id . "_";
                         $trash_file = modify::basename($file);
                         while (file_exists($trash_name . $m . $trash_file)) {
                             $m = $i++ . "_";
                         }
                         rename($file, $trash_name . $m . $trash_file);
                         touch($trash_name . $m . $trash_file);
                     } else {
                         @unlink($file);
                     }
                 }
             }
             foreach ($rdata[$field_name] as $filekey => $file) {
                 if ($file == "") {
                     unset($rdata[$field_name][$filekey]);
                     $data[$field_name] = implode("|", $rdata[$field_name]);
                     continue;
                 }
                 if (file_exists(SIMPLE_CACHE . "/upload/" . basename($file))) {
                     $filebase = modify::basename(basename($file));
                     list($target, $filename) = sys_build_filename($filebase, $this->tname);
                     dirs_checkdir($target);
                     $target .= sys_get_pathnum($id) . "/";
                     dirs_checkdir($target);
                     $target .= md5($id) . $filename;
                     rename(SIMPLE_CACHE . "/upload/" . basename($file), $target);
                     $rdata[$field_name][$filekey] = $target;
                     $data[$field_name] = implode("|", $rdata[$field_name]);
                 }
             }
             $basenames = array();
             foreach (array_reverse($rdata[$field_name]) as $filekey => $file) {
                 $basename = modify::basename($file);
                 if (isset($basenames[$basename])) {
                     $old_filekey = $basenames[$basename];
                     $basename = preg_replace("|_rev\\d+|", "", $basename);
                     $base = $basename;
                     $i = 1;
                     while (isset($basenames[$basename])) {
                         if ($pos = strrpos($base, ".")) {
                             $basename = substr($base, 0, $pos) . "_rev" . $i++ . substr($base, $pos);
                         } else {
                             $basename = $base . "_rev" . $i++;
                         }
                     }
                     $target = str_replace(modify::basename($file), $basename, $file);
                     if (rename($file, $target)) {
                         // swap
                         $rdata[$field_name][$filekey] = $rdata[$field_name][$old_filekey];
                         $rdata[$field_name][$old_filekey] = $target;
                         $data[$field_name] = implode("|", $rdata[$field_name]);
                     }
                 }
                 $basenames[$basename] = $filekey;
             }
         }
         if (!empty($field["STORE"]) and is_array($field["STORE"])) {
             foreach ($field["STORE"] as $store) {
                 list($class, $function, $params) = sys_find_callback("modify", $store["FUNCTION"]);
                 $rdata[$field_name] = call_user_func(array($class, $function), $rdata[$field_name], $rdata, $params);
             }
         }
         if (!isset($sql_data[$field_name]) and !is_null($rdata[$field_name])) {
             $sql_data[$field_name] = $rdata[$field_name];
         }
     }
     // transform
     foreach ($sql_data as $key => $value) {
         $sql_data[$key] = self::scalarize($value, $this->fields[$key]);
     }
     // reduce to new values
     $sys_fields = array("history" => "", "dsize" => "", "seen" => "");
     foreach ($sql_data as $data_key => $data_value) {
         if (isset($sys_fields[$data_key])) {
             continue;
         }
         $addfield = true;
         $field = $this->fields[$data_key];
         if (!isset($this->current_fields[$data_key])) {
             $addfield = false;
         }
         if (isset($field["NOTINALL"])) {
             $addfield = false;
         }
         if (isset($field["NOTIN"]) and in_array($this->view, $field["NOTIN"])) {
             $addfield = false;
         }
         if (isset($field["READONLYIN"]) and (in_array($this->view, $field["READONLYIN"]) or in_array("all", $field["READONLYIN"]))) {
             $addfield = false;
         }
         if (isset($field["ONLYIN"])) {
             if (in_array($this->view, $field["ONLYIN"])) {
                 $addfield = true;
             } else {
                 $addfield = false;
             }
         }
         if (!$addfield) {
             unset($sql_data[$data_key]);
         }
     }
     // build history
     $sql_data = $this->build_history($sql_data, $data_row);
     if (!array_diff(array_keys($sql_data), array("history", "seen"))) {
         $sql_data = array();
     }
     // save in db
     if ($insert) {
         $error_sql = db_insert($this->tname, $sql_data, array("handler" => $this->handler));
         if ($error_sql != "") {
             return self::_error("{t}SQL failed.{/t}", $error_sql);
         }
         if ($this->notification) {
             sys_notification("{t}Item successfully created.{/t} (" . $id . ")");
         }
     } else {
         if (count($sql_data) == 0) {
             return $id;
         }
         $error_sql = db_update($this->tname, $sql_data, array("id=@id@"), array("id" => $id, "folder" => $this->folder), array("handler" => $this->handler));
         if ($error_sql != "") {
             return self::_error("{t}SQL failed.{/t}", $error_sql);
         }
         if ($this->notification) {
             sys_notification("{t}Item successfully updated.{/t} (" . (is_numeric($id) ? $id : 1) . ")");
         }
     }
     if (empty($this->handler)) {
         db_update("simple_sys_tree", array("history" => "[" . $id . "/details] " . $sql_data["history"]), array("id=@id@"), array("id" => $this->folder));
         db_update_treesize($this->tname, $this->folder);
         if (!$insert and $this->folder != $data_row["folder"]) {
             db_update("simple_sys_tree", array("history" => "[" . $id . "/details] " . $sql_data["history"]), array("id=@id@"), array("id" => $data_row["folder"]));
             db_update_treesize($this->tname, $data_row["folder"]);
             db_search_delete($this->tname, $id, $data_row["folder"]);
         }
         if (empty($this->att["NO_SEARCH_INDEX"])) {
             db_search_update($this->tname, $id, $this->fields);
         }
         sys_log_stat($insert ? "new_records" : "changed_records", 1);
     }
     // call triggers
     $trigger = "";
     if ($insert and !empty($this->att["TRIGGER_NEW"])) {
         $trigger = $this->att["TRIGGER_NEW"];
     }
     if (!$insert and !empty($this->att["TRIGGER_EDIT"])) {
         $trigger = $this->att["TRIGGER_EDIT"];
     }
     if ($trigger and $result = asset_process_trigger($trigger, $id, $rdata, $this->tname)) {
         return self::_error("{t}Trigger failed{/t}", $result);
     }
     // send notification
     $tree_notification = db_select_value("simple_sys_tree", "notification", "id=@id@", array("id" => $this->folder));
     if ($tree_notification != "") {
         $rdata["notification"] .= "," . $tree_notification;
     }
     if (!$insert and $this->folder != $data_row["folder"]) {
         $tree_notification = db_select_value("simple_sys_tree", "notification", "id=@id@", array("id" => $data_row["folder"]));
         if ($tree_notification != "") {
             $rdata["notification"] .= "," . $tree_notification;
         }
     }
     if (!empty($rdata["notification"])) {
         $rdata["notification"] = trim($rdata["notification"], ",");
         $smtp_data = asset::build_notification($this->att["NAME"], $this->current_fields, $rdata, $sql_data, $id, $data_row);
         if ($result = asset_process_trigger("sendmail", $id, $smtp_data)) {
             return self::_error("{t}Trigger failed{/t}", $result);
         }
     }
     // update stats
     if (!empty($this->handler)) {
         foreach ($sql_data as $data_key => $data_value) {
             $field = $this->fields[$data_key];
             if ($field["SIMPLE_TYPE"] != "files") {
                 continue;
             }
             foreach (explode("|", $data_value) as $file) {
                 if (sys_strbegins($file, SIMPLE_CACHE . "/upload/")) {
                     @unlink($file);
                 }
             }
         }
     }
     return $id;
 }
Exemplo n.º 13
0
$ext = modify::getfileext(urldecode($_SERVER["REQUEST_URI"]));
if (in_array($ext, explode(",", INVALID_EXTENSIONS))) {
    sys_error(t("{t}this file extension is not allowed{/t}") . " (" . $ext . ")", "403 Forbidden");
}
$content_length = sys_get_header("Content-Length");
if ($content_length == 0 and strtolower($_REQUEST["action"]) != "move") {
    _upload_success();
}
if (strtolower($_REQUEST["action"]) == "move" and !empty($_SERVER["HTTP_DESTINATION"])) {
    $_SERVER["REQUEST_URI"] = substr($_SERVER["HTTP_DESTINATION"], strpos($_SERVER["HTTP_DESTINATION"], "/sgdav/"));
}
if ($_REQUEST["item"] == "session") {
    $path = str_replace("//", "/", urldecode($_SERVER["REQUEST_URI"]));
    $filename = basename($path);
    $path = dirname($path);
    if (sys_strbegins($filename, "~") or sys_strbegins($filename, ".") or modify::getfileext($filename) == "tmp") {
        $target = SIMPLE_CACHE . "/upload/" . $_SESSION["username"] . sha1($path) . "--" . urlencode($filename);
        if ($fp = fopen("php://input", "r") and $ft = fopen($target, "wb")) {
            while (!feof($fp)) {
                fwrite($ft, fread($fp, 8192));
            }
            fclose($fp);
            fclose($ft);
            _upload_success();
        } else {
            sys_error("cant write", "403 Forbidden");
        }
    } else {
        $target_lnk = SIMPLE_CACHE . "/upload/" . $_SESSION["username"] . sha1($path) . "--" . urlencode($filename) . ".link";
        if (file_exists($target_lnk)) {
            $link = file($target_lnk);
Exemplo n.º 14
0
 static function displayfile($table, $filename, $index = false, $limit = true)
 {
     $size = @filesize($filename);
     $ext = self::getfileext($filename);
     if ($ext == basename($filename)) {
         $ext = self::basename($filename);
     }
     $txt_files = array("ldif", "log", "css", "csv", "eml", "rfc822", "ini", "reg", "tsv", "txt", "ics", "vcf", "lang");
     $code_files = array("bas", "bat", "c", "cmd", "cpp", "csh", "inf", "sh", "vb", "vbe", "xml", "java", "js", "pas", "php", "pl", "vbs", "vcs", "wsh", "tpl", "sql");
     $bin_files = array("doc", "docx", "xls", "xlsx", "ppt", "pptx", "tar", "zip", "gz", "tgz", "pdf", "mp3", "odt", "sxw", "ods", "sxc", "odp", "sxi", "jpg", "jpeg", "tif", "url");
     $html_files = array("htm", "html");
     $return = "";
     $return_html = "";
     $cid = str_replace("simple_", "", $table) . "_" . sha1($filename . $size . @filemtime($filename));
     if ($return = sys_cache_get($cid)) {
         if (!$index and $limit and strlen($return) > FILE_TEXT_LIMIT) {
             $return = substr($return, 0, FILE_TEXT_LIMIT) . " ...";
         }
         return trim($return);
     }
     $type = "";
     if (in_array($ext, $txt_files)) {
         $type = "text";
     } else {
         if (in_array($ext, $code_files)) {
             $type = "code";
         } else {
             if (in_array($ext, $html_files)) {
                 $type = "html";
             } else {
                 if (in_array($ext, $bin_files)) {
                     $type = "bin";
                 }
             }
         }
     }
     if ($type != "" and file_exists($filename)) {
         if ($type == "bin") {
             if (filesize($filename) != 0) {
                 if (!sys_strbegins($filename, SIMPLE_STORE . "/") and $result = validate::checkvirus($filename)) {
                     $return = "ERROR Virus scanner: " . $result;
                 } else {
                     $return = trim(self::preview_bin($filename, $ext));
                 }
             }
         } else {
             $return = trim(file_get_contents($filename, false, null, -1, $limit ? FILE_TEXT_LIMIT : 131072));
         }
         if ($return != "") {
             if ($index) {
                 $rlimit = INDEX_LIMIT;
             } else {
                 $rlimit = FILE_TEXT_LIMIT;
             }
             if ($limit and strlen($return) > $rlimit) {
                 $return = substr($return, 0, $rlimit) . " ...";
             }
             if (!self::detect_utf($return)) {
                 $return = utf8_encode($return);
             }
             if ($type == "html") {
                 $return_html = substr($return, 0, strrpos($return, ">"));
             } else {
                 if ($type != "code") {
                     $return_html = nl2br(strip_tags($return, "<a><b><i>"));
                 } else {
                     $return_html = self::highlight_string($return);
                 }
             }
         }
     }
     if ($return_html == "") {
         $return_html = " ";
     }
     if (!sys_strbegins($return, "ERROR ")) {
         sys_cache_set($cid, $return_html, FILE_TEXT_CACHE);
         if ($index) {
             return $return;
         } else {
             return trim($return_html);
         }
     } else {
         sys_log_message_log("php-fail", "displayfile: " . $return);
     }
     if ($index) {
         return "";
     }
     return sprintf("{t}Cannot create preview for %s{/t}.", $ext);
 }
Exemplo n.º 15
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];
 }