Example #1
0
    public static void ApplicationLogout(HttpSessionState Session, HttpResponse Response = null)
    {
        Connector.IDatabaseConnector dbConnector     = new Connector.DatabaseConnectorClass();
        Connector.QueryParameter     logoutParameter = new Connector.QueryParameter();
        Connector.QueryResult        logoutResult    = new Connector.QueryResult();

        if (Session != null && Session["DVS_USER_ID"] != null)
        {
            if (Session["AUTHEN_TOKEN"] != null)
            {
                AMSDuplicateAuthenCore.ClearToken(Session["DVS_USER_ID"].ToString(), Session["AUTHEN_TOKEN"].ToString());
            }

            logoutParameter.Add("USER_ID", Session["DVS_USER_ID"]);
            logoutResult         = dbConnector.ExecuteStoredProcedure("SYS_I_LOGOUT", logoutParameter);
            logoutResult.Success = true;
            logoutResult.Message = string.Empty;
            logoutResult.RemoveOutputParam("error");
            Session.Abandon();
        }

        if (Response != null)
        {
            HttpCookie authenTokenCookie = new HttpCookie("AUTHEN_TOKEN");
            authenTokenCookie.Value = "";
            Response.Cookies.Add(authenTokenCookie);

            Response.ClearContent();
            Response.ContentType = "application/json";
            Response.Write(logoutResult.ToJson());
        }
    }
Example #2
0
    private void Login()
    {
        Session["DVS_LOGIN"] = "******";



        Connector.QueryResult qResult = new Connector.QueryResult();
        Response.ContentType = "application/json";
        Response.Write(qResult.ToJson());
        Response.End();

        //ReadXmlFile();
    }
Example #3
0
    private void deleteLog(string type, string retrospectDay)
    {
        Connector.QueryResult qResult = new Connector.QueryResult();
        try
        {
            DateTime endDate = DateTime.Now;
            int      minus   = 0;
            if (type == "number")
            {
                minus = Int32.Parse(retrospectDay) * (-1);
            }
            DateTime startDate = endDate.AddDays(minus);
            System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo("D:\\ProjectCode\\NHA\\NHAE145027\\Log3");

            foreach (DirectoryInfo direct in downloadedMessageInfo.GetDirectories())
            {
                foreach (FileInfo file in direct.GetFiles())
                {
                    if (type != "all")
                    {
                        if (startDate.Date <= file.CreationTime.Date && endDate.Date >= file.CreationTime.Date)
                        {
                            file.Delete();
                        }
                    }
                    else
                    {
                        file.Delete();
                    }
                }
                if (direct.GetFiles().Length <= 0)
                {
                    direct.Delete();
                }
            }
            qResult.Success = true;
        }
        catch (Exception ex)
        {
            qResult.Success = false;
            qResult.Message = ex.Message;
        }

        Response.ContentType = "application/json";
        Response.Write(qResult.ToJson());
        Response.End();
    }
Example #4
0
    public void ReadXmlFileLogin()
    {
        Setting overview = new Setting();
        string  data;

        Connector.QueryResult       qResult = new Connector.QueryResult();
        Dictionary <string, string> dataDic = new Dictionary <string, string>();


        try
        {
            System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Setting));
            //System.IO.StreamReader file = new System.IO.StreamReader("D:\\ProjectCode\\NHA\\NHAE145027\\xml\\configLog.xml");
            System.IO.StreamReader file = new System.IO.StreamReader(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml"));
            overview = (Setting)reader.Deserialize(file);
            file.Close();
            file.Dispose();

            dataDic.Add("keeplog", overview.keeplog);
            dataDic.Add("strLogpath", string.Join("|", overview.logpath));
        }
        catch (Exception ex)
        {
            //System.IO.Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName



            string startupPath = System.IO.Path.GetFullPath(".\\");

            dataDic.Add("keeplog", "90");
            string defaultLogPath = System.IO.Path.Combine(System.IO.Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, "logs");
            dataDic.Add("strLogpath", string.Join("|", defaultLogPath));

            qResult.Success = true;
            qResult.Message = "{}";
        }


        qResult.AddOutputParam("data", dataDic);


        Response.ContentType = "application/json";
        Response.Write(qResult.ToJson());
        Response.End();
    }
Example #5
0
    public void WriteXmlFile(string keepLog, string logPath)
    {
        Connector.QueryResult qResult = new Connector.QueryResult();

        System.Xml.Serialization.XmlSerializer writer;
        System.IO.FileStream file;
        Setting       overview    = new Setting();
        List <string> listlogPath = new List <string>();
        List <string> arr         = new List <string>();

        try
        {
            for (int i = 0; i <= logPath.Split(',').Length - 1; i++)
            {
                if (logPath.Split(',')[i] != "")
                {
                    arr.Add(logPath.Split(',')[i]);
                }
            }


            overview.keeplog = keepLog;
            overview.logpath = arr.ToArray();


            writer = new System.Xml.Serialization.XmlSerializer(typeof(Setting));

            file = new System.IO.FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml"), FileMode.Truncate, FileAccess.Write);

            writer.Serialize(file, overview);
            file.Close();
            file.Dispose();

            Dictionary <string, string> dic = new Dictionary <string, string>();


            dic.Add("keeplog", keepLog);
            dic.Add("strLogpath", string.Join("|", arr));

            qResult.AddOutputParam("data", dic);
        }
        catch (Exception ex)
        {
            writer = new System.Xml.Serialization.XmlSerializer(typeof(Setting));
            file   = new System.IO.FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configLog.xml"), FileMode.CreateNew, FileAccess.Write);

            writer.Serialize(file, overview);
            file.Close();
            file.Dispose();

            Dictionary <string, string> dic = new Dictionary <string, string>();


            dic.Add("keeplog", keepLog);
            dic.Add("strLogpath", string.Join("|", arr));

            qResult.AddOutputParam("data", dic);


            qResult.Success = false;
            qResult.Message = ex.Message;
        }

        Response.ContentType = "application/json";
        Response.Write(qResult.ToJson());
        Response.End();
    }
