public bool OnRequesting(PacketEventArgs requestFilter)
        {
            //// filtering header
            //// 1. get string using encoding ibm850
            //// 2. decrypt using rijndael
            //// 3. split with "</>"
            if (configuration == null)
            {
                configuration = ObjectPool.Instance.Resolve<GSMServer.Configuration.IConfiguration>();
            }
            if (string.IsNullOrEmpty(signature) || (string.IsNullOrEmpty(encodingName) || (encoding == null)))
            {
                signature = ((ApplicationSettings)configuration).General.SMSGWSignature;
                encodingName = ((ApplicationSettings)configuration).General.DefaultEncoding;
                encoding = Encoding.GetEncoding(encodingName);
            }
            
            lock (s_InternalSyncObject)
            {
                string dataFilter = "";
                if (requestFilter.Data.Length > 0)
                {
                    try
                    {
                        dataFilter = c.Decrypt(encoding.GetString(requestFilter.Data));
                    }
                    catch(FormatException fe)
                    {
                        IErrorLogging log = ObjectPool.Instance.Resolve<IErrorLogging>();
                        log.Write(fe.Message + " - on requesting");
                        return false;
                    }
                    requestFilter.Data = encoding.GetBytes(dataFilter);
                }
                if (!string.IsNullOrEmpty(dataFilter))
                {
                    Request request = JsonConvert.DeserializeObject<Request>(dataFilter, new JsonSerializerSettings
                                        {
                                            TypeNameHandling = TypeNameHandling.Objects
                                        });
                    request.RemoteEndPoint = (IPEndPoint)requestFilter.Client.RemoteEndPoint;

                    if (request.Header != null)
                    {
                        if (request.Header.Signature != null)
                        {
                            if (!request.Header.Signature.Equals(signature))
                            {
                                request.Cancel = true;
                                return false;
                            } 
                        }
                    }
                    else
                        return false; 
                }
            }
            return true;
        }
Esempio n. 2
0
        public string GetRawXml(ParameterizedMap map)
        {
            UnboxParameterizedMap param = new UnboxParameterizedMap(map);

            GSMServer.Configuration.IConfiguration config = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
            string section = param.TryGet <string>("section");

            return(config.GetRawXml(section));
        }
Esempio n. 3
0
        private void InitSerialPort(BasicInformation connection)
        {
            //// let the connection remains open until the server is closed/disposed
            connection.Connector.Open();

            connection.OnBeginExecuting();

            BaseResult <GenericTypeResult <string> > manufacturer = connection.GetManufacturer();

            if (!string.IsNullOrEmpty(manufacturer.Response.Result))
            {
                connection.GetServiceCenter();
                connection.SetErrorMessageFormat(1);
                connection.GetOperator();

                PhoneBook pb = new PhoneBook(connection);
                pb.SetPhoneBookMemory(MemoryStorage.SIMOwnNumber);
                pb.GetInfo();

                SMS sms = new SMS(connection);
                sms.SetMessageStorage(MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook);
                sms.SetMessageFormat(connection.PDUMode);

                string prefixOwnNumber = string.Empty;
                if (string.IsNullOrEmpty(prefixOwnNumber))
                {
                    GSMServer.Configuration.IConfiguration configuration = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
                    prefixOwnNumber = ((ApplicationSettings)configuration).General.PrefixOwnNumber;
                }

                BaseResult <GenericTypeResult <List <PhoneNumberInfo> > > list = pb.ReadPhoneBook(MemoryStorage.SIMOwnNumber, 1, -1);
                if (list.Response.Result.Count > 0)
                {
                    foreach (PhoneNumberInfo info in list.Response.Result)
                    {
                        if (info.Name.Equals(prefixOwnNumber))
                        {
                            connection.OwnNumber = info.PhoneNumber;
                            break;
                        }
                    }
                }
                portColletion.Add(connection);
            }
            connection.OnEndExecuting();
        }
        public bool OnRequesting(PacketEventArgs requestFilter)
        {
            //// filtering header
            //// 1. get string using encoding ibm850
            //// 2. decrypt using rijndael
            //// 3. split with "</>"
            if (configuration == null)
            {
                configuration = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
            }
            if (string.IsNullOrEmpty(signature) || (string.IsNullOrEmpty(encodingName) || (encoding == null)))
            {
                signature    = ((ApplicationSettings)configuration).General.SMSGWSignature;
                encodingName = ((ApplicationSettings)configuration).General.DefaultEncoding;
                encoding     = Encoding.GetEncoding(encodingName);
            }

            lock (s_InternalSyncObject)
            {
                string dataFilter = "";
                if (requestFilter.Data.Length > 0)
                {
                    try
                    {
                        dataFilter = c.Decrypt(encoding.GetString(requestFilter.Data));
                    }
                    catch (FormatException fe)
                    {
                        IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                        log.Write(fe.Message + " - on requesting");
                        return(false);
                    }
                    requestFilter.Data = encoding.GetBytes(dataFilter);
                }
                if (!string.IsNullOrEmpty(dataFilter))
                {
                    Request request = JsonConvert.DeserializeObject <Request>(dataFilter, new JsonSerializerSettings
                    {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    request.RemoteEndPoint = (IPEndPoint)requestFilter.Client.RemoteEndPoint;

                    if (request.Header != null)
                    {
                        if (request.Header.Signature != null)
                        {
                            if (!request.Header.Signature.Equals(signature))
                            {
                                request.Cancel = true;
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 5
0
 public bool Save(ParameterizedMap map)
 {
     GSMServer.Configuration.IConfiguration config = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
     return(config.Save());
 }
Esempio n. 6
0
        private void Initialize(string ipAddress, int port)
        {
            /// set culture to US
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            /// register configuration & worker
            ObjectPool.Instance.Register <IServer>().ImplementedBy(this);
            ObjectPool.Instance.Register <GSMServer.Configuration.IConfiguration>().ImplementedBy(new ApplicationSettings());
            ObjectPool.Instance.Register <Worker.IPipeline>().ImplementedBy(new DefaultPipeline(new ActionInvokerLookup(this)));

            /// register logging IInternalLogging
            ObjectPool.Instance.Register <IInternalLogging>().ImplementedBy(new BaseInternalLogging());
            ObjectPool.Instance.Register <ISMSLogging>().ImplementedBy(new ArchiveSMSLogging());

            /// initialize database
            InitializeDatabase();

            GSMServer.Configuration.IConfiguration settings = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();

            portColletion     = new RandomConnectionProvider();
            workerPoolManager = new WorkerPoolManager();
            workerPoolManager.AddPool(new DatabaseWorkerPool());
            workerPoolManager.AddPool(new MemoryWorkerPool());

            pluginMap = new PluginObserver();

            string countryCode = ((ApplicationSettings)settings).General.CountryCode;
            string IsNullintervalProcessQueue = ((ApplicationSettings)settings).General.IntervalWorkerQueue.ToString();
            string IsNullintervalReadMessage  = ((ApplicationSettings)settings).General.IntervalReadMessage.ToString();

            int intervalProcessQueue;
            int intervalReadMessage = TimeConstant.READ_TIMEOUT;

            if (string.IsNullOrEmpty(IsNullintervalProcessQueue))
            {
                throw new System.Configuration.ConfigurationErrorsException("Interval Queue cannot be null or zero.");
            }
            else
            {
                intervalProcessQueue = Convert.ToInt32(IsNullintervalProcessQueue);
                if (intervalProcessQueue < 1000)
                {
                    throw new InvalidOperationException("Interval Queue may cause invalid operation while sending SMS because value is to fast.");
                }
            }

            BasicInformation connection;
            StringBuilder    portname, sparity, sstop, shand;
            StringBuilder    serviceCenter = new StringBuilder();
            bool             pduMode = false;
            int       baudrate, databits;
            Parity    parity;
            StopBits  stopBits;
            Handshake handshake;

            /// for comparison is the configuration in accordance with the detected serial ports by OS?
            string[] ports = System.IO.Ports.SerialPort.GetPortNames();

            foreach (GSMServer.Configuration.SerialPort node in ((ApplicationSettings)settings).SerialPorts.Items)
            {
                portname = new StringBuilder(node.PortName);
                pduMode  = false;
                pduMode  = node.PDUMode;
                if (!string.IsNullOrEmpty(node.ServiceCenter))
                {
                    serviceCenter = new StringBuilder(countryCode + node.ServiceCenter.Substring(1, node.ServiceCenter.Length - 1));
                }

                baudrate = Convert.ToInt32(node.BaudRate);
                databits = Convert.ToInt32(node.DataBits);
                parity   = new Parity();
                sparity  = new StringBuilder(node.Parity.ToLower());
                if (sparity.ToString() == "even")
                {
                    parity = Parity.Even;
                }
                else
                if (sparity.ToString() == "mark")
                {
                    parity = Parity.Mark;
                }
                else
                if (sparity.ToString() == "none")
                {
                    parity = Parity.None;
                }
                else
                if (sparity.ToString() == "odd")
                {
                    parity = Parity.Odd;
                }
                else
                if (sparity.ToString() == "space")
                {
                    parity = Parity.Space;
                }
                stopBits = new StopBits();
                sstop    = new StringBuilder(node.StopBits.ToLower());
                if (sstop.ToString() == "none")
                {
                    stopBits = StopBits.None;
                }
                else
                if (sstop.ToString() == "one")
                {
                    stopBits = StopBits.One;
                }
                else
                if (sstop.ToString() == "onepointfive")
                {
                    stopBits = StopBits.OnePointFive;
                }
                else
                if (sstop.ToString() == "two")
                {
                    stopBits = StopBits.Two;
                }
                handshake = new Handshake();
                shand     = new StringBuilder(node.Handshake.ToLower());
                if (shand.ToString() == "none")
                {
                    handshake = Handshake.None;
                }
                else
                if (shand.ToString() == "requesttosend")
                {
                    handshake = Handshake.RequestToSend;
                }
                else
                if (shand.ToString() == "RequestToSendXOnXOff")
                {
                    handshake = Handshake.RequestToSendXOnXOff;
                }
                else
                if (shand.ToString() == "xonxoff")
                {
                    handshake = Handshake.XOnXOff;
                }

                /// check whether port there is in collection?
                if (ports.Where(b => b.ToLower().Equals(portname.ToString().ToLower())).SingleOrDefault() != null)
                {
                    connection = new BasicInformation(portname.ToString(), baudrate, parity, stopBits, databits, handshake, serviceCenter.ToString(), pduMode);
                    InitSerialPort(connection);
                }
            }

            GSMServer.Plugin.Plugin plugin;
            foreach (PluginElement pluginElement in ((ApplicationSettings)settings).Plugins.Items)
            {
                plugin = PluginActivator.Create(pluginElement.AssemblyFile, pluginElement.Type);
                if (plugin != null)
                {
                    pluginMap.Add(pluginElement.AssemblyFile, plugin);
                }
            }

            availableConnections = portColletion.ToList();
            if (portColletion.Count > 0)
            {
                intervalProcessQueue = (intervalProcessQueue / portColletion.Count) + TimeConstant.DEFAULT_INTERVAL_QUEUE;
            }
            else
            {
                intervalProcessQueue = (intervalProcessQueue) + TimeConstant.DEFAULT_INTERVAL_QUEUE;
            }

            timerReadQueue          = new System.Timers.Timer(intervalReadMessage);
            timerReadQueue.Elapsed += timerReadQueue_Elapsed;

            timerProcessRequestQueue          = new System.Timers.Timer(intervalProcessQueue);
            timerProcessRequestQueue.Elapsed += TimerProcessingRequest_Elapsed;

            if (portColletion.Count > 0)
            {
                if (!this.Active)
                {
                    this.BeginAcceptClient();
                }
            }

            base.PacketReceived += OnPacketReceived;
            base.Connected      += OnClientConnected;
            base.Disconnected   += OnClientDisconnect;
            base.Closed         += OnClosed;
            base.Open           += OnOpen;
        }