Exemple #1
0
 public KeepAlive(Session Session)
     : base(100)
 {
     this._Session = Session;
     this.Elapsed += Timer_Elapsed;
     this.AutoReset = true;
 }
Exemple #2
0
 public Customer(Session Session, string Name)
 {
     _Name = Name;
     HtmlDocument Doc = Session.GetDocument("/");
     foreach (var v in Doc.DocumentNode.Descendants("option"))
     {
         if (v.ParentNode.GetAttributeValue("id", "") != "ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input") continue;
         if (_Name == v.NextSibling.InnerHtml) _Id = (uint)v.GetAttributeValue("value", 0);
     }
     if ((_Name == null) || (_Name == "")) throw new ArgumentException("No customer found", "Id");
 }
Exemple #3
0
 public static List<Bulletin> inCP(Session Session, ICourseProjectCommons Parent)
 {
     string path = Parent.getDashboardPath();
     HtmlDocument Document = Session.GetDocument(path);
     var nodesWithHrefToBulletin = from node in Document.DocumentNode.DescendantNodes() where node.Name == "a" && node.GetAttributeValue("href", "").Contains("/Bulletin/View") select node.GetAttributeValue("href", "");
     List<Bulletin> Bulletins = new List<Bulletin>(nodesWithHrefToBulletin.Count());
     int i = 0;
     foreach (string uri_string in nodesWithHrefToBulletin)
     {
         Uri uri = uri_string.StartsWith("/") ? new Uri(Properties.Settings.Default.urlBase + uri_string) : new Uri(uri_string);
         Bulletins[i++] = new Bulletin(Session, Parent, uint.Parse(HttpUtility.ParseQueryString(uri.Query).Get("BulletinId")));
     }
     return Bulletins;
 }
Exemple #4
0
        public void SendMessage(Session Session)
        {
            /*
             * /XmlHttp/Api.aspx?Function=MessagingValidateRecipients
             * operationId: 1000
             * to:
             * cc:
             * bcc:
             * subject:
             * text:
             * files:
             * id: 0
             * messageMeasurement: 2
             * _:
            */
            Dictionary<string, string> MailData = new Dictionary<string, string>(5);
            string Persons = "";
            foreach (Person Person in To)
            {
                Persons += Person.Username + ";";
            }
            MailData.Add("to", Persons);

            Persons = "";
            foreach (Person Person in Cc)
            {
                Persons += Person.Username + ";";
            }
            MailData.Add("cc", Persons);

            Persons = "";
            foreach (Person Person in Bcc)
            {
                Persons += Person.Username + ";";
            }
            MailData.Add("bcc", Persons);

            MailData.Add("operationId", (1000).ToString());
            MailData.Add("id", (0).ToString());
            MailData.Add("text", Text);
            MailData.Add("subject", Text);
            MailData.Add("files", "");
            MailData.Add("messageMeasurement", (2).ToString());
            MailData.Add("_", "");
            Session.PostData("/XmlHttp/Api.aspx?Function=MessagingValidateRecipients", MailData);
            Session.PostData("/XmlHttp/Api.aspx?Function=MessagingSendMessage&MessageOperationID=" + (1000).ToString(), MailData);
        }
Exemple #5
0
        public PersonSearch(Session Session, string Forname, string Surname, int HierarchyId, Course Course, PersonType PersonType)
        {
            HttpWebRequest InitialLoginRequest = Session.GetHttpWebRequest("/search/search_person.aspx");
            HtmlDocument initialLoginScreen = new HtmlDocument();
            HttpWebResponse FirstResponse = (HttpWebResponse)InitialLoginRequest.GetResponse();
            initialLoginScreen.Load(FirstResponse.GetResponseStream());

            Dictionary<string, string> LoginFormData = new Dictionary<string, string>();

            LoginFormData.Add("FirstName", Forname);
            LoginFormData.Add("Lastname", Surname);
            LoginFormData.Add("CourseID", Course.Id.ToString());
            LoginFormData.Add("HierarchyId", HierarchyId.ToString());

            LoginFormData.Add("idProfileID_7", (((PersonType & PersonType.sysadmin) > 0) ? 7 : 0).ToString());
            LoginFormData.Add("idProfileID_14", (((PersonType & PersonType.examinator) > 0) ? 14 : 0).ToString());
            LoginFormData.Add("idProfileID_8", (((PersonType & PersonType.administrator) > 0) ? 8 : 0).ToString());
            LoginFormData.Add("idProfileID_9", (((PersonType & PersonType.employee) > 0) ? 9 : 0).ToString());
            LoginFormData.Add("idProfileID_10", (((PersonType & PersonType.student) > 0) ? 10 : 0).ToString());
            LoginFormData.Add("idProfileID_62007", (((PersonType & PersonType.parent) > 0) ? 62007 : 0).ToString());
            LoginFormData.Add("idProfileID_11", (((PersonType & PersonType.guest) > 0) ? 11 : 0).ToString());

            LoginFormData.Add("Search", "Søk");
            LoginFormData.Add("Advanced", "0");

            foreach (var Form in initialLoginScreen.DocumentNode.Descendants("form"))
            {
                if (Form.GetAttributeValue("name", "") == "form")
                {
                    foreach (var inp in initialLoginScreen.DocumentNode.Descendants("input"))
                    {
                        if (!LoginFormData.ContainsKey(inp.GetAttributeValue("name", ""))) LoginFormData.Add(inp.GetAttributeValue("name", ""), inp.GetAttributeValue("value", ""));
                    }
                    HtmlDocument doc = Session.PostData("/search/search_person.aspx", LoginFormData);
                    _Result = new List<Person>(10);
                    foreach (var row in (from element in doc.DocumentNode.DescendantNodes() where element.GetAttributeValue("id", "").StartsWith("row_") select element))
                    {
                        string href = row.ChildNodes[1].FirstChild.GetAttributeValue("href", "");
                        _Result.Add(new Person(Session, uint.Parse(HttpUtility.ParseQueryString(new Uri(Properties.Settings.Default.urlBase + href.Substring(href.IndexOf('/'))).Query).Get("PersonID"))));
                    }
                }
            }
        }
Exemple #6
0
 public static List<Bulletin> inProject(Session Session, Project Project)
 {
     return inCP(Session, Project);
 }
