From c086933c3f49ae87e56822699f97a54c7c54ba52 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sun, 17 Sep 2017 21:01:21 -0400 Subject: [PATCH 1/3] Modifying the remote access port --- TGCommandLine/AdminCommands.cs | 59 +++- TGCommandLine/Program.cs | 52 ++- TGControlPanel/App.config | 3 + TGControlPanel/Login.Designer.cs | 309 ++++++++++-------- TGControlPanel/Login.cs | 8 +- .../Properties/Settings.Designer.cs | 14 +- TGControlPanel/Properties/Settings.settings | 3 + TGServerService/Administration.cs | 18 +- TGServerService/App.config | 3 + .../Properties/Settings.Designer.cs | 14 +- TGServerService/Properties/Settings.settings | 3 + TGServerService/ServerService.cs | 2 +- TGServiceInterface/Administration.cs | 16 + TGServiceInterface/Server.cs | 13 +- TGServiceInterface/Service.cs | 3 +- 15 files changed, 349 insertions(+), 171 deletions(-) diff --git a/TGCommandLine/AdminCommands.cs b/TGCommandLine/AdminCommands.cs index 83d6eb4575..95c5de9056 100644 --- a/TGCommandLine/AdminCommands.cs +++ b/TGCommandLine/AdminCommands.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using TGServiceInterface; namespace TGCommandLine @@ -8,7 +9,7 @@ namespace TGCommandLine public AdminCommand() { Keyword = "admin"; - Children = new Command[] { new AdminViewGroupCommand(), new AdminSetGroupCommand(), new AdminClearGroupCommand() }; + Children = new Command[] { new AdminViewGroupCommand(), new AdminSetGroupCommand(), new AdminClearGroupCommand(), new AdminViewPortCommand(), new AdminSetPortCommand() }; } public override string GetHelpText() { @@ -16,6 +17,60 @@ namespace TGCommandLine } } + + class AdminSetPortCommand : Command + { + public AdminSetPortCommand() + { + Keyword = "set-port"; + RequiredParameters = 1; + } + public override string GetHelpText() + { + return "Set the port used for remote access. Requires a service restart to take effect"; + } + + public override string GetArgumentString() + { + return ""; + } + + protected override ExitCode Run(IList parameters) + { + ushort port; + try + { + port = Convert.ToUInt16(parameters[0]); + } + catch + { + OutputProc("Invalid port number!"); + return ExitCode.BadCommand; + } + var res = Server.GetComponent().SetRemoteAccessPort(port); + OutputProc(res ?? "Success!"); + return ExitCode.Normal; + } + } + + class AdminViewPortCommand : Command { + public AdminViewPortCommand() + { + Keyword = "view-port"; + } + public override string GetHelpText() + { + return "Print the port currently designated for remote access"; + } + + protected override ExitCode Run(IList parameters) + { + var port = Server.GetComponent().RemoteAccessPort(); + OutputProc(String.Format("{0}", port)); + return ExitCode.Normal; + } + } + class AdminViewGroupCommand : Command { public AdminViewGroupCommand() diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index 42370f1a49..0af883b430 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -23,10 +23,26 @@ namespace TGCommandLine { badConnectionString = true; break; - } - var username = userpass[0]; + } + var addrport = splits[1].Split(':'); + if (addrport.Length != 2) + { + badConnectionString = true; + break; + } + var username = userpass[0]; var password = userpass[1]; - var address = splits[1]; + var address = addrport[0]; + ushort port; + try + { + port = Convert.ToUInt16(addrport[1]); + } + catch + { + badConnectionString = true; + break; + } if(String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password) || String.IsNullOrWhiteSpace(address)) { badConnectionString = true; @@ -34,14 +50,14 @@ namespace TGCommandLine } argsAsList.RemoveAt(I); argsAsList.RemoveAt(I); - Server.SetRemoteLoginInformation(address, username, password); + Server.SetRemoteLoginInformation(address, port, username, password); break; } } if (badConnectionString) { - Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address"); + Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); return ExitCode.BadCommand; } @@ -49,7 +65,7 @@ namespace TGCommandLine if (res != null) { Console.WriteLine("Unable to connect to service: " + res); - Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address"); + Console.WriteLine("Remote connection usage: <-c/--connect> username:password@address:port"); return ExitCode.ConnectionError; } @@ -112,23 +128,33 @@ namespace TGCommandLine switch (NextCommand.ToLower()) { case "remote": - Console.Write("Enter server address: "); - var address = Console.ReadLine(); - Console.Write("Enter username: "); + Console.Write("Enter server address: "); + var address = Console.ReadLine(); + Console.Write("Enter server port: "); + ushort port; + try{ + port = Convert.ToUInt16(Console.ReadLine()); + } + catch + { + Console.WriteLine("Error: Bad port!"); + break; + } + Console.Write("Enter username: "); var username = Console.ReadLine(); Console.Write("Enter password: "); var password = ReadLineSecure(); - Server.SetRemoteLoginInformation(address, username, password); + Server.SetRemoteLoginInformation(address, port, username, password); var res = Server.VerifyConnection(); if (res != null) { Console.WriteLine("Unable to connect: " + res); - Server.SetRemoteLoginInformation(null, null, null); + Server.SetRemoteLoginInformation(null, 0, null, null); } else if (!Server.Authenticate()) { Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode..."); - Server.SetRemoteLoginInformation(null, null, null); + Server.SetRemoteLoginInformation(null, 0, null, null); } else { @@ -137,7 +163,7 @@ namespace TGCommandLine } break; case "disconnect": - Server.SetRemoteLoginInformation(null, null, null); + Server.SetRemoteLoginInformation(null, 0, null, null); Console.WriteLine("Switch to local mode"); break; case "quit": diff --git a/TGControlPanel/App.config b/TGControlPanel/App.config index 0eb965cdae..c486f0c3e1 100644 --- a/TGControlPanel/App.config +++ b/TGControlPanel/App.config @@ -32,6 +32,9 @@ + + 38607 + diff --git a/TGControlPanel/Login.Designer.cs b/TGControlPanel/Login.Designer.cs index 649631a6dd..485478d958 100644 --- a/TGControlPanel/Login.Designer.cs +++ b/TGControlPanel/Login.Designer.cs @@ -28,146 +28,172 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Login)); - this.LocalLoginButton = new System.Windows.Forms.Button(); - this.CurrentRevisionTitle = new System.Windows.Forms.Label(); - this.IPTextBox = new System.Windows.Forms.TextBox(); - this.UsernameTextBox = new System.Windows.Forms.TextBox(); - this.PasswordTextBox = new System.Windows.Forms.TextBox(); - this.RemoteLoginButton = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // LocalLoginButton - // - this.LocalLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.LocalLoginButton.Location = new System.Drawing.Point(51, 12); - this.LocalLoginButton.Name = "LocalLoginButton"; - this.LocalLoginButton.Size = new System.Drawing.Size(188, 25); - this.LocalLoginButton.TabIndex = 13; - this.LocalLoginButton.Text = "Connect to Local Service"; - this.LocalLoginButton.UseVisualStyleBackColor = true; - this.LocalLoginButton.Click += new System.EventHandler(this.LocalLoginButton_Click); - // - // CurrentRevisionTitle - // - this.CurrentRevisionTitle.AutoSize = true; - this.CurrentRevisionTitle.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CurrentRevisionTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); - this.CurrentRevisionTitle.Location = new System.Drawing.Point(81, 76); - this.CurrentRevisionTitle.Name = "CurrentRevisionTitle"; - this.CurrentRevisionTitle.Size = new System.Drawing.Size(128, 18); - this.CurrentRevisionTitle.TabIndex = 14; - this.CurrentRevisionTitle.Text = "Remote Login:"; - this.CurrentRevisionTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // IPTextBox - // - this.IPTextBox.Location = new System.Drawing.Point(73, 97); - this.IPTextBox.Name = "IPTextBox"; - this.IPTextBox.Size = new System.Drawing.Size(199, 20); - this.IPTextBox.TabIndex = 15; - // - // UsernameTextBox - // - this.UsernameTextBox.Location = new System.Drawing.Point(73, 130); - this.UsernameTextBox.Name = "UsernameTextBox"; - this.UsernameTextBox.Size = new System.Drawing.Size(199, 20); - this.UsernameTextBox.TabIndex = 16; - // - // PasswordTextBox - // - this.PasswordTextBox.Location = new System.Drawing.Point(73, 162); - this.PasswordTextBox.Name = "PasswordTextBox"; - this.PasswordTextBox.Size = new System.Drawing.Size(199, 20); - this.PasswordTextBox.TabIndex = 17; - this.PasswordTextBox.UseSystemPasswordChar = true; - // - // RemoteLoginButton - // - this.RemoteLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.RemoteLoginButton.Location = new System.Drawing.Point(51, 197); - this.RemoteLoginButton.Name = "RemoteLoginButton"; - this.RemoteLoginButton.Size = new System.Drawing.Size(188, 25); - this.RemoteLoginButton.TabIndex = 18; - this.RemoteLoginButton.Text = "Connect to Remote Service"; - this.RemoteLoginButton.UseVisualStyleBackColor = true; - this.RemoteLoginButton.Click += new System.EventHandler(this.RemoteLoginButton_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); - this.label1.Location = new System.Drawing.Point(9, 99); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(32, 18); - this.label1.TabIndex = 19; - this.label1.Text = "IP:"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); - this.label2.Location = new System.Drawing.Point(9, 132); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(52, 18); - this.label2.TabIndex = 20; - this.label2.Text = "User:"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); - this.label3.Location = new System.Drawing.Point(9, 164); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(53, 18); - this.label3.TabIndex = 21; - this.label3.Text = "Pass:"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); - this.label4.Location = new System.Drawing.Point(-19, 40); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(468, 18); - this.label4.TabIndex = 22; - this.label4.Text = "______________________________________________"; - this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // Login - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34))))); - this.ClientSize = new System.Drawing.Size(284, 237); - this.Controls.Add(this.label4); - this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Controls.Add(this.RemoteLoginButton); - this.Controls.Add(this.PasswordTextBox); - this.Controls.Add(this.UsernameTextBox); - this.Controls.Add(this.IPTextBox); - this.Controls.Add(this.CurrentRevisionTitle); - this.Controls.Add(this.LocalLoginButton); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.Name = "Login"; - this.Text = "Login"; - this.ResumeLayout(false); - this.PerformLayout(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Login)); + this.LocalLoginButton = new System.Windows.Forms.Button(); + this.CurrentRevisionTitle = new System.Windows.Forms.Label(); + this.IPTextBox = new System.Windows.Forms.TextBox(); + this.UsernameTextBox = new System.Windows.Forms.TextBox(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.RemoteLoginButton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.PortSelector = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.PortSelector)).BeginInit(); + this.SuspendLayout(); + // + // LocalLoginButton + // + this.LocalLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LocalLoginButton.Location = new System.Drawing.Point(87, 12); + this.LocalLoginButton.Name = "LocalLoginButton"; + this.LocalLoginButton.Size = new System.Drawing.Size(188, 25); + this.LocalLoginButton.TabIndex = 13; + this.LocalLoginButton.Text = "Connect to Local Service"; + this.LocalLoginButton.UseVisualStyleBackColor = true; + this.LocalLoginButton.Click += new System.EventHandler(this.LocalLoginButton_Click); + // + // CurrentRevisionTitle + // + this.CurrentRevisionTitle.AutoSize = true; + this.CurrentRevisionTitle.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.CurrentRevisionTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.CurrentRevisionTitle.Location = new System.Drawing.Point(116, 69); + this.CurrentRevisionTitle.Name = "CurrentRevisionTitle"; + this.CurrentRevisionTitle.Size = new System.Drawing.Size(128, 18); + this.CurrentRevisionTitle.TabIndex = 14; + this.CurrentRevisionTitle.Text = "Remote Login:"; + this.CurrentRevisionTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // IPTextBox + // + this.IPTextBox.Location = new System.Drawing.Point(129, 99); + this.IPTextBox.Name = "IPTextBox"; + this.IPTextBox.Size = new System.Drawing.Size(146, 20); + this.IPTextBox.TabIndex = 15; + // + // UsernameTextBox + // + this.UsernameTextBox.Location = new System.Drawing.Point(129, 132); + this.UsernameTextBox.Name = "UsernameTextBox"; + this.UsernameTextBox.Size = new System.Drawing.Size(233, 20); + this.UsernameTextBox.TabIndex = 16; + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(129, 164); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(233, 20); + this.PasswordTextBox.TabIndex = 17; + this.PasswordTextBox.UseSystemPasswordChar = true; + // + // RemoteLoginButton + // + this.RemoteLoginButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.RemoteLoginButton.Location = new System.Drawing.Point(87, 200); + this.RemoteLoginButton.Name = "RemoteLoginButton"; + this.RemoteLoginButton.Size = new System.Drawing.Size(188, 25); + this.RemoteLoginButton.TabIndex = 18; + this.RemoteLoginButton.Text = "Connect to Remote Service"; + this.RemoteLoginButton.UseVisualStyleBackColor = true; + this.RemoteLoginButton.Click += new System.EventHandler(this.RemoteLoginButton_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.label1.Location = new System.Drawing.Point(9, 99); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(120, 18); + this.label1.TabIndex = 19; + this.label1.Text = "Address/Port:"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.label2.Location = new System.Drawing.Point(9, 132); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(97, 18); + this.label2.TabIndex = 20; + this.label2.Text = "Username:"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.label3.Location = new System.Drawing.Point(9, 164); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(92, 18); + this.label3.TabIndex = 21; + this.label3.Text = "Password:"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.label4.Location = new System.Drawing.Point(-19, 40); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(468, 18); + this.label4.TabIndex = 22; + this.label4.Text = "______________________________________________"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // PortSelector + // + this.PortSelector.Location = new System.Drawing.Point(282, 99); + this.PortSelector.Maximum = new decimal(new int[] { + 65535, + 0, + 0, + 0}); + this.PortSelector.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.PortSelector.Name = "PortSelector"; + this.PortSelector.Size = new System.Drawing.Size(80, 20); + this.PortSelector.TabIndex = 23; + this.PortSelector.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + // + // Login + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34))))); + this.ClientSize = new System.Drawing.Size(374, 237); + this.Controls.Add(this.PortSelector); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.RemoteLoginButton); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.UsernameTextBox); + this.Controls.Add(this.IPTextBox); + this.Controls.Add(this.CurrentRevisionTitle); + this.Controls.Add(this.LocalLoginButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.Name = "Login"; + this.Text = "Login"; + ((System.ComponentModel.ISupportInitialize)(this.PortSelector)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -183,5 +209,6 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; - } + private System.Windows.Forms.NumericUpDown PortSelector; + } } \ No newline at end of file diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs index b99c41e37a..0daba18361 100644 --- a/TGControlPanel/Login.cs +++ b/TGControlPanel/Login.cs @@ -10,7 +10,9 @@ namespace TGControlPanel { InitializeComponent(); IPTextBox.Text = Properties.Settings.Default.RemoteIP; - UsernameTextBox.Text = Properties.Settings.Default.RemoteUsername; + var Config = Properties.Settings.Default; + UsernameTextBox.Text = Config.RemoteUsername; + PortSelector.Value = Config.RemotePort; AcceptButton = RemoteLoginButton; } @@ -18,7 +20,7 @@ namespace TGControlPanel { IPTextBox.Text = IPTextBox.Text.Trim(); UsernameTextBox.Text = UsernameTextBox.Text.Trim(); - Server.SetRemoteLoginInformation(IPTextBox.Text, UsernameTextBox.Text, PasswordTextBox.Text); + Server.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text); Properties.Settings.Default.RemoteIP = IPTextBox.Text; Properties.Settings.Default.RemoteUsername = UsernameTextBox.Text; VerifyAndConnect(); @@ -26,7 +28,7 @@ namespace TGControlPanel private void LocalLoginButton_Click(object sender, EventArgs e) { - Server.SetRemoteLoginInformation(null, null, null); + Server.SetRemoteLoginInformation(null, 0, null, null); VerifyAndConnect(); } diff --git a/TGControlPanel/Properties/Settings.Designer.cs b/TGControlPanel/Properties/Settings.Designer.cs index 9581b39651..0374631b7f 100644 --- a/TGControlPanel/Properties/Settings.Designer.cs +++ b/TGControlPanel/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace TGControlPanel.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -94,5 +94,17 @@ namespace TGControlPanel.Properties { this["RemoteUsername"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("38607")] + public ushort RemotePort { + get { + return ((ushort)(this["RemotePort"])); + } + set { + this["RemotePort"] = value; + } + } } } diff --git a/TGControlPanel/Properties/Settings.settings b/TGControlPanel/Properties/Settings.settings index 3ac96ea940..1e46d94a5a 100644 --- a/TGControlPanel/Properties/Settings.settings +++ b/TGControlPanel/Properties/Settings.settings @@ -20,5 +20,8 @@ + + 38607 + \ No newline at end of file diff --git a/TGServerService/Administration.cs b/TGServerService/Administration.cs index 0f207197e8..9725c37342 100644 --- a/TGServerService/Administration.cs +++ b/TGServerService/Administration.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.DirectoryServices.AccountManagement; using System.Security.Principal; using System.ServiceModel; @@ -109,5 +108,22 @@ namespace TGServerService TGServerService.WriteAccess(operationContext.ServiceSecurityContext.WindowsIdentity.Name, authSuccess); return authSuccess; } + + /// + public ushort RemoteAccessPort() + { + return Properties.Settings.Default.RemoteAccessPort; + } + + /// + public string SetRemoteAccessPort(ushort port) + { + if (port == 0) + return "Cannot bind to port 0"; + var Config = Properties.Settings.Default; + Config.RemoteAccessPort = port; + Config.Save(); + return null; + } } } diff --git a/TGServerService/App.config b/TGServerService/App.config index 152806066e..bec61fd243 100644 --- a/TGServerService/App.config +++ b/TGServerService/App.config @@ -70,6 +70,9 @@ + + 38607 + diff --git a/TGServerService/Properties/Settings.Designer.cs b/TGServerService/Properties/Settings.Designer.cs index 0cdb11a2cc..6da7d8aac3 100644 --- a/TGServerService/Properties/Settings.Designer.cs +++ b/TGServerService/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace TGServerService.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -262,5 +262,17 @@ namespace TGServerService.Properties { this["AuthorizedGroupSID"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("38607")] + public ushort RemoteAccessPort { + get { + return ((ushort)(this["RemoteAccessPort"])); + } + set { + this["RemoteAccessPort"] = value; + } + } } } diff --git a/TGServerService/Properties/Settings.settings b/TGServerService/Properties/Settings.settings index c0a4589eb8..d58f11cb97 100644 --- a/TGServerService/Properties/Settings.settings +++ b/TGServerService/Properties/Settings.settings @@ -62,5 +62,8 @@ + + 38607 + \ No newline at end of file diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 42ae713c5c..55ffe3c4dc 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -151,7 +151,7 @@ namespace TGServerService var instance = new TGStationServer(); - host = new ServiceHost(instance, new Uri[] { new Uri("net.pipe://localhost"), new Uri(String.Format("https://localhost:{0}", Server.HTTPSPort)) }) + host = new ServiceHost(instance, new Uri[] { new Uri("net.pipe://localhost"), new Uri(String.Format("https://localhost:{0}", Config.RemoteAccessPort)) }) { CloseTimeout = new TimeSpan(0, 0, 5) }; diff --git a/TGServiceInterface/Administration.cs b/TGServiceInterface/Administration.cs index 483e8dfb03..527acc5479 100644 --- a/TGServiceInterface/Administration.cs +++ b/TGServiceInterface/Administration.cs @@ -8,6 +8,22 @@ namespace TGServiceInterface [ServiceContract] public interface ITGAdministration { + /// + /// Get the port used for remote operation + /// + /// The port used for remote operation + [OperationContract] + ushort RemoteAccessPort(); + + /// + /// Set the port used for remote operation + /// Requires a service restart to take effect + /// + /// The new port to use for remote operation + /// null on success, error message on failure + [OperationContract] + string SetRemoteAccessPort(ushort port); + /// /// Returns the name of the windows group allowed to use the service other than administrator /// diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 4fa3733f22..6aca1d6dab 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -25,7 +25,7 @@ namespace TGServiceInterface /// /// The port used by the service /// - public const ushort HTTPSPort = 38607; + static ushort HTTPSPort = 38607; /// /// Username for remote operations @@ -50,9 +50,10 @@ namespace TGServiceInterface /// /// /// - public static void SetRemoteLoginInformation(string address, string username, string password) + public static void SetRemoteLoginInformation(string address, ushort port, string username, string password) { HTTPSURL = address; + HTTPSPort = port; HTTPSUsername = username; HTTPSPassword = password; } @@ -62,14 +63,14 @@ namespace TGServiceInterface /// /// The type of the component to retrieve /// - public static T GetComponent() - { + public static T GetComponent() + { var ToT = typeof(T); if (!ValidInterfaces.Contains(ToT)) throw new Exception("Invalid type!"); var InterfaceName = typeof(T).Name; - if (HTTPSURL == null) - return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel(); + if (HTTPSURL == null) + return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel(); //okay we're going over var binding = new WSHttpBinding(); diff --git a/TGServiceInterface/Service.cs b/TGServiceInterface/Service.cs index 0e955a27a8..4ccaa040bc 100644 --- a/TGServiceInterface/Service.cs +++ b/TGServiceInterface/Service.cs @@ -1,5 +1,4 @@ -using System; -using System.ServiceModel; +using System.ServiceModel; namespace TGServiceInterface { From f465bb875b457420e73e0149ca136e129fa813b2 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sun, 17 Sep 2017 21:04:13 -0400 Subject: [PATCH 2/3] Fix tabbing --- TGCommandLine/Program.cs | 62 ++++++++++++++-------------- TGControlPanel/Login.cs | 6 +-- TGServerService/Administration.cs | 20 ++++----- TGServerService/ServerService.cs | 2 +- TGServiceInterface/Administration.cs | 24 +++++------ TGServiceInterface/Server.cs | 10 ++--- 6 files changed, 62 insertions(+), 62 deletions(-) diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index 0af883b430..6c1e5f9aef 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -23,26 +23,26 @@ namespace TGCommandLine { badConnectionString = true; break; - } - var addrport = splits[1].Split(':'); - if (addrport.Length != 2) - { - badConnectionString = true; - break; - } - var username = userpass[0]; + } + var addrport = splits[1].Split(':'); + if (addrport.Length != 2) + { + badConnectionString = true; + break; + } + var username = userpass[0]; var password = userpass[1]; var address = addrport[0]; - ushort port; - try - { - port = Convert.ToUInt16(addrport[1]); - } - catch - { - badConnectionString = true; - break; - } + ushort port; + try + { + port = Convert.ToUInt16(addrport[1]); + } + catch + { + badConnectionString = true; + break; + } if(String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password) || String.IsNullOrWhiteSpace(address)) { badConnectionString = true; @@ -128,19 +128,19 @@ namespace TGCommandLine switch (NextCommand.ToLower()) { case "remote": - Console.Write("Enter server address: "); - var address = Console.ReadLine(); - Console.Write("Enter server port: "); - ushort port; - try{ - port = Convert.ToUInt16(Console.ReadLine()); - } - catch - { - Console.WriteLine("Error: Bad port!"); - break; - } - Console.Write("Enter username: "); + Console.Write("Enter server address: "); + var address = Console.ReadLine(); + Console.Write("Enter server port: "); + ushort port; + try{ + port = Convert.ToUInt16(Console.ReadLine()); + } + catch + { + Console.WriteLine("Error: Bad port!"); + break; + } + Console.Write("Enter username: "); var username = Console.ReadLine(); Console.Write("Enter password: "); var password = ReadLineSecure(); diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs index 0daba18361..d37e5a6c8b 100644 --- a/TGControlPanel/Login.cs +++ b/TGControlPanel/Login.cs @@ -10,9 +10,9 @@ namespace TGControlPanel { InitializeComponent(); IPTextBox.Text = Properties.Settings.Default.RemoteIP; - var Config = Properties.Settings.Default; - UsernameTextBox.Text = Config.RemoteUsername; - PortSelector.Value = Config.RemotePort; + var Config = Properties.Settings.Default; + UsernameTextBox.Text = Config.RemoteUsername; + PortSelector.Value = Config.RemotePort; AcceptButton = RemoteLoginButton; } diff --git a/TGServerService/Administration.cs b/TGServerService/Administration.cs index 9725c37342..844cf61c36 100644 --- a/TGServerService/Administration.cs +++ b/TGServerService/Administration.cs @@ -115,15 +115,15 @@ namespace TGServerService return Properties.Settings.Default.RemoteAccessPort; } - /// - public string SetRemoteAccessPort(ushort port) - { - if (port == 0) - return "Cannot bind to port 0"; - var Config = Properties.Settings.Default; - Config.RemoteAccessPort = port; - Config.Save(); - return null; - } + /// + public string SetRemoteAccessPort(ushort port) + { + if (port == 0) + return "Cannot bind to port 0"; + var Config = Properties.Settings.Default; + Config.RemoteAccessPort = port; + Config.Save(); + return null; + } } } diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 55ffe3c4dc..1191daeae6 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -109,7 +109,7 @@ namespace TGServerService if (oldVersion == newVersion && newVersion == 0) //chat refactor Properties.Settings.Default.ChatProviderData = "NEEDS INITIALIZING"; //reset chat settings to be safe } - + //you should seriously not add anything here //Use OnStart instead public TGServerService() diff --git a/TGServiceInterface/Administration.cs b/TGServiceInterface/Administration.cs index 527acc5479..5e16dc4221 100644 --- a/TGServiceInterface/Administration.cs +++ b/TGServiceInterface/Administration.cs @@ -8,21 +8,21 @@ namespace TGServiceInterface [ServiceContract] public interface ITGAdministration { - /// - /// Get the port used for remote operation - /// - /// The port used for remote operation + /// + /// Get the port used for remote operation + /// + /// The port used for remote operation [OperationContract] - ushort RemoteAccessPort(); + ushort RemoteAccessPort(); - /// - /// Set the port used for remote operation - /// Requires a service restart to take effect - /// - /// The new port to use for remote operation - /// null on success, error message on failure + /// + /// Set the port used for remote operation + /// Requires a service restart to take effect + /// + /// The new port to use for remote operation + /// null on success, error message on failure [OperationContract] - string SetRemoteAccessPort(ushort port); + string SetRemoteAccessPort(ushort port); /// /// Returns the name of the windows group allowed to use the service other than administrator diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 6aca1d6dab..11d6e8a4c0 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -53,7 +53,7 @@ namespace TGServiceInterface public static void SetRemoteLoginInformation(string address, ushort port, string username, string password) { HTTPSURL = address; - HTTPSPort = port; + HTTPSPort = port; HTTPSUsername = username; HTTPSPassword = password; } @@ -63,14 +63,14 @@ namespace TGServiceInterface /// /// The type of the component to retrieve /// - public static T GetComponent() - { + public static T GetComponent() + { var ToT = typeof(T); if (!ValidInterfaces.Contains(ToT)) throw new Exception("Invalid type!"); var InterfaceName = typeof(T).Name; - if (HTTPSURL == null) - return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel(); + if (HTTPSURL == null) + return new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel(); //okay we're going over var binding = new WSHttpBinding(); From 80902a8a8c4d774cfdb65a70c7e99dcd929dcfb1 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sun, 17 Sep 2017 21:38:34 -0400 Subject: [PATCH 3/3] Add command line safety in case we bind to a bad port --- TGServerService/ServerService.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 1191daeae6..f9207ddc41 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -151,6 +151,14 @@ namespace TGServerService var instance = new TGStationServer(); + for (var I = 0; I < args.Length - 1; ++I) + if (args[I].ToLower() == "-port") + { + Config.RemoteAccessPort = Convert.ToUInt16(args[I + 1]); + Config.Save(); + break; + } + host = new ServiceHost(instance, new Uri[] { new Uri("net.pipe://localhost"), new Uri(String.Format("https://localhost:{0}", Config.RemoteAccessPort)) }) { CloseTimeout = new TimeSpan(0, 0, 5) @@ -162,7 +170,14 @@ namespace TGServerService host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, Config.CertificateURL); host.Authorization.ServiceAuthorizationManager = instance; - host.Open(); //...or maybe here, doesn't really matter + try + { + host.Open(); + } + catch (AddressAlreadyInUseException e) + { + throw new Exception("Can't start the service due to the configured remote access port being in use. To fix this change it by starting the service with the \"-port \" argument.", e); + } } //shorthand for adding the WCF endpoint