Ejemplo n.º 1
0
        public EditAppPage() : base()
        {
            InitializeComponent();

            // Setup ViewModel
            ViewModel                       = IoC.Get <EditAppViewModel>();
            this.DataContext                = ViewModel;
            this.AnimateOutStarted         += SaveCurrentSelectedItem;
            this.AnimateOutStarted         += Dispose;
            IoC.Get <MainWindow>().Closing += OnMainWindowClosing;
        }
Ejemplo n.º 2
0
    public EditAppPage(ApplicationViewModel applicationViewModel) : base()
    {
        SwappedOut += () =>
        {
            SaveSelectedItemOnAnimateOut();
            Dispose();
        };

        InitializeComponent();

        // Setup ViewModel
        ViewModel        = new EditAppViewModel(Lib.IoC.Get <ApplicationConfigService>(), applicationViewModel);
        this.DataContext = ViewModel;
        Lib.IoC.Get <MainWindow>().Closing += OnMainWindowClosing;
        DataObject.AddPastingHandler(ApplicationPathTextbox, HandleSymlinkOnPaste);
    }
Ejemplo n.º 3
0
        public IActionResult Create([FromForm] EditAppViewModel appModel)
        {
            var stupidRegexCheck = true; // [RegularExpressionAttribute] marks null or empty strings as valid

            if (appModel.IPRestrictedDeployer)
            {
                stupidRegexCheck = !string.IsNullOrEmpty(appModel.DeployerIP);
            }
            if (ModelState.IsValid && stupidRegexCheck)
            {
                var newApp = new Application()
                {
                    ID                   = RNG.GetRandomString(10),
                    OwnerEmail           = User.Identity.Name,
                    DeployerIP           = appModel.DeployerIP,
                    Description          = appModel.Description,
                    Encrypted            = appModel.Encrypted,
                    EncryptionAlgorithm  = EncryptionAlgorithm.AES256,
                    IPRestrictedDeployer = appModel.IPRestrictedDeployer,
                    LastUpdate           = DateTime.MinValue,
                    Name                 = appModel.Name,
                    PostdeployActions    = appModel.PostdeployActions,
                    PredeployActions     = appModel.PredeployActions
                };
                _context.Applications.Add(newApp);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                if (!stupidRegexCheck)
                {
                    ModelState.AddModelError(nameof(appModel.DeployerIP), "Invalid IP address");
                }
                return(View("EditApp", appModel));
            }
        }
Ejemplo n.º 4
0
 public SetApplicationImageCommand(EditAppViewModel model)
 {
     _editAppViewModel = model;
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit([FromForm] EditAppViewModel appModel)
        {
            var stupidRegexCheck = true; // [RegularExpressionAttribute] marks null or empty strings as valid

            if (appModel.IPRestrictedDeployer)
            {
                stupidRegexCheck = !string.IsNullOrEmpty(appModel.DeployerIP);
            }
            if (ModelState.IsValid && stupidRegexCheck)
            {
                if (appModel.ID != null && _context.Applications.Exists(appModel.ID))
                {
                    var foundApp = _context.Applications.Find(appModel.ID);
                    if (foundApp.HasOwner(User))
                    {
                        var newApp = new Application()
                        {
                            ID                   = foundApp.ID,
                            OwnerEmail           = foundApp.OwnerEmail,
                            DeployerIP           = appModel.DeployerIP,
                            Description          = appModel.Description,
                            Encrypted            = appModel.Encrypted,
                            EncryptionAlgorithm  = EncryptionAlgorithm.AES256,
                            IPRestrictedDeployer = appModel.IPRestrictedDeployer,
                            LastUpdate           = foundApp.LastUpdate,
                            Name                 = appModel.Name,
                            PredeployActions     = appModel.PredeployActions,
                            PostdeployActions    = appModel.PostdeployActions
                        };
                        _context.Applications.Remove(foundApp);
                        _context.Applications.Add(newApp);
                        _context.SaveChanges();
                        if (newApp.Encrypted)
                        {
                            await _fileManager.DeleteAllNonEncryptedFilesAsync(newApp.ID);
                        }
                        else
                        {
                            await _fileManager.DeleteAllEncryptedFilesAsync(newApp.ID);
                        }
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(Unauthorized("Nice try.")); //In case someone tries to modify someone else's app using a known ID
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                if (!stupidRegexCheck)
                {
                    ModelState.AddModelError(nameof(appModel.DeployerIP), "Invalid IP address");
                }
                return(View("EditApp", appModel));
            }
        }
Ejemplo n.º 6
0
 public DeleteApplicationCommand(EditAppViewModel editAppViewModel)
 {
     _editAppViewModel = editAppViewModel;
 }
Ejemplo n.º 7
0
 public DeployAsiLoaderCommand(EditAppViewModel addAppViewModel)
 {
     ViewModel = addAppViewModel;
     ViewModel.PropertyChanged += OnApplicationChanged;
     SetCurrentApplication();
 }