fluid_cli 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +200 -1
  3. data/exe/fluid +12 -17
  4. data/lib/fluid_cli/version.rb +1 -1
  5. data/lib/fluid_cli.rb +4 -62
  6. metadata +14 -278
  7. data/Rakefile +0 -26
  8. data/dev.yml +0 -5
  9. data/lib/fluid_cli/api.rb +0 -141
  10. data/lib/fluid_cli/assets/post_auth_page/index.html.erb +0 -34
  11. data/lib/fluid_cli/assets/post_auth_page/style.css +0 -58
  12. data/lib/fluid_cli/command.rb +0 -55
  13. data/lib/fluid_cli/commands/help.rb +0 -21
  14. data/lib/fluid_cli/commands/login.rb +0 -30
  15. data/lib/fluid_cli/commands/logout.rb +0 -38
  16. data/lib/fluid_cli/commands/switch.rb +0 -23
  17. data/lib/fluid_cli/commands/theme/common/company_helper.rb +0 -15
  18. data/lib/fluid_cli/commands/theme/common/root_helper.rb +0 -95
  19. data/lib/fluid_cli/commands/theme/dev.rb +0 -62
  20. data/lib/fluid_cli/commands/theme/help.rb +0 -21
  21. data/lib/fluid_cli/commands/theme/init.rb +0 -46
  22. data/lib/fluid_cli/commands/theme/navigate.rb +0 -57
  23. data/lib/fluid_cli/commands/theme/pull.rb +0 -68
  24. data/lib/fluid_cli/commands/theme/push.rb +0 -132
  25. data/lib/fluid_cli/commands/theme.rb +0 -24
  26. data/lib/fluid_cli/commands/whoami.rb +0 -23
  27. data/lib/fluid_cli/commands.rb +0 -19
  28. data/lib/fluid_cli/company_switcher.rb +0 -69
  29. data/lib/fluid_cli/context.rb +0 -691
  30. data/lib/fluid_cli/db.rb +0 -114
  31. data/lib/fluid_cli/entry_point.rb +0 -10
  32. data/lib/fluid_cli/environment.rb +0 -32
  33. data/lib/fluid_cli/file_system_listener.rb +0 -29
  34. data/lib/fluid_cli/form.rb +0 -42
  35. data/lib/fluid_cli/git.rb +0 -319
  36. data/lib/fluid_cli/http_request.rb +0 -60
  37. data/lib/fluid_cli/identity_auth/servlet.rb +0 -39
  38. data/lib/fluid_cli/identity_auth.rb +0 -126
  39. data/lib/fluid_cli/options.rb +0 -38
  40. data/lib/fluid_cli/packager.rb +0 -36
  41. data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +0 -79
  42. data/lib/fluid_cli/theme/dev_server/errors.rb +0 -9
  43. data/lib/fluid_cli/theme/dev_server/header_hash.rb +0 -98
  44. data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +0 -39
  45. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +0 -27
  46. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +0 -28
  47. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +0 -43
  48. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +0 -16
  49. data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +0 -54
  50. data/lib/fluid_cli/theme/dev_server/hot_reload.rb +0 -75
  51. data/lib/fluid_cli/theme/dev_server/local_assets.rb +0 -92
  52. data/lib/fluid_cli/theme/dev_server/proxy.rb +0 -235
  53. data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +0 -82
  54. data/lib/fluid_cli/theme/dev_server/reload_mode.rb +0 -34
  55. data/lib/fluid_cli/theme/dev_server/sse.rb +0 -75
  56. data/lib/fluid_cli/theme/dev_server/watcher.rb +0 -57
  57. data/lib/fluid_cli/theme/dev_server/web_server.rb +0 -140
  58. data/lib/fluid_cli/theme/dev_server.rb +0 -308
  59. data/lib/fluid_cli/theme/development_theme.rb +0 -101
  60. data/lib/fluid_cli/theme/file.rb +0 -130
  61. data/lib/fluid_cli/theme/forms/select.rb +0 -33
  62. data/lib/fluid_cli/theme/mime_type.rb +0 -34
  63. data/lib/fluid_cli/theme/navigation/resource_fetcher.rb +0 -25
  64. data/lib/fluid_cli/theme/navigation/route_navigator.rb +0 -87
  65. data/lib/fluid_cli/theme/presenters/theme_presenter.rb +0 -49
  66. data/lib/fluid_cli/theme/presenters/themes_presenter.rb +0 -31
  67. data/lib/fluid_cli/theme/root.rb +0 -62
  68. data/lib/fluid_cli/theme/schema_validator.rb +0 -274
  69. data/lib/fluid_cli/theme/syncer/checksums.rb +0 -66
  70. data/lib/fluid_cli/theme/syncer/downloader.rb +0 -54
  71. data/lib/fluid_cli/theme/syncer/error_reporter.rb +0 -45
  72. data/lib/fluid_cli/theme/syncer/merger.rb +0 -53
  73. data/lib/fluid_cli/theme/syncer/operation.rb +0 -58
  74. data/lib/fluid_cli/theme/syncer/standard_reporter.rb +0 -32
  75. data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +0 -90
  76. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +0 -41
  77. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +0 -37
  78. data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +0 -64
  79. data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +0 -29
  80. data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +0 -30
  81. data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +0 -49
  82. data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +0 -71
  83. data/lib/fluid_cli/theme/syncer/uploader.rb +0 -105
  84. data/lib/fluid_cli/theme/syncer.rb +0 -500
  85. data/lib/fluid_cli/theme/theme.rb +0 -186
  86. data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +0 -22
  87. data/lib/fluid_cli/thread_pool/job.rb +0 -35
  88. data/lib/fluid_cli/thread_pool.rb +0 -49
  89. data/packaging/homebrew/fluid_cli.base.rb +0 -103
  90. data/vendor/deps/base64/.document +0 -5
  91. data/vendor/deps/base64/.gitignore +0 -9
  92. data/vendor/deps/base64/BSDL +0 -22
  93. data/vendor/deps/base64/COPYING +0 -56
  94. data/vendor/deps/base64/Gemfile +0 -9
  95. data/vendor/deps/base64/LEGAL +0 -60
  96. data/vendor/deps/base64/README.md +0 -48
  97. data/vendor/deps/base64/Rakefile +0 -31
  98. data/vendor/deps/base64/base64.gemspec +0 -28
  99. data/vendor/deps/base64/bin/console +0 -14
  100. data/vendor/deps/base64/bin/setup +0 -8
  101. data/vendor/deps/base64/lib/base64.rb +0 -382
  102. data/vendor/deps/base64/sig/base64.rbs +0 -358
  103. data/vendor/deps/base64/test/base64/test_base64.rb +0 -115
  104. data/vendor/deps/base64/test_sig/test_base64.rb +0 -44
  105. data/vendor/deps/cli-kit/REVISION +0 -1
  106. data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +0 -286
  107. data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +0 -215
  108. data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +0 -128
  109. data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +0 -125
  110. data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +0 -130
  111. data/vendor/deps/cli-kit/lib/cli/kit/args.rb +0 -16
  112. data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +0 -30
  113. data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +0 -268
  114. data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +0 -150
  115. data/vendor/deps/cli-kit/lib/cli/kit/config.rb +0 -137
  116. data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +0 -28
  117. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +0 -166
  118. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +0 -92
  119. data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +0 -91
  120. data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +0 -92
  121. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +0 -94
  122. data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +0 -248
  123. data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +0 -55
  124. data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +0 -66
  125. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +0 -260
  126. data/vendor/deps/cli-kit/lib/cli/kit/support.rb +0 -11
  127. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +0 -290
  128. data/vendor/deps/cli-kit/lib/cli/kit/util.rb +0 -118
  129. data/vendor/deps/cli-kit/lib/cli/kit/version.rb +0 -7
  130. data/vendor/deps/cli-kit/lib/cli/kit.rb +0 -139
  131. data/vendor/deps/cli-ui/REVISION +0 -1
  132. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +0 -218
  133. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +0 -101
  134. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +0 -219
  135. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +0 -67
  136. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +0 -179
  137. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +0 -152
  138. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +0 -127
  139. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +0 -286
  140. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +0 -92
  141. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +0 -63
  142. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +0 -64
  143. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +0 -132
  144. data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +0 -209
  145. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +0 -583
  146. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +0 -36
  147. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +0 -381
  148. data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +0 -48
  149. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +0 -602
  150. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +0 -79
  151. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +0 -399
  152. data/vendor/deps/cli-ui/lib/cli/ui/table.rb +0 -83
  153. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +0 -55
  154. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +0 -106
  155. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +0 -8
  156. data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +0 -46
  157. data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +0 -79
  158. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +0 -89
  159. data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +0 -142
  160. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +0 -61
  161. data/vendor/deps/cli-ui/lib/cli/ui.rb +0 -359
  162. data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +0 -78
  163. data/vendor/deps/webrick/.gitignore +0 -9
  164. data/vendor/deps/webrick/Gemfile +0 -3
  165. data/vendor/deps/webrick/LICENSE.txt +0 -22
  166. data/vendor/deps/webrick/README.md +0 -61
  167. data/vendor/deps/webrick/Rakefile +0 -10
  168. data/vendor/deps/webrick/lib/webrick/accesslog.rb +0 -157
  169. data/vendor/deps/webrick/lib/webrick/cgi.rb +0 -313
  170. data/vendor/deps/webrick/lib/webrick/compat.rb +0 -36
  171. data/vendor/deps/webrick/lib/webrick/config.rb +0 -158
  172. data/vendor/deps/webrick/lib/webrick/cookie.rb +0 -172
  173. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +0 -30
  174. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +0 -117
  175. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +0 -116
  176. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +0 -395
  177. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +0 -132
  178. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +0 -97
  179. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +0 -158
  180. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +0 -53
  181. data/vendor/deps/webrick/lib/webrick/httpauth.rb +0 -96
  182. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +0 -354
  183. data/vendor/deps/webrick/lib/webrick/httprequest.rb +0 -636
  184. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +0 -564
  185. data/vendor/deps/webrick/lib/webrick/https.rb +0 -152
  186. data/vendor/deps/webrick/lib/webrick/httpserver.rb +0 -294
  187. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +0 -152
  188. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +0 -47
  189. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +0 -126
  190. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +0 -88
  191. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +0 -552
  192. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +0 -47
  193. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +0 -23
  194. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +0 -194
  195. data/vendor/deps/webrick/lib/webrick/httputils.rb +0 -512
  196. data/vendor/deps/webrick/lib/webrick/httpversion.rb +0 -76
  197. data/vendor/deps/webrick/lib/webrick/log.rb +0 -156
  198. data/vendor/deps/webrick/lib/webrick/server.rb +0 -381
  199. data/vendor/deps/webrick/lib/webrick/ssl.rb +0 -215
  200. data/vendor/deps/webrick/lib/webrick/utils.rb +0 -265
  201. data/vendor/deps/webrick/lib/webrick/version.rb +0 -18
  202. data/vendor/deps/webrick/lib/webrick.rb +0 -232
  203. data/vendor/deps/webrick/webrick.gemspec +0 -74
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # httpauth/htdigest.rb -- Apache compatible htdigest file
4
- #
5
- # Author: IPR -- Internet Programming with Ruby -- writers
6
- # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
7
- # reserved.
8
- #
9
- # $IPR: htdigest.rb,v 1.4 2003/07/22 19:20:45 gotoyuzo Exp $
10
-
11
- require_relative 'userdb'
12
- require_relative 'digestauth'
13
- require 'tempfile'
14
-
15
- module WEBrick
16
- module HTTPAuth
17
-
18
- ##
19
- # Htdigest accesses apache-compatible digest password files. Passwords are
20
- # matched to a realm where they are valid. For security, the path for a
21
- # digest password database should be stored outside of the paths available
22
- # to the HTTP server.
23
- #
24
- # Htdigest is intended for use with WEBrick::HTTPAuth::DigestAuth and
25
- # stores passwords using cryptographic hashes.
26
- #
27
- # htpasswd = WEBrick::HTTPAuth::Htdigest.new 'my_password_file'
28
- # htpasswd.set_passwd 'my realm', 'username', 'password'
29
- # htpasswd.flush
30
-
31
- class Htdigest
32
- include UserDB
33
-
34
- ##
35
- # Open a digest password database at +path+
36
-
37
- def initialize(path)
38
- @path = path
39
- @mtime = Time.at(0)
40
- @digest = Hash.new
41
- @mutex = Thread::Mutex::new
42
- @auth_type = DigestAuth
43
- File.open(@path,"a").close unless File.exist?(@path)
44
- reload
45
- end
46
-
47
- ##
48
- # Reloads passwords from the database
49
-
50
- def reload
51
- mtime = File::mtime(@path)
52
- if mtime > @mtime
53
- @digest.clear
54
- File.open(@path){|io|
55
- while line = io.gets
56
- line.chomp!
57
- user, realm, pass = line.split(/:/, 3)
58
- unless @digest[realm]
59
- @digest[realm] = Hash.new
60
- end
61
- @digest[realm][user] = pass
62
- end
63
- }
64
- @mtime = mtime
65
- end
66
- end
67
-
68
- ##
69
- # Flush the password database. If +output+ is given the database will
70
- # be written there instead of to the original path.
71
-
72
- def flush(output=nil)
73
- output ||= @path
74
- tmp = Tempfile.create("htpasswd", File::dirname(output))
75
- renamed = false
76
- begin
77
- each{|item| tmp.puts(item.join(":")) }
78
- tmp.close
79
- File::rename(tmp.path, output)
80
- renamed = true
81
- ensure
82
- tmp.close
83
- File.unlink(tmp.path) if !renamed
84
- end
85
- end
86
-
87
- ##
88
- # Retrieves a password from the database for +user+ in +realm+. If
89
- # +reload_db+ is true the database will be reloaded first.
90
-
91
- def get_passwd(realm, user, reload_db)
92
- reload() if reload_db
93
- if hash = @digest[realm]
94
- hash[user]
95
- end
96
- end
97
-
98
- ##
99
- # Sets a password in the database for +user+ in +realm+ to +pass+.
100
-
101
- def set_passwd(realm, user, pass)
102
- @mutex.synchronize{
103
- unless @digest[realm]
104
- @digest[realm] = Hash.new
105
- end
106
- @digest[realm][user] = make_passwd(realm, user, pass)
107
- }
108
- end
109
-
110
- ##
111
- # Removes a password from the database for +user+ in +realm+.
112
-
113
- def delete_passwd(realm, user)
114
- if hash = @digest[realm]
115
- hash.delete(user)
116
- end
117
- end
118
-
119
- ##
120
- # Iterate passwords in the database.
121
-
122
- def each # :yields: [user, realm, password_hash]
123
- @digest.keys.sort.each{|realm|
124
- hash = @digest[realm]
125
- hash.keys.sort.each{|user|
126
- yield([user, realm, hash[user]])
127
- }
128
- }
129
- end
130
- end
131
- end
132
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # httpauth/htgroup.rb -- Apache compatible htgroup file
4
- #
5
- # Author: IPR -- Internet Programming with Ruby -- writers
6
- # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
7
- # reserved.
8
- #
9
- # $IPR: htgroup.rb,v 1.1 2003/02/16 22:22:56 gotoyuzo Exp $
10
-
11
- require 'tempfile'
12
-
13
- module WEBrick
14
- module HTTPAuth
15
-
16
- ##
17
- # Htgroup accesses apache-compatible group files. Htgroup can be used to
18
- # provide group-based authentication for users. Currently Htgroup is not
19
- # directly integrated with any authenticators in WEBrick. For security,
20
- # the path for a digest password database should be stored outside of the
21
- # paths available to the HTTP server.
22
- #
23
- # Example:
24
- #
25
- # htgroup = WEBrick::HTTPAuth::Htgroup.new 'my_group_file'
26
- # htgroup.add 'superheroes', %w[spiderman batman]
27
- #
28
- # htgroup.members('superheroes').include? 'magneto' # => false
29
-
30
- class Htgroup
31
-
32
- ##
33
- # Open a group database at +path+
34
-
35
- def initialize(path)
36
- @path = path
37
- @mtime = Time.at(0)
38
- @group = Hash.new
39
- File.open(@path,"a").close unless File.exist?(@path)
40
- reload
41
- end
42
-
43
- ##
44
- # Reload groups from the database
45
-
46
- def reload
47
- if (mtime = File::mtime(@path)) > @mtime
48
- @group.clear
49
- File.open(@path){|io|
50
- while line = io.gets
51
- line.chomp!
52
- group, members = line.split(/:\s*/)
53
- @group[group] = members.split(/\s+/)
54
- end
55
- }
56
- @mtime = mtime
57
- end
58
- end
59
-
60
- ##
61
- # Flush the group database. If +output+ is given the database will be
62
- # written there instead of to the original path.
63
-
64
- def flush(output=nil)
65
- output ||= @path
66
- tmp = Tempfile.create("htgroup", File::dirname(output))
67
- begin
68
- @group.keys.sort.each{|group|
69
- tmp.puts(format("%s: %s", group, self.members(group).join(" ")))
70
- }
71
- ensure
72
- tmp.close
73
- if $!
74
- File.unlink(tmp.path)
75
- else
76
- return File.rename(tmp.path, output)
77
- end
78
- end
79
- end
80
-
81
- ##
82
- # Retrieve the list of members from +group+
83
-
84
- def members(group)
85
- reload
86
- @group[group] || []
87
- end
88
-
89
- ##
90
- # Add an Array of +members+ to +group+
91
-
92
- def add(group, members)
93
- @group[group] = members(group) | members
94
- end
95
- end
96
- end
97
- end
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # httpauth/htpasswd -- Apache compatible htpasswd file
4
- #
5
- # Author: IPR -- Internet Programming with Ruby -- writers
6
- # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
7
- # reserved.
8
- #
9
- # $IPR: htpasswd.rb,v 1.4 2003/07/22 19:20:45 gotoyuzo Exp $
10
-
11
- require_relative 'userdb'
12
- require_relative 'basicauth'
13
- require 'tempfile'
14
-
15
- module WEBrick
16
- module HTTPAuth
17
-
18
- ##
19
- # Htpasswd accesses apache-compatible password files. Passwords are
20
- # matched to a realm where they are valid. For security, the path for a
21
- # password database should be stored outside of the paths available to the
22
- # HTTP server.
23
- #
24
- # Htpasswd is intended for use with WEBrick::HTTPAuth::BasicAuth.
25
- #
26
- # To create an Htpasswd database with a single user:
27
- #
28
- # htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
29
- # htpasswd.set_passwd 'my realm', 'username', 'password'
30
- # htpasswd.flush
31
-
32
- class Htpasswd
33
- include UserDB
34
-
35
- ##
36
- # Open a password database at +path+
37
-
38
- def initialize(path, password_hash: nil)
39
- @path = path
40
- @mtime = Time.at(0)
41
- @passwd = Hash.new
42
- @auth_type = BasicAuth
43
- @password_hash = password_hash
44
-
45
- case @password_hash
46
- when nil
47
- # begin
48
- # require "string/crypt"
49
- # rescue LoadError
50
- # warn("Unable to load string/crypt, proceeding with deprecated use of String#crypt, consider using password_hash: :bcrypt")
51
- # end
52
- @password_hash = :crypt
53
- when :crypt
54
- # require "string/crypt"
55
- when :bcrypt
56
- require "bcrypt"
57
- else
58
- raise ArgumentError, "only :crypt and :bcrypt are supported for password_hash keyword argument"
59
- end
60
-
61
- File.open(@path,"a").close unless File.exist?(@path)
62
- reload
63
- end
64
-
65
- ##
66
- # Reload passwords from the database
67
-
68
- def reload
69
- mtime = File::mtime(@path)
70
- if mtime > @mtime
71
- @passwd.clear
72
- File.open(@path){|io|
73
- while line = io.gets
74
- line.chomp!
75
- case line
76
- when %r!\A[^:]+:[a-zA-Z0-9./]{13}\z!
77
- if @password_hash == :bcrypt
78
- raise StandardError, ".htpasswd file contains crypt password, only bcrypt passwords supported"
79
- end
80
- user, pass = line.split(":")
81
- when %r!\A[^:]+:\$2[aby]\$\d{2}\$.{53}\z!
82
- if @password_hash == :crypt
83
- raise StandardError, ".htpasswd file contains bcrypt password, only crypt passwords supported"
84
- end
85
- user, pass = line.split(":")
86
- when /:\$/, /:{SHA}/
87
- raise NotImplementedError,
88
- 'MD5, SHA1 .htpasswd file not supported'
89
- else
90
- raise StandardError, 'bad .htpasswd file'
91
- end
92
- @passwd[user] = pass
93
- end
94
- }
95
- @mtime = mtime
96
- end
97
- end
98
-
99
- ##
100
- # Flush the password database. If +output+ is given the database will
101
- # be written there instead of to the original path.
102
-
103
- def flush(output=nil)
104
- output ||= @path
105
- tmp = Tempfile.create("htpasswd", File::dirname(output))
106
- renamed = false
107
- begin
108
- each{|item| tmp.puts(item.join(":")) }
109
- tmp.close
110
- File::rename(tmp.path, output)
111
- renamed = true
112
- ensure
113
- tmp.close
114
- File.unlink(tmp.path) if !renamed
115
- end
116
- end
117
-
118
- ##
119
- # Retrieves a password from the database for +user+ in +realm+. If
120
- # +reload_db+ is true the database will be reloaded first.
121
-
122
- def get_passwd(realm, user, reload_db)
123
- reload() if reload_db
124
- @passwd[user]
125
- end
126
-
127
- ##
128
- # Sets a password in the database for +user+ in +realm+ to +pass+.
129
-
130
- def set_passwd(realm, user, pass)
131
- if @password_hash == :bcrypt
132
- # Cost of 5 to match Apache default, and because the
133
- # bcrypt default of 10 will introduce significant delays
134
- # for every request.
135
- @passwd[user] = BCrypt::Password.create(pass, :cost=>5)
136
- else
137
- @passwd[user] = make_passwd(realm, user, pass)
138
- end
139
- end
140
-
141
- ##
142
- # Removes a password from the database for +user+ in +realm+.
143
-
144
- def delete_passwd(realm, user)
145
- @passwd.delete(user)
146
- end
147
-
148
- ##
149
- # Iterate passwords in the database.
150
-
151
- def each # :yields: [user, password]
152
- @passwd.keys.sort.each{|user|
153
- yield([user, @passwd[user]])
154
- }
155
- end
156
- end
157
- end
158
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
- #--
3
- # httpauth/userdb.rb -- UserDB mix-in module.
4
- #
5
- # Author: IPR -- Internet Programming with Ruby -- writers
6
- # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
7
- # reserved.
8
- #
9
- # $IPR: userdb.rb,v 1.2 2003/02/20 07:15:48 gotoyuzo Exp $
10
-
11
- module WEBrick
12
- module HTTPAuth
13
-
14
- ##
15
- # User database mixin for HTTPAuth. This mixin dispatches user record
16
- # access to the underlying auth_type for this database.
17
-
18
- module UserDB
19
-
20
- ##
21
- # The authentication type.
22
- #
23
- # WEBrick::HTTPAuth::BasicAuth or WEBrick::HTTPAuth::DigestAuth are
24
- # built-in.
25
-
26
- attr_accessor :auth_type
27
-
28
- ##
29
- # Creates an obscured password in +realm+ with +user+ and +password+
30
- # using the auth_type of this database.
31
-
32
- def make_passwd(realm, user, pass)
33
- @auth_type::make_passwd(realm, user, pass)
34
- end
35
-
36
- ##
37
- # Sets a password in +realm+ with +user+ and +password+ for the
38
- # auth_type of this database.
39
-
40
- def set_passwd(realm, user, pass)
41
- self[user] = pass
42
- end
43
-
44
- ##
45
- # Retrieves a password in +realm+ for +user+ for the auth_type of this
46
- # database. +reload_db+ is a dummy value.
47
-
48
- def get_passwd(realm, user, reload_db=false)
49
- make_passwd(realm, user, self[user])
50
- end
51
- end
52
- end
53
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # httpauth.rb -- HTTP access authentication
4
- #
5
- # Author: IPR -- Internet Programming with Ruby -- writers
6
- # Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
7
- # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
8
- # reserved.
9
- #
10
- # $IPR: httpauth.rb,v 1.14 2003/07/22 19:20:42 gotoyuzo Exp $
11
-
12
- require_relative 'httpauth/basicauth'
13
- require_relative 'httpauth/digestauth'
14
- require_relative 'httpauth/htpasswd'
15
- require_relative 'httpauth/htdigest'
16
- require_relative 'httpauth/htgroup'
17
-
18
- module WEBrick
19
-
20
- ##
21
- # HTTPAuth provides both basic and digest authentication.
22
- #
23
- # To enable authentication for requests in WEBrick you will need a user
24
- # database and an authenticator. To start, here's an Htpasswd database for
25
- # use with a DigestAuth authenticator:
26
- #
27
- # config = { :Realm => 'DigestAuth example realm' }
28
- #
29
- # htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
30
- # htpasswd.auth_type = WEBrick::HTTPAuth::DigestAuth
31
- # htpasswd.set_passwd config[:Realm], 'username', 'password'
32
- # htpasswd.flush
33
- #
34
- # The +:Realm+ is used to provide different access to different groups
35
- # across several resources on a server. Typically you'll need only one
36
- # realm for a server.
37
- #
38
- # This database can be used to create an authenticator:
39
- #
40
- # config[:UserDB] = htpasswd
41
- #
42
- # digest_auth = WEBrick::HTTPAuth::DigestAuth.new config
43
- #
44
- # To authenticate a request call #authenticate with a request and response
45
- # object in a servlet:
46
- #
47
- # def do_GET req, res
48
- # @authenticator.authenticate req, res
49
- # end
50
- #
51
- # For digest authentication the authenticator must not be created every
52
- # request, it must be passed in as an option via WEBrick::HTTPServer#mount.
53
-
54
- module HTTPAuth
55
- module_function
56
-
57
- def _basic_auth(req, res, realm, req_field, res_field, err_type,
58
- block) # :nodoc:
59
- user = pass = nil
60
- if /^Basic\s+(.*)/o =~ req[req_field]
61
- userpass = $1
62
- user, pass = userpass.unpack("m*")[0].split(":", 2)
63
- end
64
- if block.call(user, pass)
65
- req.user = user
66
- return
67
- end
68
- res[res_field] = "Basic realm=\"#{realm}\""
69
- raise err_type
70
- end
71
-
72
- ##
73
- # Simple wrapper for providing basic authentication for a request. When
74
- # called with a request +req+, response +res+, authentication +realm+ and
75
- # +block+ the block will be called with a +username+ and +password+. If
76
- # the block returns true the request is allowed to continue, otherwise an
77
- # HTTPStatus::Unauthorized error is raised.
78
-
79
- def basic_auth(req, res, realm, &block) # :yield: username, password
80
- _basic_auth(req, res, realm, "Authorization", "WWW-Authenticate",
81
- HTTPStatus::Unauthorized, block)
82
- end
83
-
84
- ##
85
- # Simple wrapper for providing basic authentication for a proxied request.
86
- # When called with a request +req+, response +res+, authentication +realm+
87
- # and +block+ the block will be called with a +username+ and +password+.
88
- # If the block returns true the request is allowed to continue, otherwise
89
- # an HTTPStatus::ProxyAuthenticationRequired error is raised.
90
-
91
- def proxy_basic_auth(req, res, realm, &block) # :yield: username, password
92
- _basic_auth(req, res, realm, "Proxy-Authorization", "Proxy-Authenticate",
93
- HTTPStatus::ProxyAuthenticationRequired, block)
94
- end
95
- end
96
- end