예제 #1
0
        public static bool add(
            string user,
            string passwd,
            NameValueCollection info,
            out string reason,
            string oldpass)
        {
            if (Vuser.total > 5 && Vuser.total > MyKey.ulimit_max())
            {
                reason = "Sorry license user limit reached";
                return(false);
            }
            if (!Vuser.valid_user(user, out reason))
            {
                return(false);
            }
            User user1 = UserDb.lookup(user);
            bool flag  = UserDb.add(user, passwd, info, user1 == null ? "" : user1.passwd, out reason);

            if (flag && user1 == null)
            {
                Vuser.total_add(1);
            }
            return(flag);
        }
예제 #2
0
 public static int ulimit_max()
 {
     if (MyKey.s_code.Length < 20 || MyKey.isexpired())
     {
         return(5);
     }
     return(MyKey.ulimit > 0 ? MyKey.ulimit : 10000000);
 }
예제 #3
0
 public static void init(string fname)
 {
     MyKey.keyfile = fname;
     MyKey.load();
     if (MyKey.s_code.Length <= 0)
     {
         return;
     }
     MyKey.decode(MyKey.s_code, out string _);
 }
예제 #4
0
        public static string host()
        {
            string str = Ini.getstring(En.host);

            if (str == null || str.Length == 0)
            {
                str = MyKey.get_host();
            }
            return(str);
        }
예제 #5
0
        public static void load()
        {
            NameValueCollection all = clib.pair_load(MyKey.keyfile);

            MyKey.s_email  = all.get_safe("email");
            MyKey.regid    = clib.atoi(all.get_safe("regid"));
            MyKey.s_hostid = clib.atoi(all.get_safe("hostid"));
            MyKey.s_code   = all.get_safe("code");
            if (MyKey.s_hostid != 0)
            {
                return;
            }
            MyKey.s_hostid = new Random().Next(1000000);
            MyKey.save();
        }
예제 #6
0
        public static bool decode(string key, out string reason)
        {
            byte[] xin    = clib.hex_to_byte(key);
            int    index1 = 0;
            int    mon    = 0;

            reason = "";
            if (key.Length < 30)
            {
                reason = "tooshort: Keys are 30 char long";
                return(false);
            }
            MyKey.regid = (int)xin[index1] + (int)xin[index1 + 1] * 256 + (int)xin[index1 + 2] * 65536;
            int index2 = index1 + 3;

            MyKey.regdate = (int)xin[index2] + (int)xin[index2 + 1] * 256;
            int index3 = index2 + 2;

            MyKey.host = (int)xin[index3] + (int)xin[index3 + 1] * 256;
            int num1 = index3 + 2;

            byte[] numArray1 = xin;
            int    index4    = num1;
            int    num2      = index4 + 1;

            MyKey.prodid = (int)numArray1[index4];
            byte[] numArray2 = xin;
            int    index5    = num2;
            int    num3      = index5 + 1;

            MyKey.flags = (int)numArray2[index5];
            byte[] numArray3 = xin;
            int    index6    = num3;
            int    index7    = index6 + 1;

            MyKey.ulimit = MyKey.keylib_ulimit_decode((int)numArray3[index6]);
            int num4 = MyKey.keylib_crc(xin, MyKey.PRE_CRC);
            int num5 = (int)xin[index7] + (int)xin[index7 + 1] * 256;
            int num6 = index7 + 2;

            clib.imsg("crc {0} {1}", (object)num4, (object)num5);
            MyKey.reg_day1 = (int)xin[12];
            MyKey.reg_day2 = (int)xin[13];
            MyKey.fromdate = MyKey.keylib_fromdate(MyKey.regdate, MyKey.reg_day1, MyKey.reg_day2, out mon);
            if (MyKey.host != 0)
            {
                string host = MyKey.get_host();
                if (MyKey.keylib_host(host) != MyKey.host && MyKey.keylib_host(MyKey.keylib_host_trim(host)) != MyKey.host)
                {
                    reason = string.Format("Key for wrong host=({0}) ({1}) , try activate again", (object)host, (object)MyKey.keylib_host_trim(host));
                    return(false);
                }
            }
            DateTime date = clib.unix_to_date(MyKey.fromdate);

            MyKey.expdate = date.AddMonths(mon).to_unix_date();
            if (mon == 0)
            {
                date          = clib.unix_to_date(MyKey.fromdate);
                MyKey.expdate = date.AddMonths(12).to_unix_date();
            }
            MyKey.istemp = true;
            if (mon == 0)
            {
                MyKey.istemp = false;
            }
            clib.imsg("Fromdate is {0} {1} Expires {2}", (object)MyKey.fromdate, (object)clib.nice_unix_date(MyKey.fromdate), (object)clib.nice_unix_date(MyKey.expdate));
            if (num4 == num5)
            {
                return(true);
            }
            reason = "bad crc";
            return(false);
        }
