예제 #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
        public ActionResult Index(FormCollection collection)
        {
            var serviceController = new Service.Library.Controllers.Settings();

            var results = serviceController.Search(o => o.Viewable);

            if (results.Failed || results.Entity == null || !results.Entity.Any())
            {
                throw new ApplicationException(results.Message);
            }

            foreach (var setting in results.Entity.Select(x => new SettingModel(x)))
            {
                if (!collection.AllKeys.Contains(setting.FullName))
                {
                    continue;
                }

                var value = collection[setting.FullName];

                if (string.IsNullOrWhiteSpace(value))
                {
                    if (setting.InputType != InputTypes.Checkbox && setting.InputType != InputTypes.Password)
                    {
                        ModelState.AddModelError(setting.FullName, setting.ValidationMessage);
                    }

                    continue;
                }
                else
                {
                    if (setting.InputType == InputTypes.Password)
                    {
                        var crypt = new QuickAES();

                        value = crypt.EncryptToString(value);
                    }
                }

                if (setting.InputType == InputTypes.Checkbox)
                {
                    value = collection.Get(setting.FullName).ToLower().Contains("t") ? "true" : "false";
                }

                if (!setting.Value.Equals(value))
                {
                    serviceController.Set(setting.Id, value);
                }
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            return(Index());
        }
예제 #5
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));
        }
예제 #6
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)));
            }
        }
예제 #7
0
        public void LubrizolOutSettings(string validationKey)
        {
            const string prefix = "LubrizolOut";

            var system = Context.ExternalSystems.FirstOrDefault(x => x.Id == ExternalSystems.LubrizolOut.Id);

            if (system == null)
            {
                return;
            }

            var factory = new Factory(Context);

            /*
             * Available = Factory.CreateSetting("Available", "Is the Lubrizol export available.", "true", 0, true, InputTypes.Checkbox, ExternalSystems.LubrizolOut);
             * Repeat = Factory.CreateSetting("Repeat", "Allow export task to repeat.", "true", 0, true, InputTypes.Checkbox, ExternalSystems.LubrizolOut);
             * RepeatInterval = Factory.CreateSetting("RepeatInterval", "Export repeat interval in minutes.", "3", 0, true, InputTypes.Text, ExternalSystems.LubrizolOut);
             * ServiceAddress = Factory.CreateSetting("ServiceAddress", "Service Address", "http://localhost", 2, true, InputTypes.Text, ExternalSystems.LubrizolOut);
             * Account = Factory.CreateSetting("ServiceAccount", "Service User Id", "admin", 3, true, InputTypes.Text, ExternalSystems.LubrizolOut);
             * Password = Factory.CreateSetting("ServicePassword", "Service Password", "admin", 4, true, InputTypes.Password, ExternalSystems.LubrizolOut);
             * LastUpdated = Factory.CreateSetting("LastUpdated", "Last updated timestamp on last person record exported.", "", 0, false, InputTypes.Text, ExternalSystems.LubrizolOut);
             * SourceSystem = Factory.CreateSetting("SourceSystem", "System whose data will be exported.", ExternalSystems.S2In.Id.ToString(), 0, false, InputTypes.Text, ExternalSystems.LubrizolOut);
             * ActiveEmployeeLibrary = Factory.CreateSetting("ActiveEmployeeLibrary", "Active Employees Library Url", "http://localhost", 7, true, InputTypes.Text, ExternalSystems.LubrizolOut);
             * InactiveEmployeeLibrary = Factory.CreateSetting("InactiveEmployeeLibrary", "Inactive Employees Library Url", "http://localhost", 7, true, InputTypes.Text, ExternalSystems.LubrizolOut);
             */

            var crypt = new QuickAES();

            factory.createSetting(system, prefix, LubrizolExport.Available);
            factory.createSetting(system, prefix, LubrizolExport.Repeat);
            factory.createSetting(system, prefix, LubrizolExport.RepeatInterval, "1");
            factory.createSetting(system, prefix, LubrizolExport.ServiceAddress, "http://cencle06/_vti_bin/copy.asmx");
            factory.createSetting(system, prefix, LubrizolExport.Account, "cencle06\\administrator");
            factory.createSetting(system, prefix, LubrizolExport.Password, crypt.EncryptToString("T@ipan11"));
            factory.createSetting(system, prefix, LubrizolExport.LastUpdated);
            factory.createSetting(system, prefix, LubrizolExport.SourceSystem);
            factory.createSetting(system, prefix, LubrizolExport.ActiveEmployeeLibrary, "http://cencle06:10807/Active Employees");
            factory.createSetting(system, prefix, LubrizolExport.InactiveEmployeeLibrary, "http://cencle06:10807/Inactive Employees");
            factory.createSetting(system, prefix, LubrizolExport.SqlConnection, "Integrated Security=SSPI;Persist Security Info=False;User ID=r1sm;Initial Catalog=LubrizolConnector;Data Source=.");

            Context.SubmitChanges();
        }