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 +4 -4
- data/README.md +8 -7
- data/bin/ipcam +47 -39
- data/lib/ipcam/version.rb +1 -1
- data/lib/ipcam/webserver.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 560d7ab712390e744d5068a4cf67a753f43121aafa61864a080e221053adaeb1
|
4
|
+
data.tar.gz: eb294046cfa0d83dbffe18067f82e7fea65169dd45168cb6f8cd641d6c7de4bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
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
|
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
|
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
|
-
###
|
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
|
50
|
-
opt.banner
|
48
|
+
opt.version = IPCam::VERSION
|
49
|
+
opt.banner += " [DEVICE-FILE]"
|
51
50
|
|
52
51
|
opt.on('--use-ssl') {
|
53
|
-
$use_ssl
|
52
|
+
$use_ssl = true
|
54
53
|
}
|
55
54
|
|
56
55
|
opt.on('--ssl-cert=CRT-FILE', String) { |val|
|
57
|
-
$ssl_cert
|
56
|
+
$ssl_cert = val
|
58
57
|
}
|
59
58
|
|
60
59
|
opt.on('--ssl-key=KEY-FILE', String) { |val|
|
61
|
-
$ssl_key
|
60
|
+
$ssl_key = val
|
62
61
|
}
|
63
62
|
|
64
63
|
opt.on('-D', '--digest-auth=FILE', String) { |val|
|
65
|
-
$use_dauth
|
66
|
-
$
|
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
|
81
|
-
|
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
|
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
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
data/lib/ipcam/webserver.rb
CHANGED
@@ -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| $
|
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
|