Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing;
- using System.Net;
- using System.Xml;
- public partial class login : System.Web.UI.Page
- {
- string connString;
- DataSet props;
- protected void Page_Load(object sender, EventArgs e)
- {
- SantraxVMUtil.writeLog("Entering AM:");
- if (Session["AccessLevel"] != null) FormsAuthentication.RedirectFromLoginPage("any web user", false);
- //System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/santraxSite/AccountManager");
- //System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/AccountManager/AccountManager.root/AccountManager/santraxSite/AccountManager");
- System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
- System.Configuration.ConnectionStringSettings connStringObj = rootWebConfig.ConnectionStrings.ConnectionStrings["accountManager"];
- connString = connStringObj.ConnectionString;
- /*if (connString.IndexOf("Data Source=stxprd") >= 0)
- {
- Session["BackgroundColor"] = "Navy";
- }
- else
- {
- Session["BackgroundColor"] = "Navy";//"Maroon";
- }*/
- LoginAcctManager.Focus();
- string autoLoginScript =
- "<script language=\"javascript\" type=\"text/javascript\">" +
- "autoLogin()" +
- "</script>";
- string autoLoginFunctionScript =
- "<script language=\"javascript\" type=\"text/javascript\">" +
- "function autoLogin() {" +
- "var username = getURLParam('UserName');" +
- "var password = getURLParam('Password');" +
- "if(username != null && username.length > 0) {" +
- " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$UserName.value = username;" +
- " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$Password.value = password;" +
- " form1.ctl00$ContentPlaceHolderAC$LoginAcctManager$LoginButton.click();" +
- "}" +
- "}" +
- "function getURLParam(strParamName){" +
- " var strReturn = \"\";" +
- " var strHref = window.location.href;" +
- " if ( strHref.indexOf(\"?\") > -1 ){" +
- " var strQueryString = strHref.substr(strHref.indexOf(\"?\"));" +
- " var aQueryString = strQueryString.split(\"&\");" +
- " for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){" +
- " if (aQueryString[iParam].indexOf(strParamName + \"=\") > -1 ){" +
- " var aParam = aQueryString[iParam].split(\"=\");" +
- " strReturn = aParam[1];" +
- " break;" +
- " }" +
- " }" +
- " }" +
- " return strReturn;" +
- "}" +
- "</script>";
- ClientScript.RegisterClientScriptBlock(typeof(Page), "autoLoginFunction", autoLoginFunctionScript);
- ClientScript.RegisterStartupScript(typeof(Page), "autoLogin", autoLoginScript);
- props = loadProperties();
- DataTable version = props.Tables["version_setting"];
- foreach (DataRow row in version.Rows)
- {
- for (int col = 0; col < version.Columns.Count - 1; col++)
- {
- Session["version"] = row[col];
- //SantraxVMUtil.writeLog("version:" + row[col]);
- }
- }
- DataTable phone_setting = props.Tables["phone_setting"];
- foreach (DataRow row in phone_setting.Rows)
- {
- for (int col = 0; col < phone_setting.Columns.Count - 1; col++)
- {
- Session["phone_script"] = row[col];
- //SantraxVMUtil.writeLog("phone_setting:" + row[col]);
- }
- }
- }
- protected void LoginAcctManager_Authenticate(object sender, AuthenticateEventArgs e)
- {
- Session.Clear();
- //***DataSet props = loadProperties();
- if (false)//!isIPWithinBuilding(props)
- {
- e.Authenticated = false;
- }
- else
- {
- SqlDataSourceAccessLevel.SelectCommand = "SELECT access_level FROM access_level WHERE UPPER(username)=UPPER('" + LoginAcctManager.UserName + "') and UPPER(password) = UPPER('" + LoginAcctManager.Password + "')";
- DropDownListAccessLevel.DataBind();
- string accessLevel = null;
- if (DropDownListAccessLevel.Items.Count > 0)
- {
- accessLevel = DropDownListAccessLevel.SelectedValue;
- }
- if (accessLevel != null && (accessLevel.Equals("0") || accessLevel.Equals("1") || accessLevel.Equals("2")))
- {
- e.Authenticated = true;
- if (accessLevel.Equals("0")) accessLevel = "Read Only";
- else if (accessLevel.Equals("1")) accessLevel = "Partial Update";
- else if (accessLevel.Equals("2")) accessLevel = "Full Rights";
- Session["AccessLevel"] = accessLevel;
- Session["Username"] = LoginAcctManager.UserName;
- Session["Password"] = LoginAcctManager.Password;
- Session["ConnString"] = connString;
- if (connString.IndexOf("Data Source=stxdev") >= 0)
- {
- Session["BackgroundColor"] = "Maroon";
- }
- else if (connString.IndexOf("Data Source=stxprd") >= 0)
- {
- Session["BackgroundColor"] = "Navy";
- }
- else
- {
- Session["BackgroundColor"] = "Green";
- }
- //DataTable timeTraxDrives = props.Tables["sanwebTimeTraxDrives"];
- DataTable timeTraxDrives = props.Tables["timeTraxDrive"];
- //DataTable ftpDrives = props.Tables["sanwebFtpDrives"];
- DataTable ftpDrives = props.Tables["ftpDrive"];
- SantraxVMUtil.writeLog("timeTraxDrives:" + timeTraxDrives.Rows.Count + "|" + timeTraxDrives.Columns.Count);
- SantraxVMUtil.writeLog("ftpDrives:" + ftpDrives.Rows.Count + "|" + ftpDrives.Columns.Count);
- foreach (DataRow row in timeTraxDrives.Rows)
- {
- for (int col = 0; col < timeTraxDrives.Columns.Count - 1; col++ )
- {
- SantraxVMUtil.writeLog("timeTraxDrives:" + row[col]);
- }
- }
- foreach (DataRow row in ftpDrives.Rows)
- {
- for (int col = 0; col < ftpDrives.Columns.Count - 1; col++)
- {
- SantraxVMUtil.writeLog("ftpDrives:" + row[col]);
- }
- }
- Session["sanwebTimeTraxDrives"] = timeTraxDrives;
- Session["sanwebFtpDrives"] = ftpDrives;
- /***DataTable version = props.Tables["version_setting"];
- foreach (DataRow row in version.Rows)
- {
- for (int col = 0; col < version.Columns.Count - 1; col++)
- {
- Session["version"] = row[col];
- //SantraxVMUtil.writeLog("version:" + row[col]);
- }
- }*/
- Response.Redirect("welcome.aspx");
- }
- else e.Authenticated = false;
- }
- }
- private DataSet loadProperties()
- {
- DataSet props = new DataSet();
- props.ReadXml(HttpRuntime.AppDomainAppPath + "App_Data/amProperties.xml");
- //props.WriteXml("\\\\orange\\childsrv\\vox\\amProperties.xml");
- //SantraxVMUtil.logFilePath = "\\\\orange\\childsrv\\vox\\";
- //SantraxVMUtil.writeLog("test write to orange");
- return props;
- }
- private Boolean isIPWithinBuilding(DataSet props)
- {
- DataTable sanwebSandataIPs = props.Tables["sanwebSandataIPs"];
- DataTable sanwebSandataOtherIPs = props.Tables["sanwebSandataOtherIPs"];
- string strHostName = Dns.GetHostName();
- //string strUserRemoteAdddr = Request.ServerVariables["REMOTE_ADDR"];
- //string strUserRemoteAdddr1 = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- string strUserHostName = Request.UserHostName;
- string strUserHostAddress = Request.UserHostAddress;
- SantraxVMUtil.writeLog("Checking if User Host Address is within building: " + strUserHostAddress);
- if (strUserHostAddress.Equals("127.0.0.1"))
- return true;
- //SantraxVMUtil.writeLog("===>strUserHostName =" + strUserHostName);
- //SantraxVMUtil.writeLog("===>strUserHostAddress =" + strUserHostAddress);
- //SantraxVMUtil.writeLog("===>strHostName =" + strHostName);
- //*********IPHostEntry ipEntry = Dns.GetHostEntry(strUserHostName);
- IPHostEntry ipEntry = Dns.GetHostByName(strUserHostName);
- IPAddress[] addr = ipEntry.AddressList;
- string ip = addr[0].ToString();
- //SantraxVMUtil.writeLog("===>ip =" + ip);
- string sandataIPs = "";
- string sandataOtherIPs = "";
- string machineId = "";
- int index = 0;
- foreach (DataRow row in sanwebSandataIPs.Rows)
- {
- sandataIPs = (string)row[0];
- }
- foreach (DataRow row in sanwebSandataOtherIPs.Rows)
- {
- sandataOtherIPs = (string)row[0];
- }
- if (ip != null)
- {
- index = ip.LastIndexOf(".", ip.Length);
- machineId = ip.Substring(index + 1, ip.Length - index - 1);
- //SantraxVMUtil.writeLog("===>machineId =" + machineId);
- }
- else
- return false;
- string[] stForIps = sandataIPs.Split(";".ToCharArray());
- for (int i = 0; i < stForIps.Length; i++)
- {
- string theIp = stForIps[i];
- string[] stForIp = theIp.Split(",".ToCharArray());
- string sandataIP = stForIp[0];
- string sandataStartIP = stForIp[1];
- string sandataEndIP = stForIp[2];
- SantraxVMUtil.writeLog("AccMgr ip =" + sandataIP + "," + sandataStartIP + "," + sandataEndIP);
- if (ip.StartsWith(sandataIP))
- {
- if (Int32.Parse(machineId) >= Int32.Parse(sandataStartIP) &&
- Int32.Parse(machineId) <= Int32.Parse(sandataEndIP))
- {
- return true;
- }
- }
- }
- if (sandataOtherIPs != null && sandataOtherIPs.Length > 0)
- {
- SantraxVMUtil.writeLog("AccMgr other ips =" + sandataOtherIPs);
- string[] st = sandataOtherIPs.Split(";".ToCharArray());
- for (int i = 0; i < st.Length; i++)
- {
- string sIp = st[i];
- SantraxVMUtil.writeLog("AccMgr login ip =" + ip + " tokenIp =" + sIp);
- if (ip.StartsWith(sIp))
- {
- SantraxVMUtil.writeLog("Host Address is in building.");
- return true;
- }
- }
- }
- SantraxVMUtil.writeLog("Host Address is not in building.");
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement