whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit b6ab68d: Hook up restart button
Date Fri, 22 Jan 2016 20:33:21 GMT
Commit b6ab68d49e12a746d0b340022eca65447537de51:
    Hook up restart button


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
Rakefile                                                     | +++++++++++ ----
lib/whimsy/asf/ldap.rb                                       | +++ -
www/status/Gemfile                                           | +++++++++ 
www/status/images/passenger.png                              |  
www/status/passenger.cgi                                     | ++++++++++++ ---
------------------------------------------------------------
87 changes: 71 additions, 16 deletions.
------------------------------------------------------------


diff --git a/Rakefile b/Rakefile
index 6928b45..076e708 100644
--- a/Rakefile
+++ b/Rakefile
@@ -13,9 +13,9 @@ task :update do
 
   # locate passenger ruby
   conf = Dir['/etc/apache2/*/passenger.conf'].first
-  conf = File.read(conf)[/PassengerRuby "?(.*?)"?$/, 1] if conf
-  if conf
-    passruby = "#{File.dirname(conf)}/%s#{conf[/ruby([.\d]*)$/, 1]}"
+  ruby = File.read(conf)[/PassengerRuby "?(.*?)"?$/, 1] if conf
+  if ruby
+    passruby = "#{File.dirname(ruby)}/%s#{ruby[/ruby([.\d]*)$/, 1]}"
   else
     passruby = sysruby
   end
@@ -23,7 +23,14 @@ task :update do
   # update gems
   Dir['**/Gemfile'].each do |gemfile|
     Dir.chdir File.dirname(gemfile) do
-      bundler = (File.exist?('config.ru') ? passruby : sysruby) % 'bundle'
+      ruby = File.read('Gemfile')[/^ruby ['"](.*?)['"]/, 1]
+      ruby = `which ruby#{ruby}`.chomp if ruby
+      if ruby and not ruby.empty?
+        bundler = "#{File.dirname(ruby)}/bundle#{ruby[/ruby([.\d]*)$/, 1]}"
+      else
+        bundler = (File.exist?('config.ru') ? passruby : sysruby) % 'bundle'
+      end
+
       bundler = 'bundle' unless File.exist?(bundler)
       system "#{bundler} update"
     end
diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 003c931..2ab0cb7 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -403,6 +403,8 @@ def add(people)
   module LDAP
     def self.bind(user, password, &block)
       dn = ASF::Person.new(user).dn
+      raise ::LDAP::ResultError.new('Unknown user') unless dn
+
       ASF.ldap.unbind rescue nil
       if block
         ASF.ldap.bind(dn, password, &block)
@@ -415,7 +417,7 @@ def self.bind(user, password, &block)
     # validate HTTP authorization, and optionally invoke a block bound to
     # that user.
     def self.http_auth(string, &block)
-      auth = Base64.decode64(string[/Basic (.*)/, 1] || '')
+      auth = Base64.decode64(string.to_s[/Basic (.*)/, 1] || '')
       user, password = auth.split(':', 2)
       return unless password
 
diff --git a/www/status/Gemfile b/www/status/Gemfile
new file mode 100644
index 0000000..bdc729a
--- /dev/null
+++ b/www/status/Gemfile
@@ -0,0 +1,9 @@
+source 'https://rubygems.org'
+
+ruby '2.3.0'
+
+root = '../../..'
+asf_version = File.read(File.expand_path("#{root}/asf.version", __FILE__)).chomp
+gem 'whimsy-asf', asf_version, path: File.expand_path(root, __FILE__)
+
+gem 'passenger'
diff --git a/www/status/images/passenger.png b/www/status/images/passenger.png
new file mode 100644
index 0000000..04f37e6
Binary files /dev/null and b/www/status/images/passenger.png differ
diff --git a/www/status/passenger.cgi b/www/status/passenger.cgi
index 2b04102..4ccefea 100755
--- a/www/status/passenger.cgi
+++ b/www/status/passenger.cgi
@@ -1,10 +1,16 @@
 #!/usr/local/bin/ruby2.3.0
 
+require 'bundler/setup'
+
+require 'fileutils'
 require 'open3'
 require 'wunderbar'
+require 'whimsy/asf'
+
+members = ASF.members
+user = ASF::LDAP.http_auth(ENV['HTTP_AUTHORIZATION'])
 
-if ENV['REQUEST_METHOD'] == 'POST'
-  # not implemented yet.
+unless user
   print "Status: 401 Unauthorized\r\n"
   print "WWW-Authenticate: Basic realm=\"ASF Members and Officers\"\r\n\r\n"
   exit
@@ -14,21 +20,45 @@ output, error, status = Open3.capture3 '/usr/local/bin/ruby2.3.0',
   Gem.bin_path('passenger', 'passenger-status')
 
 _html do
+  _title 'Phusion Passenger Status'
   _style %{
     input[type=submit] {
       margin-left: 2em;
       padding: 5px 15px;
-      background: #F00;
-      color: #FFF;
-      border: 2px solid #C00;
+      background: #F2DEDE;
+      color: #A94442;
+      border: 2px solid #EBCCCC;
       font-weight: bold;
       font-size: larger;
       border-radius: 5px;
       cursor: pointer;
     }
+
+    h1 a {
+      text-decoration: none;
+      outline: none;
+    }
+
+    .alert {
+      padding: 15px;
+      display: inline-block;
+      margin-left: 1em;
+      margin-bottom: 20px;
+      border: 1px solid transparent;
+      border-radius: 4px;
+      color: #3C763D;
+      background-color: #DFF0D8;
+      border-color: #D6E9C6;
+    }
   }
 
-  _h1 'Phusion Passenger Status'
+  _h1 do
+    _a href: 'https://www.phusionpassenger.com/' do
+      _img src: 'images/passenger.png'
+    end
+
+    _ 'Phusion Passenger Status'
+  end
 
   sections = output.split(/^(---.*---)\n/)
   _pre sections.shift
@@ -41,11 +71,18 @@ _html do
         _pre app
 
         path = app[/\A(\/.*):/, 1]
-        restart = File.join(path.untaint, "tmp/restart.txt") if path
-        if restart and File.exist? restart
-          _form method: 'post' do
-             _input type: 'hidden', value: restart
-             _input type: 'submit', value: 'restart'
+        if user.asf_officer_or_member?
+          restart = File.join(path.untaint, "tmp/restart.txt") if path
+          if restart and File.exist? restart
+            if _.post? and @restart == restart
+              FileUtils.touch restart
+              _span.alert "#{path} will restart on next request."
+            else
+              _form method: 'post' do
+                 _input type: 'hidden', name: 'restart', value: restart
+                 _input type: 'submit', value: 'restart'
+              end
+            end
           end
         end
       end

Mime
View raw message