public
Fork of al3x/git-wiki
Description: A wiki engine that uses a Git repository as its data store.
Homepage: http://atonie.org/2008/02/git-wiki
Clone URL: git://github.com/jnewland/git-wiki.git
rework http auth to fit in with al3x's refactoring
jnewland (author)
Wed May 14 20:03:42 -0700 2008
commit  ecd24885479fcf956c5f6491f04177e98de115c2
tree    231224fd3946a27577f11649f35b9ec51884680a
parent  384d75aabb3401a8787f343ca4fe6236887e6ecc
...
1
2
3
 
4
5
6
...
1
2
3
4
5
6
7
0
@@ -1,6 +1,7 @@
0
 Originally by Simon Rozet (http://atonie.org/2008/02/git-wiki)
0
 
0
 Modified by:
0
+ - Jesse Newland (http://jnewland.com/) - http auth
0
  - Alex Payne (http://www.al3x.net)
0
  - Jesse Andrews (http://www.overstimulate.com)
0
  - Timoni Grone (http://www.timoni.org) - stylesheet and design aid
...
2
3
4
5
 
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
...
2
3
4
 
5
6
 
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
0
@@ -2,10 +2,35 @@ h1. git-wiki
0
 
0
 A wiki engine that uses a Git repository as its data store.
0
 
0
-h2. Status
0
+h2. Getting Started
0
 
0
-Alex Payne (see AUTHORS file) is no longer actively developing this branch.
0
-Please fork from here and continue development!
0
+@git submodule init@
0
+
0
+@git submodule update@
0
+
0
+h2. Running
0
+
0
+h3. Basics
0
+
0
+@ruby git-wiki.rb@
0
+
0
+h3. Options
0
+
0
+h4. Run in production
0
+
0
+@ruby git-wiki.rb -e production@
0
+
0
+h4. Run in production on port 8777
0
+
0
+@ruby git-wiki.rb -e production -p 8080@
0
+
0
+h4. HTTP Basic Auth
0
+
0
+@cp config.yml.sample config.yml@
0
+
0
+@vim config.yml@
0
+
0
+@CONFIG=config.yml ruby git-wiki.rb -e production -p 8080@
0
 
0
 h2. Requirements
0
 
...
 
1
 
2
3
4
5
 
6
7
8
...
14
15
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
...
1
2
3
4
5
6
 
7
8
9
10
...
16
17
18
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
0
@@ -1,8 +1,10 @@
0
+require 'fileutils'
0
 require 'rubygems'
0
+require 'sinatra/lib/sinatra'
0
 require 'extensions'
0
 require 'page'
0
 
0
-%w(git redcloth rubypants).each do |gem|
0
+%w(git redcloth rubypants yaml).each do |gem|
0
   require_gem_with_feedback gem
0
 end
0
 
0
@@ -14,4 +16,16 @@ unless File.exists?(GIT_REPO) && File.directory?(GIT_REPO)
0
   Git.init(GIT_REPO)
0
 end
0
 
0
-$repo = Git.open(GIT_REPO)
0
\ No newline at end of file
0
+$repo = Git.open(GIT_REPO)
0
+
0
+config = nil
0
+begin
0
+ config = YAML.load(File.read(ENV['CONFIG']))
0
+rescue
0
+ config = {
0
+ 'username' => nil,
0
+ 'password' => nil
0
+ }
0
+end
0
+
0
+CONFIG = config
0
\ No newline at end of file
...
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
0
@@ -22,3 +22,57 @@ class Time
0
     "#{(self.to_i * 1000)}"
0
   end
0
 end
0
+
0
+module HttpAuthentication
0
+ module Basic
0
+
0
+ def authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
0
+ authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm)
0
+ end
0
+
0
+ def authenticate_with_http_basic(&login_procedure)
0
+ authenticate(&login_procedure)
0
+ end
0
+
0
+ def request_http_basic_authentication(realm = "Application")
0
+ authentication_request(realm)
0
+ end
0
+
0
+ private
0
+
0
+ def authenticate(&login_procedure)
0
+ if authorization
0
+ login_procedure.call(*user_name_and_password)
0
+ end
0
+ end
0
+
0
+ def user_name_and_password
0
+ decode_credentials.split(/:/, 2)
0
+ end
0
+
0
+ def authorization
0
+ request.env['HTTP_AUTHORIZATION'] ||
0
+ request.env['X-HTTP_AUTHORIZATION'] ||
0
+ request.env['X_HTTP_AUTHORIZATION'] ||
0
+ request.env['REDIRECT_X_HTTP_AUTHORIZATION']
0
+ end
0
+
0
+ # Base64
0
+ def decode_credentials
0
+ (authorization.split.last || '').unpack("m").first
0
+ end
0
+
0
+ def authentication_request(realm)
0
+ status(401)
0
+ header("WWW-Authenticate" => %(Basic realm="#{realm.gsub(/"/, "")}"))
0
+ throw :halt, "HTTP Basic: Access denied.\n"
0
+ end
0
+
0
+ end
0
+end
0
+
0
+module Sinatra
0
+ class EventContext
0
+ include HttpAuthentication::Basic
0
+ end
0
+end
...
1
2
3
4
5
 
 
 
 
 
 
 
 
6
7
8
...
1
2
 
3
 
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1,8 +1,14 @@
0
 #!/usr/bin/env ruby
0
 
0
-require 'fileutils'
0
 require 'environment'
0
-require 'sinatra/lib/sinatra'
0
+
0
+before do
0
+ unless CONFIG['username'].nil? && CONFIG['password'].nil?
0
+ authenticate_or_request_with_http_basic "git-wiki" do
0
+ |user, pass| user == CONFIG['username'] && pass == CONFIG['password']
0
+ end
0
+ end
0
+end
0
 
0
 get('/') { redirect "/#{HOMEPAGE}" }
0
 
...
22
23
24
25
 
26
27
28
...
22
23
24
 
25
26
27
28
0
@@ -22,7 +22,7 @@
0
       </form>
0
       <%= yield %>
0
       <div id="footer">
0
- powered by <a href="http://github.com/sr/git-wiki/network">git-wiki</a>
0
+ powered by <a href="http://github.com/jnewland/git-wiki/network">git-wiki</a>
0
       </div>
0
     </div>
0
   </body>

Comments

    No one has commented yet.