Example #1
0
        public ActionResult Generic(string key, ImageType mode)
        {
            using (BtcStatsDb db = new BtcStatsDb())
            {
                Key keyDetails = (from s in db.Keys
                                  where s.StatsKey == key
                                  select s).FirstOrDefault();

                if (keyDetails != null)
                {
                    switch (keyDetails.Pool)
                    {
                    case "eligius":
                        return(Eligius(keyDetails.ApiKey, mode));

                    case "ozcoin":
                        return(Ozcoin(keyDetails.ApiKey, mode));

                    case "ars":
                        return(Ars(keyDetails.ApiKey, mode));

                    case "mmc":
                        return(MMC(keyDetails.ApiKey, mode));

                    case "yourbtc":
                        return(YourBtc(keyDetails.ApiKey, mode));

                    case "abc":
                        return(ABC(keyDetails.ApiKey, mode));

                    case "emc":
                        return(EMC(keyDetails.ApiKey, mode));

                    case "p2pool":
                        return(P2Pool(keyDetails.ApiKey, mode));

                    case "slush":
                        return(Slush(keyDetails.ApiKey, mode));

                    case "mtred":
                        return(MtRed(keyDetails.ApiKey, mode));
                    }
                }
            }
            if (mode == ImageType.Sig)
            {
                return(new FilePathResult(Server.MapPath("~/Content/KeyNotFound.png"), "image/png"));
            }
            else
            {
                return(new FilePathResult(Server.MapPath("~/Content/KeyNotFoundAvatar.png"), "image/png"));
            }
        }
Example #2
0
        public ActionResult GetKey(string pool, string apiKey)
        {
            using (BtcStatsDb db = new BtcStatsDb())
            {
                pool   = pool.Trim();
                apiKey = apiKey.Trim();
                string existingKey = (from s in db.Keys
                                      where s.Pool == pool && s.ApiKey == apiKey
                                      select s.StatsKey).FirstOrDefault();

                if (existingKey != null)
                {
                    return(Content(existingKey));
                }

                string statsKey;
                while (true)
                {
                    RandomNumberGenerator rnd = RNGCryptoServiceProvider.Create();
                    byte[] keyBytes           = new byte[4];
                    rnd.GetNonZeroBytes(keyBytes);
                    statsKey = HttpServerUtility.UrlTokenEncode(keyBytes).Replace('_', 'a').Replace("-", "x");
                    Key duplicateKey = (from s in db.Keys
                                        where s.StatsKey == statsKey
                                        select s).FirstOrDefault();
                    if (duplicateKey == null)
                    {
                        Key newEntry = new Key();
                        newEntry.StatsKey = statsKey;
                        newEntry.Pool     = pool;
                        newEntry.ApiKey   = apiKey;
                        db.Keys.Add(newEntry);
                        db.SaveChanges();
                        break;
                    }
                }

                return(Content(statsKey));
            }
        }
Example #3
0
        public ActionResult GetKey(string pool, string apiKey)
        {
            using (BtcStatsDb db = new BtcStatsDb())
            {
                pool = pool.Trim();
                apiKey = apiKey.Trim();
                string existingKey = (from s in db.Keys
                                      where s.Pool == pool && s.ApiKey == apiKey
                                      select s.StatsKey).FirstOrDefault();

                if (existingKey != null)
                {
                    return Content(existingKey);
                }

                string statsKey;
                while (true)
                {
                    RandomNumberGenerator rnd = RNGCryptoServiceProvider.Create();
                    byte[] keyBytes = new byte[4];
                    rnd.GetNonZeroBytes(keyBytes);
                    statsKey = HttpServerUtility.UrlTokenEncode(keyBytes).Replace('_', 'a').Replace("-", "x");
                    Key duplicateKey = (from s in db.Keys
                                        where s.StatsKey == statsKey
                                        select s).FirstOrDefault();
                    if (duplicateKey == null)
                    {
                        Key newEntry = new Key();
                        newEntry.StatsKey = statsKey;
                        newEntry.Pool = pool;
                        newEntry.ApiKey = apiKey;
                        db.Keys.Add(newEntry);
                        db.SaveChanges();
                        break;
                    }
                }

                return Content(statsKey);
            }
        }
Example #4
0
        public ActionResult Generic(string key, ImageType mode)
        {
            using (BtcStatsDb db = new BtcStatsDb())
            {
                Key keyDetails = (from s in db.Keys
                                  where s.StatsKey == key
                                  select s).FirstOrDefault();

                if (keyDetails != null)
                {
                    switch (keyDetails.Pool)
                    {
                        case "eligius":
                            return Eligius(keyDetails.ApiKey, mode);
                        case "ozcoin":
                            return Ozcoin(keyDetails.ApiKey, mode);
                        case "ars":
                            return Ars(keyDetails.ApiKey, mode);
                        case "mmc":
                            return MMC(keyDetails.ApiKey, mode);
                        case "yourbtc":
                            return YourBtc(keyDetails.ApiKey, mode);
                        case "abc":
                            return ABC(keyDetails.ApiKey, mode);
                        case "emc":
                            return EMC(keyDetails.ApiKey, mode);
                        case "p2pool":
                            return P2Pool(keyDetails.ApiKey, mode);
                        case "slush":
                            return Slush(keyDetails.ApiKey, mode);
                        case "mtred":
                            return MtRed(keyDetails.ApiKey, mode);
                    }
                }
            }
            if (mode == ImageType.Sig)
            {
                return new FilePathResult(Server.MapPath("~/Content/KeyNotFound.png"), "image/png");
            }
            else
            {
                return new FilePathResult(Server.MapPath("~/Content/KeyNotFoundAvatar.png"), "image/png");
            }
        }