From b41091c4a3f57dbe86e7eac29dcf66455667cd0a Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 14:42:50 -0400 Subject: [PATCH 01/12] New static configuration page --- TGControlPanel/Main.Designer.cs | 142 +++++++++++++++ TGControlPanel/Main.cs | 2 + TGControlPanel/StaticPage.cs | 249 +++++++++++++++++++++++++++ TGControlPanel/TGControlPanel.csproj | 3 + TGServerService/Config.cs | 68 +++++++- TGServiceInterface/Config.cs | 15 +- 6 files changed, 473 insertions(+), 6 deletions(-) create mode 100644 TGControlPanel/StaticPage.cs diff --git a/TGControlPanel/Main.Designer.cs b/TGControlPanel/Main.Designer.cs index 2020a8b21d..01d1580352 100644 --- a/TGControlPanel/Main.Designer.cs +++ b/TGControlPanel/Main.Designer.cs @@ -148,6 +148,16 @@ this.RepoProgressBarLabel = new System.Windows.Forms.Label(); this.RepoProgressBar = new System.Windows.Forms.ProgressBar(); this.Panels = new System.Windows.Forms.TabControl(); + this.StaticPanel = new System.Windows.Forms.TabPage(); + this.StaticFileDownloadButton = new System.Windows.Forms.Button(); + this.StaticFilesRefreshButton = new System.Windows.Forms.Button(); + this.StaticFileUploadButton = new System.Windows.Forms.Button(); + this.StaticFileEditTextbox = new System.Windows.Forms.TextBox(); + this.StaticFileDeleteButton = new System.Windows.Forms.Button(); + this.StaticFileSaveButton = new System.Windows.Forms.Button(); + this.StaticFileCreateButton = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.StaticFileListBox = new System.Windows.Forms.ListBox(); this.ChatPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ChatPortSelector)).BeginInit(); this.ChatProviderSelectorPanel.SuspendLayout(); @@ -161,6 +171,7 @@ this.RepoPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.TestmergeSelector)).BeginInit(); this.Panels.SuspendLayout(); + this.StaticPanel.SuspendLayout(); this.SuspendLayout(); // // RepoBGW @@ -1598,12 +1609,131 @@ this.Panels.Controls.Add(this.BYONDPanel); this.Panels.Controls.Add(this.ServerPanel); this.Panels.Controls.Add(this.ChatPanel); + this.Panels.Controls.Add(this.StaticPanel); + this.Panels.Cursor = System.Windows.Forms.Cursors.Default; this.Panels.Location = new System.Drawing.Point(12, 12); this.Panels.Name = "Panels"; this.Panels.SelectedIndex = 0; this.Panels.Size = new System.Drawing.Size(876, 392); this.Panels.TabIndex = 3; // + // StaticPanel + // + this.StaticPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34))))); + this.StaticPanel.Controls.Add(this.StaticFileDownloadButton); + this.StaticPanel.Controls.Add(this.StaticFilesRefreshButton); + this.StaticPanel.Controls.Add(this.StaticFileUploadButton); + this.StaticPanel.Controls.Add(this.StaticFileEditTextbox); + this.StaticPanel.Controls.Add(this.StaticFileDeleteButton); + this.StaticPanel.Controls.Add(this.StaticFileSaveButton); + this.StaticPanel.Controls.Add(this.StaticFileCreateButton); + this.StaticPanel.Controls.Add(this.label6); + this.StaticPanel.Controls.Add(this.StaticFileListBox); + this.StaticPanel.Location = new System.Drawing.Point(4, 22); + this.StaticPanel.Name = "StaticPanel"; + this.StaticPanel.Padding = new System.Windows.Forms.Padding(3); + this.StaticPanel.Size = new System.Drawing.Size(868, 366); + this.StaticPanel.TabIndex = 5; + this.StaticPanel.Text = "Static Files"; + // + // StaticFileDownloadButton + // + this.StaticFileDownloadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.StaticFileDownloadButton.Location = new System.Drawing.Point(296, 6); + this.StaticFileDownloadButton.Name = "StaticFileDownloadButton"; + this.StaticFileDownloadButton.Size = new System.Drawing.Size(71, 22); + this.StaticFileDownloadButton.TabIndex = 32; + this.StaticFileDownloadButton.Text = "Download"; + this.StaticFileDownloadButton.UseVisualStyleBackColor = true; + this.StaticFileDownloadButton.Click += new System.EventHandler(this.StaticFileDownloadButton_Click); + // + // StaticFilesRefreshButton + // + this.StaticFilesRefreshButton.Location = new System.Drawing.Point(65, 6); + this.StaticFilesRefreshButton.Name = "StaticFilesRefreshButton"; + this.StaticFilesRefreshButton.Size = new System.Drawing.Size(71, 22); + this.StaticFilesRefreshButton.TabIndex = 31; + this.StaticFilesRefreshButton.Text = "Refresh"; + this.StaticFilesRefreshButton.UseVisualStyleBackColor = true; + this.StaticFilesRefreshButton.Click += new System.EventHandler(this.StaticFilesRefreshButton_Click); + // + // StaticFileUploadButton + // + this.StaticFileUploadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.StaticFileUploadButton.Location = new System.Drawing.Point(219, 6); + this.StaticFileUploadButton.Name = "StaticFileUploadButton"; + this.StaticFileUploadButton.Size = new System.Drawing.Size(71, 22); + this.StaticFileUploadButton.TabIndex = 30; + this.StaticFileUploadButton.Text = "Upload"; + this.StaticFileUploadButton.UseVisualStyleBackColor = true; + this.StaticFileUploadButton.Click += new System.EventHandler(this.StaticFileUploadButton_Click); + // + // StaticFileEditTextbox + // + this.StaticFileEditTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.StaticFileEditTextbox.Location = new System.Drawing.Point(219, 31); + this.StaticFileEditTextbox.Multiline = true; + this.StaticFileEditTextbox.Name = "StaticFileEditTextbox"; + this.StaticFileEditTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.StaticFileEditTextbox.Size = new System.Drawing.Size(643, 329); + this.StaticFileEditTextbox.TabIndex = 29; + // + // StaticFileDeleteButton + // + this.StaticFileDeleteButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.StaticFileDeleteButton.Location = new System.Drawing.Point(714, 6); + this.StaticFileDeleteButton.Name = "StaticFileDeleteButton"; + this.StaticFileDeleteButton.Size = new System.Drawing.Size(71, 22); + this.StaticFileDeleteButton.TabIndex = 28; + this.StaticFileDeleteButton.Text = "Delete"; + this.StaticFileDeleteButton.UseVisualStyleBackColor = true; + this.StaticFileDeleteButton.Click += new System.EventHandler(this.StaticFileDeleteButton_Click); + // + // StaticFileSaveButton + // + this.StaticFileSaveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.StaticFileSaveButton.Location = new System.Drawing.Point(791, 6); + this.StaticFileSaveButton.Name = "StaticFileSaveButton"; + this.StaticFileSaveButton.Size = new System.Drawing.Size(71, 22); + this.StaticFileSaveButton.TabIndex = 27; + this.StaticFileSaveButton.Text = "Save"; + this.StaticFileSaveButton.UseVisualStyleBackColor = true; + this.StaticFileSaveButton.Click += new System.EventHandler(this.StaticFileSaveButton_Click); + // + // StaticFileCreateButton + // + this.StaticFileCreateButton.Location = new System.Drawing.Point(142, 6); + this.StaticFileCreateButton.Name = "StaticFileCreateButton"; + this.StaticFileCreateButton.Size = new System.Drawing.Size(71, 22); + this.StaticFileCreateButton.TabIndex = 26; + this.StaticFileCreateButton.Text = "Add"; + this.StaticFileCreateButton.UseVisualStyleBackColor = true; + this.StaticFileCreateButton.Click += new System.EventHandler(this.StaticFileCreateButton_Click); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label6.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.label6.Location = new System.Drawing.Point(6, 10); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(53, 18); + this.label6.TabIndex = 14; + this.label6.Text = "Files:"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // StaticFileListBox + // + this.StaticFileListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.StaticFileListBox.FormattingEnabled = true; + this.StaticFileListBox.HorizontalScrollbar = true; + this.StaticFileListBox.Location = new System.Drawing.Point(6, 31); + this.StaticFileListBox.Name = "StaticFileListBox"; + this.StaticFileListBox.Size = new System.Drawing.Size(207, 329); + this.StaticFileListBox.TabIndex = 0; + this.StaticFileListBox.SelectedIndexChanged += new System.EventHandler(this.StaticFileListBox_SelectedIndexChanged); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1634,6 +1764,8 @@ this.RepoPanel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.TestmergeSelector)).EndInit(); this.Panels.ResumeLayout(false); + this.StaticPanel.ResumeLayout(false); + this.StaticPanel.PerformLayout(); this.ResumeLayout(false); } @@ -1757,5 +1889,15 @@ private System.Windows.Forms.Label RepoProgressBarLabel; private System.Windows.Forms.ProgressBar RepoProgressBar; private System.Windows.Forms.TabControl Panels; + private System.Windows.Forms.TabPage StaticPanel; + private System.Windows.Forms.Button StaticFileCreateButton; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.ListBox StaticFileListBox; + private System.Windows.Forms.Button StaticFileUploadButton; + private System.Windows.Forms.TextBox StaticFileEditTextbox; + private System.Windows.Forms.Button StaticFileDeleteButton; + private System.Windows.Forms.Button StaticFileSaveButton; + private System.Windows.Forms.Button StaticFilesRefreshButton; + private System.Windows.Forms.Button StaticFileDownloadButton; } } diff --git a/TGControlPanel/Main.cs b/TGControlPanel/Main.cs index 18cade4c7d..62f2c4618a 100644 --- a/TGControlPanel/Main.cs +++ b/TGControlPanel/Main.cs @@ -15,6 +15,7 @@ namespace TGControlPanel InitBYONDPage(); InitServerPage(); LoadChatPage(); + InitStaticPage(); } private void Main_Resize(object sender, EventArgs e) @@ -28,5 +29,6 @@ namespace TGControlPanel { Properties.Settings.Default.LastPageIndex = Panels.SelectedIndex; } + } } diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs new file mode 100644 index 0000000000..dac92e101a --- /dev/null +++ b/TGControlPanel/StaticPage.cs @@ -0,0 +1,249 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; +using TGServiceInterface; + +namespace TGControlPanel +{ + partial class Main + { + IDictionary IndexesToPaths = new Dictionary(); + bool changesMade = false; + void InitStaticPage() + { + BuildFileList(); + } + + void BuildFileList() + { + IndexesToPaths.Clear(); + StaticFileListBox.Items.Clear(); + IndexesToPaths.Add(StaticFileListBox.Items.Add("/"), "/"); + if (!EnumeratePath("", Server.GetComponent(), 1)) + { + StaticFileListBox.Items[0] += " (UNAUTHORIZED)"; + IndexesToPaths[0] = null; + } + StaticFileListBox.SelectedIndex = 0; + } + + bool EnumeratePath(string path, ITGConfig config, int level) + { + var Enum = config.ListStaticDirectory(path, out string error, out bool unauthorized); + if(Enum == null) + { + if (unauthorized) + return false; + else + { + MessageBox.Show(String.Format("Could not enumerate static path \"{0}\" error: {1}", path, error)); + return true; + } + } + foreach(var I in Enum) + { + if(I[0] == '/') + { + var dir = I.Remove(0, 1); + var index = StaticFileListBox.Items.Add(DSNTimes(level) + dir + '/'); + var fullpath = path + dir; + IndexesToPaths.Add(index, fullpath); + if (!EnumeratePath(fullpath, config, level + 1)) + { + StaticFileListBox.Items[index] += " (UNAUTHORIZED)"; + IndexesToPaths[index] = null; + } + continue; + } + + IndexesToPaths.Add(StaticFileListBox.Items.Add(DSNTimes(level) + I), Path.Combine(path, I)); + } + return true; + } + + string DSNTimes(int n) + { + var res = ""; + for (var I = 0; I < n; ++I) + res += " "; + return res; + } + private void StaticFilesRefreshButton_Click(object sender, EventArgs e) + { + BuildFileList(); + } + + private void StaticFileUploadButton_Click(object sender, EventArgs e) + { + if (StaticFileEditTextbox.Text != "Directory") + { + MessageBox.Show("Please select a directory to upload the file to."); + return; + } + var ofd = new OpenFileDialog() + { + CheckFileExists = true, + CheckPathExists = true, + DefaultExt = ".txt", + Multiselect = false, + Title = "Static File Upload", + ValidateNames = true, + Filter = "All files (*.*)|*.*", + AddExtension = false, + SupportMultiDottedExtensions = true, + }; + if (ofd.ShowDialog() != DialogResult.OK) + return; + + var fileToUpload = ofd.FileName; + + var FileName = Path.Combine(IndexesToPaths[StaticFileListBox.SelectedIndex], Path.GetFileName(fileToUpload)); + + string fileContents = null; + string error = null; + try + { + fileContents = File.ReadAllText(fileToUpload); + } + catch (Exception ex) + { + error = ex.ToString(); + } + if (error == null) + error = Server.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); + if (error != null) + MessageBox.Show("An error occurred: " + error); + BuildFileList(); + } + + private void StaticFileDownloadButton_Click(object sender, EventArgs e) + { + if (StaticFileEditTextbox.ReadOnly) + { + MessageBox.Show("Cannot download this file!"); + return; + } + var remotePath = IndexesToPaths[StaticFileListBox.SelectedIndex]; + if (remotePath == null) + return; + var text = Server.GetComponent().ReadText(remotePath, false, out string error, out bool unauthorized); + if (text != null) + { + var ofd = new SaveFileDialog() + { + CheckFileExists = false, + CheckPathExists = true, + DefaultExt = ".txt", + Title = "Static File Download", + ValidateNames = true, + Filter = "All files (*.*)|*.*", + AddExtension = false, + CreatePrompt = false, + OverwritePrompt = true, + SupportMultiDottedExtensions = true, + }; + if (ofd.ShowDialog() != DialogResult.OK) + return; + + try + { + File.WriteAllText(ofd.FileName, text); + return; + } + catch (Exception ex) + { + error = ex.ToString(); + } + } + MessageBox.Show("An error occurred: " + error); + } + + private void StaticFileDeleteButton_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Are you sure you want to delete " + ((string)StaticFileListBox.SelectedItem).Trim() + "?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + var res = Server.GetComponent().DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized); + if (res != null) + MessageBox.Show(res); + BuildFileList(); + } + + private void StaticFileCreateButton_Click(object sender, EventArgs e) + { + if(StaticFileEditTextbox.Text != "Directory") + { + MessageBox.Show("Please select a directory to create the file in."); + return; + } + var FileName = Program.TextPrompt("Static File/Directory Creation", "Enter the name of the file/directory:"); + if (FileName == null) + return; + + var resu = MessageBox.Show("Is this the name of a directory?", "Directory", MessageBoxButtons.YesNoCancel); + if (resu == DialogResult.Cancel) + return; + var FullFileName = Path.Combine(IndexesToPaths[StaticFileListBox.SelectedIndex], FileName); + if (resu == DialogResult.Yes) + FullFileName = Path.Combine(FullFileName, "__TGS3_CP_DIRECTORY_CREATOR__"); + var config = Server.GetComponent(); + var res = config.WriteText(FullFileName, "", out bool unauthorized); + if (res != null) + MessageBox.Show(res); + if (resu == DialogResult.Yes) + { + FullFileName = Path.Combine(FullFileName, "__TGS3_CP_DIRECTORY_CREATOR__"); + config.DeleteFile(FullFileName, out unauthorized); //don't care about this + } + BuildFileList(); + } + + private void StaticFileSaveButton_Click(object sender, EventArgs e) + { + var index = StaticFileListBox.SelectedIndex; + var res = Server.GetComponent().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out bool unauthorized); + if (res != null) + { + MessageBox.Show("Error: " + res); + var title = (string)StaticFileListBox.Items[index]; + if (unauthorized && !title.Contains(" (UNAUTHORIZED)")) + StaticFileListBox.Items[index] = title + " (UNAUTHORIZED)"; + } + } + + private void StaticFileListBox_SelectedIndexChanged(object sender, EventArgs e) + { + UpdateEditText(); + } + + void UpdateEditText() + { + var newIndex = StaticFileListBox.SelectedIndex; + var path = IndexesToPaths[newIndex]; + var title = (string)StaticFileListBox.Items[newIndex]; + if (path == "TGServiceInterface.dll") + { + StaticFileEditTextbox.ReadOnly = true; + StaticFileEditTextbox.Text = "/tg/station Server Interface DLL"; + } + else if (title[title.Length - 1] == '/') + { + StaticFileEditTextbox.ReadOnly = true; + StaticFileEditTextbox.Text = "Directory"; + } + else + { + var entry = Server.GetComponent().ReadText(path, false, out string error, out bool unauthorized); + if (entry == null) + { + StaticFileEditTextbox.ReadOnly = true; + StaticFileEditTextbox.Text = "ERROR: " + entry; + if (unauthorized && !title.Contains(" (UNAUTHORIZED)")) + StaticFileListBox.Items[newIndex] = title + " (UNAUTHORIZED)"; + } + StaticFileEditTextbox.ReadOnly = false; + StaticFileEditTextbox.Text = entry; + } + } + } +} diff --git a/TGControlPanel/TGControlPanel.csproj b/TGControlPanel/TGControlPanel.csproj index ff533121a0..976c556e7d 100644 --- a/TGControlPanel/TGControlPanel.csproj +++ b/TGControlPanel/TGControlPanel.csproj @@ -79,6 +79,9 @@ Form + + Form + Login.cs diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index 58a9d9d6f4..d7c5cc9511 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -26,7 +26,7 @@ namespace TGServerService { var configDir = repo ? RepoPath : StaticDirs; - var path = Path.Combine(configDir, staticRelativePath); + var path = configDir + '/' + staticRelativePath; //do not use path.combine or it will try and take the root lock (configLock) { var di1 = new DirectoryInfo(configDir); @@ -101,7 +101,7 @@ namespace TGServerService { try { - var path = Path.Combine(StaticDirs, staticRelativePath); + var path = StaticDirs + '/' + staticRelativePath; //do not use path.combine or it will try and take the root lock (configLock) { var di1 = new DirectoryInfo(StaticDirs); @@ -143,13 +143,75 @@ namespace TGServerService return e.ToString(); } } + [OperationBehavior(Impersonation = ImpersonationOption.Required)] + public string DeleteFile(string staticRelativePath, out bool unauthorized) + { + try + { + var path = StaticDirs + '/' + staticRelativePath; //do not use path.combine or it will try and take the root + lock (configLock) + { + var di1 = new DirectoryInfo(StaticDirs); + var fi = new FileInfo(path); + var di2 = new DirectoryInfo(fi.Directory.FullName); + + var good = false; + while (di2 != null) + { + if (di2.FullName == di1.FullName) + { + good = true; + break; + } + else di2 = di2.Parent; + } + + if (!good) + { + unauthorized = false; + return "Cannot delete above static directories!"; + } + + if (fi.Exists) + { + if (fi.Name == InterfaceDLLName) + { + unauthorized = false; + return "Cannot delete the interface DLL!"; + } + File.Delete(path); + } + else if (Directory.Exists(path)) + Program.DeleteDirectory(path); + unauthorized = false; + return null; + } + } + catch (UnauthorizedAccessException e) + { + //no need for the full stacktrace + unauthorized = true; + return e.Message; + } + catch (Exception e) + { + unauthorized = false; + return e.ToString(); + } + } [OperationBehavior(Impersonation = ImpersonationOption.Required)] public IList ListStaticDirectory(string subDir, out string error, out bool unauthorized) { try { - DirectoryInfo dirToEnum = new DirectoryInfo(Path.Combine(StaticDirs, subDir ?? "")); + if (!Directory.Exists(StaticDirs)) + { + error = null; + unauthorized = false; + return new List(); + } + DirectoryInfo dirToEnum = new DirectoryInfo(StaticDirs + '/' + subDir ?? ""); //do not use path.combine or it will try and take the root var result = new List(); foreach (var I in dirToEnum.GetFiles()) result.Add(I.Name); diff --git a/TGServiceInterface/Config.cs b/TGServiceInterface/Config.cs index 16a868304f..ff292180cf 100644 --- a/TGServiceInterface/Config.cs +++ b/TGServiceInterface/Config.cs @@ -30,7 +30,7 @@ namespace TGServiceInterface IList ListStaticDirectory(string subpath, out string error, out bool unauthorized); /// - /// For when you really just need to see the raw data of the config + /// Read from a static file /// /// The path from the Static dir. E.g. config/config.txt /// if true, the file will be read from the repository instead of the static dir @@ -41,13 +41,22 @@ namespace TGServiceInterface string ReadText(string staticRelativePath, bool repo, out string error, out bool unauthorized); /// - /// For when you really just need to set the raw data of the config + /// Write to a static file /// - /// The path from the configDir. E.g. config.txt + /// The path from the Static dir. E.g. config/config.txt /// The full text of the config file /// This will be true if error is set to a message that indicates the current user does not have access to the specified file /// null on success, error message on failure [OperationContract] string WriteText(string staticRelativePath, string data, out bool unauthorized); + + /// + /// Deletes the target static file + /// + /// The path from the Static dir. E.g. config/config.txt + /// This will be true if error is set to a message that indicates the current user does not have access to the specified file + /// null on success, error message on failure + [OperationContract] + string DeleteFile(string staticRelativePath, out bool unauthorized); } } From e3f9737f24effbdc77d20b3835ff485d80f7f9f2 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 14:45:48 -0400 Subject: [PATCH 02/12] Moves the interface DLL to the root server folder --- TGServerService/Compiler.cs | 6 +++--- TGServerService/Config.cs | 7 ------- TGServerService/DreamDaemon.cs | 6 +++--- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index f6fad6f544..2292f5b245 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -203,8 +203,8 @@ namespace TGServerService CreateSymlink(Path.Combine(GameDirA, I), Path.Combine(StaticDirs, I)); } - CreateSymlink(Path.Combine(GameDirA, InterfaceDLLName), Path.Combine(StaticDirs, InterfaceDLLName)); - CreateSymlink(Path.Combine(GameDirB, InterfaceDLLName), Path.Combine(StaticDirs, InterfaceDLLName)); + CreateSymlink(Path.Combine(GameDirA, InterfaceDLLName), InterfaceDLLName); + CreateSymlink(Path.Combine(GameDirB, InterfaceDLLName), InterfaceDLLName); CreateSymlink(GameDirLive, GameDirA); @@ -344,7 +344,7 @@ namespace TGServerService } if (!File.Exists(Path.Combine(resurrectee, InterfaceDLLName))) - CreateSymlink(Path.Combine(resurrectee, InterfaceDLLName), Path.Combine(StaticDirs, InterfaceDLLName)); + CreateSymlink(Path.Combine(resurrectee, InterfaceDLLName), InterfaceDLLName); bool repobusy_check = false; if (!Monitor.TryEnter(RepoLock)) diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index d7c5cc9511..8ff2a875a8 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -173,14 +173,7 @@ namespace TGServerService } if (fi.Exists) - { - if (fi.Name == InterfaceDLLName) - { - unauthorized = false; - return "Cannot delete the interface DLL!"; - } File.Delete(path); - } else if (Directory.Exists(path)) Program.DeleteDirectory(path); unauthorized = false; diff --git a/TGServerService/DreamDaemon.cs b/TGServerService/DreamDaemon.cs index 825f8a5c41..1786172a26 100644 --- a/TGServerService/DreamDaemon.cs +++ b/TGServerService/DreamDaemon.cs @@ -368,12 +368,12 @@ namespace TGServerService void UpdateInterfaceDll(bool overwrite) { - var targetPath = Path.Combine(StaticDirs, InterfaceDLLName); - if (File.Exists(targetPath) && !overwrite) + var targetPath = InterfaceDLLName; + if (File.Exists(InterfaceDLLName) && !overwrite) return; //Copy the interface dll to the static dir var InterfacePath = Assembly.GetAssembly(typeof(DDInteropCallHolder)).Location; - Program.CopyFileForceDirectories(InterfacePath, targetPath, true); + File.Copy(InterfacePath, InterfaceDLLName, overwrite); } //used by Start and Watchdog to start a DD instance From 49bca6a5274d28e3aed18fd01290ec7f33f83fee Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 14:53:19 -0400 Subject: [PATCH 03/12] Add delete command to CLI --- TGCommandLine/ConfigCommands.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/TGCommandLine/ConfigCommands.cs b/TGCommandLine/ConfigCommands.cs index 47dfee862d..ef2e3df3d9 100644 --- a/TGCommandLine/ConfigCommands.cs +++ b/TGCommandLine/ConfigCommands.cs @@ -10,13 +10,40 @@ namespace TGCommandLine public ConfigCommand() { Keyword = "config"; - Children = new Command[] { new ConfigServerDirectoryCommand(), new ConfigDownloadCommand(), new ConfigUploadCommand(), new ConfigListCommand() }; + Children = new Command[] { new ConfigDeleteCommand(), new ConfigServerDirectoryCommand(), new ConfigDownloadCommand(), new ConfigUploadCommand(), new ConfigListCommand() }; } public override string GetHelpText() { return "Manage settings"; } } + class ConfigDeleteCommand : Command + { + public ConfigDeleteCommand() + { + Keyword = "delete"; + RequiredParameters = 1; + } + + protected override ExitCode Run(IList parameters) + { + var res = Server.GetComponent().DeleteFile(parameters[0], out bool unauthorized); + if (res != null) + { + OutputProc(res); + return ExitCode.ServerError; + } + return ExitCode.Normal; + } + public override string GetArgumentString() + { + return ""; + } + public override string GetHelpText() + { + return "Deletes the specified file from the static tree."; + } + } class ConfigListCommand : Command { From e3b87dedc15c18276f3215b34cd5438cc8836784 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 15:06:08 -0400 Subject: [PATCH 04/12] Fix JSON list parsing --- TGServerService/Repository.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index 2e378ec579..da843e5a6b 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -50,12 +50,12 @@ namespace TGServerService ChangelogSupport = true; try { - PipDependancies = (IList)details["pip_dependancies"]; + PipDependancies = (string[])details["pip_dependancies"]; } catch { } try { - ChangelogPathsToStage = (IList)details["synchronize_paths"]; + ChangelogPathsToStage = (string[])details["synchronize_paths"]; } catch { } } @@ -64,22 +64,22 @@ namespace TGServerService } try { - StaticDirectoryPaths = (IList)json["static_directories"]; + StaticDirectoryPaths = (string[])json["static_directories"]; } catch { } try { - DLLPaths = (IList)json["dlls"]; + DLLPaths = (string[])json["dlls"]; } catch { } } public readonly bool ChangelogSupport; public readonly string PathToChangelogPy; public readonly string ChangelogPyArguments; - public readonly IList PipDependancies = new List(); - public readonly IList ChangelogPathsToStage = new List(); - public readonly IList StaticDirectoryPaths = new List(); - public readonly IList DLLPaths = new List(); + public readonly string[] PipDependancies = { }; + public readonly string[]ChangelogPathsToStage = { }; + public readonly string[] StaticDirectoryPaths = { }; + public readonly string[] DLLPaths = { }; } RepoConfig _CurrentRepoConfig; @@ -1057,7 +1057,7 @@ namespace TGServerService } if (exitCode != 0) { - if (recurse || RConfig.PipDependancies.Count == 0) + if (recurse || RConfig.PipDependancies.Length == 0) { error = "Script failed!"; return result; From c3a16526f2670ab093da67f76a91205dbc923f98 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 15:06:55 -0400 Subject: [PATCH 05/12] Refix this --- TGControlPanel/ServerPage.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TGControlPanel/ServerPage.cs b/TGControlPanel/ServerPage.cs index 2216023f64..fd7928595a 100644 --- a/TGControlPanel/ServerPage.cs +++ b/TGControlPanel/ServerPage.cs @@ -130,6 +130,7 @@ namespace TGControlPanel ResetTestmerge.Visible = RepoExists; WorldAnnounceField.Visible = RepoExists; WorldAnnounceButton.Visible = RepoExists; + WorldAnnounceLabel.Visible = RepoExists; var DM = Server.GetComponent(); var DD = Server.GetComponent(); From f9dc1120995bb4357918916e8b687012a4be5a3e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 15:25:13 -0400 Subject: [PATCH 06/12] And this --- TGServerService/Repository.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index da843e5a6b..ec6957fae7 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -35,6 +35,13 @@ namespace TGServerService /// class RepoConfig { + IList LoadArray(object o) { + var array = (object[])o; + var res = new List(); + foreach (var I in array) + res.Add((string)I); + return res; + } public RepoConfig() { if (!File.Exists(RepoTGS3SettingsPath)) @@ -50,12 +57,12 @@ namespace TGServerService ChangelogSupport = true; try { - PipDependancies = (string[])details["pip_dependancies"]; + PipDependancies = LoadArray(details["pip_dependancies"]); } catch { } try { - ChangelogPathsToStage = (string[])details["synchronize_paths"]; + ChangelogPathsToStage = LoadArray(details["synchronize_paths"]); } catch { } } @@ -64,22 +71,22 @@ namespace TGServerService } try { - StaticDirectoryPaths = (string[])json["static_directories"]; + StaticDirectoryPaths = LoadArray(json["static_directories"]); } catch { } try { - DLLPaths = (string[])json["dlls"]; + DLLPaths = LoadArray(json["dlls"]); } catch { } } public readonly bool ChangelogSupport; public readonly string PathToChangelogPy; public readonly string ChangelogPyArguments; - public readonly string[] PipDependancies = { }; - public readonly string[]ChangelogPathsToStage = { }; - public readonly string[] StaticDirectoryPaths = { }; - public readonly string[] DLLPaths = { }; + public readonly IList PipDependancies = new List(); + public readonly IList ChangelogPathsToStage = new List(); + public readonly IList StaticDirectoryPaths = new List(); + public readonly IList DLLPaths = new List(); } RepoConfig _CurrentRepoConfig; @@ -1057,7 +1064,7 @@ namespace TGServerService } if (exitCode != 0) { - if (recurse || RConfig.PipDependancies.Length == 0) + if (recurse || RConfig.PipDependancies.Count == 0) { error = "Script failed!"; return result; From 4c10971bc09947a34f08539323178df93cc098b6 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 15:26:14 -0400 Subject: [PATCH 07/12] And this --- TGControlPanel/StaticPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index dac92e101a..7c4490f1c5 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -47,7 +47,7 @@ namespace TGControlPanel { var dir = I.Remove(0, 1); var index = StaticFileListBox.Items.Add(DSNTimes(level) + dir + '/'); - var fullpath = path + dir; + var fullpath = path + '/' + dir; IndexesToPaths.Add(index, fullpath); if (!EnumeratePath(fullpath, config, level + 1)) { From 693952ae1bf4d8303bae7cab4e68f510c9668e09 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 22 Sep 2017 10:26:07 -0400 Subject: [PATCH 08/12] Remove unused vars --- TGControlPanel/StaticPage.cs | 1 - TGServerService/DreamDaemon.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index 7c4490f1c5..8e3a158acf 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -9,7 +9,6 @@ namespace TGControlPanel partial class Main { IDictionary IndexesToPaths = new Dictionary(); - bool changesMade = false; void InitStaticPage() { BuildFileList(); diff --git a/TGServerService/DreamDaemon.cs b/TGServerService/DreamDaemon.cs index 1786172a26..91db552c39 100644 --- a/TGServerService/DreamDaemon.cs +++ b/TGServerService/DreamDaemon.cs @@ -368,7 +368,6 @@ namespace TGServerService void UpdateInterfaceDll(bool overwrite) { - var targetPath = InterfaceDLLName; if (File.Exists(InterfaceDLLName) && !overwrite) return; //Copy the interface dll to the static dir From fc3541a4cea94ef1a2332681742ccd10a86e6029 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 22 Sep 2017 10:54:49 -0400 Subject: [PATCH 09/12] Fix transfer limits. Add logging --- TGControlPanel/StaticPage.cs | 8 ++------ TGServerService/Config.cs | 6 +++++- TGServerService/ServerService.cs | 10 ++++++++-- TGServiceInterface/Server.cs | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index 8e3a158acf..916dc1357a 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -220,12 +220,8 @@ namespace TGControlPanel var newIndex = StaticFileListBox.SelectedIndex; var path = IndexesToPaths[newIndex]; var title = (string)StaticFileListBox.Items[newIndex]; - if (path == "TGServiceInterface.dll") - { - StaticFileEditTextbox.ReadOnly = true; - StaticFileEditTextbox.Text = "/tg/station Server Interface DLL"; - } - else if (title[title.Length - 1] == '/') + var authed_title = title.Replace(" (UNAUTHORIZED)", ""); + if (authed_title[authed_title.Length - 1] == '/') { StaticFileEditTextbox.ReadOnly = true; StaticFileEditTextbox.Text = "Directory"; diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index 8ff2a875a8..d811b6128a 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -77,9 +77,11 @@ namespace TGServerService return null; } + var output = File.ReadAllText(path); + TGServerService.WriteInfo("Read of " + path, TGServerService.EventID.StaticRead); error = null; unauthorized = false; - return File.ReadAllText(path); + return output; } } catch (UnauthorizedAccessException e) @@ -127,6 +129,7 @@ namespace TGServerService Directory.CreateDirectory(destdir); File.WriteAllText(path, data); + TGServerService.WriteInfo(String.Format("Rewrite {0}: {1}", path, data), TGServerService.EventID.StaticWrite); unauthorized = false; return null; } @@ -176,6 +179,7 @@ namespace TGServerService File.Delete(path); else if (Directory.Exists(path)) Program.DeleteDirectory(path); + TGServerService.WriteInfo("Delete of " + path, TGServerService.EventID.StaticDelete); unauthorized = false; return null; } diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 061b922d9b..558573e747 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -81,6 +81,9 @@ namespace TGServerService InteropCallException = 7000, APIVersionMismatch = 7100, RepoConfigurationFail = 7200, + StaticRead = 7300, + StaticWrite = 7400, + StaticDelete = 7500, } static TGServerService ActiveService; //So everyone else can write to our eventlog @@ -196,8 +199,11 @@ namespace TGServerService void AddEndpoint(Type typetype) { var bindingName = Server.MasterInterfaceName + "/" + typetype.Name; - host.AddServiceEndpoint(typetype, new NetNamedPipeBinding(), bindingName); - var httpsBinding = new WSHttpBinding(); + host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { MaxReceivedMessageSize = Server.TransferLimitLocal }, bindingName); + var httpsBinding = new WSHttpBinding() + { + MaxReceivedMessageSize = Server.TransferLimitRemote + }; var requireAuth = typetype.Name != typeof(ITGConnectivity).Name; httpsBinding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check httpsBinding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None; diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 31c01b92ec..9ceacf9fa0 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -13,6 +13,16 @@ namespace TGServiceInterface /// public static readonly IList ValidInterfaces = new List { typeof(ITGByond), typeof(ITGChat), typeof(ITGCompiler), typeof(ITGConfig), typeof(ITGDreamDaemon), typeof(ITGRepository), typeof(ITGSService), typeof(ITGConnectivity), typeof(ITGAdministration), typeof(ITGInterop) }; + /// + /// The maximum message size to and from a local server + /// + public static readonly long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher + + /// + /// The maximum message size to and from a remote server + /// + public static readonly long TransferLimitRemote = 10485760; //10 MB + /// /// Base name of the communication pipe /// they are formatted as MasterPipeName/ComponentName @@ -107,7 +117,8 @@ namespace TGServiceInterface var InterfaceName = typeof(T).Name; if (HTTPSURL == null) { - outChannel = new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); + outChannel = new ChannelFactory( + new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); //10 megs outChannel.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; return outChannel.CreateChannel(); } @@ -115,7 +126,8 @@ namespace TGServiceInterface //okay we're going over var binding = new WSHttpBinding() { - SendTimeout = new TimeSpan(0, 10, 0) + SendTimeout = new TimeSpan(0, 10, 0), + MaxReceivedMessageSize = TransferLimitRemote }; var requireAuth = InterfaceName != typeof(ITGConnectivity).Name; binding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check From 7d0a95faf699c4e86f7064b89f4f45126355bdb4 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 22 Sep 2017 10:58:51 -0400 Subject: [PATCH 10/12] Fix errors not showing up in editor --- TGControlPanel/StaticPage.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index 916dc1357a..4b96b4db50 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -232,12 +232,15 @@ namespace TGControlPanel if (entry == null) { StaticFileEditTextbox.ReadOnly = true; - StaticFileEditTextbox.Text = "ERROR: " + entry; + StaticFileEditTextbox.Text = "ERROR: " + error; if (unauthorized && !title.Contains(" (UNAUTHORIZED)")) StaticFileListBox.Items[newIndex] = title + " (UNAUTHORIZED)"; } - StaticFileEditTextbox.ReadOnly = false; - StaticFileEditTextbox.Text = entry; + else + { + StaticFileEditTextbox.ReadOnly = false; + StaticFileEditTextbox.Text = entry; + } } } } From d8dd82092acef0a7b191436081812c0021fc76fa Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 22 Sep 2017 11:33:42 -0400 Subject: [PATCH 11/12] Fixes trying to write to the logs while impersonating. File contents are no longer written to the log. Adds guards for large file exceptions --- TGControlPanel/StaticPage.cs | 45 +++++++++++++++++++++++++++++--- TGServerService/Config.cs | 5 +++- TGServerService/ServerService.cs | 9 +++++++ TGServiceInterface/Config.cs | 2 ++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index 4b96b4db50..e9e211e4a3 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -110,7 +110,14 @@ namespace TGControlPanel error = ex.ToString(); } if (error == null) - error = Server.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); + try + { + error = Server.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); + } + catch (Exception ex) + { + error = "Failed to read file, most likely due to it being too large. The transfer limit is much higher on non-remote connections. " + ex.ToString(); + } if (error != null) MessageBox.Show("An error occurred: " + error); BuildFileList(); @@ -126,7 +133,16 @@ namespace TGControlPanel var remotePath = IndexesToPaths[StaticFileListBox.SelectedIndex]; if (remotePath == null) return; - var text = Server.GetComponent().ReadText(remotePath, false, out string error, out bool unauthorized); + string text, error; + try + { + text = Server.GetComponent().ReadText(remotePath, false, out error, out bool unauthorized); + } + catch (Exception ex) + { + text = null; + error = "Failed to read file, most likely due to it being too large. The transfer limit is much higher on non-remote connections. " + ex.ToString(); + } if (text != null) { var ofd = new SaveFileDialog() @@ -200,7 +216,17 @@ namespace TGControlPanel private void StaticFileSaveButton_Click(object sender, EventArgs e) { var index = StaticFileListBox.SelectedIndex; - var res = Server.GetComponent().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out bool unauthorized); + string res; + bool unauthorized; + try + { + res = Server.GetComponent().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized); + } + catch (Exception ex) + { + unauthorized = false; + res = "Failed to write file, most likely due to it being too large. The transfer limit is much higher on non-remote connections. " + ex.ToString(); + } if (res != null) { MessageBox.Show("Error: " + res); @@ -228,7 +254,18 @@ namespace TGControlPanel } else { - var entry = Server.GetComponent().ReadText(path, false, out string error, out bool unauthorized); + string entry, error; + bool unauthorized; + try + { + entry = Server.GetComponent().ReadText(path, false, out error, out unauthorized); + } + catch(Exception e) + { + entry = null; + unauthorized = false; + error = "Failed to read file, most likely due to it being too large. The transfer limit is much higher on non-remote connections. " + e.ToString(); + } if (entry == null) { StaticFileEditTextbox.ReadOnly = true; diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index d811b6128a..74d641dd53 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -78,6 +78,7 @@ namespace TGServerService } var output = File.ReadAllText(path); + TGServerService.CancelImpersonation(); TGServerService.WriteInfo("Read of " + path, TGServerService.EventID.StaticRead); error = null; unauthorized = false; @@ -129,7 +130,8 @@ namespace TGServerService Directory.CreateDirectory(destdir); File.WriteAllText(path, data); - TGServerService.WriteInfo(String.Format("Rewrite {0}: {1}", path, data), TGServerService.EventID.StaticWrite); + TGServerService.CancelImpersonation(); + TGServerService.WriteInfo("Write to " + path, TGServerService.EventID.StaticWrite); unauthorized = false; return null; } @@ -179,6 +181,7 @@ namespace TGServerService File.Delete(path); else if (Directory.Exists(path)) Program.DeleteDirectory(path); + TGServerService.CancelImpersonation(); TGServerService.WriteInfo("Delete of " + path, TGServerService.EventID.StaticDelete); unauthorized = false; return null; diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 558573e747..221e8508ab 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Security.Principal; using System.ServiceModel; using System.ServiceProcess; using TGServiceInterface; @@ -90,6 +91,14 @@ namespace TGServerService public static readonly string Version = "/tg/station 13 Server Service v" + FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion; + /// + /// You can't write to logs while impersonating, call this to cancel WCF's impersonation first + /// + public static void CancelImpersonation() + { + WindowsIdentity.Impersonate(IntPtr.Zero); + } + public static void WriteInfo(string message, EventID id) { ActiveService.EventLog.WriteEntry(message, EventLogEntryType.Information, (int)id); diff --git a/TGServiceInterface/Config.cs b/TGServiceInterface/Config.cs index ff292180cf..55027423a4 100644 --- a/TGServiceInterface/Config.cs +++ b/TGServiceInterface/Config.cs @@ -37,6 +37,7 @@ namespace TGServiceInterface /// null on success, error message on failure /// This will be true if error is set to a message that indicates the current user does not have access to the specified file /// The full text of the file on success, null on failure + /// Along with implied disconnect exceptions, if the file exceeds transfer limits [OperationContract] string ReadText(string staticRelativePath, bool repo, out string error, out bool unauthorized); @@ -47,6 +48,7 @@ namespace TGServiceInterface /// The full text of the config file /// This will be true if error is set to a message that indicates the current user does not have access to the specified file /// null on success, error message on failure + /// Along with implied disconnect exceptions, if the file exceeds transfer limits [OperationContract] string WriteText(string staticRelativePath, string data, out bool unauthorized); From 39cc432a5d45db41e411a30b602398c76fd5214e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 22 Sep 2017 11:39:13 -0400 Subject: [PATCH 12/12] Fixes send timeouts --- TGServerService/ServerService.cs | 3 ++- TGServiceInterface/Server.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 221e8508ab..1241872b77 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -208,9 +208,10 @@ namespace TGServerService void AddEndpoint(Type typetype) { var bindingName = Server.MasterInterfaceName + "/" + typetype.Name; - host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { MaxReceivedMessageSize = Server.TransferLimitLocal }, bindingName); + host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Server.TransferLimitLocal }, bindingName); var httpsBinding = new WSHttpBinding() { + SendTimeout = new TimeSpan(0, 0, 40), MaxReceivedMessageSize = Server.TransferLimitRemote }; var requireAuth = typetype.Name != typeof(ITGConnectivity).Name; diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 9ceacf9fa0..7f0d4dc621 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -118,7 +118,7 @@ namespace TGServiceInterface if (HTTPSURL == null) { outChannel = new ChannelFactory( - new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); //10 megs + new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); //10 megs outChannel.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; return outChannel.CreateChannel(); } @@ -126,7 +126,7 @@ namespace TGServiceInterface //okay we're going over var binding = new WSHttpBinding() { - SendTimeout = new TimeSpan(0, 10, 0), + SendTimeout = new TimeSpan(0, 0, 40), MaxReceivedMessageSize = TransferLimitRemote }; var requireAuth = InterfaceName != typeof(ITGConnectivity).Name;