public static async Task <ValidationResponse> ValidateAsync(LoginModel login, Cache cache) { try { var client = new SigRClient(Settings.AdminSiteUrl, Settings.STSApiKey, "SiteHub"); var domainName = login.UserName.Split('@')[1].ToLower(); var site = await SiteCache.GetSiteByDomain(cache, domainName); var cred = new STSCredential { Domain = site.OnPremDomainName, UserName = login.UserName, Password = login.Password, RemoteSiteId = site.Id }; await client.StartAsync(); ValidationResponse res = await client.ProcessSTSValidationRequest(cred); return(res); } catch (Exception ex) { Utils.AddLogEntry("Error during user validation", System.Diagnostics.EventLogEntryType.Error, 0, ex); return(new ValidationResponse { IsValid = false }); } }
public static async Task <RelayResponse> ResetPassword(PasswordReset credential, StagedUser stagedUser) { try { var client = new SigRClient(Settings.AdminSiteUrl, Settings.STSApiKey, "SiteHub"); var data = JsonConvert.SerializeObject(credential); var msg = new RelayMessage { ApiKey = Settings.AdminApiKey, Data = data, DestSiteId = stagedUser.SiteId, Identifier = stagedUser.Id, Operation = SiteOperation.ResetPW }; await client.StartAsync(); RelayResponse res = await client.ProcessRelayMessage(msg); return(res); } catch (Exception ex) { Utils.AddLogEntry("Error setting user status", EventLogEntryType.Error, 0, ex); return(new RelayResponse { Success = false, ErrorMessage = ex.Message }); } }
public static async Task <RelayResponse> GetUserStatus(StagedUser user) { try { var client = new SigRClient(Settings.AdminSiteUrl, Settings.STSApiKey, "SiteHub"); var msg = new RelayMessage { ApiKey = Settings.AdminApiKey, Data = user.LocalGuid, DestSiteId = user.SiteId, Identifier = user.Upn, Operation = SiteOperation.GetUserStatus }; await client.StartAsync(); RelayResponse res = await client.ProcessRelayMessage(msg); return(res); } catch (Exception ex) { Utils.AddLogEntry("Error getting user status", EventLogEntryType.Error, 0, ex); return(new RelayResponse { Success = false, ErrorMessage = ex.Message }); } }
public SiteListenerService(SigRClient relay, ScriptTimer timer) { InitializeComponent(); _relay = relay; _timer = timer; ServiceName = GetType().Assembly.GetCustomAttribute <AssemblyTitleAttribute>().Title; CanShutdown = true; CanStop = true; }
static void Main(string[] args) { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _scriptFolderPath = args.Where(a => a.StartsWith("-scriptPath")).FirstOrDefault(); if (_scriptFolderPath != null) { _scriptFolderPath = _scriptFolderPath.Split(':')[1]; } else { _scriptFolderPath = Path.GetFullPath(string.Format("{0}\\Scripts", dir)); } ServiceName = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyTitleAttribute>().Title; ConsoleLogSource = String.Format("{0}-console", ServiceName); ServiceUtil.AssemblyName = AssemblyName; ServiceUtil.ServiceName = ServiceName; PrintLogo(); if (args.Any(a => a == "-debug")) { _isDebug = true; } var sUrl = ConfigurationManager.AppSettings["SiteUrl"]; var sDebugUrl = ConfigurationManager.AppSettings["DebugSiteUrl"]; _timerIntervalMinutes = Convert.ToInt16(ConfigurationManager.AppSettings["TimerIntervalMinutes"]); OrgApiCalls.ApiKey = ConfigurationManager.AppSettings["ApiKey"]; OrgApiCalls.SiteUrl = (_isDebug) ? sDebugUrl : sUrl; ConsoleLogSource = Utils.SetupLog(ConsoleLogSource); try { RemoteSite siteConfig = null; try { siteConfig = OrgApiCalls.GetSiteConfig(); } catch (Exception) { WriteConsoleStatus("Failed retrieving site status"); } if (siteConfig == null) { throw new Exception("Unable to retrieve site configuration, exiting"); } var scriptConfig = GetJsonConfig(siteConfig, OrgApiCalls.SiteUrl); File.WriteAllText(Path.Combine(_scriptFolderPath, "SyncVars.json"), scriptConfig); ADTools.ADDomainName = siteConfig.OnPremDomainName; relay = new SigRClient(OrgApiCalls.SiteUrl, OrgApiCalls.ApiKey, "SiteHub", true); relay.StatusUpdate += Relay_StatusUpdate; relay.ErrorEvent += Relay_ErrorEvent; relay.PingEvent += Relay_PingEvent; InitTimers(siteConfig); relay.FireScriptEvent += Relay_FireScriptEvent; if (Environment.UserInteractive) { RunConsole(siteConfig, args); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SiteListenerService(relay, timer) }; ServiceBase.Run(ServicesToRun); } } catch (Exception ex) { var msg = Utils.GetFormattedException(ex); Utils.AddLogEntry(ConsoleLogSource, msg, EventLogEntryType.Error); } }