Create a gist now

Instantly share code, notes, and snippets.

@troelskn /app.rb forked from dstrelau/app.rb
Last active Aug 26, 2017

What would you like to do?
Gollum protected by HTTP Basic
require 'gollum/frontend/app'
require 'digest/sha1'
class App < Precious::App
User =, :email, :password_hash, :can_write)
before { authenticate! }
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end
helpers do
def authenticate!
@_auth ||=
if @_auth.provided?
if @_auth.provided? && @_auth.basic? && @_auth.credentials &&
@user = detected_user(@_auth.credentials)
return @user
response['WWW-Authenticate'] = %(Basic realm="Gollum Wiki")
throw(:halt, [401, "Not authorized\n"])
def authorize_write!
throw(:halt, [403, "Forbidden\n"]) unless @user.can_write
def users
@_users ||= {|u|*u) }
def detected_user(credentials)
users.detect do |u|
[, u.password_hash] ==
[credentials[0], Digest::SHA1.hexdigest(credentials[1])]
def commit_message
:message => params[:message],
:name =>,
:email =>
__DIR__ = File.expand_path(File.dirname(__FILE__))
$: << __DIR__
require 'rubygems'
require 'yaml'
require 'app'
App.set(:gollum_path, __DIR__ + "/wikidata")
App.set(:authorized_users, YAML.load_file(File.expand_path('users.yml', __DIR__)))
App.set(:wiki_options, {})
run App
# kill any running gollums
ps -ef | grep rackup | grep -v grep | awk '{print $2}' | xargs kill -9
# start gollum as a background process
# you can pipe output to /dev/null instead, if you don't want a log
nohup rackup -p 4567 > /var/log/gollum.log &
- - User Name
- e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4 # secret
- true
- - Another User
- b4341ce88a4943631b9573d9e0e5b28991de945d # p455w0rd
- true

ghost commented Jan 19, 2013


I would like to use this, but I have no idea how to. Can you please explain what I need to do to add this to my gollum install. Thanks


troelskn commented Jan 21, 2013

This just extends Gollum. So make sure you have that up and running first. I think requirements are low - Try to run gem install gollum (Assuming you have installed Ruby + rubygems).

Launch Gollum by running You might want to wrap this in something that makes sure to relaunch the service, if it fails as well as on machine boot. Also, if you want to expose this to the internet at large, I suggest that you put nginx+mod_cache in front of it. Google for plenty of descriptions on how.

For the latest version of gollum (>= 2.4.15), the first line of requirement should be require "gollum/app" instead of require 'gollum/frontend/app'

Reference: this blog

Hi, how could i get the encoded password string, i had tried md5 and sha1 to encode string "secret", but i can not get the same string as "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4".

sorry, i has found it, just sha1sum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment