예제 #1
0
        public S2API(string uri, string user, string password, bool encryptedPassword = true)
        {
            _uri = uri;
            var crypt = new QuickAES();

            try
            {
                if (!Login(user, password, encryptedPassword))
                {
                    throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}", user,
                                                       crypt.DecryptString(password), uri)));
                }
            }
            catch (Exception e)
            {
                throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}\n{3}", user,
                                                   crypt.DecryptString(password), uri, e)));
            }

            using (var context = new RSMDataModelDataContext())
            {
                ImportSystem = context.ExternalSystems.FirstOrDefault(x => x.Name == "S2 Import");
                ExportSystem = context.ExternalSystems.FirstOrDefault(x => x.Name == "S2 Export");
            }

            ApiVersion = GetAPIVersion();
        }
예제 #2
0
        private bool Login(string user, string pass, bool encryptedPassword)
        {
            var crypt = new QuickAES();

            var decPass = encryptedPassword ? crypt.DecryptString(pass) : pass;

            var xo = new XmlOutput()
                     .XmlDeclaration()
                     .Node("NETBOX-API").Within()
                     .Node("COMMAND").Attribute("name", "Login").Attribute("num", "1").Within()
                     .Node("PARAMS").Within()
                     .Node("USERNAME").InnerText(user)
                     .Node("PASSWORD").InnerText(decPass);

            var doc = HttpPost(xo);

            if (CallWasSuccessful(doc))
            {
                try
                {
                    SessionID = doc["NETBOX"].Attributes["sessionid"].InnerText;
                }
                catch (Exception ex)
                {
                    SessionID = "NOT NEEDED";
                }
                return(true);
            }

            throw (new Exception(doc.InnerXml));
        }
예제 #3
0
        bool Login(string user, string pass)
        {
            QuickAES  crypt   = new QuickAES();
            string    decPass = crypt.DecryptString(pass);
            XmlOutput xo      = new XmlOutput()
                                .XmlDeclaration()
                                .Node("NETBOX-API").Within()
                                .Node("COMMAND").Attribute("name", "Login").Attribute("num", "1").Within()
                                .Node("PARAMS").Within()
                                .Node("USERNAME").InnerText(user)
                                .Node("PASSWORD").InnerText(decPass);

            XmlDocument doc = HttpPost(xo);

            if (CallWasSuccessful(doc))
            {
                try
                {
                    _sessionID = doc["NETBOX"].Attributes["sessionid"].InnerText;
                }
                catch (Exception)
                {
                    _sessionID = "NOT NEEDED";
                }
                return(true);
            }

            throw (new Exception(doc.InnerXml));
        }
예제 #4
0
        private NetworkCredential CreateCredentials(string user, string pass, bool encryptedPassword)
        {
            if (encryptedPassword && !string.IsNullOrWhiteSpace(pass))
            {
                var crypt = new QuickAES();

                var decPass = crypt.DecryptString(pass);

                return(new NetworkCredential(user, decPass));
            }

            return(new NetworkCredential(user, pass));
        }
예제 #5
0
        public S2API(string uri, string user, string password)
        {
            _uri = uri;
            QuickAES crypt = new QuickAES();

            try
            {
                if (!Login(user, password))
                {
                    throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}", user, crypt.DecryptString(password), uri)));
                }
            }
            catch (Exception e)
            {
                throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}\n{3}", user, crypt.DecryptString(password), uri, e)));
            }
        }