예제 #7
0
        public static bool keylib_activate_get(
            string prod,
            string sregid,
            string email,
            out string keycode,
            out string reason)
        {
            string str1    = "netwinsite.com";
            string str2    = MyKey.keylib_host_new(MyKey.get_host());
            string postUrl = string.Format("http://{0}/cgi-bin/keycgi.exe", (object)str1);

            keycode           = "failed";
            MyKey.robot_email = string.Format("{{host: {0}}}\r\n{{regid: {1}}}\r\n{{email: {2}}}\r\n{{product: {3}}}\r\n{{build: {4}}}\r\n{{hostid: {5}}}\r\n", (object)str2, (object)sregid, (object)email, (object)prod, (object)MyKey.keylib_build_date(), (object)MyKey.s_hostid);
            if (email.Length > 0)
            {
                MyKey.s_email = email;
            }
            reason = "";
            sregid = sregid.ToLower();
            if (sregid.StartsWith("n"))
            {
                sregid = sregid.Substring(1);
            }
            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            postParameters.Add("cmd", (object)"activate");
            postParameters.Add("regid", (object)sregid);
            postParameters.Add(nameof(email), (object)email);
            postParameters.Add("host", (object)str2);
            postParameters.Add("product", (object)prod);
            postParameters.Add("build", (object)MyKey.keylib_build_date());
            postParameters.Add("hostid", (object)MyKey.s_hostid);
            string end;

            try
            {
                string          userAgent       = "ftpdav";
                HttpWebResponse httpWebResponse = WebHelpers.MultipartFormDataPost(postUrl, userAgent, postParameters, "", "");
                end = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd();
                httpWebResponse.Close();
                stat.imsg("image post response {0}", (object)end);
            }
            catch (Exception ex)
            {
                stat.imsg("image post failed to connect {0}", (object)ex.ToString());
                return(false);
            }
            keycode = "";
            string str3 = "";

            foreach (string str4 in end.string_lines_any())
            {
                clib.imsg("Response: {0}", (object)str4);
                if (str4.StartsWith("key: "))
                {
                    keycode = str4.Substring(5);
                }
                if (str4.StartsWith("key_state: "))
                {
                    str3 = str4.Substring(1);
                }
                if (str4.StartsWith("error: "))
                {
                    reason = str4.Substring(7);
                }
            }
            if (reason.Length > 0)
            {
                return(false);
            }
            clib.imsg("key state {0}", (object)str3);
            MyKey.s_code = keycode;
            return(true);
        }
예제 #8
0
 private static int keylib_host(string host)
 {
     host = host.ToLower();
     return(host == "*" ? 0 : MyKey.keylib_crc(clib.string_to_byte(host), host.Length) & (int)ushort.MaxValue);
 }
예제 #9
0
 public static string show()
 {
     return(string.Format("Regid={0} regdate={1} host={2} prodid={3} flags={4} ulimit={5} istemp={6} host={7} expires={8}", (object)MyKey.regid, (object)MyKey.regdate, (object)MyKey.host, (object)MyKey.prodid, (object)MyKey.flags, (object)MyKey.ulimit, (object)MyKey.istemp, (object)MyKey.keylib_host_new(MyKey.get_host()), (object)clib.nice_unix_date(MyKey.expdate)));
 }
예제 #10
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());
        }