コード例 #1
0
        public ActionResult Delete(string preset_id)
        {
            if (Session["LoggedIn"] != null)
            {
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                try
                {
                    var query = (from preset1 in db.presets
                                 where preset1.pre_id == int.Parse(preset_id)
                                 select preset1).Single();

                    db.presets.DeleteOnSubmit(query);
                    db.SubmitChanges();
                }
                catch { return RedirectToAction("Index"); }

                db.Connection.Close();

                return RedirectToAction("Index",Random.Equals(3,10));
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #2
0
        public ActionResult ChangePassword(string pwdCurrent, string pwdNew, string pwdRepeat)
        {
            if (Session["LoggedIn"] != null)
            {
               /*
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                var query = (from set1 in db.settings select set1).Single();
                query.lookup_time = int.Parse(set);
                db.SubmitChanges();
                db.Connection.Close();
                */
                if (pwdNew != pwdRepeat)
                {
                    return RedirectToAction("Index", "Settings",
                        new { message = "The passwords you entered did not match!", msgType = "error" });
                }

                if (pwdNew.Length < 6)
                {
                    return RedirectToAction("Index", "Settings",
                        new { message = "Please enter a password of minimum 6 characters!", msgType = "error" });
                }

                if (pwdNew.Length > 50)
                {
                    return RedirectToAction("Index", "Settings",
                        new { message = "The password is too long. Please enter a password that you can remember.", msgType = "error" });
                }

                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                var query = (from pass1 in db.users select pass1).Single();

                if (query.password != pwdCurrent)
                {
                    db.Connection.Close();

                    return RedirectToAction("Index", "Settings",
                            new { message = "Please enter the correct current password.", msgType = "error" });
                }

                query.password = pwdNew;
                db.SubmitChanges();
                db.Connection.Close();

                return RedirectToAction("Index", "Settings",
                        new { message = "The password was successfully changed.", msgType = "success" });
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #3
0
        //
        // GET: /Intrusions/
        public ActionResult Index(string order)
        {
            if (Session["LoggedIn"] != null)
            {
                ViewData["atPage"] = "intrusions";
                ViewData["Title"] = "SpaceLock - Intrusion Archive";

                SpaceLockLSDataContext db = new SpaceLockLSDataContext();
                int i=0,count;
                DateTime d;

                var query = from details in db.intrusions orderby details.int_id ascending select details;
                if (order == "1")
                {
                    ViewData["order"] = "0";
                    query = from details in db.intrusions orderby details.int_date select details;
                }
                else
                {
                    ViewData["order"] = "1";
                }

                count = query.ToList().Count;

                string[]    int_ids = new string[count],
                            int_dates = new string[count],
                            int_times = new string[count],
                            int_descs = new string[count];

                foreach (var detail in query)
                {
                    int_ids[i] = detail.int_id.ToString();
                    int_times[i] = detail.int_time.ToString();
                    int_descs[i] = Server.HtmlEncode(detail.int_desc.ToString());

                    d = DateTime.Parse(detail.int_date.ToString());
                    int_dates[i] = d.ToString("D").Split(',')[1] + d.ToString("D").Split(',')[2];
                    i++;
                }

                ViewData["int_ids"] = int_ids;
                ViewData["int_dates"] = int_dates;
                ViewData["int_times"] = int_times;
                ViewData["int_descs"] = int_descs;
                ViewData["int_count"] = i;
                db.Connection.Close();
                return View();
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #4
0
        //
        // GET: /Control/
        public ActionResult Index()
        {
            if (Session["LoggedIn"] != null)
            {
                ViewData["Title"] = "SpaceLock - Control";
                ViewData["atPage"] = "control";

                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                // Preset status
                var status = (from stat in db.camStatus select stat).Single();
                var presets = from pre in db.presets  orderby pre.pre_id descending select pre;
                try
                {
                    var preset_info = (from pres in db.presets
                                       where
                                           pres.pre_id == status.pre_id
                                       select pres).Single();

                    ViewData["current_preset"] = "<b>" + preset_info.pre_name + "</b>";
                }
                catch
                {
                    ViewData["current_preset"] = "<i>no preset loaded</i>";
                }

                ViewData["surveillance"] = status.surveillance;

                int count = presets.ToList().Count;
                int[] pre_ids = new int[count];
                string[] pre_names = new string[count];

                int  i = 0;
                foreach (var row in presets)
                {
                    pre_names[i] = row.pre_name;
                    pre_ids[i] = row.pre_id;
                    i++;
                }

                ViewData["pre_ids"] = pre_ids;
                ViewData["pre_names"] = pre_names;
                ViewData["pre_count"] = count;

                return View();
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #5
0
        public ActionResult Delete(string desc_id)
        {
            if (Session["LoggedIn"] != null)
            {
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();
                var query = (from details in db.intrusions where details.int_id == int.Parse(desc_id) select details).Single();

                db.intrusions.DeleteOnSubmit(query);
                db.SubmitChanges();
                db.Connection.Close();

                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #6
0
        //
        // GET: /Stream/
        public ActionResult Index()
        {
            string boundary = "----------1234567890";

            SpaceLockLSDataContext db = new SpaceLockLSDataContext();

            Response.Clear();
            Response.ContentType = "image/jpeg";

            var frames = (from f in db.Streams
                          select f).Single(); // sample the first 50 frames

            byte[] frame = frames.frame.ToArray();

            Response.BinaryWrite(frame);
            db.Connection.Close();
            return null;
        }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: ideamonk/SpaceLock
        /// <summary>
        /// Validates the user's attempt to login. Shows error messages accordingly
        /// </summary>
        /// <param name="txtUser">Username entered by the user</param>
        /// <param name="txtPass">Password entered by the user</param>
        /// <returns>An appropriate view depending on password</returns>
        public ActionResult DoLogin(string txtUser, string txtPass)
        {
            SpaceLockLSDataContext spacelockDC;
            try
            {
                // Try creating a Data Context
                spacelockDC = new SpaceLockLSDataContext();
            }
            catch
            {
                ViewData["message"] = "Failed to Connect to DB [DataContext failed]!";
                return View("ShowLogin");
            }

            var query =
                from user1 in spacelockDC.users where user1.username == txtUser select user1.password;

            if (query.ToList().Count == 1)
            {
                // There was some password stored for given username in the DB
                if (query.ToArray().Last() == txtPass)
                {
                    // Passwords match
                    Session.Timeout = 60;
                    Session["LoggedIn"] = "True";
                    spacelockDC.Connection.Close();

                    return RedirectToAction("Index");
                }
                else
                {
                    ViewData["message"] = "Wrong Username or Password!";
                }
            }
            else
            {
                // nothing was selected - invalid username
                ViewData["message"] = "Wrong Username or Password!";
            }

            spacelockDC.Connection.Close();
            return View("ShowLogin");
        }
コード例 #8
0
        //
        // GET: /Settings/
        public ActionResult Index(string message,string msgType)
        {
            if (Session["LoggedIn"] != null)
            {
                ViewData["Title"] = "SpaceLock - Settings";
                ViewData["atPage"] = "config";

                if (msgType == "error")
                    ViewData["error"] = message;
                else
                    ViewData["success"] = message;

                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                try
                {
                    var setting =
                        (from set1 in db.settings select set1).Single();

                    if (setting.int_tracking == 1)
                    {
                        ViewData["tracking"] = "on";
                        ViewData["_tracking"] = "off";
                    }
                    else
                    {
                        ViewData["tracking"] = "off";
                        ViewData["_tracking"] = "on";
                    }

                    if (setting.sms_alerts == 1)
                    {
                        ViewData["sms"] = "on";
                        ViewData["_sms"] = "off";
                    }
                    else
                    {
                        ViewData["sms"] = "off";
                        ViewData["_sms"] = "on";
                    }

                    ViewData["lookup"] = setting.lookup_time;
                    ViewData["maxarch"] = setting.archive_max;
                }
                catch
                {
                    ViewData["error"] = "Error retrieving SpaceLock settings";
                }

                db.Connection.Close();

                return View();
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #9
0
        public ActionResult Tracking(string set)
        {
            if (Session["LoggedIn"] != null)
            {
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                var query = (from set1 in db.settings select set1).Single();
                query.int_tracking = int.Parse(set);
                db.SubmitChanges();
                db.Connection.Close();

                return RedirectToAction("Index",Random.Equals(3,10));
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: ideamonk/SpaceLock
        /// <summary>
        /// Default Page for a visitor.
        /// </summary>
        /// <returns>To Login page if Session is not set, else takes them in.</returns>
        public ActionResult Index()
        {
            if (Session["LoggedIn"] != null)
            {
                ViewData["Title"] = "SpaceLock - Home";
                ViewData["atPage"] = "home";

                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                // Last 5 Intrusions
                int i = 0, count=5;
                DateTime d;

                var query = from details in db.intrusions orderby details.int_id descending select details;

                string[] int_ids = new string[count],
                            int_dates = new string[count],
                            int_times = new string[count],
                            int_descs = new string[count];

                foreach (var detail in query)
                {
                    int_ids[i] = detail.int_id.ToString();
                    int_times[i] = detail.int_time.ToString();
                    int_descs[i] = Server.HtmlEncode(detail.int_desc.ToString());

                    d = DateTime.Parse(detail.int_date.ToString());
                    int_dates[i] = d.ToString("D").Split(',')[1] + d.ToString("D").Split(',')[2];
                    i++;

                    if (i >= 5) break;
                }

                ViewData["int_ids"] = int_ids;
                ViewData["int_dates"] = int_dates;
                ViewData["int_times"] = int_times;
                ViewData["int_count"] = i;

                // Preset Status
                var status = (from stat in db.camStatus select stat).Single();
                try
                {
                    var preset_info = (from presets in db.presets
                                       where
                                           presets.pre_id == status.pre_id
                                       select presets).Single();

                    ViewData["current_preset"] = preset_info.pre_name;
                }
                catch
                {
                    ViewData["current_preset"] = "<i>no preset loaded</i>";
                }

                ViewData["uptime"] = status.uptime.ToString();

                d = DateTime.Parse(status.last_date.ToString());
                ViewData["last_date"] = d.ToString("D").Split(',')[1] + d.ToString("D").Split(',')[2];
                ViewData["last_time"] = status.last_time.ToString();
                ViewData["surveillance"] = status.surveillance;

                db.Connection.Close();

                return View();
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #11
0
        /// <summary>
        /// Stop the Surveillance
        /// </summary>
        public ActionResult Stop()
        {
            if (Session["LoggedIn"] != null)
            {
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                var query = (from status in db.camStatus select status).Single();
                query.surveillance = 0;
                db.SubmitChanges();
                db.Connection.Close();

                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #12
0
        public ActionResult Save(string preset_name)
        {
            if (Session["LoggedIn"] != null)
            {
                if (preset_name != null && preset_name.Length>0)
                {
                    SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                    var query = (from stat in db.camStatus
                                 select stat).Single();

                    preset mypreset = new preset
                    {
                        pre_name = preset_name,
                        cam_x = query.cam_x,
                        cam_y = query.cam_y,
                        cam_z = query.cam_z,
                    };

                    db.presets.InsertOnSubmit(mypreset);
                    db.SubmitChanges();
                    db.Connection.Close();
                }
                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }
コード例 #13
0
        /// <summary>
        /// Loads a predefined camera configuration
        /// </summary>
        public ActionResult Load(string preset_id)
        {
            if (Session["LoggedIn"] != null)
            {
                SpaceLockLSDataContext db = new SpaceLockLSDataContext();

                var query = (from status in db.camStatus select status).Single();
                query.pre_id = int.Parse(preset_id);
                db.SubmitChanges();
                db.Connection.Close();

                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("ShowLogin","Home");
            }
        }