示例#1
0
        public IActionResult Create([FromBody] UpdateQue item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            item.Id = db.GetSequence <UpdateQue>();
            db.InsertData <UpdateQue>(item);

            return(Ok(new { id = item.Id }));
        }
示例#2
0
        static void DoSSH(DeviceIdentity Dev, UpdateQue Que)
        {
            // Setup Credentials and Server Information
            ConnectionInfo ConnNfo = new ConnectionInfo(Dev.IpAddress, 22, Dev.UserName,
                                                        new AuthenticationMethod[] {
                // Pasword based Authentication
                new PasswordAuthenticationMethod(Dev.UserName, Dev.Password)
            }
                                                        );

            /*
             * // Execute a (SHELL) Command - prepare upload directory
             * using (var sshclient = new SshClient(ConnNfo))
             * {
             *  sshclient.Connect();
             *  using (var cmd = sshclient.CreateCommand("mkdir -p /tmp/uploadtest && chmod +rw /tmp/uploadtest"))
             *  {
             *      cmd.Execute();
             *      Console.WriteLine("Command>" + cmd.CommandText);
             *      Console.WriteLine("Return Value = {0}", cmd.ExitStatus);
             *  }
             *  sshclient.Disconnect();
             * }
             *
             * // Upload A File
             * using (var sftp = new SftpClient(ConnNfo))
             * {
             *  string uploadfn = "Renci.SshNet.dll";
             *
             *  sftp.Connect();
             *  sftp.ChangeDirectory("/tmp/uploadtest");
             *  using (var uplfileStream = System.IO.File.OpenRead(uploadfn))
             *  {
             *      sftp.UploadFile(uplfileStream, uploadfn, true);
             *  }
             *  sftp.Disconnect();
             * }
             */
            // Execute (SHELL) Commands
            Random rnd = new Random();

            using (var sshclient = new SshClient(ConnNfo))
            {
                sshclient.Connect();

                // quick way to use ist, but not best practice - SshCommand is not Disposed, ExitStatus not checked...
                Console.WriteLine(sshclient.CreateCommand($"cd Downloads/ && wget -O foo-{rnd.Next(1,100)}.html {Que.FirmwareUrl}").Execute());
                Console.WriteLine($"SSH executed on {Dev.Name}");
                sshclient.Disconnect();
            }
        }
示例#3
0
        public IActionResult PutData([FromRoute] int id, [FromBody] UpdateQue item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            if (item.Id > 0)
            {
                db.InsertData <UpdateQue>(item);
            }

            return(Ok(new { id = item.Id }));
        }