示例#1
0
        private void PrepareInstall(IPackage package, ApplicationMap applicationMap, bool prepareOnly)
        {
            _output.WriteLine("Updating {0}...", package.Id);
            var process = new Process();

            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.ErrorDialog            = false;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.EnableRaisingEvents = true;
            process.StartInfo.FileName  = "deployd.exe";
            process.StartInfo.Arguments = string.Format("-{2} -app=\"{0}\" -e=\"{1}\" {3} --from {4} --to {5}",
                                                        package.Id,
                                                        _instanceConfiguration.Environment,
                                                        prepareOnly ? "p" : "i",
                                                        _instanceConfiguration.ForceDownload ? "-f" : "",
                                                        _packageSourceConfiguration.PackageSource,
                                                        applicationMap.InstallPath);
            _log.DebugFormat("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
            process.OutputDataReceived += (sender, args) => _output.WriteLine(args.Data);
            process.ErrorDataReceived  += (sender, args) => _output.WriteLine(args.Data);
            process.Exited             += (sender, args) => _log.DebugFormat("Process exited with code {0}", process.ExitCode);
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
        }
示例#2
0
        public Application GetRegisteredApplication(string appName)
        {
            if (string.IsNullOrEmpty(appName))
            {
                throw new ArgumentException(nameof(appName));
            }

            ApplicationMap.TryGetValue(appName.ToUpperInvariant(), out var result);
            return(result);
        }
示例#3
0
        internal void Add(Application app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            ApplicationMap.AddOrUpdate(app.Name.ToUpperInvariant(), app, (key, existing) => { return(app); });
            AddInstances(app);
        }
示例#4
0
        public void Execute()
        {
            List <IPackage> packagesToUpdate = new List <IPackage>();
            var             activeFinders    = _finders.Where(x => x.SupportsPathType()).ToList();

            var location =
                activeFinders.Select(locator => locator.CanFindPackageAsObject(_instanceConfiguration.AppName))
                .FirstOrDefault(result => result != null);

            var allPackages = _query.GetLatestVersions(_packageSourceConfiguration.PackageSource);

            foreach (var package in allPackages)
            {
                var appmap = new ApplicationMap(package.Id, _fs.Path.Combine(_installationRoot.Path, package.Id));
                if (!File.Exists(appmap.VersionFile))
                {
                    _log.DebugFormat("{0} is not installed", package.Id);
                    continue;
                }

                SemanticVersion installedVersion;
                if (SemanticVersion.TryParse(File.ReadAllText(appmap.VersionFile), out installedVersion))
                {
                    if (package.Version > installedVersion)
                    {
                        _output.WriteLine(package.Id + " is out of date");
                        packagesToUpdate.Add(package);
                    }
                }
            }

            if (packagesToUpdate.Count == 0)
            {
                _output.WriteLine("Everything up to date");
                return;
            }

            foreach (var package in packagesToUpdate)
            {
                var appmap = new ApplicationMap(package.Id, _fs.Path.Combine(_installationRoot.Path, package.Id));
                PrepareInstall(package, appmap, _instanceConfiguration.Prep);
            }
        }
        public void CopyVariablesToEnvironment_MapsApplicationMapToEnvironment()
        {
            _runner = new CommandLineRunner(_log.Object, _config.Object, _fs.Object, _output);
            var map = new ApplicationMap("testApp", "c:\\install\\path");

            _config.Setup(x => x.ApplicationMap).Returns(map);
            var startInfo = new ProcessStartInfo {
                FileName = HookFileName
            };

            _runner.CopyVariablesToEnvironment(startInfo);

            const string prefix             = "Deployd.";
            var          countOfDeploydKeys = startInfo.EnvironmentVariables.Keys.Cast <string>().Count(var => var.StartsWith(prefix));

            Assert.That(startInfo.EnvironmentVariables[prefix + "AppName"], Is.EqualTo(map.AppName));
            Assert.That(startInfo.EnvironmentVariables[prefix + "InstallPath"], Is.EqualTo(map.InstallPath));
            Assert.That(startInfo.EnvironmentVariables[prefix + "Lock"], Is.EqualTo(map.Lock));
            Assert.That(startInfo.EnvironmentVariables[prefix + "Lockfile"], Is.EqualTo(map.Lockfile));
            Assert.That(startInfo.EnvironmentVariables[prefix + "Staging"], Is.EqualTo(map.Staging));
            Assert.That(startInfo.EnvironmentVariables[prefix + "VersionFile"], Is.EqualTo(map.VersionFile));
            Assert.That(countOfDeploydKeys, Is.GreaterThan(0));
        }
示例#6
0
        public void OpenFile(string SourceFile)
        {
            SelectedTab = -1;

            if (SourceFile == null)
            {
                var dialog = new OpenFileDialog()
                {
                    Filter = "Report Files (*.rxml Files)|*.rxml|Vuln Files (*.pxml)|*.pxml|All|*.*"
                };
                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                SourceFile = dialog.FileName;
            }

            var info = new FileInfo(SourceFile);

            ReportDir = info.Directory.FullName;

            if (info.Extension == ".rxml")
            {
                var reportFiles = ReportFile.Load(SourceFile);

                Func <string, string> getFilePath = x => info.DirectoryName + "\\" +
                                                    new FileInfo(x).Name;

                var staticAnalysisReport = reportFiles
                                           .SingleOrDefault(x => x.Name == "Static analysis");

                if (staticAnalysisReport != null)
                {
                    var alerts = StaticAnalysisFileAlertCollection
                                 .Load(getFilePath(staticAnalysisReport.Filename))
                                 .SelectMany(x => x.Alerts.Select(y => new
                    {
                        x.Filename,
                        Alert = y,
                    }))
                                 .OrderBy(x => x.Alert.Name);

                    if (alerts.Any())
                    {
                        StaticAnalysisVisibility = Visibility.Visible;
                        StaticAnalysisAlerts     = alerts;
                    }
                }

                var vulnReport = reportFiles
                                 .SingleOrDefault(x => new FileInfo(x.Filename).Extension == ".pxml");

                if (vulnReport != null)
                {
                    VulnerabilityTabVisibility = Visibility.Visible;
                    SelectedTab = 0;

                    var alerts = ScanAlertCollection.Load(getFilePath(vulnReport.Filename));

                    if (alerts == null)
                    {
                        return;
                    }

                    CreateAlertViewModels(alerts);
                }
                else
                {
                    VulnerabilityTabVisibility = Visibility.Collapsed;
                }


                var inputMap = reportFiles
                               .SingleOrDefault(x => x.Name == "Input Map Report");

                if (inputMap != null)
                {
                    var inputMapFile = inputMap.Filename;
                    InputTable = ApplicationMap
                                 .FromXml(getFilePath(inputMapFile)).Pages
                                 .ToDictionary(
                        x => string.Format(
                            "{0} ({1})",
                            x.Page,
                            x.SuperglobalNameCollectionTable.Sum(y => y.Value.Count())),
                        x => new Dictionary <string, List <object> >()
                    {
                        { "GET", x.Get.Select(y => (object)(new { Key = y })).ToList() },
                        { "POST", x.Post.Select(y => (object)(new { Key = y })).ToList() },
                        { "REQUEST", x.Request.Select(y => (object)(new { Key = y })).ToList() },
                        { "Files", x.Files.Select(y => (object)(new { Key = y })).ToList() },
                        { "Cookies", x.Cookie.Select(y => (object)(new { Key = y })).ToList() }
                    }
                        .Where(y => y.Value.Any())
                        .ToDictionary(
                            y => string.Format("{0} ({1})", y.Key,
                                               y.Value.Count()), y => y.Value));

                    InputMapVisibility = Visibility.Visible;
                    if (SelectedTab == -1)
                    {
                        SelectedTab = 1;
                    }
                }


                var coverageReport = reportFiles
                                     .SingleOrDefault(x => x.Name == "Annotation");

                if (coverageReport != null)
                {
                    CoverageVisibility = Visibility.Visible;
                    if (SelectedTab == -1)
                    {
                        SelectedTab = 2;
                    }

                    var annotationFile = Path.Combine(info.DirectoryName, coverageReport.Filename);
                    var pluginTable    = PluginAnnotationTable.Load(annotationFile);

                    CoverageTables = pluginTable.Items
                                     .Select(x => new CodeCoverageCalculator(x).CalculateCoverage(false))
                                     .ToArray();
                }
                else
                {
                    CoverageVisibility = Visibility.Collapsed;
                }

                if (SelectedTab != -1)
                {
                    DynamicAnalysisVisibility = Visibility.Visible;
                    SelectedRootTab           = 0;
                }
                else
                {
                    SelectedRootTab = 1;
                }
            }
            else
            {
                var alerts = ScanAlertCollection.Load(SourceFile);

                if (alerts == null)
                {
                    return;
                }

                DynamicAnalysisVisibility  = Visibility.Visible;
                SelectedRootTab            = 0;
                VulnerabilityTabVisibility = Visibility.Visible;
                InputMapVisibility         = Visibility.Collapsed;
                CoverageVisibility         = Visibility.Collapsed;
                SelectedTab = 0;

                CreateAlertViewModels(alerts);
            }
        }
示例#7
0
    void ToolbarClicked(object Object, System.EventArgs e)
    {
        PictureBox Toolbar = (PictureBox)Controls.Find("Toolbar", true)[0];
        Graphics   Panel   = Graphics.FromImage(Toolbar.Image);

        Int32 VerticalPosition = PointToClient(Cursor.Position).Y;

        if (Menu == null)
        {
            if (VerticalPosition < BUTTON_SIZE)
            {
                // Create an empty MainMenu.
                MainMenu Main = new MainMenu();

                MenuItem FileItem  = new MenuItem("File");
                MenuItem Workspace = new MenuItem("Open Workspace");
                Workspace.Click += delegate(object Item, EventArgs Args)
                {
                    FolderBrowserDialog Dialog = new FolderBrowserDialog();
                    DialogResult        Result = Dialog.ShowDialog();
                    if (Result == DialogResult.OK)
                    {
                        OnExit(null, null);
                        GLOBAL.workspace = Dialog.SelectedPath;

                        if (File.Exists(GLOBAL.workspace + "/.portauth/" + "settings.json"))
                        {
                            var Deserializer = new JavaScriptSerializer();
                            PROJECT = Deserializer.Deserialize <Project>(File.ReadAllText(GLOBAL.workspace + "/.portauth/" + "settings.json"));
                            ListBox Navigator = (ListBox)Controls.Find("Navigator", true)[0];
                            Navigator.Items.Clear();
                            Path.Clear();
                            if (File.Exists(GLOBAL.workspace + "/.portauth/" + "index.html"))
                            {
                                DrawChart(File.ReadAllText(GLOBAL.workspace + "/.portauth/" + "index.html"));
                            }
                            else
                            {
                                wipe();
                            }
                            AddTargets(Navigator);
                            ApplicationMap.Clear();
                            foreach (Assignment A in PROJECT.assignments)
                            {
                                ApplicationMap.Add(A.name, A.target);
                            }
                        }
                    }
                };

                FileItem.MenuItems.Add(Workspace);

                MenuItem Export = new MenuItem("Export");
                Export.Click += delegate(object Item, EventArgs Args)
                {
                    ListBox Navigator = (ListBox)Controls.Find("Navigator", true)[0];
                    if (Navigator.SelectedIndex >= 0)
                    {
                        string Target     = ((string)Navigator.Items[Navigator.SelectedIndex]).Trim();
                        string TargetPath = ApplicationMap[Target];
                        Path.Text = TargetPath;

                        if (File.Exists(GLOBAL.workspace + "/.portauth/" + Target + "/index.html"))
                        {
                            SaveFileDialog Dialog = new SaveFileDialog();
                            Dialog.Filter           = "web page (*.html)|*.html";
                            Dialog.InitialDirectory = GLOBAL.workspace;
                            DialogResult Result = Dialog.ShowDialog();
                            if (Result == DialogResult.OK)
                            {
                                File.Copy(GLOBAL.workspace + "/.portauth/" + Target + "/index.html", Dialog.FileName, true);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No report selected.");
                    }
                };

                FileItem.MenuItems.Add(Export);

                MenuItem ExitItem = new MenuItem("Exit");
                ExitItem.Click += delegate(object Item, EventArgs Args){ Close(); };
                FileItem.MenuItems.Add(ExitItem);
                Main.MenuItems.Add(FileItem);

                MenuItem Edit = new MenuItem("Edit");
                MenuItem Set  = new MenuItem("Set Target Binary");
                Set.Name   = ":Path";
                Set.Click += LinkedEvent;
                Edit.MenuItems.Add(Set);
                Main.MenuItems.Add(Edit);

                MenuItem Attach  = new MenuItem("Attach to Running Process");
                MenuItem Detach  = new MenuItem("Detach");
                MenuItem Start   = new MenuItem("Start Profile");
                MenuItem Profile = new MenuItem("Profile");
                Profile.MenuItems.Add(Attach);
                Profile.MenuItems.Add(Detach);
                Profile.MenuItems.Add(Start);
                Start.Click += delegate(object Item, EventArgs Args){ Categorize(); };
                Main.MenuItems.Add(Profile);

                Menu = Main;
            }
        }
        else
        {
            Menu = null;
            Panel.DrawImage(new Bitmap("icons/selected.png"), 0.0f, BUTTON_SIZE * 1, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);
            Panel.DrawImage(new Bitmap("icons/category.png"), 0.0f, BUTTON_SIZE * 1, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);
        }

        Refresh();
    }
示例#8
0
    public Monitor()
    {
        Theme Default =
            new Theme
            (
                System.Drawing.ColorTranslator.FromHtml("#363636"),
                System.Drawing.ColorTranslator.FromHtml("#2A292B"),
                System.Drawing.ColorTranslator.FromHtml("#232323"),
                Color.Blue
            );

        if (File.Exists("settings.json"))
        {
            var Deserializer = new JavaScriptSerializer();
            GLOBAL = Deserializer.Deserialize <Settings>(File.ReadAllText("settings.json"));
        }

        if (File.Exists(GLOBAL.workspace + "/.portauth/" + "settings.json"))
        {
            var Deserializer = new JavaScriptSerializer();
            PROJECT = Deserializer.Deserialize <Project>(File.ReadAllText(GLOBAL.workspace + "/.portauth/" + "settings.json"));
        }

        BackColor = Default.WorkspaceColor;

        Text            = "Monitor";
        Width           = SCREEN_WIDTH;
        Height          = SCREEN_HEIGHT;
        FormBorderStyle = FormBorderStyle.FixedDialog;

        Int32 BufferX = 448;
        Int32 BufferY = 4;

        Button FileButton = new Button();

        FileButton.Width     = BUTTON_SIZE;
        FileButton.Location  = new Point(BufferX, BufferY);
        FileButton.BackColor = Color.LightGray;
        Controls.Add(FileButton);

        Path.Width       = 432;
        Path.Font        = new Font(UNIVERSAL_FONT, 16, FontStyle.Regular, GraphicsUnit.Pixel);
        Path.Location    = new Point(FileButton.Width + BufferX, BufferY);
        Path.BorderStyle = BorderStyle.None;
        Controls.Add(Path);

        Header.Width       = 768;
        Header.Height     += 64;
        Header.Multiline   = true;
        Header.Font        = new Font(UNIVERSAL_FONT, 16, FontStyle.Regular, GraphicsUnit.Pixel);
        Header.Location    = new Point(952, BufferY);
        Header.BorderStyle = BorderStyle.None;
        Header.ForeColor   = Color.White;
        Header.BackColor   = Default.WorkspaceColor;
        Controls.Add(Header);

        Coverage.Width       = 384;
        Coverage.Font        = new Font(UNIVERSAL_FONT, 16, FontStyle.Regular, GraphicsUnit.Pixel);
        Coverage.Location    = new Point(952, BufferY + 96);
        Coverage.BorderStyle = BorderStyle.None;
        Coverage.ForeColor   = Color.White;
        Coverage.BackColor   = Default.WorkspaceColor;
        Controls.Add(Coverage);

        Key.Font        = new Font(UNIVERSAL_FONT, 24, FontStyle.Regular, GraphicsUnit.Pixel);
        Key.Location    = new Point(FileButton.Width + BufferX, BufferY + 512);
        Key.BorderStyle = BorderStyle.None;
        Key.Height      = 32;
        Controls.Add(Key);

        Description.Font        = new Font(UNIVERSAL_FONT, 16, FontStyle.Regular, GraphicsUnit.Pixel);
        Description.Location    = new Point(BufferX, BufferY + 576);
        Description.Multiline   = true;
        Description.BorderStyle = BorderStyle.None;
        Description.Height      = 318;
        Description.Width       = 1080;
        Description.ForeColor   = Color.White;
        Description.BackColor   = Default.WorkspaceColor;
        Controls.Add(Description);

        LinkItems(new Control[] { FileButton, Path }, "Path");

        Int32 Count = SCREEN_HEIGHT / BUTTON_SIZE;
        Int32 Diff  = SCREEN_HEIGHT - (Count * BUTTON_SIZE);

        PictureBox ImageButton = new PictureBox();

        ImageButton.Name       = "Toolbar";
        ImageButton.ClientSize = new Size(BUTTON_SIZE, BUTTON_SIZE * Count);
        ImageButton.Image      = new Bitmap(BUTTON_SIZE, BUTTON_SIZE * Count, PixelFormat.Format32bppPArgb);
        Graphics Panel = Graphics.FromImage(ImageButton.Image);

        Bitmap[] Icons = new Bitmap[Count];
        Icons[0] = new Bitmap("icons/menu.png");
        Icons[1] = new Bitmap("icons/category.png");
        Icons[2] = new Bitmap("icons/green.png");
        Icons[3] = new Bitmap("icons/coverage.png");

        Int32 Icon = 0;

        while (Icon < Count)
        {
            if (Icons[Icon] != null)
            {
                Panel.DrawImage(Icons[Icon], 0.0f, BUTTON_SIZE * Icon, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);
            }
            Icon++;
        }

        ImageButton.BackColor = Default.ButtonColor;
        ImageButton.Click    += ToolbarClicked;
        Controls.Add(ImageButton);

        ListBox Navigator = new ListBox();

        Navigator.BorderStyle = BorderStyle.None;
        Navigator.Font        = new Font(UNIVERSAL_FONT, 24, FontStyle.Bold, GraphicsUnit.Pixel);

        AddTargets(Navigator);

        if (PROJECT.assignments != null)
        {
            foreach (var assignment in PROJECT.assignments)
            {
                if (ApplicationMap.ContainsKey(assignment.name))
                {
                    ApplicationMap[assignment.name] = assignment.target;
                }
            }
        }
        else
        {
            PROJECT.assignments = new Assignment[0];
        }

        Navigator.DoubleClick          += ListDoubleClick;
        Navigator.SelectedIndexChanged += TargetSelectionChanged;
        Navigator.ClientSize            = new Size(BUTTON_SIZE + 384, SCREEN_HEIGHT - Diff - BUTTON_SIZE);
        Navigator.BackColor             = Default.NavigatorColor;
        Navigator.Name = "Navigator";
        Controls.Add(Navigator);

        Int32 OffsetX = BufferX;
        Int32 OffsetY = 32;

        Chart.ClientSize = new Size(CHART_SIZE + OffsetX, CHART_SIZE + OffsetY);
        Chart.Padding    = new System.Windows.Forms.Padding(OffsetX, OffsetY, 0, 0);
        Controls.Add(Chart);

        PictureBox TrimBar = new PictureBox();

        TrimBar.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
        TrimBar.Image      = new Bitmap(SCREEN_WIDTH, BUTTON_SIZE, PixelFormat.Format32bppPArgb);
        TrimBar.Padding    = new System.Windows.Forms.Padding(0, SCREEN_HEIGHT - Diff - BUTTON_SIZE - 1, 0, 0);
        Controls.Add(TrimBar);

        Graphics Trim = Graphics.FromImage(TrimBar.Image);

        Trim.Clear(Default.StatusColor);
        Trim.DrawImage(new Bitmap("icons/play.png"), OffsetX, 0.0f, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);

        Control Window = new Control();

        Window.BackColor  = Color.White;
        Window.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
        Controls.Add(Window);

        Application.ApplicationExit += OnExit;

        if (File.Exists(GLOBAL.workspace + "/.portauth/" + "index.html"))
        {
            DrawChart(File.ReadAllText(GLOBAL.workspace + "/.portauth/" + "index.html"));
        }
        else
        {
            wipe();
        }

        ToolTip Percentage = new ToolTip();

        Percentage.Popup += new PopupEventHandler(HandlePopup);
        Percentage.SetToolTip(Chart, "Result");

        Panel.DrawImage(new Bitmap("icons/selected.png"), 0.0f, BUTTON_SIZE * 1, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);
        Panel.DrawImage(new Bitmap("icons/category.png"), 0.0f, BUTTON_SIZE * 1, new RectangleF(0.0f, 0.0f, BUTTON_SIZE, BUTTON_SIZE), GraphicsUnit.Pixel);
    }
 public InstanceConfiguration()
 {
     ApplicationMap = new ApplicationMap(string.Empty, string.Empty);
 }
示例#10
0
        public void Execute()
        {
            _output.WriteLine();

            var installed    = new Dictionary <IPackage, Application>();
            var notInstalled = new List <IPackage>();
            var allPackages  = _query.GetLatestVersions(_packageSourceConfiguration.PackageSource);

            if (allPackages == null)
            {
                _output.WriteLine("Could not determine status for feed");
                return;
            }

            foreach (var sourcePackage in allPackages)
            {
                string installPath = _fs.Path.Combine(_installationRoot.Path, sourcePackage.Id);
                _logger.DebugFormat("Checking {0}", installPath);

                var appMap      = new ApplicationMap(sourcePackage.Id, installPath);
                var application = new Application(appMap, _fs, _logger, _instanceConfiguration, new InstallationPadLock(appMap, _fs), _output);


                if (_fs.File.Exists(appMap.VersionFile))
                {
                    _logger.DebugFormat("{0} exists", installPath);
                    SemanticVersion installedVersion;
                    if (SemanticVersion.TryParse(_fs.File.ReadAllText(appMap.VersionFile), out installedVersion))
                    {
                        installed.Add(sourcePackage, application);

                        if (application.GetInstalledVersion() < sourcePackage.Version.Version)
                        {
                            notInstalled.Add(sourcePackage);
                        }
                    }
                    else
                    {
                        notInstalled.Add(sourcePackage);
                    }
                }
                else
                {
                    _logger.DebugFormat("{0} not found", installPath);
                    notInstalled.Add(sourcePackage);
                }
            }

            _output.WriteLine("Installed packages: (* = updates are available)");

            foreach (var package in installed.Keys)
            {
                var installedVersion = installed[package].GetInstalledVersion();
                _output.Write("{0} {1}{2}", package.Id,
                              installedVersion,
                              installedVersion < package.Version.Version ? "*" : "");

                if (installed[package].IsStaged)
                {
                    var stagedVersion = installed[package].GetStagedVersion();
                    if (stagedVersion != null && stagedVersion != installedVersion)
                    {
                        _output.Write("  (staged: {0})", stagedVersion);
                    }
                }
                _output.WriteLine();
            }

            _output.WriteLine();
            _output.WriteLine("Available packages:");
            foreach (var package in notInstalled)
            {
                _output.WriteLine("{0} {1}", package.Id, package.Version);
            }
        }