Example #6
0
    private void searchFile(string[] logFilter, string age, string strDateAge, string startTime, string endTime, string source, string machine, string search)
    {
        Connector.QueryResult       connect = new Connector.QueryResult();
        Dictionary <string, object> objList = new Dictionary <string, object>();

        try
        {
            string[] filterType = new string[4] {
                "ERROR", "WARN", "INFO", "DEBUG"
            };

            System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(System.IO.Path.Combine(machine));

            // System.IO.Path.Combine(machine);

            // System.IO.StreamReader file = new System.IO.StreamReader();

            DateTime dateAge      = new DateTime();
            DateTime startDateObj = startDate(age, strDateAge);
            DateTime endDateObj   = endDate(age, strDateAge);



            int    startT = int.Parse(startTime);
            int    endT   = int.Parse(endTime);
            string strHr  = "";
            int    hr     = 0;

            foreach (DirectoryInfo direct in downloadedMessageInfo.GetDirectories())
            {
                Dictionary <string, List <string> > resultDic = new Dictionary <string, List <string> >();
                if ((startDateObj.Month <= direct.CreationTime.Month && startDateObj.Year <= direct.CreationTime.Year) &&
                    (endDateObj.Month >= direct.CreationTime.Month && endDateObj.Year >= direct.CreationTime.Year))
                {
                    foreach (FileInfo file in direct.GetFiles())
                    {
                        List <string> resultList = new List <string>();

                        try
                        {
                            if (startDateObj.Date <= file.CreationTime.Date && endDateObj.Date >= file.CreationTime.Date)
                            {
                                if ((file.Name.ToUpper().IndexOf(source.ToUpper()) >= 0) || source == "all")
                                {
                                    //   System.IO.StreamReader StrRead = new System.IO.StreamReader(file.FullName, Encoding.Default);


                                    using (FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                    {
                                        using (StreamReader StrRead = new StreamReader(fileStream, Encoding.Default))
                                        {
                                            string txtRead = "";
                                            int    i       = 0;

                                            //  string json = StrRead.ReadToEnd();

                                            while (!(StrRead.EndOfStream))
                                            {
                                                string txt = StrRead.ReadLine().ToString();

                                                if (Array.IndexOf(filterType, txt.Split(' ')[0].Trim()) < 0 || i == 0)
                                                {
                                                    txtRead += txt + "<br/>";
                                                }
                                                else
                                                {
                                                    if (Array.IndexOf(logFilter, txtRead.Split(' ')[0].Trim()) >= 0)
                                                    {
                                                        strHr = txtRead.Split(':')[0].Trim();
                                                        hr    = int.Parse(strHr.Substring(strHr.Length - 2, 2));
                                                        if (hr >= startT && hr <= endT)
                                                        {
                                                            resultList.Add(txtRead);
                                                        }
                                                    }

                                                    txtRead = txt + "<br/>";;
                                                }

                                                i++;
                                            }

                                            StrRead.Close();
                                            StrRead.Dispose();

                                            if (Array.IndexOf(logFilter, txtRead.Split(' ')[0].Trim()) >= 0)
                                            {
                                                strHr = txtRead.Split(':')[0].Trim();
                                                hr    = int.Parse(strHr.Substring(strHr.Length - 2, 2));
                                                if (hr >= startT && hr <= endT)
                                                {
                                                    resultList.Add(txtRead);
                                                }
                                            }


                                            if (resultList.Count > 0)
                                            {
                                                resultDic.Add(file.Name, resultList);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }

                objList.Add(direct.Name.ToString(), resultDic);
            }

            connect.AddOutputParam("data", objList);
            connect.AddOutputParam("search", search);
        }
        catch (Exception ex)
        {
            connect.Message = ex.Message;
            connect.Success = false;
        }



        Response.ContentType = "application/json";
        Response.Write(connect.ToJson());
        Response.End();
    }
Example #7
0
    protected void ApplicationLogin(string storeName)
    {
        Connector.QueryParameter loginParameter = new Connector.QueryParameter(Request);
        Connector.QueryResult    loginResult    = null;
        try
        {
            if (loginParameter.Parameter != null && loginParameter.Parameter.ContainsKey("USERNAME") && loginParameter.Parameter.ContainsKey("PASSWORD"))
            {
                if (loginParameter["USERNAME"].Equals(Encoding.UTF8.GetString(Convert.FromBase64String(hdUSername))) &&
                    loginParameter["PASSWORD"].Equals(Encoding.UTF8.GetString(Convert.FromBase64String(hdPassword))))
                {
                    //for hidden user
                    loginResult           = new Connector.QueryResult();
                    loginResult.Success   = true;
                    loginResult.Message   = "";
                    loginResult.DataTable = new DataTable();
                    loginResult.DataTable.Columns.Add("USER_ID", typeof(string));
                    loginResult.DataTable.Rows.Add(new object[] { "999999999" });
                }
                else
                {
                    if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "1")
                    {
                        loginResult = AuthenByDB(storeName, loginParameter);
                    }
                    else if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "2")
                    {
                        loginResult = AuthenByAD(loginParameter);
                    }
                    else if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "3")
                    {
                        loginResult = AuthenByAD(loginParameter);
                        if (loginResult == null || !loginResult.Success)
                        {
                            loginResult = AuthenByDB(storeName, loginParameter);
                        }
                    }
                }
            }
            else
            {
                throw new Exception("ERROR_REQUIRED_USER");
                //ERROR_INVALID_LOGIN: "******",
                //ERROR_INVALID_USER: "******",
                //ERROR_INVALID_PASSWORD: "******",
                //ERROR_NO_PERMISSION: "ชื่อผู้ใช้งานนี้ไม่มีสิทธิ์การใช้งาน"
                //loginResult.Message = "ERROR_INVALID_LOGIN";
            }
        }
        catch (Exception ex)
        {
            loginResult = new Connector.QueryResult(ex);
        }

        if (loginResult.Success)
        {
            string userID = Session["DVS_USER_ID"].ToString();
            string token  = AMSDuplicateAuthenCore.GenerateToken();

            Session["AUTHEN_TOKEN"] = token;

            if (AMSCore.WebConfigReadKey("ENABLE_DUPLICATE_AUTHEN_CHECKING") == "true")
            {
                AMSDuplicateAuthenCore.StoreToken(userID, token);
            }

            HttpCookie authenTokenCookie = new HttpCookie("AUTHEN_TOKEN");
            authenTokenCookie.Value = token;
            Response.Cookies.Add(authenTokenCookie);
        }

        Response.ContentType = "application/json";
        Response.Write(loginResult.ToJson());
    }
Example #8
0
    protected bool PageSelector(string request, out string wgNamespace, out Dictionary <string, object> wgParameters)
    {
        wgNamespace  = string.Empty;
        wgParameters = new Dictionary <string, object>();

        switch (request)
        {
        case "portal":
            wgNamespace = "viewer/Portal/Portal";
            if (Session != null && Session["DVS_USER_ID"] != null)
            {
                if (!checkAuthentication())
                {
                    return(false);
                }

                if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "1")
                {
                    wgParameters = new Dictionary <string, object>()
                    {
                        { "permission", GetSystemPermission(Session["DVS_USER_ID"].ToString()).ToDictionary() }
                    };
                }
                else if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "2")
                {
                    wgParameters = new Dictionary <string, object>()
                    {
                        { "permission", AuthenByAD(Session["DVS_USER_ID"].ToString()).ToDictionary() }
                    };
                }
                else if (AMSCore.WebConfigReadKey("AUTHENTICATION_TYPE") == "3")
                {
                }
            }
            else if (AMSCore.WebConfigReadKey("GUEST_ENABLED") != null && AMSCore.WebConfigReadKey("GUEST_ENABLED").Equals("1"))
            {
                Session["DVS_IS_GUEST"] = true;
                Session["DVS_USER_ID"]  = AMSCore.WebConfigReadKey("GUEST_USER_ID");
                wgParameters            = new Dictionary <string, object>()
                {
                    { "permission", GetSystemPermission(Session["DVS_USER_ID"].ToString()).ToDictionary() }
                };
            }
            break;

        case "logout":
        {
            ApplicationLogout(Session, Response);
            if (Request.HttpMethod != "POST")
            {
                Response.Redirect("~/", true);
            }
            return(false);
        }

        case "system":
            if (Request.HttpMethod == "POST")
            {
                Response.ClearContent();

                Connector.QueryParameter reqParameter = new Connector.QueryParameter(Request);
                if (reqParameter["SYS_ID"].Equals("-1"))
                {
                    Session.Remove("DVS_SYSTEM_ID");
                }
                else
                {
                    Session["DVS_SYSTEM_ID"] = reqParameter["SYS_ID"];
                }
                Response.ContentType = "application/json";
                Response.Write(new Connector.QueryResult().ToJson());

                return(false);
            }
            else if (!checkAuthentication())
            {
                return(false);
            }

            break;

        case "forgetPassword":
        {
            wgNamespace  = "viewer/ForgetPassword/ForgetPassword";
            wgParameters = new Dictionary <string, object>()
            {
                { "token", Request.Params["token"] },
                { "userid", Request.Params["userid"] },
                { "forgetByEmail", true }
            };
            break;
        }

        case "APP_Q_LOGIN":
        {
            Response.ClearContent();

            ApplicationLogin("APP_Q_LOGIN");
            return(false);
        }

        case "UM_Q_VERIFY_USER":
        case "UM_U_PWD":
        case "UM_U_RESET_PWD":
        case "UM_Q_MAIL_TOKEN":
        {
            Response.ClearContent();

            string storeName = request;

            Connector.IDatabaseConnector dbConnector  = new Connector.DatabaseConnectorClass();
            Connector.QueryParameter     reqParameter = new Connector.QueryParameter(Request);

            Connector.QueryResult logoutResult = dbConnector.ExecuteStoredProcedure(storeName, reqParameter);

            Response.ContentType = "application/json";
            Response.Write(logoutResult.ToJson());
            return(false);
        }

        default:
            break;
        }

        return(true);
    }