public static void need_auth(Websvc w) { Random random = new Random(); byte[] numArray = new byte[10]; random.NextBytes(numArray); Web.any_header(w, "text/plain", "401 Authorization required"); Web.wh(w, "WWW-Authenticate: Basic realm=\"{0}\"\r\n", (object)MyMain.realm()); Web.wh(w, "WWW-Authenticate: Digest"); Web.wh(w, " realm=\"{0}\",", (object)MyMain.realm()); Web.wh(w, " qop=\"auth\","); Web.wh(w, " nonce=\"{0}\",", (object)clib.byte_to_hex(numArray, ((IEnumerable <byte>)numArray).Count <byte>())); Web.wh(w, " opaque=\"placeholder\"\r\n"); Web.wp(w, "Authorization required"); w.body_send(); if (!Ini.istrue(En.debug_http)) { return; } clib.imsg("http: requesting authentication"); }
public static bool load(string path) { Ini.savepath = path; try { TextReader textReader = (TextReader) new StreamReader(path); try { while (true) { string[] strArray; do { string str = textReader.ReadLine(); if (str != null) { strArray = str.Split("~\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } else { goto label_7; } }while (((IEnumerable <string>)strArray).Count <string>() < 2); Ini.do_set(strArray[0], strArray[1]); } } catch (Exception ex) { clib.imsg("load failed {0}", (object)ex.ToString()); } label_7: textReader.Close(); } catch (Exception ex) { clib.imsg("Could not open {0} {1} - Not serious, using defaults", (object)path, (object)ex.Message); return(true); } return(true); }
public static void startListeners() { clib.imsg("Creating tcpserver's..."); MyMain.s_websvc = new Websvc(); MyMain.s_WebServer = new TcpServer((TcpServiceProvider)MyMain.s_websvc, Ini.getstring(En.bind), Ini.getint(En.web_port_ssl), true); MyMain.s_WebServer.Start(); MyMain.webdavsvc = new Websvc(); MyMain.webdavsvc.iswebdav = true; MyMain.WebDavServer = new TcpServer((TcpServiceProvider)MyMain.webdavsvc, Ini.getstring(En.bind), Ini.getint(En.webdav_port), false); MyMain.WebDavServer.Start(); MyMain.s_webdavsvc = new Websvc(); MyMain.s_webdavsvc.iswebdav = true; MyMain.s_WebDavServer = new TcpServer((TcpServiceProvider)MyMain.s_webdavsvc, Ini.getstring(En.bind), Ini.getint(En.webdav_port_ssl), true); if (!MyMain.s_WebDavServer.Start()) { return; } MyMain.ftpservice = new FtpService(); MyMain.ftpServer = new TcpServer((TcpServiceProvider)MyMain.ftpservice, Ini.getstring(En.bind), Ini.getint(En.ftp_port), false); MyMain.ftpServer.Start(); clib.imsg("Going to listeon on port {0} for http admin connections", (object)Ini.getint(En.web_port)); MyMain.websvc = new Websvc(); MyMain.WebServer = new TcpServer((TcpServiceProvider)MyMain.websvc, Ini.getstring(En.bind), Ini.getint(En.web_port), false); if (!MyMain.WebServer.Start()) { MyMain.WebServer = new TcpServer((TcpServiceProvider)MyMain.websvc, Ini.getstring(En.bind), Ini.getint(En.web_port) + 1, false); if (MyMain.WebServer.Start()) { clib.imsg("Listing on next port worked. So changing setting..."); Ini.do_set(En.web_port, clib.int_to_string(Ini.getint(En.web_port) + 1)); } } MyMain.websvc2 = new Websvc(); MyMain.WebServer2 = new TcpServer((TcpServiceProvider)MyMain.websvc2, Ini.getstring(En.bind), 6080, false); MyMain.WebServer2.Start(); }
public static void page_end(Websvc w) { Web.wp(w, "<hr>\n"); if (w.ses != null) { Web.wp(w, "<p>WEBDAV:\n"); string str1 = clib.make_url("http", Ini.host(), Ini.getint(En.webdav_port), "/"); Web.wp(w, "<a href=\"{0}\">{0}</a>", (object)str1); Web.wp(w, " or "); string str2 = clib.make_url("https", Ini.host(), Ini.getint(En.webdav_port_ssl), "/"); Web.wp(w, "<a href=\"{0}\">{0}</a>", (object)str2); Web.wp(w, "<BR>FTP:\n"); string str3 = string.Format("ftp://{0}:{1}", (object)Ini.host(), (object)Ini.getint(En.ftp_port)); Web.wp(w, "<a href=\"{0}\">{0}</a>", (object)str3); Web.wp(w, "<BR> Web Browser: "); string str4 = Ini.url_browse(); Web.wp(w, "<a href=\"{0}\">{0}</a>", (object)str4); Web.wp(w, " or "); string str5 = clib.make_url("https", Ini.host(), Ini.getint(En.web_port_ssl), "/"); Web.wp(w, "<a href=\"{0}\">{0}</a>", (object)str5); Web.wp(w, "<BR> <a href=\"http://netwinsite.com/ftpdav/guide.htm\">Guide to free WebDav/FTP Clients</a>"); } Web.wp(w, "</div>"); }
public static void console_main(bool block) { MyMain.start_time = DateTime.Now; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyMain.CurrentDomain_UnhandledException); Timer timer = new Timer(new TimerCallback(MyMain.tsecond_Elapsed), (object)null, 0, 1000); clib.init_log_files(); clib.set_debug(true); clib.imsg("Logging home {0}", (object)clib.log_file("imsg.log")); clib.imsg("Starting FTPDAV Version {0} Build {1}", (object)clib.Version(), (object)clib.Build()); clib.startstop("Starting FTPDAV Version {0} {1}", (object)clib.Version(), (object)clib.Build()); Ini.init(clib.work("config.ini")); clib.set_debug(MyMain.main_debug); clib.log_idle(); Quota.init(); clib.set_tmp(clib.work("tmp")); Directory.CreateDirectory(clib.tmp()); Directory.CreateDirectory(clib.work("userdb")); Directory.CreateDirectory(clib.work("spawn")); Directory.CreateDirectory(clib.work("log")); Vuser.init(clib.work("userdb")); Link.set_paths(clib.work(""), clib.app("")); Profile.load(); SimpleHash.unit_test(); Link.set_ssl_password(Ini.getstring(En.ssl_password)); clib.set_debug(true); MyMain.startListeners(); if (!MyMain.main_debug) { clib.imsg("Going quiet now as no -debug switch on command line..."); } clib.set_debug(MyMain.main_debug); MyKey.init(clib.work("key.dat")); try { File.Delete(clib.work("ftpdav.exit")); } catch { clib.imsg("FAILED TO DELETE FTPDAV.EXIT"); } if (!block) { return; } while (true) { try { File.WriteAllText(clib.work("main.running"), "running"); if (File.Exists(clib.work("ftpdav.exit"))) { clib.imsg("Exiting because ftpdav.exit found"); try { File.Delete(clib.work("ftpdav.exit")); goto label_18; } catch (Exception ex) { clib.imsg("Delete failed {0}", (object)ex.Message); goto label_18; } } } catch { } Thread.Sleep(1000); if (!MyMain.shutdown) { if (clib.time() - MyMain.last > 60) { MyMain.last = clib.time(); Quota.save(); } } else { break; } } clib.imsg("Exiting because shutdown flag true"); label_18: File.Delete(clib.work("main.running")); clib.imsg("Key pressed or ftpdav.exit found =============================="); Quota.save(); clib.startstop("Clean shutdown FTPDAV Version {0}", (object)clib.Version()); }
private void process_header(string header) { this.head.Clear(); this.content_type = ""; this.content_len = 0; this.imsg("content_mystery, process_header started {0}", (object)this.content_len); this.depth = 2; string[] strArray = clib.string_lines(header); string rline = strArray[0]; this.save_request = rline; if (Ini.istrue(En.debug_http)) { this.imsg("http: ===< Request: {0}", (object)rline); } foreach (string str1 in strArray) { int length = str1.IndexOf(":"); if (length >= 0) { string str2 = str1.Substring(0, length); string str3 = str1.Substring(length + 1); if (str3.Length > 0 && str3.StartsWith(" ")) { str3 = str3.Substring(1); } if (Ini.istrue(En.debug_http)) { this.imsg("http: {0}: {1}", (object)str2, (object)str3); } try { this.head.Add(str2.ToLower(), str3); } catch { } } } this.isgzip = this.head_get("Content-Encoding").Contains("gzip"); if (this.isgzip) { this.inmem = true; this.mem_body = new MyBuffer(); } this.isie = this.head_get("User-Agent").Contains("MSIE"); this.was_content = false; this.content_len = clib.atoi(this.head_get("Content-Length")); if (this.content_len > 0) { this.was_content = true; } this.imsg("do_headers: mystery content_len is {0} {1}", (object)this.content_len, (object)rline); this.in_chunked = false; string str4 = this.head_get("Timeout"); if (str4 != null) { int num = str4.IndexOf("Second-"); this.h_timeout = num < 0 ? 3600 : clib.atoi(str4.Substring(num + "Second-".Length)); } string str5 = this.head_get("Transfer-Encoding"); if (str5 != null && str5.ToLower().Contains("chunked")) { this.in_chunked = true; this.chunk_len = 0; } this.do_continue = false; if (this.head_get("Expect").Contains("100-continue")) { this.do_continue = true; } if (this.do_continue) { this.imsg("Sending: HTTP/1.1 100 Continue\n"); this.chan.write("HTTP/1.1 100 Continue\r\n\r\n"); } this.destination = this.head_get("Destination"); this.destination = clib.url_decode(this.destination); this.imsg("decoded dest is now {0}", (object)this.destination); this.overwrite = true; string str6 = this.head_get("Overwrite"); if (str6 != null) { if (str6.ToLower().Contains("t")) { this.overwrite = true; } if (str6.ToLower().Contains("f")) { this.overwrite = false; } } string lower = (this.head_get("Depth") ?? "2").Trim().ToLower(); if (lower.Length == 0) { this.depth = 2; } else if (lower == "0") { this.depth = 0; } else if (lower == "1") { this.depth = 1; } else if (lower == "infinity") { this.depth = 2; } this.imsg("Depth is {0}", (object)this.depth); this.cookie = this.head_get("Cookie"); this.imsg("Main request: {0} {1}", (object)this.content_len, (object)rline); if (!this.decode_request(rline)) { this.imsg("decode_request failed - close link"); this.imsg("decode_request failed - close link"); this.chan.EndConnection(); } else { this.imsg("decode_request worked okk"); } }
public static int getint(En idx) { return(clib.atoi(Ini.getstring(idx))); }
public static string url_browse() { return(clib.make_url("http", Ini.host(), Ini.getint(En.web_port), "/")); }
public static string add_domain(string user) { return(user.IndexOf("@") < 0 ? user + "@" + Ini.default_domain() : user); }
public static bool check(string user, string pass, out string reason) { bool flag1 = false; reason = "user doesn't exist or invalid password"; bool flag2 = UserDb.check(user, pass); if (flag2) { User user1 = UserDb.lookup(user); flag1 = user1.isadmin(); switch (user1.info["status"]) { case "pending": reason = "Sorry you must activate using the token from your email first"; return(false); default: string stuff = user1.info["cached"]; if (stuff != null && stuff.Length > 0) { clib.imsg("found cached life of {0}", (object)stuff); if (clib.time() > clib.atoi(stuff)) { clib.imsg("EXPIRED, MAKE HIM CHECK AGAIN age {0} {1}", (object)(clib.time() - clib.atoi(stuff)), (object)stuff); flag2 = false; } } break; } } if (!flag1 && !Vuser.valid_user(user, out reason)) { return(false); } if (!flag2) { string dest = Ini.getstring(En.auth_imap); if (dest.Length > 0) { Imap imap = new Imap(); clib.imsg("auth_imap {0} {1}", (object)user, (object)dest); string result; if (imap.login(dest, 143, "nossl", user, pass, out result)) { NameValueCollection info = new NameValueCollection(); User user1 = UserDb.lookup(user); if (user1 != null && user1.info != null) { info = user1.info; } info.Set("cached", clib.int_to_string(clib.time() + 604800)); clib.imsg("Imap: login worked for that user/pass {0}", (object)user); string reason1; if (!UserDb.add(user, pass, info, "", out reason1)) { clib.imsg("cacheadd: {0}", (object)reason1); } imap.netclose(); flag2 = true; } else { clib.imsg("imap: login failed on remost host {0}", (object)result); } } } return(flag2); }