ipcam 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3646608decd74c82db0631040a7ddd1b4f94ae1feef0ae39272505a4b27e45f
4
- data.tar.gz: bf43c0a17f8e99a083776aa4e983ab86525dc1cdf0f3949588549f54dd2662af
3
+ metadata.gz: 560d7ab712390e744d5068a4cf67a753f43121aafa61864a080e221053adaeb1
4
+ data.tar.gz: eb294046cfa0d83dbffe18067f82e7fea65169dd45168cb6f8cd641d6c7de4bb
5
5
  SHA512:
6
- metadata.gz: 56806547cb2de27720261e2c026337709e505f05ac8c73a9581f2d692a81af66c1358b4b99cc174e9035243e60aaaeecff87fb4b2ab080f5c6d75f8a1995536b
7
- data.tar.gz: 15787dd7f41e5a406e50d8b9ffc4c6fc3802e677b1680a3aa5b9e4d29bb711c4af91495a28e2c6465aca9cc65f03fc4f6afc7ac90e69b7bf8a4d4642c1d1efb6
6
+ metadata.gz: f01b1b5825e9016e857d4fa74ed464dfa2d3476ac2a8dfc3413ea6f22ccaceb571369bd0785a3c0b2ce2336cc4059e7da5cbff6f8cf13d82e0d650294783e266
7
+ data.tar.gz: 32b7d575b904f7fa1703c45a9e84ec47a22849c5a26cfb6522d7cb4d9a45e5ea8c10133b23c84193949133847bf7e0cb227104c1910338e2fc38e9dd8b67a4cb
data/README.md CHANGED
@@ -25,8 +25,8 @@ options:
25
25
  --use-ssl
26
26
  --ssl-cert=CRT-FILE
27
27
  --ssl-key=KEY-FILE
28
- -D, --digest-auth=FILE
29
- -A, --add-user=USER,PASSWD
28
+ -D, --digest-auth=YAML-FILE
29
+ -A, --add-user
30
30
  --bind=ADDR
31
31
  --port=PORT
32
32
  -d, --database-file=FILE
@@ -57,8 +57,9 @@ Then connect to port 4567 by http browser and operate. The accessible URLs are a
57
57
  <dt>-D, --digest-auth=YAML-FILE</dt>
58
58
  <dd>Specifies to use restrict access by Digest Authentication. This argument is followed by a password file written in YAML.</dd>
59
59
 
60
- <dt>-A, --add-user=USER-NAME,PASSWORD</dt>
61
- <dd>Add entry to the password file. If you specify this option, only to add an entry to the password file to exit this application.</dd>
60
+ <dt>-A, --add-user</dt>
61
+ <dd>Add entry to the password file. If this option is specified, the user name and password must be specified as arguments. And if you specify this option, only to add an entry to the password file to exit this application.<br>
62
+ Overwrites the entry if you specify an existing user name.</dd>
62
63
 
63
64
  <dt>--bind=ADDR</dt>
64
65
  <dd>Specify the address to which the HTTP server binds. by default, IPv6 any address("::") is used.</dd>
@@ -91,13 +92,13 @@ This file can be created using the "--add-user" option. The actual procedure is
91
92
  ##### create password file, and add user "foo"
92
93
  If specified password file does not exist and the "--digest-auth" and "--add-user" options are specified together, new password file containing user entry will be created.
93
94
  ```
94
- ipcam --digest-auth passwd.yml --add-user foo,XXXXXXX
95
+ ipcam --digest-auth passwd.yml --add-user foo XXXXXXX
95
96
  ```
96
97
 
97
98
  ##### and add user "bar"
98
99
  If specified password file exists and the "--digest-auth" option and "--add-user" option are specified together, a user entry is added to the password file.
99
100
  ```
100
- ipcam --digest-auth passwd.yml --add-user bar,YYYYYY
101
+ ipcam --digest-auth passwd.yml --add-user bar YYYYYY
101
102
  ```
102
103
 
103
104
  #### Run the server
@@ -109,7 +110,7 @@ ipcam --digest-auth passwd.yml --use-ssl --ssl-cert cert/server.crt --ssl-key ce
109
110
  #### Delete user from password file
110
111
  To delete a user, edit the YAML file directly.
111
112
 
112
- ### device-file
113
+ ### Device file
113
114
  specify target device file (ex: /dev/video1). if omittedm, it will use "/dev/video0".
114
115
 
115
116
  ## etc
data/bin/ipcam CHANGED
@@ -11,7 +11,6 @@ require 'pathname'
11
11
  require 'optparse'
12
12
  require 'logger'
13
13
  require 'yaml'
14
- require 'digest/md5'
15
14
 
16
15
  Thread.abort_on_exception = true
17
16
 
@@ -46,50 +45,28 @@ OptionParser.new { |opt|
46
45
  :level => :INFO
47
46
  }
48
47
 
49
- opt.version = IPCam::VERSION
50
- opt.banner += " [DEVICE-FILE]"
48
+ opt.version = IPCam::VERSION
49
+ opt.banner += " [DEVICE-FILE]"
51
50
 
52
51
  opt.on('--use-ssl') {
53
- $use_ssl = true
52
+ $use_ssl = true
54
53
  }
55
54
 
56
55
  opt.on('--ssl-cert=CRT-FILE', String) { |val|
57
- $ssl_cert = val
56
+ $ssl_cert = val
58
57
  }
59
58
 
60
59
  opt.on('--ssl-key=KEY-FILE', String) { |val|
61
- $ssl_key = val
60
+ $ssl_key = val
62
61
  }
63
62
 
