Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.73 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Drawing;
  12. using System.Net;
  13. using System.Xml;
  14.  
  15. public partial class login : System.Web.UI.Page
  16. {
  17. string connString;
  18. DataSet props;
  19.  
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22. SantraxVMUtil.writeLog("Entering AM:");
  23. if (Session["AccessLevel"] != null) FormsAuthentication.RedirectFromLoginPage("any web user", false);
  24. //System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/santraxSite/AccountManager");
  25. //System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/AccountManager/AccountManager.root/AccountManager/santraxSite/AccountManager");
  26. System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
  27. System.Configuration.ConnectionStringSettings connStringObj = rootWebConfig.ConnectionStrings.ConnectionStrings["accountManager"];
  28. connString = connStringObj.ConnectionString;
  29. /*if (connString.IndexOf("Data Source=stxprd") >= 0)
  30. {
  31. Session["BackgroundColor"] = "Navy";
  32. }
  33. else
  34. {
  35. Session["BackgroundColor"] = "Navy";//"Maroon";
  36. }*/
  37. LoginAcctManager.Focus();
  38.  
  39. string autoLoginScript =
  40. "<script language=\"javascript\" type=\"text/javascript\">" +
  41. "autoLogin()" +
  42. "</script>";
  43. string autoLoginFunctionScript =
  44. "<script language=\"javascript\" type=\"text/javascript\">" +
  45. "function autoLogin() {" +
  46. "var username = getURLParam('UserName');" +
  47. "var password = getURLParam('Password');" +
  48. "if(username != null && username.length > 0) {" +
  49. " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$UserName.value = username;" +
  50. " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$Password.value = password;" +
  51. " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$LoginButton.click();" +
  52. "}" +
  53. "}" +
  54. "function getURLParam(strParamName){" +
  55. " var strReturn = \"\";" +
  56. " var strHref = window.location.href;" +
  57. " if ( strHref.indexOf(\"?\") > -1 ){" +
  58. " var strQueryString = strHref.substr(strHref.indexOf(\"?\"));" +
  59. " var aQueryString = strQueryString.split(\"&\");" +
  60. " for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){" +
  61. " if (aQueryString[iParam].indexOf(strParamName + \"=\") > -1 ){" +
  62. " var aParam = aQueryString[iParam].split(\"=\");" +
  63. " strReturn = aParam[1];" +
  64. " break;" +
  65. " }" +
  66. " }" +
  67. " }" +
  68. " return strReturn;" +
  69. "}" +
  70. "</script>";
  71.  
  72. ClientScript.RegisterClientScriptBlock(typeof(Page), "autoLoginFunction", autoLoginFunctionScript);
  73. ClientScript.RegisterStartupScript(typeof(Page), "autoLogin", autoLoginScript);
  74. props = loadProperties();
  75. DataTable version = props.Tables["version_setting"];
  76. foreach (DataRow row in version.Rows)
  77. {
  78. for (int col = 0; col < version.Columns.Count - 1; col++)
  79. {
  80. Session["version"] = row[col];
  81. //SantraxVMUtil.writeLog("version:" + row[col]);
  82. }
  83. }
  84. DataTable phone_setting = props.Tables["phone_setting"];
  85. foreach (DataRow row in phone_setting.Rows)
  86. {
  87. for (int col = 0; col < phone_setting.Columns.Count - 1; col++)
  88. {
  89. Session["phone_script"] = row[col];
  90. //SantraxVMUtil.writeLog("phone_setting:" + row[col]);
  91. }
  92. }
  93. }
  94. protected void LoginAcctManager_Authenticate(object sender, AuthenticateEventArgs e)
  95. {
  96. Session.Clear();
  97. //***DataSet props = loadProperties();
  98. if (false)//!isIPWithinBuilding(props)
  99. {
  100. e.Authenticated = false;
  101. }
  102. else
  103. {
  104. SqlDataSourceAccessLevel.SelectCommand = "SELECT access_level FROM access_level WHERE UPPER(username)=UPPER('" + LoginAcctManager.UserName + "') and UPPER(password) = UPPER('" + LoginAcctManager.Password + "')";
  105. DropDownListAccessLevel.DataBind();
  106. string accessLevel = null;
  107. if (DropDownListAccessLevel.Items.Count > 0)
  108. {
  109. accessLevel = DropDownListAccessLevel.SelectedValue;
  110. }
  111. if (accessLevel != null && (accessLevel.Equals("0") || accessLevel.Equals("1") || accessLevel.Equals("2")))
  112. {
  113. e.Authenticated = true;
  114. if (accessLevel.Equals("0")) accessLevel = "Read Only";
  115. else if (accessLevel.Equals("1")) accessLevel = "Partial Update";
  116. else if (accessLevel.Equals("2")) accessLevel = "Full Rights";
  117. Session["AccessLevel"] = accessLevel;
  118. Session["Username"] = LoginAcctManager.UserName;
  119. Session["Password"] = LoginAcctManager.Password;
  120. Session["ConnString"] = connString;
  121. if (connString.IndexOf("Data Source=stxdev") >= 0)
  122. {
  123. Session["BackgroundColor"] = "Maroon";
  124. }
  125. else if (connString.IndexOf("Data Source=stxprd") >= 0)
  126. {
  127. Session["BackgroundColor"] = "Navy";
  128. }
  129. else
  130. {
  131. Session["BackgroundColor"] = "Green";
  132. }
  133. //DataTable timeTraxDrives = props.Tables["sanwebTimeTraxDrives"];
  134. DataTable timeTraxDrives = props.Tables["timeTraxDrive"];
  135. //DataTable ftpDrives = props.Tables["sanwebFtpDrives"];
  136. DataTable ftpDrives = props.Tables["ftpDrive"];
  137. SantraxVMUtil.writeLog("timeTraxDrives:" + timeTraxDrives.Rows.Count + "|" + timeTraxDrives.Columns.Count);
  138. SantraxVMUtil.writeLog("ftpDrives:" + ftpDrives.Rows.Count + "|" + ftpDrives.Columns.Count);
  139. foreach (DataRow row in timeTraxDrives.Rows)
  140. {
  141. for (int col = 0; col < timeTraxDrives.Columns.Count - 1; col++ )
  142. {
  143. SantraxVMUtil.writeLog("timeTraxDrives:" + row[col]);
  144. }
  145. }
  146. foreach (DataRow row in ftpDrives.Rows)
  147. {
  148. for (int col = 0; col < ftpDrives.Columns.Count - 1; col++)
  149. {
  150. SantraxVMUtil.writeLog("ftpDrives:" + row[col]);
  151. }
  152. }
  153. Session["sanwebTimeTraxDrives"] = timeTraxDrives;
  154. Session["sanwebFtpDrives"] = ftpDrives;
  155.  
  156. /***DataTable version = props.Tables["version_setting"];
  157. foreach (DataRow row in version.Rows)
  158. {
  159. for (int col = 0; col < version.Columns.Count - 1; col++)
  160. {
  161. Session["version"] = row[col];
  162. //SantraxVMUtil.writeLog("version:" + row[col]);
  163. }
  164. }*/
  165.  
  166. Response.Redirect("welcome.aspx");
  167. }
  168. else e.Authenticated = false;
  169. }
  170. }
  171. private DataSet loadProperties()
  172. {
  173. DataSet props = new DataSet();
  174. props.ReadXml(HttpRuntime.AppDomainAppPath + "App_Data/amProperties.xml");
  175. //props.WriteXml("\\\\orange\\childsrv\\vox\\amProperties.xml");
  176. //SantraxVMUtil.logFilePath = "\\\\orange\\childsrv\\vox\\";
  177. //SantraxVMUtil.writeLog("test write to orange");
  178. return props;
  179. }
  180. private Boolean isIPWithinBuilding(DataSet props)
  181. {
  182. DataTable sanwebSandataIPs = props.Tables["sanwebSandataIPs"];
  183. DataTable sanwebSandataOtherIPs = props.Tables["sanwebSandataOtherIPs"];
  184. string strHostName = Dns.GetHostName();
  185. //string strUserRemoteAdddr = Request.ServerVariables["REMOTE_ADDR"];
  186. //string strUserRemoteAdddr1 = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  187. string strUserHostName = Request.UserHostName;
  188. string strUserHostAddress = Request.UserHostAddress;
  189. SantraxVMUtil.writeLog("Checking if User Host Address is within building: " + strUserHostAddress);
  190. if (strUserHostAddress.Equals("127.0.0.1"))
  191. return true;
  192. //SantraxVMUtil.writeLog("===>strUserHostName =" + strUserHostName);
  193. //SantraxVMUtil.writeLog("===>strUserHostAddress =" + strUserHostAddress);
  194. //SantraxVMUtil.writeLog("===>strHostName =" + strHostName);
  195.  
  196. //*********IPHostEntry ipEntry = Dns.GetHostEntry(strUserHostName);
  197. IPHostEntry ipEntry = Dns.GetHostByName(strUserHostName);
  198. IPAddress[] addr = ipEntry.AddressList;
  199. string ip = addr[0].ToString();
  200. //SantraxVMUtil.writeLog("===>ip =" + ip);
  201. string sandataIPs = "";
  202. string sandataOtherIPs = "";
  203. string machineId = "";
  204. int index = 0;
  205. foreach (DataRow row in sanwebSandataIPs.Rows)
  206. {
  207. sandataIPs = (string)row[0];
  208. }
  209. foreach (DataRow row in sanwebSandataOtherIPs.Rows)
  210. {
  211. sandataOtherIPs = (string)row[0];
  212. }
  213. if (ip != null)
  214. {
  215. index = ip.LastIndexOf(".", ip.Length);
  216. machineId = ip.Substring(index + 1, ip.Length - index - 1);
  217. //SantraxVMUtil.writeLog("===>machineId =" + machineId);
  218. }
  219. else
  220. return false;
  221.  
  222. string[] stForIps = sandataIPs.Split(";".ToCharArray());
  223. for (int i = 0; i < stForIps.Length; i++)
  224. {
  225. string theIp = stForIps[i];
  226. string[] stForIp = theIp.Split(",".ToCharArray());
  227. string sandataIP = stForIp[0];
  228. string sandataStartIP = stForIp[1];
  229. string sandataEndIP = stForIp[2];
  230. SantraxVMUtil.writeLog("AccMgr ip =" + sandataIP + "," + sandataStartIP + "," + sandataEndIP);
  231. if (ip.StartsWith(sandataIP))
  232. {
  233. if (Int32.Parse(machineId) >= Int32.Parse(sandataStartIP) &&
  234. Int32.Parse(machineId) <= Int32.Parse(sandataEndIP))
  235. {
  236. return true;
  237. }
  238. }
  239. }
  240. if (sandataOtherIPs != null && sandataOtherIPs.Length > 0)
  241. {
  242. SantraxVMUtil.writeLog("AccMgr other ips =" + sandataOtherIPs);
  243. string[] st = sandataOtherIPs.Split(";".ToCharArray());
  244. for (int i = 0; i < st.Length; i++)
  245. {
  246. string sIp = st[i];
  247. SantraxVMUtil.writeLog("AccMgr login ip =" + ip + " tokenIp =" + sIp);
  248. if (ip.StartsWith(sIp))
  249. {
  250. SantraxVMUtil.writeLog("Host Address is in building.");
  251. return true;
  252. }
  253. }
  254. }
  255. SantraxVMUtil.writeLog("Host Address is not in building.");
  256. return false;
  257. }
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement