Browse Source

client: expose run command

run argument is already supported but not exposed at client side. Enable
this great feature.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Alon Bar-Lev 5 years ago
parent
commit
d013f2e04a
3 changed files with 25 additions and 1 deletions
  1. 6 1
      bin/wssh
  2. 4 0
      wssh/static/wssh.js
  3. 15 0
      wssh/templates/index.html

+ 6 - 1
bin/wssh

@@ -48,6 +48,10 @@ if __name__ == '__main__':
     parser.add_argument('destination',
         help='[user@]hostname')
 
+    parser.add_argument('command',
+        nargs='*',
+        help='optional command to be executed')
+
     args = parser.parse_args()
 
     if '@' in args.destination:
@@ -88,7 +92,8 @@ if __name__ == '__main__':
         'password': password,
         'port': str(args.ssh_port),
         'private_key': key,
-        'key_passphrase': key_passphrase
+        'key_passphrase': key_passphrase,
+        'run': ' '.join(args.command) if args.command else None,
     }
 
     # Filter empty parameters

+ 4 - 0
wssh/static/wssh.js

@@ -58,6 +58,10 @@ WSSHClient.prototype._generateEndpoint = function(options) {
             endpoint += '&key_passphrase=' + encodeURIComponent(
                 options.key_passphrase);
     }
+    if (options.command != "") {
+        endpoint += '&run=' + encodeURIComponent(
+            options.command);
+    }
     return endpoint;
 };
 

+ 15 - 0
wssh/templates/index.html

@@ -108,6 +108,19 @@
                         </div>
                     </div>
 
+                    <div class="control-group">
+                        <label class="control-label">
+                            Command
+                        </label>
+                        <div class="controls">
+                            <input type="text" id="command" class="input-large" />
+                            <p class="help-block">
+                                Enter command to be executed or
+                                empty for interactive.
+                            </p>
+                        </div>
+                    </div>
+
                     <div class="form-actions">
                         <button type="submit" class="btn btn-primary">
                             Connect
@@ -196,6 +209,7 @@
                     var username = $('input:text#username');
                     var hostname = $('input:text#hostname');
                     var portnumber = $('input:text#portnumber');
+                    var command = $('input:text#command');
 
                     var authentication = $(
                         'input[name=authentication_method]:checked',
@@ -203,6 +217,7 @@
                     var options = {
                         username: username.val(),
                         hostname: hostname.val(),
+                        command: command.val(),
                         authentication_method: authentication
                     };