Exemple #7
0
        private static void Main(string[] args)
        {
            Session sess = new Session();  //Create a new Session object
            Console.WriteLine("ASP.NET_Id: [" + sess.Id + "]"); //Output the value of the ASP.NET_SessionId cookie
            Console.Write("CustomerId? ");          //Get the customer id from the user
            uint CustomerId = uint.Parse(Console.ReadLine());
            sess.Customer = new Customer(sess, CustomerId);

            Console.WriteLine("Customer: " + sess.Customer.Name); //Output the customer's name
            System.Diagnostics.Debug.Assert((new Customer(sess, sess.Customer.Name).Id == CustomerId) && (new Customer(sess, sess.Customer.Name).Name == sess.Customer.Name));  //Check that creating a customer from that name, gives the same customer as creating one with the CustomerId

            Console.Write("Username: "******"Password: "******"Welcome, " + Me.Name + "!");//Print my name

            while (true) //Until the user exits
            {
                try
                {
                    Console.Write("."); //Print prompt
                    string order = Console.ReadLine(); //Get command
                    string[] orders = order.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);   //Split command into parts
                    orders[0] = orders[0].ToLower();//Make part one lowercase (to simplify the if's in our code)
                    if ((orders[0] == "exit") || (orders[0] == "quit") || (orders[0] == "break")) break;
                    if (orders[0] == "project")
                    {
                        if (orders[1] == "set-active") new Project(sess, uint.Parse(orders[2])).setActive();//Set the active context to the project with this id
                        if (orders[1] == "get-active") //Get project id of active context
                        {
                            if (sess.ActiveContext.StartsWith("P")) Console.WriteLine(sess.ActiveContext);
                            else Console.WriteLine("Active context is not a project");
                        }
                        if (orders[1] == "get-root")    //Get the root directory of the active context if it's a project
                        {
                            if (sess.ActiveContext.StartsWith("P"))
                            {
                                Console.WriteLine((new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))).getRootDirectory()).Name);
                            }
                            else Console.WriteLine("Active context is not a project");
                        }
                        if (orders[1] == "active-toggle-archive") //send project in active context to archive
                        {
                            if (sess.ActiveContext.StartsWith("P")) new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))).toArchive();
                            else Console.WriteLine("Active context is not a project");
                        }
                    }
                    if (orders[0] == "course")
                    {
                        if (orders[1] == "set-active") new Course(sess, int.Parse(orders[2])).setActive(); //Set active context course id
                        if (orders[1] == "get-active") //Get the active context course id
                        {
                            if (sess.ActiveContext.StartsWith("C")) Console.WriteLine(sess.ActiveContext);
                            else Console.WriteLine("Active context is not a course");
                        }
                        if (orders[1] == "get-root")        //Get the root directory of the course
                        {
                            if (sess.ActiveContext.StartsWith("C"))
                            {
                                new Course(sess, int.Parse(sess.ActiveContext.Substring(1))).getRootDirectory();
                            }
                            else Console.WriteLine("Active context is not a course");
                        }
                    }
                    if (orders[0] == "keepalive")
                    {
                        if (orders[1] == "get-messenger-status")        //Show as online
                        {
                            Console.WriteLine(sess.KeepAlive.MessengerStatus);
                        }
                        if (orders[1] == "set-messenger-status")        //Show as offline
                        {
                            sess.KeepAlive.MessengerStatus = uint.Parse(orders[2]);
                        }
                    }
                    if (orders[0] == "make-http-request") sess.GetHttpWebRequest(orders[1]).GetResponse().Close();  //Make a HTTP-GET request, with the session cookies
                    if (orders[0] == "session")
                    {
                        if (orders[1] == "logout") sess.Logout();           //Log out
                        if (orders[1] == "login") sess.Login(orders[2], orders[3]); //login <user> <password>
                    }
                    if (orders[0] == "mail")
                    {
                        if (orders[1] == "get-in-folder")       //Get mails in folder by id
                        {
                            itsLib.Messaging.MailBox mb = new itsLib.Messaging.MailBox(sess, int.Parse(orders[2]));
                            Console.WriteLine("Messages in folder \"" + mb.Name + "\"");    //Print folder name
                            List<Mail> mails = mb.GetMails();   //Get the mails in message folder
                            foreach (Mail Mail in mails)
                            {
                                Console.Write("From: " + Mail.From.Username + "\t\t");  //Output who sent the mail
                                foreach (Person Person in Mail.To)
                                {
                                    if (Person != null) Console.Write(Person.Username + "\t\t"); //And all recipients
                                }
                                Console.WriteLine(Mail.Subject);    //And lastly the subject
                            }
                        }
                        if (orders[1] == "create")
                        {
                            MailCreator NewMail = new MailCreator();
                            do
                            {
                                Console.Write("To: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.To.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("To: " + NewMail.To[NewMail.To.Count - 1].Name);
                            } while (true);
                            do
                            {
                                Console.Write("Cc: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.Cc.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("Cc: " + NewMail.Cc[NewMail.Cc.Count - 1].Name);
                            } while (true);
                            do
                            {
                                Console.Write("Bcc: ");
                                order = Console.ReadLine().Trim();
                                if (order != "") NewMail.Bcc.Add(new Person(sess, uint.Parse(order)));
                                else break;
                                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1);
                                Console.WriteLine("Bcc " + NewMail.Bcc[NewMail.Bcc.Count - 1].Name);
                            } while (true);
                            Console.Write("Subject: ");
                            NewMail.Subject = Console.ReadLine();
                            do
                            {
                                Console.Write("Text: ");
                                order = Console.ReadLine();
                                if (order != "") NewMail.Text += order + '\n'.ToString();
                                else break;
                            } while (true);
                            NewMail.SendMessage(sess);
                        }
                    }
                    if (orders[0] == "bulletin")
                    {
                        if (orders[1] == "in-active")   //Get bulletin (by id) in the currently active context (project or course)
                        {
                            List<Bulletin> bulletins;
                            if (sess.ActiveContext.StartsWith("C")) bulletins = Bulletin.inCP(sess, new Course(sess, int.Parse(sess.ActiveContext.Substring(1))));
                            else bulletins = Bulletin.inCP(sess, new Project(sess, uint.Parse(sess.ActiveContext.Substring(1))));
                            foreach (Bulletin bulletin in bulletins)
                            {
                                Console.WriteLine(bulletin.By.Username + ":" + bulletin.Title + ":" + bulletin.Text);
                            }
                        }
                    }
                    if (orders[0] == "find-person")
                    {
                        if (orders[1] == "any")         //List all persons
                        {
                            PersonSearch ps = PersonSearch.GetAll(sess);
                            foreach (Person Person in ps.Result)
                            {
                                Console.WriteLine(Person.Name);
                            }
                        }
                    }
                }
                catch (Exception e) { Console.WriteLine(e.Message); }
            }
        }
