コード例 #1
0
ファイル: ClientController.cs プロジェクト: ismkdc/OrangeDNS
        public ActionResult Add(Client Model)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                if (!ModelState.IsValid)
                {
                    ViewData["ResultMsg"] = "Hata kullanıcı eklenemedi!"; return(View());
                }

                Client client = dc.Clients.SingleOrDefault(c => c.Ip == Model.Ip);
                if (client != null)
                {
                    client.Name = Model.Name;
                }
                else
                {
                    dc.Clients.Add(Model);
                }

                dc.SaveChanges();
                ModelState.Clear();
                ViewData["ResultMsg"] = "Kullanıcı başarıyla eklendi!";
            }
            return(View());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ismkdc/OrangeDNS
        static void Main(string[] args)
        {
            dc         = new OrangeDNSDataContext();
            updateTime = int.Parse(dc.GeneralSettings.SingleOrDefault(s => s.Name == "UpdateTime").Value);
            mainDns    = dc.GeneralSettings.SingleOrDefault(s => s.Name == "MainDns").Value;
            Timer updateData = new Timer(TimerCallback, null, 0, updateTime);

            using (DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10))
            {
                server.QueryReceived += OnQueryReceived;
                server.Start();
                while (true)
                {
                    string input = Console.ReadLine();
                    switch (input)
                    {
                    case "exit":
                        return;

                    case "update":
                        TimerCallback(null);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #3
0
 public ActionResult BulkAdd(HttpPostedFileBase myFile, int type, string forwardIp, int category)
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         ViewData["Categories"] = dc.Categories.ToList();
         BinaryReader b       = new BinaryReader(myFile.InputStream);
         byte[]       binData = b.ReadBytes((int)myFile.InputStream.Length);
         string       result  = System.Text.Encoding.UTF8.GetString(binData);
         string[]     domains = result.Split('\n');
         foreach (var item in domains)
         {
             dc.Domains.Add(new Domain()
             {
                 Url = item, Type = (DType)type, CategoryId = category, ForwardIp = forwardIp
             });
         }
         dc.SaveChanges();
     }
     ViewData["ResultMsg"] = "Domainler başarıyla eklendi!";
     return(View());
 }
コード例 #4
0
ファイル: ClientController.cs プロジェクト: ismkdc/OrangeDNS
        public ActionResult Block(string clientIp)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            List <Client> clients = null;

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                Client client = dc.Clients.SingleOrDefault(d => d.Ip == clientIp);
                if (client.IsBlocked)
                {
                    client.IsBlocked      = false;
                    ViewData["ResultMsg"] = "Kullanıcı bloğu başarıyla kaldırıldı!";
                }
                else
                {
                    client.IsBlocked      = true;
                    ViewData["ResultMsg"] = "Kullanıcı başarıyla bloklandı!";
                }
                dc.SaveChanges();
                clients = dc.Clients.ToList();
            }

            return(View("index", clients));
        }
コード例 #5
0
ファイル: ClientController.cs プロジェクト: ismkdc/OrangeDNS
        public JsonResult Search()
        {
            if (Session["UserId"] == null)
            {
                return(Json(""));
            }

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                return(Json(dc.Clients.Where(l => String.IsNullOrEmpty(l.Name)).Select(l => l.Ip).ToList(), JsonRequestBehavior.AllowGet));
            }
        }
コード例 #6
0
 public ActionResult Edit(int SettingId)
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         GeneralSettings setting = dc.GeneralSettings.SingleOrDefault(s => s.Id == SettingId);
         return(View(setting));
     }
 }
コード例 #7
0
 public ActionResult BulkAdd()
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         ViewData["Categories"] = dc.Categories.ToList();
     }
     return(View());
 }
コード例 #8
0
        // GET: Category
        public ActionResult Index()
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            List <Category> categories = null;

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                categories = dc.Categories.ToList();
            }
            return(View(categories));
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: ismkdc/OrangeDNS
 public string Internet()
 {
     if (Session["UserId"] == null)
     {
         return("");
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         GeneralSettings setting = dc.GeneralSettings.SingleOrDefault(s => s.Name == "GlobalBlock");
         setting.Value = setting.Value == "1" ? "0" : "1";
         dc.SaveChanges();
     }
     return("1");
 }
コード例 #10
0
 public ActionResult Edit(GeneralSettings Model)
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         GeneralSettings setting = dc.GeneralSettings.SingleOrDefault(s => s.Name == Model.Name);
         setting.Value = Model.Value;
         dc.SaveChanges();
         ViewData["ResultMsg"] = "Değer başarıyla güncellendi";
         return(View(setting));
     }
 }
コード例 #11
0
 // GET: Domain
 public ActionResult Index()
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         ViewData["Domains"] = dc.Domains.Select(d => new DomainViewModel()
         {
             Id = d.Id, Url = d.Url, ForwardIp = d.ForwardIp, Type = d.Type.ToString(), Category = d.Category.Name
         }).ToList();
     }
     return(View());
 }
