// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; public class Admin : IAdmin { private bool SystemUpdateMode; public Admin() { this.SystemUpdateMode = Spludlow.Config.GetBoolean("Spludlow.SystemUpdateMode"); } private void ValidateSecurityKey(string securityKey) { if (Spludlow.Security.IsValidSecurityKey(securityKey) == true) return; throw new ApplicationException("Admin Web Service; Invalid Security Key"); } private void ValidateSystemUpdateMode() { if (this.SystemUpdateMode == false) throw new ApplicationException("Method Not Premitted with SystemUpdateMode switched off."); } public void SetSecurityKey(string oldSecurityKey, string newSecurityKey) { this.ValidateSystemUpdateMode(); this.ValidateSecurityKey(oldSecurityKey); Spludlow.Security.SetCurrentUserSecurityKey(newSecurityKey); } public int UpdateWebServiceAdmin(string securityKey) { this.ValidateSystemUpdateMode(); this.ValidateSecurityKey(securityKey); // Un-comment this exception to prevent the Admin Web Service from being able to update its self //throw new ApplicationException("System Update mode has been disabled."); return Spludlow.Release.UpdateWebServiceAdmin(); } public DataSet ServiceQueryAll(string securityKey) { this.ValidateSecurityKey(securityKey); return Spludlow.ServiceProcesses.QueryAll(); } public DataSet ServiceQueries(string securityKey, string[] serviceNames) { this.ValidateSecurityKey(securityKey); return Spludlow.ServiceProcesses.Queries(serviceNames); } public string ServiceQuery(string securityKey, string serviceName) { this.ValidateSecurityKey(securityKey); return Spludlow.ServiceProcesses.Query(serviceName); } public void ServiceStarts(string securityKey, string[] serviceNames) { this.ValidateSecurityKey(securityKey); Spludlow.ServiceProcesses.Start(serviceNames); } public void ServiceStart(string securityKey, string serviceName) { this.ValidateSecurityKey(securityKey); Spludlow.ServiceProcesses.Start(serviceName); } public void ServiceStops(string securityKey, string[] serviceNames) { this.ValidateSecurityKey(securityKey); Spludlow.ServiceProcesses.Stop(serviceNames); } public void ServiceStop(string securityKey, string serviceName) { this.ValidateSecurityKey(securityKey); Spludlow.ServiceProcesses.Stop(serviceName); } public DataSet WebQueryAll(string securityKey) { this.ValidateSecurityKey(securityKey); return Spludlow.WebServer.QueryAll(); } public DataSet WebQueries(string securityKey, string[] applicationPoolNames) { this.ValidateSecurityKey(securityKey); return Spludlow.WebServer.Queries(applicationPoolNames); } public string WebQuery(string securityKey, string applicationPoolName) { this.ValidateSecurityKey(securityKey); return Spludlow.WebServer.Query(applicationPoolName); } public void WebRecycles(string securityKey, string[] applicationPoolNames) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Recycle(applicationPoolNames); } public void WebRecycle(string securityKey, string applicationPoolName) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Recycle(applicationPoolName); } public void WebStarts(string securityKey, string[] applicationPoolNames) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Start(applicationPoolNames); } public void WebStart(string securityKey, string applicationPoolName) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Start(applicationPoolName); } public void WebStops(string securityKey, string[] applicationPoolNames) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Stop(applicationPoolNames); } public void WebStop(string securityKey, string applicationPoolName) { this.ValidateSecurityKey(securityKey); Spludlow.WebServer.Stop(applicationPoolName); } public DataSet WebQuerySites(string securityKey) { this.ValidateSecurityKey(securityKey); return Spludlow.WebServer.QuerySites(); } public string[] QueryEventLogs(string securityKey, int daysBack, bool includeEverything) { this.ValidateSecurityKey(securityKey); DataSet dataSet = Spludlow.EventLogs.QueryRaw(daysBack, includeEverything); return Spludlow.Parameters.EncodeParameter(dataSet, true, false); // Too big to return normally and don't want to re-encode } }