Exemple #8
0
 public static PersonSearch GetAll(Session Session)
 {
     return new PersonSearch(Session, "", " ");
 }
Exemple #9
0
 public PersonSearch(Session Session, string Forname, string Surname)
     : this(Session, Forname, Surname, -1)
 {
 }
Exemple #10
0
 public Project(Session Session, uint Id)
 {
     this.Id = Id;
     this.Session = Session;
 }
Exemple #11
0
 public static Person Nobody(Session sess)
 {
     return new Person(sess, 0);
 }
Exemple #12
0
 public static Person Me(Session sess)
 {
     uint Uid = 0;
     HtmlDocument top_menu = sess.GetDocument("/TopMenu.aspx?Course=&CPHFrame=1&item=menu_intranet");
     var e = from element in top_menu.DocumentNode.Descendants("a") where element.GetAttributeValue("class", "") == "user_name" select element.GetAttributeValue("href", "");
     Uri user_info_Uri = new Uri(Properties.Settings.Default.urlBase + e.First());
     Uid = uint.Parse(HttpUtility.ParseQueryString(user_info_Uri.Query).Get("PersonId"));
     return new Person(sess, Uid);
 }
Exemple #13
0
 public Person(Session sess, uint Uid)
 {
     this._Id = Uid;
     this.sess = sess;
     if (Uid == 0) return;
 }
Exemple #14
0
 public Bulletin(Session Session, ICourseProjectCommons Parent, uint Id)
 {
     this.Id = Id;
     this.Session = Session;
     this.Parent = Parent;
 }
Exemple #15
0
 public PersonSearch(Session Session, string Forname, string Surname, int HierarchyId, Course Course)
     : this(Session, Forname, Surname, HierarchyId, Course, PersonType.administrator | PersonType.employee | PersonType.examinator | PersonType.guest | PersonType.parent | PersonType.student | PersonType.sysadmin)
 {
 }
Exemple #16
0
 public static List<Bulletin> inCourse(Session Session, Course Course)
 {
     return inCP(Session, Course);
 }
Exemple #17
0
 public PersonSearch(Session Session, string Forname, string Surname, int HierarchyId)
     : this(Session, Forname, Surname, HierarchyId, new Course(Session, -1))
 {
 }
Exemple #18
0
 public Course(Session Session, int Id)
 {
     this._Id = Id;
     this.Session = Session;
 }
