From 22a0e92b63352c6595b80f454ddc35420327bc82 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 18 Oct 2017 10:47:31 +0100 Subject: [PATCH] Added usersname and password option for the updater #1460 --- src/Ombi.Helpers/StringHelper.cs | 23 ++++++++++++- src/Ombi.Helpers/StringHelpers.cs | 34 ------------------- .../Jobs/Ombi/OmbiAutomaticUpdater.cs | 12 +++++-- .../Settings/Models/UpdateSettings.cs | 2 ++ .../ClientApp/app/interfaces/ISettings.ts | 2 ++ .../app/settings/update/update.component.html | 14 ++++++++ .../app/settings/update/update.component.ts | 2 ++ 7 files changed, 52 insertions(+), 37 deletions(-) delete mode 100644 src/Ombi.Helpers/StringHelpers.cs diff --git a/src/Ombi.Helpers/StringHelper.cs b/src/Ombi.Helpers/StringHelper.cs index fdb1dea84..daa8cabe7 100644 --- a/src/Ombi.Helpers/StringHelper.cs +++ b/src/Ombi.Helpers/StringHelper.cs @@ -1,5 +1,7 @@ -using System.Globalization; +using System; +using System.Globalization; using System.Linq; +using System.Security; using System.Security.Cryptography; using System.Text; @@ -44,5 +46,24 @@ namespace Ombi.Helpers return string.Join("", (sha1.ComputeHash(Encoding.UTF8.GetBytes(input))).Select(x => x.ToString("x2")).ToArray()); } + + public static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s); + public static bool HasValue(this string s) => !IsNullOrEmpty(s); + + public static SecureString ToSecureString(this string password) + { + if (password == null) + throw new ArgumentNullException(nameof(password)); + + var securePassword = new SecureString(); + + foreach (var c in password) + { + securePassword.AppendChar(c); + } + + securePassword.MakeReadOnly(); + return securePassword; + } } } \ No newline at end of file diff --git a/src/Ombi.Helpers/StringHelpers.cs b/src/Ombi.Helpers/StringHelpers.cs deleted file mode 100644 index 00b699581..000000000 --- a/src/Ombi.Helpers/StringHelpers.cs +++ /dev/null @@ -1,34 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2017 Jamie Rees -// File: StringHelpers.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion -namespace Ombi.Helpers -{ - public static class StringHelpers - { - public static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s); - public static bool HasValue(this string s) => !IsNullOrEmpty(s); - } -} \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs index 2a4527a0a..699116e3a 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs @@ -157,7 +157,7 @@ namespace Ombi.Schedule.Jobs.Ombi } // Extract it Ctx.WriteLine("Extracting ZIP"); - Extract(zipDir, tempPath, extension); + Extract(zipDir, tempPath); Ctx.WriteLine("Finished Extracting files"); Ctx.WriteLine("Starting the Ombi.Updater process"); @@ -175,6 +175,14 @@ namespace Ombi.Schedule.Jobs.Ombi Arguments = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + " " + extension, WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"), }; + if (settings.Username.HasValue()) + { + start.UserName = settings.Username; + } + if (settings.Password.HasValue()) + { + start.Password = settings.Password.ToSecureString(); + } using (var proc = new Process { StartInfo = start }) { proc.Start(); @@ -189,7 +197,7 @@ namespace Ombi.Schedule.Jobs.Ombi } } - private void Extract(string zipDir, string tempPath, string osPlat) + private void Extract(string zipDir, string tempPath) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { diff --git a/src/Ombi.Settings/Settings/Models/UpdateSettings.cs b/src/Ombi.Settings/Settings/Models/UpdateSettings.cs index ccf4d2f86..e1a696161 100644 --- a/src/Ombi.Settings/Settings/Models/UpdateSettings.cs +++ b/src/Ombi.Settings/Settings/Models/UpdateSettings.cs @@ -3,5 +3,7 @@ public class UpdateSettings : Settings { public bool AutoUpdateEnabled { get; set; } + public string Username { get; set; } + public string Password { get; set; } } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/app/interfaces/ISettings.ts index 6589b3b62..55614ffe2 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISettings.ts @@ -17,6 +17,8 @@ export interface IOmbiSettings extends ISettings { export interface IUpdateSettings extends ISettings { autoUpdateEnabled: boolean; + username: string; + password: string; } export interface IEmbySettings extends ISettings { diff --git a/src/Ombi/ClientApp/app/settings/update/update.component.html b/src/Ombi/ClientApp/app/settings/update/update.component.html index 5201e163e..f8715a0da 100644 --- a/src/Ombi/ClientApp/app/settings/update/update.component.html +++ b/src/Ombi/ClientApp/app/settings/update/update.component.html @@ -20,6 +20,20 @@ + + If you are getting any permissions issues, you can specify a user for the update process to run under. + +
+ + +
+ +
+ + +
+ + diff --git a/src/Ombi/ClientApp/app/settings/update/update.component.ts b/src/Ombi/ClientApp/app/settings/update/update.component.ts index 097eed0ab..8699f54ef 100644 --- a/src/Ombi/ClientApp/app/settings/update/update.component.ts +++ b/src/Ombi/ClientApp/app/settings/update/update.component.ts @@ -22,6 +22,8 @@ export class UpdateComponent implements OnInit { .subscribe(x => { this.form = this.fb.group({ autoUpdateEnabled: [x.autoUpdateEnabled], + username: [x.username], + password: [x.password], }); }); }