6279: Move webshell action into VirtualMachinesController, tweak formatting & config.
authorTom Clegg <tom@curoverse.com>
Thu, 9 Jul 2015 20:38:16 +0000 (16:38 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 9 Jul 2015 20:38:16 +0000 (16:38 -0400)
* Document config var

* Accept formatting references like %{hostname} and %{uuid} in config
  var instead of always appending "/#{hostname}"

* Fix favicon, js, and stylesheet paths (use asset_path helper); move
  js and css into public/webshell/

* Use j() quoting helper in js.erb

apps/workbench/app/controllers/actions_controller.rb
apps/workbench/app/controllers/virtual_machines_controller.rb
apps/workbench/app/views/users/_manage_virtual_machines.html.erb
apps/workbench/app/views/virtual_machines/webshell.html.erb [moved from apps/workbench/app/views/virtual_machines/_webshell.html.erb with 69% similarity]
apps/workbench/config/application.default.yml
apps/workbench/config/routes.rb
apps/workbench/public/webshell/README [new file with mode: 0644]
apps/workbench/public/webshell/shell_in_a_box.js [moved from apps/workbench/public/shell_in_a_box.js with 100% similarity]
apps/workbench/public/webshell/styles.css [moved from apps/workbench/public/webshell_styles.css with 100% similarity]

index 22f3a09ff6462c861b85fbb62f50ee3981013b3a..cbe7e37fe5ca4c7f38b1b642db9f62294414aacb 100644 (file)
@@ -228,29 +228,6 @@ You can try recreating the collection to get a copy with full provenance data."
     end
   end
 
-  # webshell action is used to login to an arvados shell using workbench
-  # https://code.google.com/p/shellinabox/source/browse/#git%2Fshellinabox
-  expose_action :webshell do
-    shell_in_a_box_url_config = Rails.configuration.shell_in_a_box_url
-
-    return render_not_found if not shell_in_a_box_url_config
-
-    return unprocessable "Missing parameters" if not params['login'] or not params['hostname']
-
-    @webshell_login = params['login']
-    @webshell_hostname = params['hostname'].chomp('.shell')
-
-    if not shell_in_a_box_url_config.end_with?('/')
-      shell_in_a_box_url_config += '/'
-    end
-    @webshell_url = shell_in_a_box_url_config + @webshell_hostname
-
-    respond_to do |format|
-      render partial: 'virtual_machines/webshell'
-      return
-    end
-  end
-
   protected
 
   def derive_unique_filename filename, manifest_files
index a62ba81b0941cf46870ddc7f27bf3b97692fd172..73231f8cc09023ef13006fa6ad3e910d8881e874 100644 (file)
@@ -19,4 +19,14 @@ class VirtualMachinesController < ApplicationController
     end
     super
   end
+
+  def webshell
+    return render_not_found if not Rails.configuration.shell_in_a_box_url
+    @webshell_url = Rails.configuration.shell_in_a_box_url % {
+      uuid: @object.uuid,
+      hostname: @object.hostname,
+    }
+    render layout: false
+  end
+
 end
index 75e7d155af84ca1b5e017fd79d8c0a7346f796a9..2257df90d0c7f54954c9599a6e6eef0ae58f691b 100644 (file)
@@ -66,6 +66,9 @@
           <th> Host name </th>
           <th> Login name </th>
           <th> Command line </th>
+          <% if Rails.configuration.shell_in_a_box_url %>
+            <th> Web shell <span class="label label-info">beta</span></th>
+          <% end %>
         </tr>
       </thead>
       <tbody>
                 <% end %>
               <% end %>
             </td>
-            <td>
-              <% if  Rails.configuration.shell_in_a_box_url %>
-                <% if @my_vm_logins[vm[:uuid]] %>
-                  <% @my_vm_logins[vm[:uuid]].each do |login| %>
-                    <%= link_to 'Login', webshell_path(login: login, hostname: vm[:hostname]) %>
+            <% if Rails.configuration.shell_in_a_box_url %>
+              <td>
+                <% @my_vm_logins[vm[:uuid]].andand.each do |login| %>
+                  <%= link_to webshell_virtual_machine_path(vm, login: login), title: "Open a terminal session in your browser", class: 'btn btn-xs btn-default' do %>
+                    Log in as <%= login %><br />
                   <% end %>
                 <% end %>
-              <% end %>
-            </td>
+              </td>
+            <% end %>
           </tr>
         <% end %>
       </tbody>
similarity index 69%
rename from apps/workbench/app/views/virtual_machines/_webshell.html.erb
rename to apps/workbench/app/views/virtual_machines/webshell.html.erb
index 46cd03db1fa3057edf9c5d283215156f27220d98..360606e8647ea05723bb081237e327698853227a 100644 (file)
@@ -1,6 +1,6 @@
 <html>
-    <title>Shell login into <%= @webshell_hostname %> </title>
-    <link rel="stylesheet" href="/webshell_styles.css" type="text/css">
+    <title><%= @object.hostname %> / <%= Rails.configuration.site_name %></title>
+    <link rel="stylesheet" href="<%= asset_path 'webshell/styles.css' %>" type="text/css">
     <style type="text/css">
       body {
         margin: 0px;
       })();
 
       function login(username, token) {
-        var sh = new ShellInABox("<%= @webshell_url %>");
+        var sh = new ShellInABox("<%= @webshell_url %>");
         setTimeout(function() {
-          sh.keysPressed("<%= @webshell_login %>\n");
+          sh.keysPressed("<%= j params[:login] %>\n");
           setTimeout(function() {
-            sh.keysPressed("<%= Thread.current[:arvados_api_token] %>\n");
+            sh.keysPressed("<%= Thread.current[:arvados_api_token] %>\n");
           }, 1000);
         }, 1000);
       }
-    -->
+    // -->
 </script>
-    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
-    <script type="text/javascript" src="/shell_in_a_box.js"></script>
+    <link rel="icon" href="<%= asset_path 'favicon.ico' %>" type="image/x-icon">
+    <script type="text/javascript" src="<%= asset_path 'webshell/shell_in_a_box.js' %>"></script>
   </head>
   <!-- Load ShellInABox from a timer as Konqueror sometimes fails to
        correctly deal with the enclosing frameset (if any), if we do not
        do this
    -->
-<body onload="setTimeout('login()', 1000)"
+<body onload="setTimeout(login, 1000)"
     scroll="no"><noscript>JavaScript must be enabled for ShellInABox</noscript>
 </body>
 </html>
index 155b9d1c1fc1c0c204e3ed577315cd92c8375b22..744c0c3ba3b7b3b8f1340df03045b554eab1ea82 100644 (file)
@@ -215,5 +215,12 @@ common:
   # Ask Arvados API server to compress its response payloads.
   api_response_compression: true
 
-  # ShellInABox URL
+  # ShellInABox service endpoint URL for a given VM.  If false, do not
+  # offer web shell logins.
+  #
+  # E.g., using a path-based proxy server to forward connections to shell hosts:
+  # https://webshell.uuid_prefix.arvadosapi.com/%{hostname}
+  #
+  # E.g., using a name-based proxy server to forward connections to shell hosts:
+  # https://%{hostname}.webshell.uuid_prefix.arvadosapi.com/
   shell_in_a_box_url: false
index 7c40d0e80b3853bdf7ad1437ea3bffc898534930..f72278a2a41d12d36129816c5e78621928152f7e 100644 (file)
@@ -17,6 +17,7 @@ ArvadosWorkbench::Application.routes.draw do
   resources :traits
   resources :api_client_authorizations
   resources :virtual_machines
+  get '/virtual_machines/:id/webshell/:login' => 'virtual_machines#webshell', :as => :webshell_virtual_machine
   resources :authorized_keys
   resources :job_tasks
   resources :jobs do
@@ -93,7 +94,6 @@ ArvadosWorkbench::Application.routes.draw do
   get 'actions' => 'actions#show'
   get 'websockets' => 'websocket#index'
   post "combine_selected" => 'actions#combine_selected_files_into_collection'
-  get "webshell" => 'actions#webshell'
 
   root :to => 'projects#index'
 
diff --git a/apps/workbench/public/webshell/README b/apps/workbench/public/webshell/README
new file mode 100644 (file)
index 0000000..b8920c5
--- /dev/null
@@ -0,0 +1,3 @@
+See also
+* VirtualMachinesController#webshell
+* https://code.google.com/p/shellinabox/source/browse/#git%2Fshellinabox