protected void Application_Start(object sender, EventArgs e) { if (!hapConfig.Current.FirstRun) { RegistryKey EventSource = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\EventLog\Application\Home Access Plus+"); if (EventSource == null) { HAP.AD.User _user = new HAP.AD.User(); _user.Authenticate(hapConfig.Current.AD.User, hapConfig.Current.AD.Password); try { _user.ImpersonateContained(); EventLog.CreateEventSource("Home Access Plus+", "Application"); } catch { } finally { _user.EndContainedImpersonate(); } } } HttpContext.Current.Cache.Insert("hapBannedIps", new List <Banned>()); API.APIRoutes.Register(RouteTable.Routes); RouteTable.Routes.Add(new Route("download/{drive}/{*path}", new DownloadRoutingHandler())); RouteTable.Routes.Add(new Route("bookingsystem/r-{resource}", new PageRouteHandler("~/bookingsystem/default.aspx", true))); RouteTable.Routes.Add(new Route("bookingsystem/t-{type}", new PageRouteHandler("~/bookingsystem/default.aspx", true))); RouteTable.Routes.Add(new Route("bookingsystem/{room}/display", new BookingSystemDislayRoutingHandler())); RouteTable.Routes.Add(new Route("tracker/web/{year}/{month}/", new PageRouteHandler("~/tracker/weblog.aspx", true))); RouteTable.Routes.Add(new Route("tracker/web/{year}/{month}/d/{day}", new PageRouteHandler("~/tracker/weblog.aspx", true))); RouteTable.Routes.Add(new Route("tracker/{year}/{month}/", new PageRouteHandler("~/tracker/log.aspx", true))); RouteTable.Routes.Add(new Route("tracker/{year}/{month}/c/{computer}/", new PageRouteHandler("~/tracker/log.aspx", true))); RouteTable.Routes.Add(new Route("tracker/{year}/{month}/d/{day}/", new PageRouteHandler("~/tracker/log.aspx", true))); RouteTable.Routes.Add(new Route("tracker/{year}/{month}/c/{computer}/d/{day}/", new PageRouteHandler("~/tracker/log.aspx", true))); }
public void ProcessRequest(HttpContext context) { if (context.User.Identity.IsAuthenticated) { HAP.AD.User _user = new HAP.AD.User(); _user.Authenticate(hapConfig.Current.AD.User, hapConfig.Current.AD.Password); string errorlist = ""; try { _user.ImpersonateContained(); using (DirectorySearcher dsSearcher = new DirectorySearcher()) { errorlist += "Creating Directory Search and Searching for then current user\n"; dsSearcher.Filter = "(&(objectClass=user) (sAMAccountName=" + ((HAP.AD.User)Membership.GetUser()).UserName + "))"; errorlist += "Using filter: " + dsSearcher.Filter + "\n"; dsSearcher.PropertiesToLoad.Add("thumbnailPhoto"); SearchResultCollection results = dsSearcher.FindAll(); errorlist += "Found " + results.Count + " results, processing 1st result\n"; if (results.Count > 0) { errorlist += "Found " + results[0].Properties["thumbnailPhoto"].Count + " thumnbnailPhotos\n"; if (results[0].Properties["thumbnailPhoto"].Count > 0) { byte[] data = results[0].Properties["thumbnailPhoto"][0] as byte[]; if (data != null) { errorlist += "Data found, making picture\n"; using (MemoryStream s = new MemoryStream(data)) { context.Response.ContentType = "image/png"; MemoryStream m = new MemoryStream(); Image i = Bitmap.FromStream(s); FixedSize(i, 92, 92).Save(m, ImageFormat.Png); m.WriteTo(context.Response.OutputStream); } } else { throw new Exception(); } } else { throw new Exception(); } } else { throw new Exception(); } } } catch { _user.EndContainedImpersonate(); if (!hapConfig.Current.School.HidePhotoErrors) { HAP.Web.Logging.EventViewer.Log("HAP.Web.API.MyPic", errorlist, System.Diagnostics.EventLogEntryType.Error, true); } context.Response.Redirect("~/api/tiles/icons/128/128/images/icons/metro/folders-os/UserNo-Frame.png"); } finally { _user.EndContainedImpersonate(); } } else { context.Response.Redirect("~/api/tiles/icons/92/92/images/icons/metro/folders-os/UserNo-Frame.png"); } }
protected void Save_Click(object sender, EventArgs e) { error.Visible = false; Config = Cache["tempConfig"] as hapConfig; try { Config.School.Name = name.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the School Name"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.School.WebSite = schoolurl.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the School Url"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.AD.UPN = upn.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD UPN"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.AD.User = un.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD Username"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } if (up.Text.Length > 0) { Config.AD.Password = up.Text; } try { Config.AD.StudentsGroup = sg.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD Students Group"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.AD.MaxLogonAttemps = int.Parse(admaxlogon.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD Max Logon Attemps"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.AD.MaxRecursions = int.Parse(adrecur.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD Max Recursive Attemps"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.AD.UseNestedLookups = adnest.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD Use Nested Lookups"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.Server = smtpaddress.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP Server Address"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.Enabled = smtpenabled.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP Enabled Checkbox"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.FromEmail = smtpfromemail.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP From Address"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.FromUser = smtpfromname.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP From User"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.Port = int.Parse(smtpport.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP Port"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.SSL = smtpssl.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP Server SSL Checkbox"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.User = smtpuser.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP User"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { if (smtppassword.Text.Length > 0) { Config.SMTP.Password = smtppassword.Text; } } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the SMTP Password"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.Exchange = ewsurl.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Exchange EWS Url"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { if (impassword.Text.Length > 0) { Config.SMTP.ImpersonationPassword = impassword.Text; } } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Impersonation Password"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.ImpersonationDomain = imdomain.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Impersonation Domain"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.SMTP.ImpersonationUser = imuser.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Impersonation User"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { adorgs.DataSource = Config.AD.OUs.Values; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the AD OUs"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Homepage.AnnouncementBox.ShowTo = hp_ab_st.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Home Page Announcement Box Show To "; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Homepage.AnnouncementBox.EnableEditTo = hp_ab_adt.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Home Page Announcement Box Enable Edit To"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.ProxyServer.Address = proxyaddress.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Proxy Server Address"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.ProxyServer.Enabled = proxyenabled.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Proxy Server Enable Box"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.ProxyServer.Port = int.Parse(proxyport.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Proxy Server Port"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.KeepXmlClean = bsclean.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Keep XML Clean Option"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.ArchiveXml = bsarch.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Keep XML Clean Option"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.Admins = bsadmins.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Admins"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.MaxDays = int.Parse(bsdays.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Max Days"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.MaxBookingsPerWeek = int.Parse(bsmax.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Max Bookings Per Week"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.BookingSystem.TwoWeekTimetable = bstwoweek.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Booking System Two Week Timetable Option"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.MyFiles.HideExtensions = mscbExt.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the My Files Hidden Extensions"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.MyFiles.WriteChecks = mscbWrite.Checked; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the My Files Write Checks Option"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Tracker.OverrideCode = trackercode.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Logon Tracker Override Code"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Tracker.Provider = trackerprovider.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Logon Tracker Provider"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Tracker.MaxStaffLogons = int.Parse(trackerstafflogs.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Logon Tracker Max Staff Logons"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Tracker.MaxStudentLogons = int.Parse(trackerstudentlogs.Text); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Logon Tracker Max Student Logons"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.HelpDesk.Admins = helpdeskadmins.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Help Desk Admin Groups"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.HelpDesk.FirstLineEmails = helpdeskfirstline.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Help Desk First Line Emails"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.MyFiles.LiveAppId = liveid.Text; } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error with the Live App Id"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } try { Config.Save(); RegistryKey EventSource = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\EventLog\Application\Home Access Plus+"); if (EventSource == null) { HAP.AD.User _user = new HAP.AD.User(); _user.Authenticate(Config.AD.User, Config.AD.Password); try { _user.ImpersonateContained(); EventLog.CreateEventSource("Home Access Plus+", "Application"); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error Creating Event Log Source"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } finally { _user.EndContainedImpersonate(); } } Response.Redirect("~/Setup.aspx?Saved=1"); } catch (Exception ex) { error.Visible = true; errormessage.Text = "Error Saving the Configuration"; errormessagemore.Text = ex.Message + "<br /><br />" + ex.StackTrace; } }
public Me() { config = hapConfig.Current; User = ((HAP.AD.User)Membership.GetUser()); Name = User.DisplayName; HAP.AD.User _user = new HAP.AD.User(); _user.Authenticate(hapConfig.Current.AD.User, hapConfig.Current.AD.Password); string errorlist = ""; try { _user.ImpersonateContained(); using (DirectorySearcher dsSearcher = new DirectorySearcher()) { errorlist += "Creating Directory Search and Searching for then current user\n"; dsSearcher.Filter = "(&(objectClass=user) (sAMAccountName=" + ((HAP.AD.User)Membership.GetUser()).UserName + "))"; errorlist += "Using filter: " + dsSearcher.Filter + "\n"; dsSearcher.PropertiesToLoad.Add("thumbnailPhoto"); SearchResultCollection results = dsSearcher.FindAll(); errorlist += "Found " + results.Count + " results, processing 1st result\n"; if (results.Count > 0) { errorlist += "Found " + results[0].Properties["thumbnailPhoto"].Count + " thumnbnailPhotos\n"; if (results[0].Properties["thumbnailPhoto"].Count > 0) { byte[] data = results[0].Properties["thumbnailPhoto"][0] as byte[]; if (data != null) { errorlist += "Data found, making picture url\n"; Photo = "~/api/mypic"; } else { throw new Exception(); } } else { throw new Exception(); } } else { throw new Exception(); } } } catch { _user.EndContainedImpersonate(); if (!hapConfig.Current.School.HidePhotoErrors) { HAP.Web.Logging.EventViewer.Log("HAP.Web.API.MyPic", errorlist, System.Diagnostics.EventLogEntryType.Error, true); } Photo = null; } finally { _user.EndContainedImpersonate(); } Email = User.Email == null ? "" : User.Email; OtherData = new Dictionary <string, string>(); try { OtherData.Add("Comment", User.Comment); } catch { } try { OtherData.Add("Notes", User.Notes); } catch { } try { OtherData.Add("LastLoginDate", User.LastLoginDate.ToString()); } catch { } try { OtherData.Add("LastName", User.LastName); } catch { } try { OtherData.Add("FirstName", User.FirstName); } catch { } try { OtherData.Add("EmployeeID", User.EmployeeID); } catch { } try { OtherData.Add("DisplayName", User.DisplayName); } catch { } try { OtherData.Add("MiddleNames", User.MiddleNames); } catch { } }