Exemple #1
0
 public ADOU GetADTree(string username, string password, string domain)
 {
     try
     {
         if (username.Length < 2 && password.Length < 2 && domain.Length < 2)
         {
             throw new Exception("Invailid Domain/Credentials");
         }
         HAP.AD.User _user = new AD.User();
         _user.Authenticate(username, password, domain);
         PrincipalContext pc;
         try { pc = new PrincipalContext(ContextType.Domain, domain, null, ContextOptions.Negotiate | ContextOptions.SecureSocketLayer, username, password); }
         catch { pc = new PrincipalContext(ContextType.Domain, domain, username, password); }
         DirectoryEntry root;
         if (hapConfig.Current.AD.SecureLDAP)
         {
             root = new DirectoryEntry("LDAP://DC=" + domain.Replace(".", ",DC="), username, password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.Signing);
         }
         else
         {
             root = new DirectoryEntry("LDAP://DC=" + domain.Replace(".", ",DC="), username, password);
         }
         return(FillNode(root));
     }
     catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Setup API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); return(null); }
 }
Exemple #2
0
        public void ResetPassword(string username)
        {
            User u = new AD.User(username);

            u.ResetPassword();
        }
Exemple #3
0
        public Ticket[] setNewTicket(string subject, string note, [Optional] string room, string username)
        {
            hapConfig   config = hapConfig.Current;
            XmlDocument doc    = new XmlDocument();
            User        u      = new AD.User(username);

            doc.Load(Server.MapPath("~/App_Data/Tickets.xml"));
            int x;

            if (doc.SelectSingleNode("/Tickets").ChildNodes.Count > 0)
            {
                XmlNodeList tickets = doc.SelectNodes("/Tickets/Ticket");
                x = int.Parse(tickets[tickets.Count - 1].Attributes["id"].Value) + 1;
            }
            else
            {
                x = 1;
            }
            string     _id    = x.ToString();
            XmlElement ticket = doc.CreateElement("Ticket");

            ticket.SetAttribute("id", x.ToString());
            ticket.SetAttribute("subject", subject);
            ticket.SetAttribute("priority", "Normal");
            ticket.SetAttribute("status", "New");
            XmlElement node = doc.CreateElement("Note");

            node.SetAttribute("datetime", DateTime.Now.ToUniversalTime().ToString("u"));
            node.SetAttribute("username", username);
            node.InnerXml = "<![CDATA[Room: " + room + "<br />\n" + note + "]]>";
            ticket.AppendChild(node);
            doc.SelectSingleNode("/Tickets").AppendChild(ticket);

            XmlWriterSettings set = new XmlWriterSettings();

            set.Indent      = true;
            set.IndentChars = "   ";
            set.Encoding    = System.Text.Encoding.UTF8;
            XmlWriter writer = XmlWriter.Create(Server.MapPath("~/App_Data/Tickets.xml"), set);

            doc.Save(writer);
            writer.Flush();
            writer.Close();

            MailMessage mes = new MailMessage();

            mes.Subject = "A Ticket (#" + x + ") has been Created";
            mes.From    = new MailAddress(u.Email, u.DisplayName);
            mes.Sender  = mes.From;
            mes.ReplyToList.Add(mes.From);

            mes.To.Add(new MailAddress(config.SMTP.FromEmail, config.SMTP.FromUser));

            mes.IsBodyHtml = true;
            FileInfo     template = new FileInfo(Server.MapPath("~/HelpDesk/newuserticket.htm"));
            StreamReader fs       = template.OpenText();

            mes.Body = fs.ReadToEnd().Replace("{0}", x.ToString()).Replace("{1}",
                                                                           subject).Replace("{2}",
                                                                                            note).Replace("{3}",
                                                                                                          room).Replace("{4}",
                                                                                                                        u.DisplayName).Replace("{5}",
                                                                                                                                               HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath);

            SmtpClient smtp = new SmtpClient(config.SMTP.Server, config.SMTP.Port);

            if (!string.IsNullOrEmpty(config.SMTP.User))
            {
                smtp.Credentials = new NetworkCredential(config.SMTP.User, config.SMTP.Password);
            }
            smtp.EnableSsl = config.SMTP.SSL;
            smtp.Send(mes);
            return(getMyTickets(username));
        }