/// <summary>
        ///     netsh http add urlacl http://*:8888/ user=warden_094850238
        /// </summary>
        public int ReserveLocalPort(int port, string userName)
        {
            if (String.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException("userName");
            }

            if (port == default(ushort))
            {
                port = IPUtilities.RandomFreePort();
            }

            log.Info("Reserving port {0} for user {1}", port, userName);

            //string arguments = String.Format("http add urlacl http://*:{0}/ user={1}", port, userName);
            if (netShRunner.AddRule(port, userName))
            {
                try
                {
                    firewallManager.OpenPort(port, userName);
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format("Error adding firewall rule for port '{0}', user '{1}'", port, userName), ex);
                }
            }
            else
            {
                throw new Exception(String.Format("Error reserving port '{0}' for user '{1}'", port, userName));
            }

            return(port);
        }
Beispiel #2
0
        private ValueTask <bool> TryProcessOpcodeAsync(
            ref VoiceGatewayPayload payload,
            CancellationToken cancellationToken = default)
        {
            switch (payload.Opcode)
            {
            case VoiceGatewayOpcode.Hello:
            {
                _heartbeatInterval = payload.Hello.HeartbeatInterval;
                _ = _heartbeatMutex.Release();

                return(SendIdentifyAsync(cancellationToken));
            }

            case VoiceGatewayOpcode.Ready:
            {
                if (!IPUtilities.TryParseAddress(
                        payload.Ready.SlicedIp, out var address))
                {
                    return(new ValueTask <bool>(false));
                }

                var remote = new IPEndPoint(address, payload.Ready.Port);
                ClientSsrcUpdated?.Invoke(this, payload.Ready.Ssrc);
                Ssrc = payload.Ready.Ssrc;
                RemoteEndPointUpdated?.Invoke(this, remote);
                EndPoint = remote;

                return(ClientEndPoint != null
                        ? SendSelectProtocolAsync(
                           payload.Ready, cancellationToken)
                        : HandleTaskAsync(
                           PerformDiscoveryAndSelectProtocolAsync(
                               payload.Ready, cancellationToken)));
            }

            case VoiceGatewayOpcode.SessionDescription:
            {
                SessionEncryptionKeyUpdated?.Invoke(this,
                                                    _sessionEncryptionKey.Memory.Slice(0,
                                                                                       SessionEncryptionKeyLength));

                Ready?.Invoke(this, null !);
                return(new ValueTask <bool>(true));
            }

            case VoiceGatewayOpcode.HeartbeatAck:
            {
                Debug.Assert(_nonce == payload.Nonce + 1,
                             "Nonces didn't match");
                return(new ValueTask <bool>(true));
            }
            }

            return(new ValueTask <bool>(false));
Beispiel #3
0
        private void LoadGridView()
        {
            //format grid header
            dataGridView1.Columns[1].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[3].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[5].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[6].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Rows.Clear();

            try
            {
                _ipList = IPUtilities.GetAllIpInfo(_myConnection);

                foreach (string key in _ipList.Keys)
                {
                    //create new instances of the objects to create the row
                    DataGridViewRow          row                 = new DataGridViewRow();
                    DataGridViewTextBoxCell  ipNameCell          = new DataGridViewTextBoxCell();
                    DataGridViewTextBoxCell  ipTypeCell          = new DataGridViewTextBoxCell();
                    DataGridViewTextBoxCell  activitiesCell      = new DataGridViewTextBoxCell();
                    DataGridViewTextBoxCell  runbookInstanceCell = new DataGridViewTextBoxCell();
                    DataGridViewTextBoxCell  dataInstanceCell    = new DataGridViewTextBoxCell();
                    DataGridViewCheckBoxCell isRegistered        = new DataGridViewCheckBoxCell();
                    DataGridViewCheckBoxCell isDeployed          = new DataGridViewCheckBoxCell();

                    string value = string.Empty;
                    ipNameCell.Value = key;
                    _ipList.TryGetValue(key, out value);
                    ipNameCell.Tag = value;

                    //add formatting
                    ipTypeCell.Style.Alignment          = DataGridViewContentAlignment.MiddleCenter;
                    activitiesCell.Style.Alignment      = DataGridViewContentAlignment.MiddleCenter;
                    runbookInstanceCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dataInstanceCell.Style.Alignment    = DataGridViewContentAlignment.MiddleCenter;

                    //add the cells to the row
                    row.Cells.Add(ipNameCell);
                    row.Cells.Add(ipTypeCell);
                    row.Cells.Add(activitiesCell);
                    row.Cells.Add(runbookInstanceCell);
                    row.Cells.Add(dataInstanceCell);
                    row.Cells.Add(isRegistered);
                    row.Cells.Add(isDeployed);

                    //add the row to the gridview
                    dataGridView1.Rows.Add(row);
                }


                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    try
                    {
                        string packId = row.Cells[0].Tag.ToString();
                        IPType ipType = IPUtilities.GetIPType(packId, _myConnection);

                        row.Cells[1].Value = ipType.ToString();
                        row.Cells[2].Value = IPUtilities.GetNumberOfActivitiesInIP(packId, _myConnection, ipType).ToString();
                        row.Cells[3].Value = IPUtilities.GetActivityInstancesCountForIP(packId, _myConnection, ipType).ToString();
                        row.Cells[4].Value = IPUtilities.GetActivityInstanceDataCountForIP(packId, _myConnection, ipType).ToString();

                        if (ipType == IPType.Toolkit)
                        {
                        }
                        else if (ipType == IPType.Native)
                        {
                            row.DefaultCellStyle.BackColor = Color.LightGray;
                        }
                        else  //unknown type
                        {
                            row.DefaultCellStyle.BackColor = Color.Cornsilk;
                        }
                        string productCode  = IPUtilities.GetProductCodeForIP(packId, _myConnection);
                        bool   isDeployed   = IPUtilities.IpIsDeployed(productCode, _computerName);
                        bool   isRegistered = IPUtilities.IpIsRegistered(packId);

                        row.Cells[5].Value = isRegistered;
                        row.Cells[6].Value = isDeployed;

                        if ((isRegistered == false) && (isDeployed == false))
                        {
                            row.DefaultCellStyle.BackColor = Color.LightSalmon;
                        }
                    }
                    catch { }
                }
                //re-sort columns to prioritize non-deployed, non-registered IPs
                dataGridView1.Sort(dataGridView1.Columns[1], ListSortDirection.Descending);
                dataGridView1.Sort(dataGridView1.Columns[6], ListSortDirection.Ascending);
                dataGridView1.Sort(dataGridView1.Columns[5], ListSortDirection.Ascending);

                //prevent the first row from being selected by default
                dataGridView1.SelectedRows[0].Selected = false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #4
0
        public void PerformRemovalActions(string packID)
        {
            tabControl1.SelectedTab = tabControl1.TabPages[1];
            StringBuilder sb = new StringBuilder();

            LoggingWindowText = String.Empty;
            sb.AppendLine("");
            sb.AppendLine("Starting removal of selected items...");
            sb.AppendLine("");
            Dictionary <string, string> activitiesList = IPUtilities.GetActivitesInIP(packID);

            LoggingWindowText = sb.ToString();

            bool removeOnlyDeletedJobHistory = (radioRemoveDeletedJobHistory.Checked);

            if (!radioRemoveNoJobHistory.Checked)
            {
                // actions start at the lowest level first to avoid any dependency / foreign key errors
                if (radioRemoveAllJobHistory.Checked)
                {
                    sb.AppendLine("Deleting job history for all activities in the IP...");
                }
                else if (radioRemoveDeletedJobHistory.Checked)
                {
                    sb.AppendLine("Deleting job history for all deleted activities in the IP...");
                }
                sb.AppendLine("");
                LoggingWindowText = sb.ToString();
                foreach (string activityName in activitiesList.Keys)
                {
                    sb.AppendLine(string.Format("   Activity: {0}", activityName));
                    string activityID = string.Empty;
                    if (activitiesList.TryGetValue(activityName, out activityID))
                    {
                        sb.AppendLine(string.Format("    Table: [OBJECTINSTANCEDATA]   Records deleted: {0}", IPUtilities.RemoveJobDataForActivityType(activityID, _myConnection, removeOnlyDeletedJobHistory).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [OBJECTINSTANCES]      Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedJobHistory).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine("");
                    }
                }
            }
            else
            {
                sb.AppendLine("Skipping job history deletion...");
                sb.AppendLine("");
            }


            bool removeOnlyDeletedActivities = (radioRemoveDeletedActivities.Checked);

            if (!radioRemoveNoActivities.Checked)
            {
                //TODO:  Add code to validate that any dependent table data has already been removed before doing this.

                if (radioRemoveAllActivities.Checked)
                {
                    sb.AppendLine("Deleting all activities in the IP from all runbooks...");
                }
                else if (radioRemoveDeletedActivities.Checked)
                {
                    sb.AppendLine("Deleting all activities in the IP that are marked 'Deleted'...");
                }
                sb.AppendLine("");
                LoggingWindowText = sb.ToString();
                foreach (string activityName in activitiesList.Keys)
                {
                    sb.AppendLine(string.Format("   Activity: {0}", activityName));
                    string activityID = string.Empty;
                    if (activitiesList.TryGetValue(activityName, out activityID))
                    {
                        sb.AppendLine(string.Format("    Table: [LINKTRIGGERS]   Records deleted: {0}", IPUtilities.RemoveJobDataForActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [LINKS]          Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [OBJECT_AUDIT]   Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [OBJECTLOOPING]  Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [OBJECTS]        Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine(string.Format("    Table: [CONFIGURATION]  Records deleted: {0}", IPUtilities.RemoveInstancesOfActivityType(activityID, _myConnection, removeOnlyDeletedActivities).ToString()));
                        LoggingWindowText = sb.ToString();
                        sb.AppendLine("");
                    }
                }
            }
            else
            {
                sb.AppendLine("Skipping activity deletion...");
                sb.AppendLine("");
            }
            LoggingWindowText = sb.ToString();



            //if (checkBoxCleanAll.Checked)
            //{
            //    sb.AppendLine("Remove all data related to the IP.");
            //    sb.AppendLine("");
            //}
            //if (checkBoxUnregisterIP.Checked)
            //{
            //    sb.AppendLine("Unregister the IP");
            //    sb.AppendLine("");
            //}
            //if (checkBoxUndeployIP.Checked)
            //{
            //    sb.AppendLine("Undeploy the IP");
            //    sb.AppendLine("");
            //}
        }
Beispiel #5
0
        private void DisplayIPDetails()
        {
            textBoxSelectedIPInfo.Enabled = true;
            SelectionWindowText           = "Loading IP Detail Information...";

            StringBuilder sb          = new StringBuilder();
            string        ipName      = dataGridView1.SelectedCells[0].Value.ToString();
            string        packID      = GetSelectedPackID();
            string        productCode = IPUtilities.GetProductCodeForIP(packID, _myConnection);
            IPType        ipType      = (IPType)Enum.Parse(typeof(IPType), dataGridView1.SelectedCells[1].Value.ToString());

            sb.AppendLine("IP Name            : " + ipName);
            sb.AppendLine("Registered Version : " + IPUtilities.GetRegisteredIPVersion(packID, _myConnection));
            sb.AppendLine("IP Type            : " + ipType.ToString());
            if (dataGridView1.SelectedCells[5].Value.ToString() == "True")
            {
                sb.AppendLine("IP Registered?     : Yes");
                checkBoxUnregisterIP.Enabled = true;
            }
            else
            {
                sb.AppendLine("IP Registered?     : No");
            }

            sb.AppendLine("Runbook Designers  :");
            List <string> designers = Infrastructure.GetRunbookDesigners(_myConnection);

            foreach (string designer in designers)
            {
                string ipVersion = IPUtilities.GetDeployedIpVersion(productCode, designer);
                if (!string.IsNullOrEmpty(ipVersion))
                {
                    sb.AppendLine("\t" + designer.PadRight(20) + "\tVersion " + ipVersion + " deployed");
                    checkBoxUndeployIP.Enabled = true;
                }
                else
                {
                    sb.AppendLine("\t" + designer.PadRight(20) + "\tIP not deployed");
                }
            }
            sb.AppendLine("Runbook Servers:");
            List <string> rbServers = Infrastructure.GetRunbookDesigners(_myConnection);

            foreach (string rbServer in rbServers)
            {
                string ipVersion = IPUtilities.GetDeployedIpVersion(productCode, rbServer);
                if (!string.IsNullOrEmpty(ipVersion))
                {
                    sb.AppendLine("\t" + rbServer.PadRight(20) + "\tVersion " + ipVersion + " deployed");
                    checkBoxUndeployIP.Enabled = true;
                }
                else
                {
                    sb.AppendLine("\t" + rbServer.PadRight(20) + "\tIP not deployed");
                }
            }

            sb.AppendLine("");
            int numActivities = IPUtilities.GetNumberOfActivitiesInIP(packID, _myConnection, ipType);

            sb.AppendLine("Number of Activities in the IP                   : " + numActivities);


            int numActivitiesInRunbooks = IPUtilities.GetActivityInstancesCountForIP(packID, _myConnection, ipType);

            sb.AppendLine("# of Times the Activities are Used in Runbooks   : " + numActivitiesInRunbooks);
            radioRemoveAllActivities.Enabled = (numActivitiesInRunbooks > 0);

            int numActivitiesInJobs = IPUtilities.GetActivityInstanceDataCountForIP(packID, _myConnection, ipType);

            sb.AppendLine("# of Times the Activities were Run in Jobs       : " + numActivitiesInJobs);
            radioRemoveAllJobHistory.Enabled = (numActivitiesInJobs > 0);
            sb.AppendLine("");

            int numDeletedActivitiesInRunbooks = IPUtilities.GetActivityInstancesCountForIP(packID, _myConnection, ipType, true);

            sb.AppendLine("# of 'Deleted' Activities in Runbooks            : " + numDeletedActivitiesInRunbooks);
            radioRemoveDeletedActivities.Enabled = (numDeletedActivitiesInRunbooks > 0);

            int numDeletedActivitiesInJobs = IPUtilities.GetActivityInstanceDataCountForIP(packID, _myConnection, ipType, true);

            sb.AppendLine("# of Job Data Items for 'Deleted' Activities     : " + numDeletedActivitiesInJobs);
            radioRemoveDeletedJobHistory.Enabled = (numDeletedActivitiesInJobs > 0);

            //only get list of activities for Toolkit-based IPs.
            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("List of Activities in the IP and the runbooks where they are used:");
            sb.AppendLine("");
            Dictionary <string, string> activitiesList = IPUtilities.GetActivitesInIP(packID);

            sb.AppendLine("   Activity Name    /   Runbooks Where Used");
            sb.AppendLine("-------------------------------------------------------------------------");
            if (null != activitiesList)
            {
                foreach (string activity in activitiesList.Keys)
                {
                    sb.AppendLine("  " + activity);
                    string activityType = string.Empty;
                    if (activitiesList.TryGetValue(activity, out activityType))
                    {
                        List <string> runbookNames = IPUtilities.GetRunbookNamesWhereActivityTypeIsUsed(activityType, _myConnection);
                        if (runbookNames.Count > 0)
                        {
                            foreach (string name in runbookNames)
                            {
                                sb.AppendLine("                 " + name);
                            }
                            sb.AppendLine("");
                        }
                    }
                }
            }

            sb.AppendLine("");
            SelectionWindowText = sb.ToString();
        }
Beispiel #6
0
        public InfoResponse GetInfoResponse()
        {
            var hostIp = IPUtilities.GetLocalIPAddress().ToString();

            return(new InfoResponse(hostIp, hostIp, container.Directory, container.State));
        }
Beispiel #7
0
        private async Task run()
        {
            if (Clipboard.ContainsText())
            {
                string   clipboard = Clipboard.GetText();
                string[] lines     = clipboard.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                prgrssbr.Maximum = lines.Length;

                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i].Trim();
                    prgrssbr.Value = i;
                    string ip = IPUtilities.ExtractFirstIpFromLine(line);
                    if (ip != null)
                    {
                        IPInfo info = await getinfo(ip);//long operation

                        VisualIPData vpdt = new VisualIPData(info.Data, lines[i]);
                        visualIPData_.Add(vpdt);
                    }
                }

                var query = visualIPData_.GroupBy(x => x.Organisation)
                            .Select(g => new { Value = g.Key, Count = g.Count() })
                            .OrderByDescending(x => x.Count);

                //generate percents and colors
                Random random = new Random();
                foreach (var field in query)
                {
                    Percents prcnts = new Percents();
                    prcnts.Field   = field.Value;
                    prcnts.Percent = (int)((double)field.Count / (double)visualIPData_.Count * 100);

                    int colorR = random.Next(130, 255);
                    int colorG = random.Next(130, 255);
                    int colorB = random.Next(130, 255);

                    prcnts.BackgroundColor = new SolidColorBrush(Color.FromRgb((byte)colorR, (byte)colorG, (byte)colorB));
                    percents_.Add(prcnts);
                }

                //assign colors based on field.Value
                foreach (VisualIPData data in visualIPData_)
                {
                    foreach (Percents percents in percents_)
                    {
                        if (data.Organisation == percents.Field)
                        {
                            data.BackgroundColor = percents.BackgroundColor;
                        }
                    }
                }

                lstw.ItemsSource         = visualIPData_;
                lstwPercents.ItemsSource = percents_;
                lstw.Visibility          = System.Windows.Visibility.Visible;
                lstwPercents.Visibility  = System.Windows.Visibility.Visible;

                prgrssbr.Visibility = System.Windows.Visibility.Collapsed;
            }
        }