Exemplo n.º 1
0
 private void ShowMessage(SmsPdu pdu)
 {
     if (pdu is SmsSubmitPdu)
     {
         // Stored (sent/unsent) message
         SmsSubmitPdu data = (SmsSubmitPdu)pdu;
         Output("SENT/UNSENT MESSAGE");
         Output("Recipient: " + data.DestinationAddress);
         Output("Message text: " + data.UserDataText);
         Output("-------------------------------------------------------------------");
         return;
     }
     if (pdu is SmsDeliverPdu)
     {
         // Received message
         SmsDeliverPdu data = (SmsDeliverPdu)pdu;
         Output("Mensaje Recibido");
         Output("Emisor: " + data.OriginatingAddress);
         Output("Hora de envio: " + data.SCTimestamp.ToString());
         Output("Texto del mensaje: " + data.UserDataText);
         Output("-------------------------------------------------------------------");
         try
         {
             var request  = (HttpWebRequest)WebRequest.Create(Constants.getServer() + "/api/v1/sms/create");
             var postData = MessageToJson(data.SCTimestamp.ToString(), data.OriginatingAddress, data.UserDataText, DateTime.Now.Ticks.ToString());
             var data2    = Encoding.UTF8.GetBytes(postData);
             request.Method        = "POST";
             request.ContentType   = "application/json";
             request.ContentLength = data2.Length;
             using (var stream = request.GetRequestStream())
             {
                 stream.Write(data2, 0, data2.Length);
             }
             var response       = (HttpWebResponse)request.GetResponse();
             var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
             response.Close();
         }
         catch (System.Net.WebException wx)
         {
             MessageBox.Show(wx.Message);
         }
         CommSetting.comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
         return;
     }
     if (pdu is SmsStatusReportPdu)
     {
         // Status report
         SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
         Output("STATUS REPORT");
         Output("Recipient: " + data.RecipientAddress);
         Output("Status: " + data.Status.ToString());
         Output("Timestamp: " + data.DischargeTime.ToString());
         Output("Message ref: " + data.MessageReference.ToString());
         Output("-------------------------------------------------------------------");
         return;
     }
     Output("Unknown message type: " + pdu.GetType().ToString());
 }
Exemplo n.º 2
0
        private void ExtractSMSText(SmsPdu pdu)
        {
            if (pdu is SmsSubmitPdu)
            {
                // Stored (sent/unsent) message
                SmsSubmitPdu data = (SmsSubmitPdu)pdu;
                Debug.WriteLine("SENT/UNSENT MESSAGE");
                Debug.WriteLine("Recipient: " + data.DestinationAddress);
                Debug.WriteLine("Message text: " + data.UserDataText);
                Debug.WriteLine("-------------------------------------------------------------------");
                return;
            }
            if (pdu is SmsDeliverPdu)
            {
                // Received message
                SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                Debug.WriteLine("RECEIVED MESSAGE");
                Debug.WriteLine("Sender: " + data.OriginatingAddress);
                Debug.WriteLine("Sent: " + data.SCTimestamp.ToString());
                Debug.WriteLine("Message text: " + data.UserDataText);

                var checkNInfo = Newtonsoft.Json.JsonConvert
                                 .DeserializeObject <CheckInInfo>(data.UserDataText);

                Messenger.Default.Send(new Messages.NewCheckInMessage
                {
                    CheckInInfo = checkNInfo
                });

                Debug.WriteLine("-------------------------------------------------------------------");
                return;
            }
            if (pdu is SmsStatusReportPdu)
            {
                // Status report
                SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
                Debug.WriteLine("STATUS REPORT");
                Debug.WriteLine("Recipient: " + data.RecipientAddress);
                Debug.WriteLine("Status: " + data.Status.ToString());
                Debug.WriteLine("Timestamp: " + data.DischargeTime.ToString());
                Debug.WriteLine("Message ref: " + data.MessageReference.ToString());
                Debug.WriteLine("-------------------------------------------------------------------");
                return;
            }
            Debug.WriteLine("Unknown message type: " + pdu.GetType().ToString());
        }
Exemplo n.º 3
0
        private void ShowMessage(SmsPdu pdu)
        {
            if (pdu is SmsSubmitPdu)
            {
                // Stored (sent/unsent) message
                SmsSubmitPdu data = (SmsSubmitPdu)pdu;
                Output("SENT/UNSENT MESSAGE");
                Output("Recipient: " + data.DestinationAddress);
                Output("Message text: " + data.UserDataText);
                Output("-------------------------------------------------------------------");
                return;
            }
            if (pdu is SmsDeliverPdu)
            {
                // Received message
                SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                Output("RECEIVED MESSAGE");
                Output("Sender: " + data.OriginatingAddress);
                Output("Sent: " + data.SCTimestamp.ToString());
                Output("Message text: " + data.UserDataText);
                Output("-------------------------------------------------------------------");

                BindGrid(pdu);

                return;
            }
            if (pdu is SmsStatusReportPdu)
            {
                // Status report
                SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
                Output("STATUS REPORT");
                Output("Recipient: " + data.RecipientAddress);
                Output("Status: " + data.Status.ToString());
                Output("Timestamp: " + data.DischargeTime.ToString());
                Output("Message ref: " + data.MessageReference.ToString());
                Output("-------------------------------------------------------------------");
                return;
            }
            Output("Unknown message type: " + pdu.GetType().ToString());
        }
