Exemple #1
0
    protected void GV_LHO_Details_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName.ToLower().Trim())
        {
        case "shutdown_command":
        {
            ReqCommandExecute objReq = new ReqCommandExecute();
            ResCommandExecute objRes = new ResCommandExecute();

            int row;
            row = Convert.ToInt32(e.CommandArgument.ToString());
            string kiosk_ip = GV_LHO_Details.Rows[row].Cells[1].Text;

            using (WebClient client = new WebClient())
            {
                objReq.KioskIPs    = new string[(1)];
                objReq.Command     = "system#shutdown";
                objReq.KioskIPs[0] = kiosk_ip;
                objReq.Patchdata   = "";
                objReq.DisplayData = "Shutdown PC";


                client.Headers[HttpRequestHeader.ContentType] = "text/json";
                ServicePointManager.SecurityProtocol          = SecurityProtocolType.Tls12;

                string     JsonString    = JsonConvert.SerializeObject(objReq);
                EncRequest objEncRequest = new EncRequest();
                objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                string result = client.UploadString(URL + "/CommandExecute", "POST", dataEncrypted);

                EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result);
                objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);

                //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData);
                //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply));
                //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData));
                //objRes = (ResCommandExecute)objDCS.ReadObject(objMS);


                Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
                json.NullValueHandling = NullValueHandling.Ignore;
                StringReader sr = new StringReader(objResponse.ResponseData);
                Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                objRes = json.Deserialize <ResCommandExecute>(reader);

                if (objRes.Result == true)
                {
                    Response.Write("<script type='text/javascript'>alert('Command Send Successfully')</script>");
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('catch error : " + objRes.Error + "  ')</script>");
                }
            }
        }
        break;

        case "restart_command":
        {
            ReqCommandExecute objReq = new ReqCommandExecute();
            ResCommandExecute objRes = new ResCommandExecute();
            int row;
            row = Convert.ToInt32(e.CommandArgument.ToString());
            string kiosk_ip = GV_LHO_Details.Rows[row].Cells[1].Text;
            using (WebClient client = new WebClient())
            {
                objReq.KioskIPs    = new string[(1)];
                objReq.Command     = "system#restart";
                objReq.KioskIPs[0] = kiosk_ip;
                objReq.Patchdata   = "";
                objReq.DisplayData = "Restart PC";


                client.Headers[HttpRequestHeader.ContentType] = "text/json";
                ServicePointManager.SecurityProtocol          = SecurityProtocolType.Tls12;

                string     JsonString    = JsonConvert.SerializeObject(objReq);
                EncRequest objEncRequest = new EncRequest();
                objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                string result = client.UploadString(URL + "/CommandExecute", "POST", dataEncrypted);

                EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result);
                objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);
                //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData);
                //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply));
                //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData));
                //objRes = (ResCommandExecute)objDCS.ReadObject(objMS);


                Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
                json.NullValueHandling = NullValueHandling.Ignore;
                StringReader sr = new StringReader(objResponse.ResponseData);
                Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                objRes = json.Deserialize <ResCommandExecute>(reader);

                if (objRes.Result == true)
                {
                    Response.Write("<script type='text/javascript'>alert('Command Send Successfully')</script>");
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('catch error : " + objRes.Error + ")</script>");
                }
            }
        }
        break;

        default:
            break;
        }
    }
Exemple #2
0
    protected void downloadCommand_Click(object sender, EventArgs e)
    {
        try
        {
            if ((MachineLogs.Checked || EJLogs.Checked) && (startDT.Text == "" || endDT.Text == ""))
            {
                srch.Value   = "";
                startDT.Text = ""; endDT.Text = "";
                bindKioskHealth(filtercategories1.SelectedItem.Text);
                var page = HttpContext.Current.CurrentHandler as Page;
                ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Fill Start Date and End Date');", true);
                return;
            }
            else if (OtherData.Checked && (orderid.Text == "" || filtercategories.SelectedIndex == 0))
            {
                srch.Value   = "";
                startDT.Text = ""; endDT.Text = "";
                bindKioskHealth(filtercategories1.SelectedItem.Text);
                DownloadData.Style["display"] = "block";
                SelectDate.Style["display"]   = "none";
                OtherData.Checked             = true;
                var page = HttpContext.Current.CurrentHandler as Page;
                ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Select Type and Give Valid Path');", true);
                return;
            }
            else
            {
                ReqCommandExecute reqCommandExecute = new ReqCommandExecute();
                string            CommandString     = "";
                if (MachineLogs.Checked || EJLogs.Checked)
                {
                    if (MachineLogs.Checked)
                    {
                        CommandString = "MachineLogs";
                    }
                    else
                    {
                        CommandString = "EjLogs";
                    }

                    DateTime startDate, endDate;

                    if (!DateTime.TryParseExact(startDT.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out startDate) || !DateTime.TryParseExact(endDT.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out endDate))
                    {
                        srch.Value   = "";
                        startDT.Text = ""; endDT.Text = "";
                        bindKioskHealth(filtercategories1.SelectedItem.Text);
                        var page = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Date Format Not Proper');", true);
                        return;
                    }
                    else if (startDate > endDate || endDate > DateTime.Today)
                    {
                        srch.Value = "";
                        bindKioskHealth(filtercategories1.SelectedItem.Text);
                        startDT.Text = ""; endDT.Text = "";
                        var page = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Start Date can not be greater than End Date and End Date should be less than equal to today');", true);
                        return;
                    }

                    if ((endDate.Date - startDate.Date).TotalDays > 7)
                    {
                        srch.Value = "";
                        bindKioskHealth(filtercategories1.SelectedItem.Text);
                        var page = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Date difference should be less than or equal to 7 days.');", true);
                        return;
                    }

                    CommandString += "#" + startDate.ToString("yyyy-MM-dd") + "#" + endDate.ToString("yyyy-MM-dd");
                    reqCommandExecute.DisplayData = "Log Pull";
                }
                else
                {
                    CommandString = "OtherData#" + filtercategories.SelectedItem.Text + "#" + orderid.Text;
                    DownloadData.Style["display"] = "block";
                    SelectDate.Style["display"]   = "none";
                    OtherData.Checked             = true;
                    reqCommandExecute.DisplayData = filtercategories.SelectedItem.Text + " Pull";
                }

                string[] ipArray = hiddenItem.Value.Split('#');
                Array.Resize(ref ipArray, ipArray.Length - 1);
                reqCommandExecute.KioskIPs  = ipArray;
                reqCommandExecute.Command   = CommandString;
                reqCommandExecute.Patchdata = "";
                using (WebClient client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "text/json";
                    ServicePointManager.SecurityProtocol          = SecurityProtocolType.Tls12;
                    string     JsonString    = JsonConvert.SerializeObject(reqCommandExecute);
                    EncRequest objEncRequest = new EncRequest();
                    objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                    string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                    string result1 = client.UploadString(URL + "/CommandExecute", "POST", dataEncrypted);

                    EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result1);
                    objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);

                    //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData);
                    //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply));
                    //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData));
                    //ResCommandExecute objRes = (ResCommandExecute)objDCS.ReadObject(objMS);


                    Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
                    json.NullValueHandling = NullValueHandling.Ignore;
                    StringReader sr = new StringReader(objResponse.ResponseData);
                    Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                    ResCommandExecute objRes = json.Deserialize <ResCommandExecute>(reader);

                    if (objRes.Result)
                    {
                        srch.Value   = "";
                        startDT.Text = ""; endDT.Text = "";
                        var page = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Request Send SuccessFully');", true);
                        bindKioskHealth(filtercategories1.SelectedItem.Text);
                    }
                    else
                    {
                        srch.Value   = "";
                        startDT.Text = ""; endDT.Text = "";
                        var page = HttpContext.Current.CurrentHandler as Page;
                        ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Request Sending Failed');", true);
                        bindKioskHealth(filtercategories1.SelectedItem.Text);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            srch.Value   = "";
            startDT.Text = ""; endDT.Text = "";
            var page = HttpContext.Current.CurrentHandler as Page;
            ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Exception :" + ex.Message + "');", true);
            bindKioskHealth(filtercategories1.SelectedItem.Text);
        }
    }
    protected void UploadBtn_Click(object sender, EventArgs e)
    {
        if (!file5.HasFile)
        {
            SearchText.Value = "";
            bindKioskHealth(filtercategories1.SelectedItem.Text);
            uploader5.Text = "";
            var page = HttpContext.Current.CurrentHandler as Page;
            ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Please Upload file');", true);
            return;
        }
        else
        {
            uploader5.Text = "";
            string ipList = hiddenItem.Value;
            hiddenItem.Value = "";
            string[] ipArray = ipList.Split('#');
            if (ipArray.Length == 0)
            {
                SearchText.Value = "";
                bindKioskHealth(filtercategories1.SelectedItem.Text);
                var page = HttpContext.Current.CurrentHandler as Page;
                ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Select Atleast One Kiosk');", true);
                return;
            }

            if (".zip".Contains(Path.GetExtension(file5.FileName).ToLower()))
            {
                if (File.Exists(Server.MapPath(file5.FileName)))
                {
                    File.Delete(Server.MapPath(file5.FileName));
                }

                File.WriteAllBytes(Server.MapPath(file5.FileName), file5.FileBytes);

                if (ZipFile.IsZipFile(Server.MapPath(file5.FileName)))
                {
                    //To Check Password Exits or not  //Lokesh Added[20 Jan 2013]
                    //using (ZipFile zp_patch1 = ZipFile.Read(Server.MapPath(file5.FileName)))
                    //{
                    //    foreach (var e1 in zp_patch1)
                    //    {
                    //        if (e1.IsDirectory == false && e1.UsesEncryption == false)
                    //        {
                    //            var page = HttpContext.Current.CurrentHandler as Page;
                    //            ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Invalid patch file');", true);
                    //            return;
                    //        }
                    //    }
                    //}
                    //End

                    //check if zip password is the default(admin) password
                    //if (ZipFile.CheckZipPassword(Server.MapPath(file5.FileName), "lipi@data@systems@df"))
                    //{
                    Array.Resize(ref ipArray, ipArray.Length - 1);
                    ReqCommandExecute reqCommandExecute = new ReqCommandExecute();
                    reqCommandExecute.KioskIPs    = ipArray;
                    reqCommandExecute.Command     = "patchupdate#" + file5.FileName;
                    reqCommandExecute.DisplayData = "Patch : " + file5.FileName;
                    byte[] data = file5.FileBytes;

                    reqCommandExecute.Patchdata = Convert.ToBase64String(data);
                    using (WebClient client = new WebClient())
                    {
                        string JsonString = JsonConvert.SerializeObject(reqCommandExecute);

                        EncRequest objEncRequest = new EncRequest();
                        objEncRequest.RequestData = AesGcm256.Encrypt(JsonString);
                        string dataEncrypted = JsonConvert.SerializeObject(objEncRequest);

                        client.Headers[HttpRequestHeader.ContentType] = "text/json";
                        ServicePointManager.SecurityProtocol          = SecurityProtocolType.Tls12;
                        string result1 = client.UploadString(URL + "/CommandExecute", "POST", dataEncrypted);

                        EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result1);
                        objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData);

                        //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData);
                        //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply));
                        //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData));
                        //ResCommandExecute objRes = (ResCommandExecute)objDCS.ReadObject(objMS);

                        Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
                        json.NullValueHandling = NullValueHandling.Ignore;
                        StringReader sr = new StringReader(objResponse.ResponseData);
                        Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
                        ResCommandExecute objRes = json.Deserialize <ResCommandExecute>(reader);

                        if (objRes.Result)
                        {
                            SearchText.Value = "";
                            var page = HttpContext.Current.CurrentHandler as Page;
                            ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Patch Updation Requested SuccessFully');", true);
                            bindKioskHealth(filtercategories1.SelectedItem.Text);
                        }
                        else
                        {
                            SearchText.Value = "";
                            var page = HttpContext.Current.CurrentHandler as Page;
                            ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Patch Updation Request Failed');", true);
                            bindKioskHealth(filtercategories1.SelectedItem.Text);
                        }
                    }
                    //}
                    //else
                    //{
                    //    var page = HttpContext.Current.CurrentHandler as Page;
                    //    ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Invalid patch file');", true);
                    //    return;
                    //}
                }
                else
                {
                    var page = HttpContext.Current.CurrentHandler as Page;
                    ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Invalid patch file');", true);
                    return;
                }
            }
            else
            {
                SearchText.Value = "";
                bindKioskHealth(filtercategories1.SelectedItem.Text);
                var page = HttpContext.Current.CurrentHandler as Page;
                ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "errorDisplay('Upload Valid Patch File');", true);
                return;
            }
        }
    }