Esempio n. 1
0
        public void PersistSums()
        {
            Decimal uptime = GetUptime();

            ParentalControlsRegistry.IncrementKey("DaySum", uptime);
            ParentalControlsRegistry.IncrementKey("WeekSum", uptime);
            if (!Utils.IsWeekDay())
            {
                ParentalControlsRegistry.IncrementKey("WeekEndSum", uptime);
            }
        }
        public CredentialEditor()
        {
            InitializeComponent();

            Console.WriteLine("Path: {0}", ParentalControlsRegistry.GetRegistryKey(true).GetValue("Path").ToString() + @"\" + MainForm.CREDENTIALS_FILE);

            file = ParentalControlsCredentialsFile.Load(ParentalControlsRegistry.GetRegistryKey(true).GetValue("Path").ToString() + @"\" + MainForm.CREDENTIALS_FILE);

            foreach (ParentalControlsCredential cred in file.ParentalControlsCredentials)
            {
                comboBox1.Items.Add(cred);
            }

            foreach (Control c in groupBox1.Controls)
            {
                c.Enabled = false;
            }
        }
Esempio n. 3
0
        private void init()
        {
            try
            {
                DateTime now = DateTime.Now;
                Thread.Sleep(10000);
                ParentalControlsRegistry.SetValue("DayQuota", Properties.Settings.Default.TagesKontingent);
                ParentalControlsRegistry.SetValue("WeekQuota", Properties.Settings.Default.WochenKontingent);
                ParentalControlsRegistry.SetValue("WeekEndQuota", Properties.Settings.Default.WochenendKontingent);

                Utils.log.Debug("Diese Woche verbraucht:   " + ParentalControlsRegistry.GetValue("WeekSum"));
                Utils.log.Debug("Heute verbraucht:         " + ParentalControlsRegistry.GetValue("DaySum"));
                if (!Utils.IsWeekDay())
                {
                    Utils.log.Debug("Am Wochenende verbraucht: " + ParentalControlsRegistry.GetValue("WeekEndSum"));
                }

                if (Utils.FirstRunThisDay())
                {
                    ParentalControlsRegistry.SetValue("LastStart", now);
                    ParentalControlsRegistry.SetValue("DaySum", "0,00");
                    if (now.DayOfWeek == DayOfWeek.Monday)
                    {
                        ParentalControlsRegistry.SetValue("WeekSum", "0,00");
                    }
                    else if (now.DayOfWeek == DayOfWeek.Saturday)
                    {
                        ParentalControlsRegistry.SetValue("WeekEndSum", "0,00");
                    }
                }

                _thread              = new Thread(WorkerThreadFunc);
                _thread.Name         = "ParentalControls.Worker";
                _thread.IsBackground = true;
                _thread.Start();
            }
            catch (Exception e)
            {
                Utils.log.Error(e.Message + "\n" + e.StackTrace);
            }
        }
Esempio n. 4
0
        void WorkerThreadFunc()
        {
            try
            {
                /*AlarmsFile file = new AlarmsFile();
                 * file.FileName = (string)ParentalControlsRegistry.GetValue("AlarmFile");
                 * file.Add(new Alarm("Std", new Time(16, 15), DayOfWeek.Sunday, true));
                 * file.Save();*/
                while (!_shutdownEvent.WaitOne(0))
                {
                    decimal uptime = GetUptime();

                    //alle 5 Minuten (1/60*5*100 = 83)
                    if (uptime > 0 && Convert.ToInt32(uptime * 100) % 83 == 0)
                    {
                        Utils.log.Debug("Restzeit Heute:           " + Utils.RestZeit(Utils.Span.Day, uptime));
                        Utils.log.Debug("Restzeit Woche:           " + Utils.RestZeit(Utils.Span.Week, uptime));
                        if (!Utils.IsWeekDay())
                        {
                            Utils.log.Debug("Restzeit Wochenende:      " + Utils.RestZeit(Utils.Span.WeekEnd, uptime));
                        }
                    }
                    string data = "";
                    callback.ExchangeData(data);

                    Utils.log.Debug("Aktives Fenster: " + m_ActiveWndTitle);

                    if (!Utils.BeforeSchoolDay() &&
                        DateTime.Now >= DateTime.Parse(DateTime.Now.ToString("dd.MM.yyyy ") + Properties.Settings.Default.FeierabendWochenEnde))
                    {
                        shutdown("After " + Properties.Settings.Default.FeierabendWochenEnde);
                        return;
                    }
                    else if (Utils.BeforeSchoolDay() &&
                             DateTime.Now >= DateTime.Parse(DateTime.Now.ToString("dd.MM.yyyy ") + Properties.Settings.Default.FeierabendWochenTag))
                    {
                        shutdown("After " + Properties.Settings.Default.FeierabendWochenTag);
                        return;
                    }

                    if (Utils.IsWeekDay() &&
                        Convert.ToDecimal(ParentalControlsRegistry.GetValue("DaySum")) + uptime >
                        Convert.ToDecimal(ParentalControlsRegistry.GetValue("DayQuota")))
                    {
                        shutdown("DaySum > " + ParentalControlsRegistry.GetValue("DayQuota"));
                        return;
                    }
                    else if (!Utils.IsWeekDay() &&
                             Convert.ToDecimal(ParentalControlsRegistry.GetValue("WeekEndQuota", "-1")) > 0 &&
                             Convert.ToDecimal(ParentalControlsRegistry.GetValue("WeekEndSum")) + uptime >
                             Convert.ToDecimal(ParentalControlsRegistry.GetValue("WeekEndQuota")))
                    {
                        shutdown("WeekEndSum > " + ParentalControlsRegistry.GetValue("WeekEndQuota"));
                        return;
                    }
                    else if (Convert.ToDecimal(ParentalControlsRegistry.GetValue("WeekSum")) + uptime >
                             Convert.ToDecimal(ParentalControlsRegistry.GetValue("WeekQuota")))
                    {
                        shutdown("WeekSum > " + ParentalControlsRegistry.GetValue("WeekQuota"));
                        return;
                    }

                    /*if (file.IsValidForSaving())
                     * {
                     *  foreach (Alarm alarm in file.Alarms)
                     *  {
                     *      if (alarm.RepeatDays.HasFlag(Utils.GetCurrentDay()) && IsTimeToAlarm(alarm))
                     *      {
                     *          if (ShowBlocker())
                     *          {
                     *              Time a = GetCurrentTime();
                     *              Console.WriteLine("The Alarm Blocker showed at {0}:{1} {2}.", a.Hour, a.Minutes, (a.Hour > 12 ? "PM" : "AM"));
                     *          }
                     *      }
                     *  }
                     * }*/
                    Thread.Sleep(waitTime);
                }
            }
            catch (Exception e)
            {
                Utils.log.Debug(e.Message);
            }
        }
Esempio n. 5
0
        bool ShowBlocker()
        {
            Process p = Process.Start(ParentalControlsRegistry.GetRegistryKey(true).GetValue("Path") + @"\ParentalControls.GUI.exe");

            return(p.Start());
        }
Esempio n. 6
0
        public void FirstInstall()
        {
            Enable(false);
            RegistryKey reg = ParentalControlsRegistry.GetRegistryKey();

            reg.SetValue("Path", Application.StartupPath, RegistryValueKind.String);
            reg.SetValue("AlarmFile", Application.StartupPath + @"\" + ALARMS_FILE);

            TaskDialog dialog = new TaskDialog();

            dialog.Caption         = Application.ProductName + " Setup";
            dialog.InstructionText = Application.ProductName + " is mostly setup!";
            dialog.Text            = "What you need to do is setup a password for any cases that you need to force close an alarm.";

            TaskDialogButton button = new TaskDialogButton("btnOne", "Continue");

            button.Click += (aa, ab) =>
            {
                TaskDialogButton tdb = (TaskDialogButton)aa;
                ((TaskDialog)tdb.HostingDialog).Close(TaskDialogResult.Ok);

                if (file2.ParentalControlsCredentials.Count > 0)
                {
                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text            = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();

                    return;
                }

                NetworkCredential cred = null;
                WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm.", out cred);
                while (cred == null || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                {
                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm. (Credentials must not be empty)", out cred);
                }
                ParentalControlsCredential c;
                try
                {
                    c = (ParentalControlsCredential)cred;
                    c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    file2.Add(c);
                    file2.Save();
                }
                catch {  }
                TaskDialog ndialog = new TaskDialog();
                ndialog.Caption         = Application.ProductName + " Setup";
                ndialog.InstructionText = "Want to test your credentials?";
                ndialog.FooterText      = "Fun Fact: You can create as many accounts as you want!";
                ndialog.FooterIcon      = TaskDialogStandardIcon.Information;

                TaskDialogCommandLink linka = new TaskDialogCommandLink("linkA", "Test Credentials");

                linka.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.Yes);

                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                    c = new ParentalControlsCredential();
                    try
                    {
                        c = (ParentalControlsCredential)cred;
                        c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    }
                    catch { }

                    bool wevalidated = true;

                    while (cred == null || !file2.Validate(c) || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                    {
                        TaskDialog ddialog = new TaskDialog();

                        ddialog.InstructionText = "Credentials Invalid";
                        ddialog.Text            = "You want to stop testing credentials?";

                        ddialog.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;

                        if (ddialog.Show() == TaskDialogResult.Yes)
                        {
                            wevalidated = false;
                            break;
                        }
                        else
                        {
                            WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                        }
                    }
                    TaskDialog dadialog = new TaskDialog();
                    if (wevalidated)
                    {
                        dadialog.InstructionText = "Credentials Valid!";
                    }
                    else
                    {
                        dadialog.InstructionText = "Setup Complete!";
                    }
                    dadialog.Text = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                TaskDialogCommandLink linkb = new TaskDialogCommandLink("linkB", "Skip Test");

                linkb.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.No);

                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text            = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                ndialog.Controls.Add(linka);
                ndialog.Controls.Add(linkb);

                ndialog.Show();
                file2.Save();
            };
            dialog.Controls.Add(button);

            dialog.Show();
            Enable(true);
            // Kind of an hacky way of making this window get focused after showing dialogs.
            SwitchToSelf();
        }