forked from splice/indaba-parkplace
/
parkplace
executable file
·89 lines (71 loc) · 2.43 KB
/
parkplace
1
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
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
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env ruby
$:.unshift "./lib"
require 'optparse'
$PARKPLACE_ACCESSORIES = true
require 'rubygems'
gem 'mongrel'
gem 'activesupport', '~> 2.2.0'
gem 'activerecord', '~> 2.2.0'
require 'parkplace'
DEFAULT_PASSWORD = 'pass@word1'
DEFAULT_SECRET = 'OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV'
#
options = ParkPlace.options
options.host = "127.0.0.1"
options.port = 3002
opts = OptionParser.new do |opts|
opts.banner = "Usage: parkplace [options] [host] [port]"
opts.separator "Default host is #{options.host}, default port is #{options.port}."
opts.separator ""
opts.separator "Specific options:"
opts.on("-d", "--directory DIRECTORY",
"Park Place directory (defaults to #{options.parkplace_dir || 'None'})") do |d|
options.parkplace_dir = d
end
opts.on("-D", "--[no-]daemon", "Daemon mode") do |d|
options.daemon = d
end
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options.verbose = v
end
opts.on("-u", "--debug", "Debug Mode") do |v|
begin
require 'ruby-debug'
Debugger.start
rescue LoadError
end
$DEBUG = v
end
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
# Another typical switch to print the version.
opts.on_tail("--version", "Show version") do
puts ParkPlace::VERSION
exit
end
end
opts.parse! ARGV
options.host = ARGV[0] if ARGV[0]
options.port = ARGV[1].to_i if ARGV[1]
ParkPlace.config(options)
include ParkPlace
ParkPlace::Models::Base.establish_connection(options.database)
ParkPlace::Models::Base.logger = Logger.new('camping.log') if $DEBUG
ParkPlace.create
num_users = ParkPlace::Models::User.count
if num_users == 0
puts "** No users found, creating the `admin' user."
ParkPlace::Models::User.create :login => "admin", :password => DEFAULT_PASSWORD,
:email => "admin@parkplace.net", :key => "44CF9590006BF252F707", :secret => DEFAULT_SECRET,
:activated_at => Time.now, :superuser => 1
end
admin = ParkPlace::Models::User.find_by_login "admin"
if num_users == 1 and admin and admin.password == hmac_sha1( DEFAULT_PASSWORD, admin.secret )
puts "** Please login in with `admin' and password `#{DEFAULT_PASSWORD}'"
puts "** You should change the default password for the admin at soonest chance!"
end
ParkPlace.serve(options.host, options.port)