Exemplo n.º 4
0
        private void ShowMessage(SmsPdu pdu)
        {
            if (pdu is SmsSubmitPdu)
            {
                // Stored (sent/unsent) message
                SmsSubmitPdu data = (SmsSubmitPdu)pdu;
                OutputSent("SENT MESSAGE");
                OutputSent("Recipient: " + data.DestinationAddress);
                OutputSent("Message text: " + data.UserDataText);
                OutputSent("-------------------------------------------------------------------");
                return;
            }
            if (pdu is SmsDeliverPdu)
            {
                // Received message
                SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                UpdateLog("Received", "Reply", data.OriginatingAddress, data.UserDataText);
                OutputReceived("RECEIVED MESSAGE");
                OutputReceived("Sender: " + data.OriginatingAddress);
                OutputReceived("Area: " + GetArea(data.OriginatingAddress.ToString()));
                OutputReceived("Sent: " + data.SCTimestamp.ToString());
                OutputReceived("Message text: " + data.UserDataText);
                OutputReceived("-------------------------------------------------------------------");

                OutputCPnumber(data.OriginatingAddress);
                varmessage = data.UserDataText;
                string[] message = varmessage.Split('/');

                if (message[0].ToUpper() == "AREA")
                {
                    if (message.Length == 2)
                    {
                        OutputAreaMobileNumber(message[1]);
                        OutputCode(message[0]);

                        return;
                    }
                    else
                    {
                        SendMessage("Invalid Keywords", cpnumberTxtBox.Text, "Sorry, You Texted An Invalid Command.");
                    }
                }
                else if (message[0].ToUpper() == "TB")
                {
                    if (message.Length == 3)
                    {
                        OutputGroup(message[1]);
                        OutputMessage(message[2]);
                        OutputCode(message[0]);

                        return;
                    }
                    else
                    {
                        SendMessage("Invalid Keywords", cpnumberTxtBox.Text, "Sorry, You Texted An Invalid Command. Text HELP For More Information.");
                    }
                }
                else if (message[0].ToUpper() == "TBALL")
                {
                    if (message.Length == 2)
                    {
                        OutputMessage(message[1]);
                        OutputCode(message[0]);

                        return;
                    }
                    else
                    {
                        SendMessage("Invalid Keywords", cpnumberTxtBox.Text, "Sorry, You Texted An Invalid Command. Text HELP For More Information.");
                    }
                }
            }
            else
            {
                Output("Unknown message type: " + pdu.GetType().ToString());
            }
        }
Exemplo n.º 5
0
        private static void ModemPollingLoop()
        {
            //Find a port where the modem is at
            _logger.Info("Searching for a modem...");
            for (int i = 1; i <= 256; i++)
            {
                if (TestConnection($"COM{i}"))
                {
                    break;
                }
            }

            if (_comm.IsOpen() && _comm.IsConnected())
            {
                _logger.Info("Modem found");
                _logger.Info("Setting modem settings...");
                _comm.SelectCharacterSet("ucs2"); //Use UTF-16 encoding when getting data from modem

                //Hook debugging event if user wants to debug modem commands
                if (_config.GetValue("Debug/ModemCommands", false))
                {
                    _comm.LoglineAdded += comm_LoglineAdded;
                }

                try
                {
                    _comm.SetSmscAddress(_config.GetValue("General/SMSCenter", ""));
                }
                catch (Exception)
                {
                    _logger.Warn("Invalid SMS Center number or this feature is not supported by current modem");
                }

                _logger.Info("Listening for incoming messages...");
                while (_comm.IsOpen())
                {
                    if (_comm.IsConnected())
                    {
                        try
                        {
                            //Get all messages saved on SIM
                            DecodedShortMessage[] messages = _comm.ReadMessages(PhoneMessageStatus.All,
                                                                                PhoneStorageType.Sim);

                            foreach (DecodedShortMessage message in messages)
                            {
                                SmsPdu pdu = message.Data;
                                if (pdu is SmsDeliverPdu) // Check if it's SMS and not some kind of a service message
                                {
                                    SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                                    _logger.Debug($"Received message from {data.OriginatingAddress}: " +
                                                  data.UserDataText + $" [TIMESTAMP: {data.SCTimestamp.ToSortableString()}]");

                                    ChangePassword(data.OriginatingAddress, data.UserDataText);

                                    //Delete message so it won't be parsed again
                                    //and so we don't have a problem with free space on SIM
                                    //in the future
                                    _comm.DeleteMessage(message.Index, message.Storage);
                                }
                                else
                                {
                                    _logger.Warn($"Received unknown message type: {pdu.GetType()}");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Warn($"Cannot read messages: {ex.Message} ({ex.GetType()})");
                            break;
                        }

                        //Sleep 5 seconds between message checks
                        Thread.Sleep(5000);
                    }
                    else
                    {
                        _logger.Error("Lost cellular network connection");
                        break;
                    }
                }
            }
            else
            {
                _logger.Fatal("No modem found");
            }

            //Close modem connection
            try
            {
                _comm.Close();
            }
            catch (Exception) { }
        }