Exemplo n.º 1
0
        public void DeleteServiceTest()
        {
            var id = (Guid.Parse("2DE8380F-A6DC-4525-9E73-9A42DD2BB45E"));

            Service service = _context.Service.Find(id);

            Assert.IsNotNull(service, "There is no service by Id in DB.");
            _ServiceController.DeleteService(id);
            Assert.IsNull(_context.Service.Find(id), "No service by ID after delete.");

            _context.Add(service);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public void DeleteService_ServiceToDeleteId_ServiceDeleted()
        {
            long id     = 1;
            var  result = _controller.DeleteService(id);

            Assert.IsInstanceOf <RedirectToActionResult>(result);

            Assert.IsTrue(_context.Services.FirstOrDefault(service => service.Id == 1).IsDeleted);

            _context.Database.EnsureDeleted();
        }
Exemplo n.º 3
0
 void DeleteItemFromServiceViewBox(object sender, EventArgs e)
 {
     if (ViewBox.LvServices.SelectedIndices.Count <= 0)
     {
         MetroMessageBox.Show(this, "Select a file first");
     }
     else
     {
         //WindowStateHelper.DoMinimize();
         if (MetroMessageBox.Show(this, string.Format("Are you sure you want to Delete {0} ?", ViewBox.LvServices.SelectedItems[0].SubItems[1].Text), "Confirm!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
         {
             int ID = Convert.ToInt16(ViewBox.LvServices.SelectedItems[0].Text);
             SvController.DeleteService(ID);
             btnServices_Click(sender, e);
         }
     }
 }
Exemplo n.º 4
0
        public string Executioner(MySqlConnection con, string mac, Agent tm)
        {
            string       stm = string.Format("SELECT * FROM mib.execute where mac_address='{0}'", mac);
            MySqlCommand cmd = con.CreateCommand();

            cmd.CommandText = stm;

            MySqlDataReader scal = cmd.ExecuteReader();

            scal.Read();
            int boot_flag    = Convert.ToInt16(scal[1]);
            int service_flag = Convert.ToInt16(scal[2]);
            int kill_flag    = Convert.ToInt16(scal[3]);
            int script_flag  = Convert.ToInt16(scal[4]);
            int port_flag    = Convert.ToInt16(scal[5]);

            string boot_command = Convert.ToString(scal[6]);
            string service_name = Convert.ToString(scal[7]);
            string kill_name    = Convert.ToString(scal[8]);
            string script       = Convert.ToString(scal[9]);
            int    portno       = Convert.ToInt16(scal[10]);

            scal.Close();


            if (service_flag == 1)
            {
                try {
                    ServiceController sc  = new ServiceController();
                    string[]          val = service_name.Split(';');
                    string            re  = "";
                    if (val[0].Equals("start", StringComparison.InvariantCultureIgnoreCase))
                    {
                        re = sc.StartService(val[1]);
                        if (re == "0")
                        {
                            service_name = "started";
                        }
                        service_flag = 0;
                    }
                    else if (val[0].Equals("stop", StringComparison.InvariantCultureIgnoreCase))
                    {
                        re = sc.StopService(val[1]);
                        if (re == "0")
                        {
                            service_flag = 0;
                        }
                        service_name = "stopped";
                    }
                    else if (val[0].Equals("delete", StringComparison.InvariantCultureIgnoreCase))
                    {
                        re = sc.DeleteService(val[1]);
                        if (re == "0")
                        {
                            service_flag = 0;
                        }
                        service_name = "deleted";
                    }
                    else
                    {
                        service_flag = 1;
                    }
                }
                catch (Exception)
                {
                    service_flag = 2;
                }
                tm.ServiceUpdate(con, mac);
            }
            if (kill_flag == 1)
            {
                try {
                    TaskKill tk = new TaskKill();
                    tk.KillByName(kill_name);
                    kill_flag = 0;
                    kill_name = "Done";
                }
                catch (Exception) {
                    kill_flag = 2;
                }
                tm.ProcessUpdate(con, mac);
            }
            if (script_flag == 1)
            {
                try
                {
                    PowerShellExecutor pse = new PowerShellExecutor();
                    string             val = pse.RunShellScript(script);
                    script_flag = 0;
                    script      = val;
                }
                catch (Exception e)
                {
                    script_flag = 2;
                }
            }
            if (port_flag == 1)
            {
                try {
                    OpenPortScan ops = new OpenPortScan();
                    string       val = ops.GetPortProcessName(portno);
                    if (val == "-1")
                    {
                        port_flag = 2;
                    }
                    else
                    {
                        TaskKill tk = new TaskKill();
                        tk.KillByName(val);
                        port_flag = 0;
                    }
                }
                catch (Exception)
                {
                    port_flag = 2;
                }
            }

            if (boot_flag == 1)
            {
                try {
                    boot_flag = 0;
                    string query2 = string.Format("UPDATE execute SET mac_address = '{0}',boot_flag ={1},service_flag = {2},kill_flag = {3},script_flag = {4},port_flag = {5},boot_command = '{6}',service_name = '{7}',kill_name = '{8}',script = '{9}',portno={10},online=NOW() WHERE mac_address = '{0}'", mac, boot_flag, service_flag, kill_flag, script_flag, port_flag, boot_command, service_name, kill_name, script, port_flag);
                    //Console.WriteLine(query2);
                    cmd             = con.CreateCommand();
                    cmd.CommandText = query2;
                    cmd.ExecuteNonQuery();
                    //Console.WriteLine("...");
                    if (boot_command.Equals("shutdown", StringComparison.InvariantCultureIgnoreCase))
                    {
                        BootController bc  = new BootController();
                        string         val = bc.ShutdownWindows();
                        if (val == "0")
                        {
                            boot_flag = 0;
                        }
                    }
                    else if (boot_command.Equals("restart", StringComparison.InvariantCultureIgnoreCase))
                    {
                        BootController bc  = new BootController();
                        string         val = bc.RestartWindows();
                        if (val == "0")
                        {
                            boot_flag = 0;
                        }
                    }
                    else if (boot_command.Equals("sleep", StringComparison.InvariantCultureIgnoreCase))
                    {
                        BootController bc  = new BootController();
                        string         val = bc.SleepWindows();
                        if (val == "0")
                        {
                            boot_flag = 0;
                        }
                    }
                    else
                    {
                        boot_flag = 1;
                    }
                }
                catch (Exception)
                {
                    boot_flag = 2;
                }
            }

            string query = string.Format("UPDATE mib.execute SET mac_address = '{0}',boot_flag = {1},service_flag = {2},kill_flag = {3},script_flag = {4},port_flag = {5},boot_command = '{6}',service_name = '{7}',kill_name = '{8}',script = \"{9}\", portno = {10},online=NOW() WHERE mac_address = '{0}'", mac, boot_flag, service_flag, kill_flag, script_flag, port_flag, boot_command, service_name, kill_name, script, port_flag);

            //Console.WriteLine(query);
            cmd = con.CreateCommand();

            cmd.CommandText = query;
            cmd.ExecuteNonQuery();
            Console.Write("...");
            return("0");
        }