Пример #1
0
        public void LoadForwardInfoList()
        {
            try
            {
                this.ForwardInfoList.Clear();

                foreach (string line in File.ReadAllLines(INFO_FILE, Encoding.GetEncoding(932)))
                {
                    string[] tokens = line.Split(',');

                    ForwardInfo fi = new ForwardInfo()
                    {
                        Started       = int.Parse(tokens[0]) != 0,
                        RecvPortNo    = Tools.Range(int.Parse(tokens[1]), 1, 65535),
                        ForwardPortNo = Tools.Range(int.Parse(tokens[2]), 1, 65535),
                        ForwardDomain = Tools.DomainFltr(tokens[3]),
                        ConnectMax    = Tools.Range(int.Parse(tokens[4]), 1, 500),
                        DecMode       = int.Parse(tokens[5]) != 0,
                        RawKey        = Tools.PassphraseFltr(tokens[6]),
                    };

                    this.ForwardInfoList.Add(fi);
                }
            }
            catch
            { }
        }
Пример #2
0
        private void Btn開始停止_Click(object sender, EventArgs e)
        {
            using (this.TimerOff.LocalIncrement())
            {
                int rowidx = this.GetMSSelectRowIndex();

                if (rowidx == -1)
                {
                    return;
                }

                ForwardInfo fi = Gnd.I.ForwardInfoList[rowidx];

                if (fi.Started == false && fi.ポートの重複有り())
                {
#if true
#if false
                    if (MessageBox.Show(
                            "ポート " + fi.RecvPortNo + " を使用しているフォワードがあります。\n" +
                            "続行すると当該フォワードを停止します。",
                            "ポート番号の重複",
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Warning,
                            MessageBoxDefaultButton.Button2
                            ) != DialogResult.OK
                        )
                    {
                        return;
                    }
#endif

                    foreach (ForwardInfo sFI in Gnd.I.ForwardInfoList)
                    {
                        if (sFI.RecvPortNo == fi.RecvPortNo)
                        {
                            sFI.Started = false;
                        }
                    }
#else
                    MessageBox.Show(
                        "ポート " + fi.RecvPortNo + " を使用しているフォワードがあります。",
                        "ポート番号の重複",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning
                        );
                    return;
#endif
                }
                fi.Started = fi.Started ? false : true;

                // 間違えて停止してしまった時の猶予期間、要らない気がする...
                if (fi.Started == false)
                {
                    this.FISleepCount = 5;
                }

                this.UpdateUi();
            }
        }
        public 何かを待つWin(ForwardInfo fi)
        {
            this.FI = fi;

            InitializeComponent();

            this.TimerOn = true;
        }
Пример #4
0
        private void Btn変更_Click(object sender, EventArgs e)
        {
            using (this.TimerOff.LocalIncrement())
            {
                int rowidx = this.GetMSSelectRowIndex();

                if (rowidx == -1)
                {
                    return;
                }

                ForwardInfo fi             = Gnd.I.ForwardInfoList[rowidx];
                bool        startFIStarted = fi.Started;

                using (Form f = new EditWin(fi))
                {
                    f.ShowDialog();
                }
                fi.停止チェック();

                fi.Started = startFIStarted;
                this.UpdateUi();
            }
        }
Пример #5
0
        public EditWin(ForwardInfo fi)
        {
            this.FI = fi;

            InitializeComponent();
        }
Пример #6
0
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            if (this.TimerOff.IsZero() == false)
            {
                return;
            }

            if (1 <= Gnd.I.シャットダウン_Count)
            {
                Gnd.I.シャットダウン_Count--;
                return;
            }
            using (this.TimerOff.LocalIncrement())
            {
                if (this.TimerCount % 2 == 0 && 0 < this.MinimizeCount)
                {
                    this.WindowState = FormWindowState.Minimized;
                    this.MinimizeCount--;
                }

                if (0 < this.WSSleepCount)
                {
                    this.WSSleepCount--;
                }
                else if (this.TimerCount % 20 == 0)
                {
                    if (this.WindowState == FormWindowState.Minimized)
                    {
                        this.Visible = false;
                        this.TaskTrayIcon.Visible = true;
                    }
                    else
                    {
                        this.Visible = true;
                        this.TaskTrayIcon.Visible = false;
                    }
                }

                if (0 < this.FISleepCount)
                {
                    this.FISleepCount--;
                }
                else
                {
                    int cycle = Math.Max(10, Gnd.I.ForwardInfoList.Count);
                    int index = (int)(this.TimerCount % (ulong)cycle);

                    if (index < Gnd.I.ForwardInfoList.Count)
                    {
                        ForwardInfo fi = Gnd.I.ForwardInfoList[index];

                        fi.巡回Proc();

                        if (fi.Modified)
                        {
                            fi.Modified = false;
#if true
                            try
                            {
                                this.MainSheet.Rows[index].Cells[(int)MSColumn_e.MSC_STARTED].Value = "停止(エラー)";
                            }
                            catch
                            { }
#else // 行数が多いと重すぎる。
                            this.UpdateUi();
#endif
                        }
                    }
                }

                if (this.TimerCount % 600 == 0)
                {
                    GC.Collect();
                }

                this.TimerCount++;
            }
        }
Пример #7
0
        private void UpdateUi()
        {
            this.StatusLabel.Text = "リスト更新中...";
            this.Refresh();

            try
            {
                using (new UISuspend(this.MainSheet))
                {
                    int lastSelectRowIndex = this.GetMSSelectRowIndex();

                    DataGridView ms = this.MainSheet;

                    if (ms.ColumnCount == 0)                     // ? 未初期化
                    {
                        lastSelectRowIndex = 0;

                        ms.RowCount    = 0;
                        ms.ColumnCount = 0;

                        //ms.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                        //ms.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

                        ms.DefaultCellStyle.Font = new Font("メイリオ", 10f);

                        this.MSAddColumn("状態");
                        this.MSAddColumn("待ち受けポート");
                        this.MSAddColumn("転送先ポート");
                        this.MSAddColumn("転送先ホスト名");
                        this.MSAddColumn("最大接続数");
                        this.MSAddColumn("暗号モード");
                        this.MSAddColumn("鍵");
                    }
                    if (Gnd.I.ForwardInfoList.Count < ms.RowCount)
                    {
                        ms.RowCount = Gnd.I.ForwardInfoList.Count;
                    }
                    ms.RowCount = Gnd.I.ForwardInfoList.Count;

                    for (int rowidx = 0; rowidx < Gnd.I.ForwardInfoList.Count; rowidx++)
                    {
                        ForwardInfo fi = Gnd.I.ForwardInfoList[rowidx];
                        //ms.Rows.Add();
                        DataGridViewRow r = ms.Rows[rowidx];

                        string cryptMode = "----";

                        if (fi.RawKey == "")
                        {
                            cryptMode = "なし";
                        }
                        else if (fi.DecMode)
                        {
                            cryptMode = "復号";
                        }
                        else
                        {
                            cryptMode = "暗号化";
                        }

                        r.Cells[(int)MSColumn_e.MSC_STARTED].Value        = fi.Started ? "開始" : "停止";
                        r.Cells[(int)MSColumn_e.MSC_RECV_PORT].Value      = fi.RecvPortNo;
                        r.Cells[(int)MSColumn_e.MSC_FORWARD_PORT].Value   = fi.ForwardPortNo;
                        r.Cells[(int)MSColumn_e.MSC_FORWARD_DOMAIN].Value = fi.ForwardDomain;
                        r.Cells[(int)MSColumn_e.MSC_CONNECT_MAX].Value    = fi.ConnectMax;
                        r.Cells[(int)MSColumn_e.MSC_CRYPT_MODE].Value     = cryptMode;
                        r.Cells[(int)MSColumn_e.MSC_RAWKEY].Value         = fi.RawKey;
                    }
                    ms.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

                    foreach (DataGridViewColumn c in ms.Columns)
                    {
                        c.Width += 20;
                    }
                    this.MSSelectRow(lastSelectRowIndex, false);
                }
            }
            finally
            {
                this.StatusLabel.Text = Gnd.I.STATUSLABEL_BLANK;
            }
        }