Compare commits
No commits in common. "627374669343623431bc03307b224a121ddbeff6" and "65a08de6d8553eafabe6272b147d9512e00eb34f" have entirely different histories.
6273746693
...
65a08de6d8
@ -2265,7 +2265,6 @@ namespace AppServer
|
|||||||
if (Program.cfg.enableEmailService)
|
if (Program.cfg.enableEmailService)
|
||||||
{
|
{
|
||||||
SM.Debug(new string[] { "Checking mail at:" + DateTime.Now.ToString(), "For " + Program.cfg.emailAddress.ToString() + " on " + Program.cfg.pop3Server.ToString() });
|
SM.Debug(new string[] { "Checking mail at:" + DateTime.Now.ToString(), "For " + Program.cfg.emailAddress.ToString() + " on " + Program.cfg.pop3Server.ToString() });
|
||||||
|
|
||||||
emailHT = dbsubsoperManage.getAll_imei_sc_id("ByMail");
|
emailHT = dbsubsoperManage.getAll_imei_sc_id("ByMail");
|
||||||
if (emailHT.Count > 0)
|
if (emailHT.Count > 0)
|
||||||
{
|
{
|
||||||
@ -2289,23 +2288,19 @@ namespace AppServer
|
|||||||
DB.SetLastEmailTime(sslServer.getLastEmailTime());
|
DB.SetLastEmailTime(sslServer.getLastEmailTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DBsmsManager DBsms = new DBsmsManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
|
|
||||||
DBvehiclesManager dbvehs = new DBvehiclesManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
|
DBvehiclesManager dbvehs = new DBvehiclesManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
|
||||||
|
|
||||||
|
|
||||||
foreach (EmailtoSMS obj in EmailList)
|
foreach (EmailtoSMS obj in EmailList)
|
||||||
{
|
{
|
||||||
String seqID = "0." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Millisecond.ToString();
|
String seqID = "0." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Millisecond.ToString();
|
||||||
|
SM.Debug(new string[] {"-----START OK----",
|
||||||
SM.Debug(new string[] { "-----START OK----",
|
"From: " + obj.from,
|
||||||
"From: " + obj.from,
|
"ID: " + obj.id,
|
||||||
"ID: " + obj.id,
|
"Text: " + obj.text});
|
||||||
"Text: " + obj.text});
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// app server idx =0
|
// app server idx =0
|
||||||
|
DBsmsManager DB = new DBsmsManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
|
||||||
//bigu code remove # from text and also replace "'"
|
//bigu code remove # from text and also replace "'"
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -2316,15 +2311,13 @@ namespace AppServer
|
|||||||
{
|
{
|
||||||
SM.Debug("Error on converting email:" + ex.ToString());
|
SM.Debug("Error on converting email:" + ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
//end bigu code
|
//end bigu code
|
||||||
if (!obj.is_group) DBsms.insert_sms_received(obj.id, obj.text, 7, obj.from, seqID);
|
if (!obj.is_group) DB.insert_sms_received(obj.id, obj.text, 7, obj.from, seqID);
|
||||||
if (obj.is_sierra)
|
if (obj.is_sierra)
|
||||||
{
|
{
|
||||||
if (emailHT.Contains(obj.from))
|
if (emailHT.Contains(obj.from))
|
||||||
{
|
{
|
||||||
SM.Debug("Email received <<" + obj.text + ">> from address: " + obj.from);
|
SM.Debug("Email received <<" + obj.text + ">> from address: " + obj.from);
|
||||||
|
|
||||||
seqID = "1." + Utils.GetSecondsLocalFromDT(DateTime.Now).ToString() + DateTime.Now.Millisecond.ToString();
|
seqID = "1." + Utils.GetSecondsLocalFromDT(DateTime.Now).ToString() + DateTime.Now.Millisecond.ToString();
|
||||||
string test = "#132#" + ((SW_Subscriber)emailHT[obj.from]).imei + "#" + obj.text + "#hyt#";
|
string test = "#132#" + ((SW_Subscriber)emailHT[obj.from]).imei + "#" + obj.text + "#hyt#";
|
||||||
String cmdok = "#" + seqID + test; Int32 tmp = cmdok.Length + 1; tmp += tmp.ToString().Length; cmdok = "#" + tmp.ToString() + cmdok;
|
String cmdok = "#" + seqID + test; Int32 tmp = cmdok.Length + 1; tmp += tmp.ToString().Length; cmdok = "#" + tmp.ToString() + cmdok;
|
||||||
@ -2332,7 +2325,6 @@ namespace AppServer
|
|||||||
byte[] buf = enc.GetBytes(cmdok);
|
byte[] buf = enc.GetBytes(cmdok);
|
||||||
//send to messagebus
|
//send to messagebus
|
||||||
MainForm.udp.Send(buf, buf.Length);
|
MainForm.udp.Send(buf, buf.Length);
|
||||||
|
|
||||||
SM.Debug("Email thread successfully sent data to message bus");
|
SM.Debug("Email thread successfully sent data to message bus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2347,36 +2339,26 @@ namespace AppServer
|
|||||||
obj.text = obj.text.Remove(140 - 3 - obj.from.Length) + " [" + obj.from + "]";
|
obj.text = obj.text.Remove(140 - 3 - obj.from.Length) + " [" + obj.from + "]";
|
||||||
else
|
else
|
||||||
obj.text = obj.text + " [" + obj.from + "]";
|
obj.text = obj.text + " [" + obj.from + "]";
|
||||||
|
|
||||||
//send SMS on message buss
|
//send SMS on message buss
|
||||||
if (!obj.is_sierra)
|
if (!obj.is_sierra)
|
||||||
{
|
{
|
||||||
|
UnitSysPosition tmpX = dbvehs.getSystemPosition(dbvehs.getSCID(obj.id));
|
||||||
if (dbvehs != null)
|
|
||||||
|
string msg = "#143#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
|
||||||
|
if (obj.is_group) msg = "#144#" + tmpX.Gw_id + "." + tmpX.R_gw_id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
|
||||||
|
|
||||||
|
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + msg), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + msg).Length);
|
||||||
|
|
||||||
|
if (obj.is_group)
|
||||||
{
|
{
|
||||||
UnitSysPosition tmpX = dbvehs.getSystemPosition(dbvehs.getSCID(obj.id));
|
Int32 oldgatewayID = 0;
|
||||||
|
foreach (RadioGateway obj2 in RadioListIP)
|
||||||
string cmd = $"{tmpX.Gw_id}.{tmpX.R_gw_id}.{obj.id}#{obj.text}#{DateTime.Now.GetSecondsLocalFromDT()}#";
|
|
||||||
string code = (obj.is_group) ? "#144#" : "#143#" ;
|
|
||||||
byte[] msg = Utils.Convert_text_For_multicast("#0.0" + code + cmd);
|
|
||||||
|
|
||||||
if (msg != null && msg.Length > 0)
|
|
||||||
MainForm.udp.Send(msg, msg.Length);
|
|
||||||
|
|
||||||
if (obj.is_group)
|
|
||||||
{
|
{
|
||||||
Int32 oldgatewayID = 0;
|
if (oldgatewayID != obj2.Gw_id)
|
||||||
foreach (RadioGateway obj2 in RadioListIP)
|
|
||||||
{
|
{
|
||||||
if (oldgatewayID != obj2.Gw_id)
|
oldgatewayID = (Int32)obj2.Gw_id;
|
||||||
{
|
string msg2 = "#144#" + obj2.Gw_id + "." + obj2.Id + "." + obj.id + "#" + obj.text + "#" + (DateTime.Now.GetSecondsLocalFromDT()) + "#";
|
||||||
oldgatewayID = (Int32)obj2.Gw_id;
|
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + msg2), SafeMobileLib.Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + msg2).Length);
|
||||||
cmd = $"#144#{obj2.Gw_id}.{obj2.Id}.{obj.id}#{obj.text}#{DateTime.Now.GetSecondsLocalFromDT()}#";
|
|
||||||
byte[] msg2 = Utils.Convert_text_For_multicast("#1." + (DateTime.Now.GetSecondsLocalFromDT()) + DateTime.Now.Ticks.ToString() + cmd);
|
|
||||||
|
|
||||||
if( msg2 != null && msg2.Length > 0)
|
|
||||||
MainForm.udp.Send(msg2, msg2.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@ namespace SafeMobileLib
|
|||||||
private bool isSSL = true;
|
private bool isSSL = true;
|
||||||
private Int64 lastEmailTime = 0;
|
private Int64 lastEmailTime = 0;
|
||||||
private Int64 startEmailServiceTime = 0;
|
private Int64 startEmailServiceTime = 0;
|
||||||
public static Dictionary<string, int> blackList = new Dictionary<string, int>();
|
|
||||||
public const int MAX_ATTEMPTS = 100;
|
|
||||||
|
|
||||||
// blank constructor in order to be used in Email Checking
|
// blank constructor in order to be used in Email Checking
|
||||||
public EmailServerSSL()
|
public EmailServerSSL()
|
||||||
@ -380,46 +378,11 @@ namespace SafeMobileLib
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void HandleBlacklist(string key)
|
|
||||||
{
|
|
||||||
// add key to backlist
|
|
||||||
if (!blackList.ContainsKey(key))
|
|
||||||
blackList.Add(key, MAX_ATTEMPTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsBlacklisted(string key)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!blackList.ContainsKey(key))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// avoid to connect to pop3 MAX_ATTEMPTS times => give another chance to try to connect to pop 3 when count = 0
|
|
||||||
int count = blackList[key];
|
|
||||||
if (count == 0)
|
|
||||||
{
|
|
||||||
blackList.Remove(key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
blackList[key] = count - 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect to the Pop Server in order to be used to get the emails
|
/// Connect to the Pop Server in order to be used to get the emails
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ConnectEmailPopServer()
|
private void ConnectEmailPopServer()
|
||||||
{
|
{
|
||||||
if (IsBlacklisted(serverIP))
|
|
||||||
{
|
|
||||||
|
|
||||||
Utils.WriteLine($"ConnectEmailPopServer : Could not conenct to the pop server '{serverIP}'. The pop server '{serverIP}' is in blacklist count = {blackList[serverIP]}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Thread t = new Thread(() =>
|
Thread t = new Thread(() =>
|
||||||
{
|
{
|
||||||
ConnectAsync();
|
ConnectAsync();
|
||||||
@ -458,25 +421,18 @@ namespace SafeMobileLib
|
|||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine("PopServerNotFoundException -> " + ee.ToString());
|
Console.WriteLine("PopServerNotFoundException -> " + ee.ToString());
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
HandleBlacklist(serverIP);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (InvalidLoginException e)
|
catch (InvalidLoginException e)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine("InvalidLoginException -> " + e.ToString());
|
Console.WriteLine("InvalidLoginException -> " + e.ToString());
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
HandleBlacklist(serverIP);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("ConnectEmailPopServer -> " + ex.ToString());
|
Console.WriteLine("ConnectEmailPopServer -> " + ex.ToString());
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
HandleBlacklist(serverIP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,10 +441,8 @@ namespace SafeMobileLib
|
|||||||
Int32 tmp = cmdok.Length + 1;
|
Int32 tmp = cmdok.Length + 1;
|
||||||
tmp += tmp.ToString().Length;
|
tmp += tmp.ToString().Length;
|
||||||
String TMPcmdok = "#" + tmp.ToString() + cmdok;
|
String TMPcmdok = "#" + tmp.ToString() + cmdok;
|
||||||
if (tmp != TMPcmdok.Length)
|
if (tmp != TMPcmdok.Length) cmdok = "#" + TMPcmdok.Length + cmdok;
|
||||||
cmdok = "#" + TMPcmdok.Length + cmdok;
|
else cmdok = TMPcmdok;
|
||||||
else
|
|
||||||
cmdok = TMPcmdok;
|
|
||||||
|
|
||||||
System.Text.Encoding enc = System.Text.Encoding.ASCII;
|
System.Text.Encoding enc = System.Text.Encoding.ASCII;
|
||||||
byte[] buf = enc.GetBytes(cmdok);
|
byte[] buf = enc.GetBytes(cmdok);
|
||||||
|
Loading…
Reference in New Issue
Block a user