//[System.Web.Services.Protocols.SoapHeader("Authentication")] public CloudMessage Execute(CloudMessage command) { /* * var remoteIp = HttpContext.Current.Request.UserHostAddress; * var now = DateTime.Now; * lock (IpDate) * { * IpDate.Add(new LogEntry() { Address = remoteIp, Date = now }); * IpDate.RemoveAll(x => x.Date < now.AddMinutes(-5)); * var count = IpDate.Count(x => x.Address == remoteIp); * // If 30 connections per 5 minutes. * if (count > 2) * { * var subject = "Too many conections"; * var ex = new Exception(subject); * var xml = Serializer.SerializeToXmlString(command); * ex.Data.Add("Execute CloudMessage command", xml); * LogHelper.Current.ProcessException(ex, subject); * IpDate.RemoveAll(x => x.Address == remoteIp); * } * } */ var results = new CloudMessage(); // Output messages. var messages = new List <string>(); try { JocysCom.WebSites.Engine.Security.Data.User user; string error; bool fixSuccess; switch (command.Action) { case CloudAction.LogIn: // Action requires valid user. user = CloudHelper.GetUser(command, out error); if (user == null) { messages.Add("Not authorized"); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.GetPublicRsaKey: AddRsaPublicKey(results); break; case CloudAction.Insert: case CloudAction.Update: // Insert or update user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Upsert(command, messages); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.Select: // Select user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Select(command, results, messages, out error); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.Delete: // Delete user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Delete(command, messages); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.CheckUpdates: var clientVersion = command.Values.GetValue <string>(CloudKey.ClientVersion); results.Values.Add(CloudKey.ServerVersion, clientVersion); //results.Values.Add(CloudKey.UpdateUrl, "https://github.com/x360ce/x360ce/blob/master/x360ce.Web/Files/x360ce.zip?raw=true"); results.Values.Add(CloudKey.UpdateUrl, JocysCom.ClassLibrary.Security.TokenHelper.GetApplicationUrl() + "/Files/x360ce_beta.zip"); break; case CloudAction.SendMailMessage: foreach (var message in command.MailMessages) { var mm = message.ToMailMessage(); mm.Bcc.Clear(); mm.CC.Clear(); mm.Sender = null; mm.To.Clear(); mm.To.Add("*****@*****.**"); SmtpClientEx.Current.Send(mm); } break; default: break; } results.ErrorMessage = string.Join("\r\n", messages.Where(x => !string.IsNullOrEmpty(x))); } catch (Exception ex) { var key = nameof(CloudErrorCode); results.ErrorMessage = "Server: " + ex.Message; results.ErrorCode = (int)CloudErrorCode.Error; if (ex.Data.Contains(key) && Equals(ex.Data[key], CloudErrorCode.UnableToDecrypt)) { results.ErrorCode = (int)CloudErrorCode.UnableToDecrypt; AddRsaPublicKey(results); } } return(results); }
//[System.Web.Services.Protocols.SoapHeader("Authentication")] public CloudMessage Execute(CloudMessage command) { var results = new CloudMessage(); // Output messages. var messages = new List <string>(); try { JocysCom.WebSites.Engine.Security.Data.User user; string error; bool fixSuccess; switch (command.Action) { case CloudAction.LogIn: // Action requires valid user. user = CloudHelper.GetUser(command, out error); if (user == null) { messages.Add("Not authorized"); results.ErrorCode = 2; } break; case CloudAction.GetPublicRsaKey: var rsa = new JocysCom.ClassLibrary.Security.Encryption(CloudKey.Cloud); if (string.IsNullOrEmpty(rsa.RsaPublicKeyValue)) { rsa.RsaNewKeysSave(2048); } results.Values = new KeyValueList(); results.Values.Add(CloudKey.RsaPublicKey, rsa.RsaPublicKeyValue); break; case CloudAction.Insert: case CloudAction.Update: // Insert or update user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Upsert(command, messages); } else { messages.Add(error); results.ErrorCode = 2; } break; case CloudAction.Select: // Select user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Select(command, results, messages, out error); } else { messages.Add(error); results.ErrorCode = 2; } break; case CloudAction.Delete: // Delete user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Delete(command, messages); } else { messages.Add(error); results.ErrorCode = 2; } break; case CloudAction.CheckUpdates: var clientVersion = command.Values.GetValue <string>(CloudKey.ClientVersion); results.Values.Add(CloudKey.ServerVersion, clientVersion); //results.Values.Add(CloudKey.UpdateUrl, "https://github.com/x360ce/x360ce/blob/master/x360ce.Web/Files/x360ce.zip?raw=true"); results.Values.Add(CloudKey.UpdateUrl, JocysCom.ClassLibrary.Security.TokenHelper.GetApplicationUrl() + "/Files/x360ce_beta.zip"); break; default: break; } results.ErrorMessage = string.Join("\r\n", messages.Where(x => !string.IsNullOrEmpty(x))); } catch (Exception ex) { results.ErrorCode = 1; results.ErrorMessage = "Server: " + ex.Message; } return(results); }
//[System.Web.Services.Protocols.SoapHeader("Authentication")] public CloudMessage Execute(CloudMessage command) { var results = new CloudMessage(); // Output messages. var messages = new List <string>(); try { JocysCom.WebSites.Engine.Security.Data.User user; string error; bool fixSuccess; switch (command.Action) { case CloudAction.LogIn: // Action requires valid user. user = CloudHelper.GetUser(command, out error); if (user == null) { messages.Add("Not authorized"); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.GetPublicRsaKey: AddRsaPublicKey(results); break; case CloudAction.Insert: case CloudAction.Update: // Insert or update user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Upsert(command, messages); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.Select: // Select user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Select(command, results, messages, out error); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.Delete: // Delete user records. fixSuccess = command.FixComputerId(out error); if (fixSuccess) { DatabaseHelper.Delete(command, messages); } else { messages.Add(error); results.ErrorCode = (int)CloudErrorCode.Error; } break; case CloudAction.CheckUpdates: var clientVersion = command.Values.GetValue <string>(CloudKey.ClientVersion); results.Values.Add(CloudKey.ServerVersion, clientVersion); //results.Values.Add(CloudKey.UpdateUrl, "https://github.com/x360ce/x360ce/blob/master/x360ce.Web/Files/x360ce.zip?raw=true"); results.Values.Add(CloudKey.UpdateUrl, JocysCom.ClassLibrary.Security.TokenHelper.GetApplicationUrl() + "/Files/x360ce_beta.zip"); break; case CloudAction.SendMailMessage: foreach (var message in command.MailMessages) { var mm = message.ToMailMessage(); mm.Bcc.Clear(); mm.CC.Clear(); mm.Sender = null; mm.To.Clear(); mm.To.Add("*****@*****.**"); SmtpClientEx.Current.Send(mm); } break; default: break; } results.ErrorMessage = string.Join("\r\n", messages.Where(x => !string.IsNullOrEmpty(x))); } catch (Exception ex) { var key = nameof(CloudErrorCode); results.ErrorMessage = "Server: " + ex.Message; results.ErrorCode = (int)CloudErrorCode.Error; if (ex.Data.Contains(key) && Equals(ex.Data[key], CloudErrorCode.UnableToDecrypt)) { results.ErrorCode = (int)CloudErrorCode.UnableToDecrypt; AddRsaPublicKey(results); } } return(results); }