ban 0.0.1 → 0.1.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc1YjBmYzk5YTJkMzczMzEyZTNjZTE3MGExNjNhNDg3NGJmMTEyNg==
4
+ OGFmMWY5Y2IzODBjODkzMTk5OTc5NTU5NzRlYjIyM2QzMTgxMTYwZQ==
5
5
  data.tar.gz: !binary |-
6
- ZTg0MzMwZGNjOGI0M2I1NjYzOGUxOTY0YjFmMzgzYmI2NzZmZmRmNw==
6
+ ZWZkMWMyZWI0OWZkNDk1YzBmMWRmMjQyMjZmZWEwZDUzNDdiY2FkYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmIzODg4ZTMyNTI3NmRhNDY5NmUxMWI4YWJlYTllOGFlNDdhM2ZkNTU0MTA2
10
- MWM4MzczYTJjNDk3YWU0M2M0NWM0N2QxZGM0NTY3YzgxNTcxNWY3YmQ0MDFh
11
- YTBhMzY2YjEzNjE2NjEzNmRjYTEyYzQyN2MxMjQxNTAzZmRkZTU=
9
+ NjE2OTM4NzNjYWJhYzI3NTg0YWE5ZWQzYjgzMmJlODgyMDlhMGEzM2ExODNh
10
+ MTg2OTdiMTZkY2M3NzIxMzQ5OTJhNTUxNTExMTA1NjRhZGFmODI2MjYyNDEz
11
+ MDI2ZGRhNjA0YjgxMGM4MTY0N2MyZWY1MzYxMTZlNDk1ODljNWI=
12
12
  data.tar.gz: !binary |-
13
- MzNlZjlmZGIxYWUwNDA4MzMxYzE5MTE2ZmQ4Njc0YzljZjliNjU2MmRjZGQz
14
- OTAyMTQzZGEzNDAwYTE3M2FlMDY3ZTJkZDEzYjhkMzJlMTBmN2NjNmIzODM3
15
- OWM3MTdiZTM5NWJjNTlmYzcyYjQyMjlmZGJlMWZjMzllYTYyZWM=
13
+ Yjk0ODcyZDYwMWJmMWU1OGYyZTQyMjA5ZmE3NTM3OTgzNTE0ZDNkMDAxOTI1
14
+ YTEwNTEzZWJlMzRmMzNkNjExYzljYzc5NTQ5YzBhMzcyNjQyYzA0OTViOWIy
15
+ MWNmZDEyN2M4MDdhZTNjNmMyNDY4YmE3YTFiMmYzYzY5ZTE5ZDM=
data/bin/ban CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $0 = 'ban'
3
4
  begin
4
5
  require 'ban'
5
6
  rescue LoadError
data/init/ban.conf ADDED
@@ -0,0 +1,13 @@
1
+ # Upstart configuration file
2
+ # Note: expects ban to be installed with the system ruby.
3
+ description "Starts the ban home control system"
4
+ version "0.0.1"
5
+
6
+ start on runlevel [2345]
7
+ stop on runlevel [016]
8
+
9
+ chdir "/tmp"
10
+ exec /usr/bin/ruby -S ban server
11
+ respawn
12
+
13
+ console log
data/lib/ban/cli.rb CHANGED
@@ -3,6 +3,10 @@ module Ban
3
3
  option :device, default: nil
4
4
  option :port, type: :numeric, default: 8080
5
5
  option :interface, type: :string, default: '0.0.0.0'
6
+ option :user, type: :string, default: 'dialout'
7
+ option :group, type: :string, default: 'nobody'
8
+ option :chroot, type: :string, default: Dir.getwd
9
+ option :em_threads, type: :numeric, default: 4
6
10
  desc "server", "starts the ban server"
7
11
  def server
8
12
  device = options[:device]
@@ -10,9 +14,10 @@ module Ban
10
14
  port = options[:port]
11
15
 
12
16
  EM.epoll
17
+ EM.threadpool_size = options[:em_threads]
13
18
  EM.run do
14
19
  board = Board.new
15
- server = Server.new
20
+ server = Server.new(options[:user], options[:group], options[:chroot])
16
21
 
17
22
  board.on :event do |event|
18
23
  if event.valid?
data/lib/ban/server.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  module Ban
2
2
  class Server
3
3
  include EventEmitter
4
- def initialize
4
+
5
+ def initialize(user, group, chroot)
5
6
  @clients = []
7
+ @user, @group, @chroot = user, group, chroot
6
8
  end
7
9
 
8
10
  def broadcast(event)
@@ -13,6 +15,7 @@ module Ban
13
15
 
14
16
  def start(interface, port)
15
17
  @server = EM::WebSocket.run(host: interface, port: port) do |ws|
18
+ drop_priviledges!
16
19
  ws.onopen do |handshake|
17
20
  Ban::Logger.debug "WebSocket connection open"
18
21
  @clients << ws
@@ -33,5 +36,15 @@ module Ban
33
36
  end
34
37
  end
35
38
  end
39
+
40
+ def drop_priviledges!
41
+ gid = Etc.getgrnam(@user).gid
42
+ uid = Etc.getpwnam(@group).uid
43
+ Dir.chroot(@chroot)
44
+ Process::Sys.setgid(gid)
45
+ Process::Sys.setuid(uid)
46
+ rescue => ex
47
+ Ban::Logger.warn "Dropping the proviledges didn't work: #{ex}"
48
+ end
36
49
  end
37
50
  end
data/lib/ban/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ban
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0.pre0"
3
3
  end
data/lib/ban.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ban/version'
2
2
  require 'logger'
3
3
  require 'json'
4
+ require 'etc'
4
5
 
5
6
  # used gems
6
7
  require 'eventmachine'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0.pre0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Landgraf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,7 @@ files:
144
144
  - doc/ban-layout.svg
145
145
  - doc/ban.fzz
146
146
  - examples/client.rb
147
+ - init/ban.conf
147
148
  - ino.ini
148
149
  - lib/ban.rb
149
150
  - lib/ban/board.rb
@@ -175,9 +176,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
176
  version: '0'
176
177
  required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  requirements:
178
- - - ! '>='
179
+ - - ! '>'
179
180
  - !ruby/object:Gem::Version
180
- version: '0'
181
+ version: 1.3.1
181
182
  requirements: []
182
183
  rubyforge_project:
183
184
  rubygems_version: 2.0.6