64
63
  opt.on('-D', '--digest-auth=FILE', String) { |val|
65
- $use_dauth = true
66
- $pwd_file = Pathname.new(val)
67
-
68
- if $pwd_file.exist?
69
- if $pwd_file.world_readable? || $pwd_file.world_writable?
70
- raise("password file shall be not world readble/writable")
71
- end
72
-
73
- $pwd_db = YAML.load_file(val)
74
- else
75
-
76
- $pwd_db = {}
77
- end
64
+ $use_dauth = true
65
+ $passwd_file = Pathname.new(val)
78
66
  }
79
67
 
80
- opt.on('-A', '--add-user=USER,PASSWD', Array) { |val|
81
- raise("passwd file is not specified") if not $pwd_db
82
- raise("user \"#{val[0]}\" is already exist") if $pwd_db.include?(val[0])
83
-
84
- $pwd_db[val[0]] = \
85
- Digest::MD5.hexdigest("#{val[0]}:#{TRADITIONAL_NAME}:#{val[1]}")
86
-
87
- $pwd_file.open("w") { |f|
88
- f.chmod(0o600)
89
- f.write($pwd_db.to_yaml)
90
- }
91
-
92
- exit
68
+ opt.on('-A', '--add-user-mode') {
69
+ $add_user_mode = true
93
70
  }
94
71
 
95
72
  opt.on('--bind=ADDR') { |val|
@@ -102,7 +79,7 @@ OptionParser.new { |opt|
102
79
  }
103
80
 
104
81
  opt.on('-d', '--database-file=FILE') { |val|
105
- $db_file = Pathname.new(val)
82
+ $db_file = Pathname.new(val)
106
83
  }
107
84
 
108
85
  opt.on('-e', '--extend-header') { |val|
@@ -147,26 +124,51 @@ OptionParser.new { |opt|
147
124
  $log_device = STDOUT
148
125
  end
149
126
 
150
- $logger = Logger.new($log_device,
151
- log[:shift_age],
152
- log[:shift_size],
153
- :level => log[:level],
154
- :datetime_format => "%Y-%m-%dT%H:%M:%S")
127
+ $logger = Logger.new($log_device,
128
+ log[:shift_age],
129
+ log[:shift_size],
130
+ :level => log[:level],
131
+ :datetime_format => "%Y-%m-%dT%H:%M:%S")
155
132
 
156
133
  $bind_addr ||= "::"
157
134
  $http_port ||= 4567
158
135
  $ws_port ||= 4568
159
136
  $db_file ||= Pathname.new(ENV['HOME']) + ".#{APP_NAME}.db"
160
- $target = ARGV[0] || "/dev/video0"
161
137
 
162
138
  if $db_file.exist? and (not $db_file.writable?)
163
139
  raise("#{$db_file.to_s} is not writable")
164
140
  end
165
141
 
166
142
  if $use_ssl
143
+ $ssl_cert ||= ENV["SSL_CERT_FILE"]
144
+ $ssl_key ||= ENV["SSL_KEY_FILE"]
145
+
167
146
  raise("SSL cert file not specified") if not $ssl_cert
168
147
  raise("SSL key file not specified") if not $ssl_key
169
148
  end
149
+
150
+ if $use_dauth
151
+ if $passwd_file.exist?
152
+ if $passwd_file.world_readable? || $passwd_file.world_writable?
153
+ raise("password file shall be not world readble/writable")
154
+ end
155
+
156
+ $passwd_db = YAML.load_file($passwd_file)
157
+ raise("invalid password db") if not $passwd_db.kind_of?(Hash)
158
+ else
159
+
160
+ $passwd_db = {}
161
+ end
162
+ end
163
+
164
+ if $add_user_mode
165
+ raise("password file is not specified") if not $passwd_db
166
+ raise("user name is not specified") if not ARGV[0]
167
+ raise("password is not specified") if not ARGV[1]
168
+
169
+ else
170
+ $target = ARGV[0] || "/dev/video0"
171
+ end
170
172
  }
171
173
 
172
174
  #
@@ -179,4 +181,10 @@ require "#{APP_LIB_DIR + "websock"}"
179
181
  #
180
182
  # アプリケーションの起動
181
183
  #
184
+
185
+ if $add_user_mode
186
+ IPCam::WebServer.add_user(ARGV[0], ARGV[1])
187
+ exit
188
+ end
189
+
182
190
  IPCam.start
data/lib/ipcam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IPCam
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -13,6 +13,7 @@ require 'puma/configuration'
13
13
  require 'puma/events'
14
14
  require 'eventmachine'
15
15
  require 'securerandom'
16
+ require 'digest/md5'
16
17
 
17
18
  module IPCam
18
19
  class WebServer < Sinatra::Base
@@ -184,7 +185,7 @@ module IPCam
184
185
  class << self
185
186
  if $use_dauth
186
187
  def new(*)
187
- ret = Rack::Auth::Digest::MD5.new(super) {|user| $pwd_db[user]}
188
+ ret = Rack::Auth::Digest::MD5.new(super) {|user| $passwd_db[user]}
188
189
 
189
190
  ret.realm = TRADITIONAL_NAME
190
191
  ret.opaque = SecureRandom.alphanumeric(32)
@@ -192,6 +193,20 @@ module IPCam
192
193
 
193
194
  return ret
194
195
  end
196
+
197
+ def make_a1_string(user, pass)
198
+ return Digest::MD5.hexdigest("#{user}:#{TRADITIONAL_NAME}:#{pass}")
199
+ end
200
+ private :make_a1_string
201
+
202
+ def add_user(user, pass)
203
+ $passwd_db[user] = make_a1_string(user, pass)
204
+
205
+ $passwd_file.open("w") { |f|
206
+ f.chmod(0o600)
207
+ f.write($passwd_db.to_yaml)
208
+ }
209
+ end
195
210
  end
196
211
 
197
212
  def bind_url
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipcam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirosho Kuwagata