Beispiel #1
0
 public bool set_profile(string username, string groups, long quota)
 {
     this.quota_permitted = quota;
     if (this.quota_permitted == 0L)
     {
         this.quota_permitted = clib.nice_atol(Ini.getstring(En.quota_default));
     }
     if (this.quota_permitted == 0L)
     {
         this.quota_permitted = 1000000000L;
     }
     if (username == "anonymous")
     {
         groups = "anonymous";
     }
     for (int i = 0; i < Profile.profile_n(); ++i)
     {
         Profile profile = Profile.profile_get(i);
         if (profile.matches(username, groups))
         {
             this.profile = profile;
         }
     }
     if (this.profile == null)
     {
         clib.imsg("NO PROFILE FOUND FOR THIS USER");
     }
     this.current_user = username;
     return(this.profile != null);
 }
Beispiel #2
0
        public static string host()
        {
            string str = Ini.getstring(En.host);

            if (str == null || str.Length == 0)
            {
                str = MyKey.get_host();
            }
            return(str);
        }
Beispiel #3
0
        public static string default_domain()
        {
            string str = Ini.getstring(En.default_domain);

            if (str.Length == 0)
            {
                str = Ini.host();
            }
            return(str);
        }
Beispiel #4
0
        public static List <string> valid_groups()
        {
            List <string> list = ((IEnumerable <string>)Ini.getstring(En.user_groups).Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).ToList <string>();

            if (list.Count <string>() == 0)
            {
                list.Add("admin");
                list.Add("user");
                list.Add("anonymous");
            }
            return(list);
        }
Beispiel #5
0
        public long quota()
        {
            string stuff = this.info.Get(nameof(quota));

            if (stuff == null)
            {
                if (this.is_upgraded())
                {
                    stuff = Ini.getstring(En.upgrade_quota);
                }
                if (stuff == null)
                {
                    return(0);
                }
            }
            return(clib.nice_atol(stuff));
        }
Beispiel #6
0
 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();
 }
Beispiel #7
0
        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());
        }
Beispiel #8
0
 public static int getint(En idx)
 {
     return(clib.atoi(Ini.getstring(idx)));
 }
Beispiel #9
0
        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);
        }