public BoardCredentials getRosterCredentials(BoardCredentials BoardCreds, StreamWriter streamWriterReport) { try { var helper = new PsaHelper(); char[] delimiters = new char[] { ',' }; string mid = Convert.ToString(BoardCreds.ModuleId); BoardCreds.DatasourceId = helper.GetDataSourceId(mid); string retsLoginURL = ""; LoginInfo loginInfo = helper.GetDataAggTraceInfo(BoardCreds.DatasourceId, ref retsLoginURL); string DefFilePath = ""; string loginType = ""; var connections = helper.GetDefConnections(BoardCreds.ModuleId); if (connections != null) { foreach (var connection in connections) { if (string.IsNullOrWhiteSpace(retsLoginURL) == false && string.IsNullOrWhiteSpace(loginType) == false) { break; } if (!connection.connection_name.EndsWith(".sql", StringComparison.OrdinalIgnoreCase)) { continue; } DefFilePath = connection.definition_file; var iniReader = new IniFile(connection.definition_file); var tcpIp = iniReader.Read("TcpIp", "Common"); if (tcpIp == "14") { //Check DEF loginType = "Master"; BoardCreds.isRets = true; } else if (tcpIp == "9" || tcpIp == "11" || tcpIp == "13") { loginType = "AgentCredentials"; BoardCreds.isRets = true; } else { BoardCreds.isRets = false; } if (string.IsNullOrWhiteSpace(retsLoginURL) == true) { var mainscript = iniReader.GetSectionContent("MainScript"); retsLoginURL = getURL(mainscript); } } } BoardCreds.IsValidCredential = false; if (loginInfo != null) { BoardCreds.IsValidCredential = true; BoardCreds.RETSURL = retsLoginURL; BoardCreds.LoginType = loginType; BoardCreds.Username = loginInfo.UserName; BoardCreds.Password = loginInfo.Password; BoardCreds.UserAgent = loginInfo.UserAgent; BoardCreds.UserAgentPass = loginInfo.UaPassword; writetofile(BoardCreds, streamWriterReport); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(BoardCreds); }
public BoardCredentials getCredentials(BoardCredentials BoardCreds, StreamWriter streamWriterReport) { TCSEntities tcsDb = null; TCSEntitiesProduction tcsproddb = null; tcsDb = new TCSEntities(); tcsproddb = new TCSEntitiesProduction(); try { var helper = new PsaHelper(); var connections = helper.GetDefConnections(BoardCreds.ModuleId); bool credsfound = false; char[] delimiters = new char[] { ',' }; string DefFilePath = ""; string mid = Convert.ToString(BoardCreds.ModuleId); BoardCreds.DatasourceId = helper.GetDataSourceId(mid); foreach (var connection in connections) { if (credsfound == true) { continue; } if (connection.connection_name.EndsWith(".sql", StringComparison.OrdinalIgnoreCase)) { continue; } DefFilePath = connection.definition_file; //BoardId = connection.board_id ?? 0; var iniReader = new IniFile(connection.definition_file); var tcpIp = iniReader.Read("TcpIp", "Common"); //var HTTPUserAgent = iniReader.Read("SecList", "HttpUserAgent"); ////var RetsUAUserAgent = iniReader.Read("SecList", "RetsUAUserAgent"); ////var RetsUAPwd = iniReader.Read("SecList", "RetsUAPwd"); //var SecList = iniReader.GetSectionContent("SecList"); //var mainscript = iniReader.GetSectionContent("MainScript"); //string RetsUAUserAgent = ParseSecList(SecList,"RetsUAUserAgent"); //string RetsUAPwd = ParseSecList(SecList, "RetsUAPwd"); BoardCreds.UserAgent = ""; BoardCreds.UserAgentPass = ""; if (tcpIp == "14") { //Check DEF BoardCreds.LoginType = "Master"; BoardCreds.Username = "******"; BoardCreds.Password = "******"; BoardCreds.IsValidCredential = true; BoardCreds.isRets = true; return(BoardCreds); } else if (tcpIp == "9" || tcpIp == "11" || tcpIp == "13") { BoardCreds.LoginType = "AgentCredentials"; BoardCreds.isRets = true; } else { BoardCreds.isRets = false; BoardCreds.IsValidCredential = false; return(BoardCreds); } //Check DB credsfound = true; //BoardCreds.RETSURL = getURL(mainscript); try { var AssociatedBoards = from boards in tcsproddb.cma_mls_boards where (boards.module_id == BoardCreds.ModuleId) select boards.board_id; foreach (var Board in AssociatedBoards) { BoardCreds.BoardId = Board; DateTime dt = DateTime.Now.AddDays(-30); var UniqueUsers = from users in tcsproddb.tcs_request_log join errors in tcsproddb.tcs_error_log on users.request_id equals errors.request_id into fg from fgi in fg.DefaultIfEmpty() where (users.client_name == "TMK" || users.client_name == "TPO" || users.client_name == "TMKListingAlert") && (users.board_id == Board) && (users.when_created > dt) && (fgi.error_code == null) orderby users.when_created descending group users by users.mls_user_name into uTable select new { USER = uTable.Key, LOCATION = uTable.Max(x => x.location_path) }; int i = 0; foreach (var user in UniqueUsers) { if ((user.USER != "") && (user.LOCATION != "")) { if (BoardCreds.ModuleId == 2360) { if (user.USER.IndexOf("fl.") > -1) { continue; } } try { System.IO.StreamReader log; log = new System.IO.StreamReader(user.LOCATION); string copiedlog = log.ReadToEnd(); log.Close(); int startsub = copiedlog.IndexOf("<Login>") + 7; int endsub = copiedlog.IndexOf("</Login>") - startsub; string logininfo = copiedlog.Substring(startsub, endsub); logininfo = logininfo.Replace("<password>", ","); logininfo = logininfo.Replace("</password>", ","); string[] creds = logininfo.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); if (creds.Length > 0) { BoardCreds.Username = creds[0]; } if (creds.Length > 1) { BoardCreds.Password = creds[1]; } writetofile(BoardCreds, streamWriterReport); BoardCreds.IsValidCredential = true; i++; if (i > 0) { break; } } catch { } } } } if (String.IsNullOrEmpty(BoardCreds.Username)) { var query = (from users in tcsDb.CleanLogins1 where (users.module_id.Equals(mid)) select new { Username = users.user_name, Password = users.password }); var agentCredential = query.FirstOrDefault(); if (agentCredential == null) { query = (from users in tcsDb.tcs_clean_loggins where (users.module_id.Equals(BoardCreds.ModuleId)) select new { Username = users.user_name, Password = users.password }); agentCredential = query.FirstOrDefault(); } BoardCreds.Username = agentCredential.Username; BoardCreds.Password = agentCredential.Password; BoardCreds.IsValidCredential = true; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } catch (Exception ex) { } finally { tcsDb.Dispose(); tcsproddb.Dispose(); } return(BoardCreds); }