コード例 #12
0
        // GET: Setting
        public ActionResult Index()
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }

            List <GeneralSettings> settings = null;

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                settings = dc.GeneralSettings.ToList();
            }
            return(View(settings));
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: ismkdc/OrangeDNS
        private static void TimerCallback(Object o)
        {
            try
            {
                domainList    = dc.Domains.ToList();
                globalBlock   = dc.GeneralSettings.SingleOrDefault(s => s.Name == "GlobalBlock").Value;
                globalBlockIp = dc.GeneralSettings.SingleOrDefault(s => s.Name == "GlobalBlockIp").Value;
                mainDns       = dc.GeneralSettings.SingleOrDefault(s => s.Name == "MainDns").Value;
                dc.Dispose();
                dc = new OrangeDNSDataContext();
            }
            catch (Exception e) { Console.WriteLine(e.Message); }

            Console.WriteLine("Domain list updated: " + DateTime.Now);
            GC.Collect();
        }
コード例 #14
0
        public ActionResult Delete(int categoryId)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            List <Category> categories = null;

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                Category category = dc.Categories.SingleOrDefault(c => c.Id == categoryId);
                dc.Categories.Remove(category);
                dc.SaveChanges();
                categories = dc.Categories.ToList();
            }
            ViewData["ResultMsg"] = "Kategori başarıyla silindi!";
            return(View("index", categories));
        }
コード例 #15
0
 public ActionResult Delete(int domainId)
 {
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("login", "home"));
     }
     using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
     {
         Domain domain = dc.Domains.SingleOrDefault(d => d.Id == domainId);
         dc.Domains.Remove(domain);
         dc.SaveChanges();
         ViewData["Domains"] = dc.Domains.Select(d => new DomainViewModel()
         {
             Id = d.Id, Url = d.Url, ForwardIp = d.ForwardIp, Type = d.Type.ToString(), Category = d.Category.Name
         }).ToList();
     }
     ViewData["ResultMsg"] = "Domain başarıyla silindi!";
     return(View("index"));
 }
コード例 #16
0
        public ActionResult Add(Category Model)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                if (!ModelState.IsValid)
                {
                    ViewData["ResultMsg"] = "Hata kategori eklenemedi!"; return(View());
                }

                dc.Categories.Add(Model);
                dc.SaveChanges();
                ModelState.Clear();
                ViewData["ResultMsg"] = "Kategori başarıyla eklendi!";
            }
            return(View());
        }
コード例 #17
0
ファイル: HomeController.cs プロジェクト: ismkdc/OrangeDNS
 public ActionResult Login(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
         {
             model.Password = getSHA1Hash(model.Password);
             OrangeDNS.Data.User user = dc.Users.SingleOrDefault(u => u.Username == model.Username && u.Password == model.Password);
             if (user != null)
             {
                 Session["UserId"] = user.Id;
                 Session["name"]   = user.Name;
                 return(RedirectToAction("index"));
             }
             else
             {
                 ViewBag.ErrorMsg = "Kullanıcı adı veya şifre hatalı";
             }
         }
     }
     return(View());
 }
コード例 #18
0
ファイル: ClientController.cs プロジェクト: ismkdc/OrangeDNS
        public ActionResult Delete(string clientIp)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login", "home"));
            }
            List <Client> clients = null;

            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                Client client = dc.Clients.SingleOrDefault(d => d.Ip == clientIp);
                foreach (var item in dc.Logs.Where(l => l.ClientIp == clientIp))
                {
                    dc.Logs.Remove(item);
                }
                dc.Clients.Remove(client);
                dc.SaveChanges();
                clients = dc.Clients.ToList();
            }
            ViewData["ResultMsg"] = "Kullanıcı başarıyla silindi!";
            return(View("index", clients));
        }
コード例 #19
0
ファイル: HomeController.cs プロジェクト: ismkdc/OrangeDNS
        public ActionResult Index()
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("login"));
            }
            using (OrangeDNSDataContext dc = new OrangeDNSDataContext())
            {
                List <Model.TopDomainsViewModel> topDomains = dc.Logs.GroupBy(l => l.Request).Select(d => new Model.TopDomainsViewModel()
                {
                    Name = d.Key, Count = d.Count()
                }).OrderByDescending(d => d.Count).Take(5).ToList();
                int counter = 1;
                foreach (var item in topDomains)
                {
                    item.Order = counter;
                    counter++;
                }
                ViewData["TopDomains"] = topDomains;

                List <Model.TopUsersViewModel> topUsers = dc.Logs.GroupBy(l => l.ClientIp).Select(d => new Model.TopUsersViewModel()
                {
                    Ip = d.Key, Count = d.Count()
                }).OrderByDescending(d => d.Count).Take(5).ToList();
                counter = 1;
                foreach (var item in topUsers)
                {
                    item.Name  = dc.Clients.SingleOrDefault(c => c.Ip == item.Ip).Name;
                    item.Order = counter;
                    counter++;
                }
                ViewBag.Internet     = dc.GeneralSettings.SingleOrDefault(s => s.Name == "GlobalBlock").Value;
                ViewData["TopUsers"] = topUsers;
            }
            return(View());
        }