//private   SmppConnection mySmppClient = new SmppConnection();

        /// <summary>
        /// ------------>
        /// </summary>
        /// <param name="transportprotocol"></param>
        public SmppMessenger(TransportProtocols transportprotocol, string DeliveryResponseMessageQueue, string shortCodePrefixToTrim)
        {
            m_DeliveryResponseMessageQueue = DeliveryResponseMessageQueue;
            ShortCodePrefixToTrim          = shortCodePrefixToTrim; // 234 prefix to trim from shortcodes
            // log4net here
            string appId = String.Format(@"{0}\{1}.exe", Environment.CurrentDirectory,
                                         Assembly.GetExecutingAssembly().GetName().FullName);

            XmlConfigurator.Configure(new System.IO.FileInfo(Settings.Default.InstrumentationFileName));
            log4net.LogicalThreadContext.Properties["identity"] = appId;

            //id:483D47F1 sub:001 dlvrd:001 submit date:0905151857 done date:0905151857 stat:DELIVRD err:000 Text:Dear Godwin Akpabio

            tProtocol = transportprotocol;

            // Treat the mode in which client will bind based on protocol version
            if (tProtocol.ProtocolVersion < 3.4)
            {
                // Transmitter
                smppconn = new SmppConnection();
                InitializeParameters(smppconn, SmppConnectionMode.Transmitter, tProtocol);

                // Client disconnected

                smppconn.OnEnquireLinkReq += new SmppEnquireLinkHandler(smppconn_OnEnquireLinkReq);
                smppconn.OnUnBindReq      += new SmppUnBindHandler(smppconn_OnUnBindReq);
                //No neet towait for message      //smppconn.OnDeliverSmReq += new SmppDeliverSmHandler(smppconn_OnDeliverSmReq);

                // Receiver


                smppconn2 = new SmppConnection();
                InitializeParameters(smppconn2, SmppConnectionMode.Receiver, tProtocol);

                // Client disconnected

                smppconn2.OnEnquireLinkReq += new SmppEnquireLinkHandler(smppconn_OnEnquireLinkReq);
                smppconn2.OnUnBindReq      += new SmppUnBindHandler(smppconn_OnUnBindReq);
                smppconn2.OnDeliverSmReq   += new SmppDeliverSmHandler(smppconn_OnDeliverSmReq);
            }
            else
            {
                // Tranceiver
                smppconn = new SmppConnection();
                InitializeParameters(tProtocol);

                // Client disconnected

                smppconn.OnEnquireLinkReq += new SmppEnquireLinkHandler(smppconn_OnEnquireLinkReq);
                smppconn.OnUnBindReq      += new SmppUnBindHandler(smppconn_OnUnBindReq);
                smppconn.OnDeliverSmReq   += new SmppDeliverSmHandler(smppconn_OnDeliverSmReq);
            }


            enquireTimer          = new System.Timers.Timer(double.Parse(tProtocol.EnquireLinkInterval.ToString()));
            enquireTimer.Elapsed += new ElapsedEventHandler(timerElapsedEvent);
            enquireTimer.Enabled  = false;
        }
        /// <summary>
        /// Returns a list of specific Protocols passed as argument
        /// </summary>
        /// <param name="Protocol"></param>
        /// <returns></returns>
        public ArrayList GetProtocolList(string Protocol)
        {
            ArrayList ar = new ArrayList();

            try
            {
                //
                SqlCommand cmd = new SqlCommand("Select [NetworkID] ,[OperatorID],[TransportMode] ,[RemoteHost] ,[RemotePort],[SystemID],[Password],[ProtocolVersion],[EnquireLinkEnabled] ,[EnquireLinkInterval],[SourceAddress] ,[AddressPrefix],[AddressRange] ,[Timeout] ,[AddrTON],[AddrNPI],[DestTON],[DestNPI],[SourceTONNumeric],[SourceToNAlpha] FROM [Protocols] where [ActiveStatus] = 1 and [TransportMode] = '" + Protocol.ToUpper() + "'", this.Cnn);

                TransportProtocols tp = null;
                SqlDataReader      dr = cmd.ExecuteReader();
                if (dr.HasRows == true)
                {
                    while (dr.Read() == true)
                    {
                        tp                     = new TransportProtocols();
                        tp.NetworkID           = dr.GetString(0);
                        tp.OperatorID          = dr.GetString(1);
                        tp.TransportMode       = dr.GetString(2);
                        tp.RemoteHost          = dr.GetString(3);
                        tp.RemotePort          = int.Parse(dr.GetValue(4).ToString());
                        tp.SystemID            = dr.GetString(5);
                        tp.Password            = dr.GetString(6);
                        tp.ProtocolVersion     = double.Parse(dr.GetValue(7).ToString());
                        tp.EnquireLinkEnabled  = byte.Parse(dr.GetValue(8).ToString());
                        tp.EnquireLinkInterval = int.Parse(dr.GetValue(9).ToString());
                        tp.SourceAddress       = dr.GetString(10);
                        tp.AddressPrefix       = dr.GetString(11);;
                        tp.AddressRange        = dr.GetString(12);;
                        tp.Timeout             = int.Parse(dr.GetValue(13).ToString());
                        tp.AddrTON             = byte.Parse(dr.GetValue(14).ToString());
                        tp.AddrNPI             = byte.Parse(dr.GetValue(15).ToString());
                        tp.DestTON             = byte.Parse(dr.GetValue(16).ToString());
                        tp.DestNPI             = byte.Parse(dr.GetValue(17).ToString());
                        tp.SourceTONNumeric    = byte.Parse(dr.GetValue(18).ToString());
                        tp.SourceTonAlpha      = byte.Parse(dr.GetValue(19).ToString());

                        ar.Add(tp);
                    }
                }
                dr.Dispose();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                string exx = ex.Message;
            }

            return(ar);
        }
        /// <summary>
        /// -------------------->
        /// </summary>
        /// <param name="transportprotocol"></param>
        public void InitializeParameters(TransportProtocols transportprotocol)
        {
            smppconn.Settings.RemoteHost = transportprotocol.RemoteHost; // in case

            if (IsValidIP(transportprotocol.RemoteHost) == true)
            {
                smppconn.Settings.RemoteHost = transportprotocol.RemoteHost;
            }
            else
            {
                try
                {
                    IPAddress[] address = Dns.GetHostAddresses(transportprotocol.RemoteHost);

                    foreach (IPAddress theaddress in address)
                    {
                        smppconn.Settings.RemoteHost = theaddress.ToString();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //  ex.Message;
                }
            }



            smppconn.Settings.Timeout        = transportprotocol.Timeout;
            smppconn.Settings.ConnectionMode = SmppConnectionMode.Transceiver;
            // smppconn.Settings.RemoteHost = transportprotocol.RemoteHost;
            smppconn.Settings.RemotePort = transportprotocol.RemotePort;
            smppconn.Settings.BindParams.AddressRange = transportprotocol.AddressRange;
            //smppconn.Settings.BindParams.AddressNpi = Convert.ToByte(1);
            //smppconn.Settings.BindParams.AddressTon = Convert.ToByte(1);
            smppconn.Settings.BindParams.Password         = transportprotocol.Password;
            smppconn.Settings.BindParams.SystemId         = transportprotocol.SystemID;
            smppconn.Settings.BindParams.SystemType       = transportprotocol.SystemType;
            smppconn.Settings.BindParams.InterfaceVersion = Convert.ToByte(52);

            //logger.Error(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ": " + ex.Message + "\n");

            logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + " Client Initialized Successfully\n");
        }
Пример #4
0
        static string NetShArgumentsForRule(int port, RuleDirections direction, TransportProtocols protocol)
        {
            string strArguments = "";

            if (Functions.OSSupportsAdvancedFirewallInNetSH)
            {
                strArguments += "advfirewall firewall add rule name=" + "\"" + "Remote Potato - " + port.ToString() + " " + direction.ToString() + "\"";
                strArguments += " dir=" + ((direction == RuleDirections.Inbound) ? "in" : "out");
                strArguments += " action=allow";
                strArguments += " protocol=" + ((protocol == TransportProtocols.TCP) ? "TCP" : "UDP");
                strArguments += " localport=" + port.ToString();
            }
            else
            {
                // XP old syntax
                strArguments += "firewall add portopening name=" + "\"" + "Remote Potato - " + port.ToString() + " " + direction.ToString() + "\"";
                strArguments += " protocol=" + ((protocol == TransportProtocols.TCP) ? "TCP" : "UDP");
                strArguments += " port=" + port.ToString();
            }

            return(strArguments);
        }
        private void InitializeParameters(SmppConnection smppX, SmppConnectionMode smppConnectionMode, TransportProtocols tProtocol)
        {
            if (IsValidIP(tProtocol.RemoteHost) == true)
            {
                smppX.Settings.RemoteHost = tProtocol.RemoteHost;
            }
            else
            {
                try
                {
                    IPAddress[] address = Dns.GetHostAddresses(tProtocol.RemoteHost);

                    foreach (IPAddress theaddress in address)
                    {
                        smppX.Settings.RemoteHost = theaddress.ToString();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //  ex.Message;
                }
            }

            smppX.Settings.Timeout                 = tProtocol.Timeout;
            smppX.Settings.ConnectionMode          = smppConnectionMode;
            smppX.Settings.RemotePort              = tProtocol.RemotePort;
            smppX.Settings.BindParams.AddressRange = tProtocol.AddressRange;
            //mySmppClient.Settings.BindParams.AddressNpi = Convert.ToByte(1);
            //mySmppClient.Settings.BindParams.AddressTon = Convert.ToByte(1);

            smppX.Settings.BindParams.Password         = tProtocol.Password;
            smppX.Settings.BindParams.SystemId         = tProtocol.SystemID;
            smppX.Settings.BindParams.SystemType       = tProtocol.SystemType;
            smppX.Settings.BindParams.InterfaceVersion = Convert.ToByte(52);
            logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ": Initialized Successfully\n");
        }
Пример #6
0
        static bool AddFirewallRule(int port, RuleDirections direction, TransportProtocols protocol)
        {
            System.Diagnostics.Process process = null;
            System.Diagnostics.ProcessStartInfo processStartInfo;

            processStartInfo = new System.Diagnostics.ProcessStartInfo();
            processStartInfo.FileName = "netsh.exe";
            processStartInfo.Arguments = NetShArgumentsForRule(port, direction, protocol);
            if (Functions.OSSupportsAdvancedFirewallInNetSH)
                processStartInfo.Verb = "runas";
            processStartInfo.UseShellExecute = true;
            //processStartInfo.UseShellExecute = false;
            //processStartInfo.CreateNoWindow = true;
            //processStartInfo.RedirectStandardOutput = true;
            processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            try
            {
                process = System.Diagnostics.Process.Start(processStartInfo);

                DateTime begunProcess = DateTime.Now;
                bool processTimeout = false;
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(200);
                    TimeSpan elapsed = (DateTime.Now - begunProcess);
                    if (elapsed.TotalSeconds > 25)
                    {
                        processTimeout = true;
                        break;
                    }
                }

                if (processTimeout)
                {
                    Functions.WriteLineToLogFile("FirewallHelper: NOT OK - TimeOut");
                    return false;
                }
                else if (process.ExitCode != 0)
                {
                    string processOutput = process.StandardOutput.ReadToEnd();

                    Functions.WriteLineToLogFile("FirewallHelper: NOT OK (error code " + process.ExitCode.ToString() );
                    Functions.WriteLineToLogFile(processOutput);

                    return false;
                }
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("FirewallHelper: Exception trying to add a firewall rule using netsh.");
                Functions.WriteExceptionToLogFile(ex);
                return false;
            }
            finally
            {
                if (process != null)
                {
                    process.Dispose();
                }
            }

            Functions.WriteLineToLogFile("FirewallHelper: Rule Added 0 OK");
            return true;
        }
Пример #7
0
        static string NetShArgumentsForRule(int port, RuleDirections direction, TransportProtocols protocol)
        {
            string strArguments = "";

            if (Functions.OSSupportsAdvancedFirewallInNetSH)
            {
                strArguments += "advfirewall firewall add rule name=" + "\"" + "Remote Potato - " + port.ToString() + " " + direction.ToString() + "\"";
                strArguments += " dir=" + ((direction == RuleDirections.Inbound) ? "in" : "out");
                strArguments += " action=allow";
                strArguments += " protocol=" + ((protocol == TransportProtocols.TCP) ? "TCP" : "UDP");
                strArguments += " localport=" + port.ToString();
            }
            else
            {
                // XP old syntax
                strArguments += "firewall add portopening name=" + "\"" + "Remote Potato - " + port.ToString() + " " + direction.ToString() + "\"";
                strArguments += " protocol=" + ((protocol == TransportProtocols.TCP) ? "TCP" : "UDP");
                strArguments += " port=" + port.ToString();
            }

            return strArguments;
        }
Пример #8
0
        static bool AddFirewallRule(int port, RuleDirections direction, TransportProtocols protocol)
        {
            System.Diagnostics.Process          process = null;
            System.Diagnostics.ProcessStartInfo processStartInfo;

            processStartInfo           = new System.Diagnostics.ProcessStartInfo();
            processStartInfo.FileName  = "netsh.exe";
            processStartInfo.Arguments = NetShArgumentsForRule(port, direction, protocol);
            if (Functions.OSSupportsAdvancedFirewallInNetSH)
            {
                processStartInfo.Verb = "runas";
            }
            processStartInfo.UseShellExecute = true;
            //processStartInfo.UseShellExecute = false;
            //processStartInfo.CreateNoWindow = true;
            //processStartInfo.RedirectStandardOutput = true;
            processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            try
            {
                process = System.Diagnostics.Process.Start(processStartInfo);

                DateTime begunProcess   = DateTime.Now;
                bool     processTimeout = false;
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(200);
                    TimeSpan elapsed = (DateTime.Now - begunProcess);
                    if (elapsed.TotalSeconds > 25)
                    {
                        processTimeout = true;
                        break;
                    }
                }

                if (processTimeout)
                {
                    Functions.WriteLineToLogFile("FirewallHelper: NOT OK - TimeOut");
                    return(false);
                }
                else if (process.ExitCode != 0)
                {
                    string processOutput = process.StandardOutput.ReadToEnd();

                    Functions.WriteLineToLogFile("FirewallHelper: NOT OK (error code " + process.ExitCode.ToString());
                    Functions.WriteLineToLogFile(processOutput);

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("FirewallHelper: Exception trying to add a firewall rule using netsh.");
                Functions.WriteExceptionToLogFile(ex);
                return(false);
            }
            finally
            {
                if (process != null)
                {
                    process.Dispose();
                }
            }

            Functions.WriteLineToLogFile("FirewallHelper: Rule Added 0 OK");
            return(true);
        }