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()); }
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; } } } }
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()); }
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)); }
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)); } }
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)); } }
public ActionResult BulkAdd() { if (Session["UserId"] == null) { return(RedirectToAction("login", "home")); } using (OrangeDNSDataContext dc = new OrangeDNSDataContext()) { ViewData["Categories"] = dc.Categories.ToList(); } return(View()); }
// 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)); }
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"); }
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)); } }
// 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()); }
// 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)); }
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(); }
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)); }
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")); }
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()); }
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()); }
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)); }
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()); }