Exemple #19
0
        private static void Connection(object o)
        {
            TcpClient tc = (TcpClient)o;
            TcpClient dataClient = null;
            TcpListener pasvListener = null;

            NetworkStream ns = new NetworkStream(tc.Client);
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);
            StreamReader dataStreamReader;
            StreamWriter dataStreamWriter = null;

            Session sess = new Session();
            string user = "", pass = "", usernameEncoded, usernameDecoded;
            sw.AutoFlush = true;
            string tmpS = "";
            uint CustomerId = 0;
            string wd = "/";
            bool binaryFlag = false;

            sw.WriteLine("220 its ftpd");
            while (tc.Connected)
            {
                string command;
                try
                {
                    sw.Flush();
                    if ((sr == null) || (sw == null)) return;
                    command = sr.ReadLine().Trim();
                    Console.WriteLine(">" + command);
                }
                catch (IOException) { return; }
                string cmd = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0].ToUpper();
                if (cmd == "USER")
                {
                    try
                    {
                        usernameEncoded = command.Substring(cmd.IndexOf("USER ") + "USER ".Length + 1);
                        usernameDecoded = Base16.from16(usernameEncoded);
                        user = usernameDecoded.Split('@')[0];
                        CustomerId = uint.Parse(usernameDecoded.Split('@')[1]);
                        sw.WriteLine("331 Password required");
                    }
                    catch (Exception e) { sw.WriteLine("530 " + e.Message); }
                    continue;
                }
                if (cmd == "PASS")
                {
                    pass = command.Substring(cmd.IndexOf("PASS ") + "PASS ".Length + 1);
                    try
                    {
                        Customer Customer = new Customer(sess, CustomerId);
                        sess.Customer = Customer;
                        sess.Login(user, Base16.from16(pass));
                        if (sess.LoggedIn) sw.WriteLine("230 You may continue");
                        else sw.WriteLine("530 Denied");
                    }
                    catch (Exception e) { sw.WriteLine("530 " + e.Message); }
                    continue;
                }
                if (cmd == "PWD")
                {
                    sw.WriteLine("257 \"" + wd + "\"");
                    continue;
                }
                if (cmd == "CWD")
                {
                    wd = command.Substring("CWD ".Length + 1);
                    if (wd == "") wd = "/";
                    sw.WriteLine("250 " + wd);
                    continue;
                }
                if (cmd == "TYPE")
                {
                    tmpS = command.Substring("TYPE ".Length + 1);
                    if ((tmpS == "A") || (tmpS == "A N")) binaryFlag = false;
                    if ((tmpS == "I") || (tmpS == "L 8")) binaryFlag = true;
                    sw.WriteLine("200 " + binaryFlag.ToString());
                    continue;
                }

                if (cmd == "SYST")
                {
                    sw.WriteLine("215 ITSL");
                    continue;
                }
                if (cmd == "EPSV")
                {
                    sw.WriteLine("502 NO IPv6");
                    continue;
                }
                if (cmd == "FEAT")
                {
                    sw.WriteLine("211 No features"); //Should probably use some other code
                    continue;
                }
                if (cmd == "PASV")
                {
                    try
                    {
                        sw.WriteLine("227 =127,0,0,1,0,20"); // Implement proper code for finding IP/Port of server
                    }
                    catch (Exception)
                    {
                    }
                    if (pasvListener == null)
                    {
                        pasvListener = new TcpListener(20);
                        pasvListener.Start();
                    }
                    dataClient = pasvListener.AcceptTcpClient();
                    continue;
                }
                if (cmd == "PORT")
                {
                    string uri = command.Substring("PORT".Length + 1);
                    string[] parts = uri.Split(',');
                    int port = int.Parse(parts[4]) * 256 + int.Parse(parts[5]);
                    string ip = "";
                    foreach (string part in parts)
                    {
                        ip += part + ".";
                    }
                    ip = ip.Substring(0, ip.LastIndexOf('.') - 1);
                    ip = ip.Substring(0, ip.LastIndexOf('.'));
                    ip = ip.Substring(0, ip.LastIndexOf('.'));
                    dataClient = new TcpClient(ip, port);
                    sw.WriteLine("200 Connected");
                    dataStreamReader = new StreamReader(new NetworkStream(dataClient.Client));
                    dataStreamWriter = new StreamWriter(new NetworkStream(dataClient.Client));

                    continue;
                }
                if (cmd == "NLST")
                {
                    if (wd == "/")
                    {
                        sw.WriteLine("150");
                        dataStreamWriter.WriteLine("eportfolio\r\ncourses\r\nprojects\r\n");
                        dataStreamWriter.Flush();
                        dataStreamWriter.Close();
                        dataClient.Close();
                        sw.WriteLine("226");
                    }
                    continue;
                }
                if (command.Length >= (cmd.Length + 2)) Console.WriteLine("UNKNOWN \"" + cmd + "\" in \"" + command.Substring(cmd.Length + 1) + "\"");
                else Console.WriteLine("UNKNOWN \"" + cmd + "\"");
            }
        }