pangdudu-robots 0.2.2 → 0.2.3

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.
@@ -1,21 +1,5 @@
1
1
  <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
2
2
  <busconfig>
3
- <policy user="root">
4
- <allow own="org.robots.Service" />
5
- <allow own="org.ruby.Service" />
6
- </policy>
7
- <policy group="netdev">
8
- <allow own="org.robots.Service" />
9
- <allow own="org.ruby.Service" />
10
- </policy>
11
- <policy group="robots">
12
- <allow own="org.robots.Service" />
13
- <allow own="org.ruby.Service" />
14
- </policy>
15
- <policy at_console="true">
16
- <allow own="org.robots.Service" />
17
- <allow own="org.ruby.Service" />
18
- </policy>
19
3
  <policy context="default">
20
4
  <allow send_destination="org.robots.Service"/>
21
5
  <allow receive_sender="org.robots.Service"/>
@@ -1,7 +1,3 @@
1
- <!-- This configuration file controls the per-user-login-session message bus.
2
- Add a session-local.conf and edit that rather than changing this
3
- file directly. -->
4
-
5
1
  <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
6
2
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
7
3
  <busconfig>
@@ -10,15 +6,13 @@
10
6
 
11
7
  <!-- If we fork, keep the user's original umask to avoid affecting
12
8
  the behavior of child processes. -->
13
- <keep_umask/>
9
+ <!-- <keep_umask/> -->
14
10
 
15
11
  <!-- Listen to everything on tcp! -->
16
12
  <listen>tcp:host=0.0.0.0,port=2687,family=ipv4</listen>
17
13
  <!-- Listen on socket at this file location -->
18
- <listen>unix:path=/tmp/robots_session_bus_socket</listen>
14
+ <!-- <listen>unix:path=/tmp/robots_session_bus_socket</listen> -->
19
15
 
20
- <standard_session_servicedirs />
21
-
22
16
  <policy context="default">
23
17
  <!-- Allow everything to be sent -->
24
18
  <allow send_destination="*" eavesdrop="true"/>
@@ -32,10 +26,4 @@
32
26
  further restrict the above policy for specific services. -->
33
27
  <include>org.robots.service.conf</include>
34
28
 
35
- <!-- raise the service start timeout to 40 seconds as it can timeout
36
- on the live cd on slow machines -->
37
- <limit name="service_start_timeout">60000</limit>
38
-
39
- <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
40
-
41
29
  </busconfig>
@@ -1,2 +1,2 @@
1
1
  #!/bin/bash
2
- dbus-daemon --config-file=remote.session.dbus.conf
2
+ dbus-daemon --config-file=$HOME/.robots/config/remote.session.dbus.conf
@@ -67,7 +67,7 @@ class VisualizerAgent
67
67
  @gui.resize(@width, @height)
68
68
  @gui.show()
69
69
  #just because it's fun
70
- add_dbug_agents
70
+ #add_dbug_agents
71
71
  @app.exec()
72
72
  end
73
73
 
@@ -92,9 +92,9 @@ Thread.new do
92
92
  loop do
93
93
  sleep 1
94
94
  #send an xml message over the system
95
- #alive_msg = va.create_xml_alive_msg
96
- #dlog "alive_msg: #{alive_msg.to_s}"
97
- #va.send_msg alive_msg
95
+ alive_msg = va.create_xml_alive_msg
96
+ dlog "alive_msg: #{alive_msg.to_s}"
97
+ va.send_msg alive_msg
98
98
  end
99
99
  end
100
100
 
@@ -13,24 +13,23 @@ class Robot
13
13
 
14
14
  def initialize
15
15
  dlog "new Robot initialized."
16
- @hostname = Socket.gethostname
17
- @sessiontype = "system" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
18
- @daemonconfig = "~/.robots/config/remote.session.dbus.conf" #listens on path and tcp
19
- @dbusdaemon = nil #we'll start our own dbus-daemon if we have to
20
- @dbussession = nil #get_bus will get one for us
21
- @coreservice = nil #the service we use to export objects with
16
+ @localhost = Socket.gethostname
17
+ @daemonhost = "127.0.0.1"
18
+ @remote = false #if you want to connect remotely, change this value
19
+ @sessiontype = "robots" #could be session,system or robots (use robots, if you want it to work over multiple hosts)
20
+ @daemonconfig = "~/.robots/config/remote.session.dbus.conf" #listens on tcp
21
+ @robots_socket_name = "tcp:host=#{@daemonhost},port=2687,family=ipv4" #look at: ~/.robots/config/remote.session.dbus.conf
22
22
  @robotsservice = "org.robots.Service"
23
23
  @emitterpath = "/org/robots/Service/Emitter"
24
- @emitterinterface = "org.ruby.Service.EmitterInterface"
25
- @listeners = [] # listeners for incoming messages are here
26
- @emitters = {} #holds emitters we use
27
- @infrastructure = {} #holds infrastructure objects
24
+ @emitterinterface = "org.robots.Service.EmitterInterface"
25
+ @coreservice, @dbussession, @dbusdaemon = nil,nil,nil
26
+ @listeners,@emitters,@infrastructure = [],{},{}
28
27
  @servicetypes = fill_servicetypes #refer to robots_infrastructure.rb
29
28
  end
30
29
 
31
30
  #start the mojo
32
31
  def run
33
- check_for_dbus_daemon if @sessiontype.eql? "robots" #will start a daemon if necessary
32
+ check_for_dbus_daemon if @sessiontype.eql? "robots" #will start a dbus-daemon if necessary
34
33
  setup_robots_service
35
34
  register_callbacks
36
35
  #test_messages; #main_loop;
@@ -56,22 +55,24 @@ class Robot
56
55
 
57
56
  #check if a dbus-daemon suitable for robots is running, otherwise start one
58
57
  def check_for_dbus_daemon
59
- @daemonconfig = File.expand_path(@daemonconfig) #dbus-daemon won't accept otherwise
60
- #ok, no config file, not good!
61
- unless File.exist? @daemonconfig
62
- wlog "no daemon config: #{@daemonconfig}!"
63
- wlog "will sleep for 5 seconds,..."
64
- sleep 5 #give the user time to realize
65
- end
66
- #if the config file is there
67
- if File.exist? @daemonconfig
68
- @dbusdaemon = DbusDaemon.new @daemonconfig
69
- got_twins = @dbusdaemon.got_twin_daemon? #check if a daemon like this is already running
70
- ilog "custom dbus-daemon is already running." if got_twins #inform user
71
- unless got_twins #no suitable dbus-daemon running, start one
72
- @dbusdaemon.start_daemon
73
- ilog "custom dbus-daemon started and running, check \"ps x | grep \"dbus-daemon\", if plan a CTRL-C."
74
- #@dbusdaemon.stop_daemon #must get called sometimes, super nasty, use " ps x | grep "dbus-daemon" "
58
+ unless @remote
59
+ @daemonconfig = File.expand_path(@daemonconfig) #dbus-daemon won't accept otherwise
60
+ #ok, no config file, not good!
61
+ unless File.exist? @daemonconfig
62
+ wlog "no daemon config: #{@daemonconfig}!"
63
+ wlog "will sleep for 5 seconds,..."
64
+ sleep 5 #give the user time to realize
65
+ end
66
+ #if the config file is there
67
+ if File.exist? @daemonconfig
68
+ @dbusdaemon = DbusDaemon.new @daemonconfig
69
+ got_twins = @dbusdaemon.got_twin_daemon? #check if a daemon like this is already running
70
+ ilog "custom dbus-daemon is already running." if got_twins #inform user
71
+ unless got_twins #no suitable dbus-daemon running, start one
72
+ @dbusdaemon.start_daemon
73
+ ilog "custom dbus-daemon started and running, check \"ps x | grep \"dbus-daemon\", if plan a CTRL-C."
74
+ #@dbusdaemon.stop_daemon #must get called sometimes, super nasty, use " ps x | grep "dbus-daemon" "
75
+ end
75
76
  end
76
77
  end
77
78
  end
@@ -127,11 +128,16 @@ class Robot
127
128
  def register_callbacks
128
129
  #setup callbacks for infrastructure emitters
129
130
  @emitters.each { |name,emitter| register_emitter_callback name,emitter }
130
- #setup service browser
131
- bus = DBus::SystemBus.instance #needs to be the system bus for the avahi stuff
132
- proxy = bus.introspect("org.freedesktop.Avahi","/")
133
- @avahi = proxy["org.freedesktop.Avahi.Server"]
134
- @servicetypes.each { |name,type| register_service_callback name,type }
131
+ #old systems sometimes don't have avahi
132
+ if DBus::SystemBus.instance.proxy.ListNames[0].include? "org.freedesktop.Avahi"
133
+ #setup service browser
134
+ bus = DBus::SystemBus.instance #needs to be the system bus for the avahi stuff
135
+ proxy = bus.introspect("org.freedesktop.Avahi","/")
136
+ @avahi = proxy["org.freedesktop.Avahi.Server"]
137
+ @servicetypes.each { |name,type| register_service_callback name,type }
138
+ else
139
+ wlog "Sorry, no Avahi service running, no magic service discovery."
140
+ end
135
141
  end
136
142
 
137
143
  #register an emitter callback
@@ -212,9 +218,8 @@ class Robot
212
218
  @dbussession = DBus::SystemBus.instance if @sessiontype.eql? "system"
213
219
  @dbussession = DBus::SessionBus.instance if @sessiontype.eql? "session"
214
220
  if @sessiontype.eql? "robots"
215
- #i somehow feel bad for doing it like this with ENV[]:
216
- @robots_socket_name = "unix:path=/tmp/robots_session_bus_socket" #look at: config/remote.session.dbus.conf
217
221
  DBus.const_set("SessionSocketName", @robots_socket_name) #overwrite the modules constant
222
+ evil_hack_remote_cookie if @remote #i need not say more,...
218
223
  @dbussession = DBus::SessionBus.instance
219
224
  end
220
225
  end
@@ -226,6 +231,27 @@ class Robot
226
231
  return @dbussession
227
232
  end
228
233
 
234
+ #because dbus remote auth still betrays us, we need to hack it
235
+ def evil_hack_remote_cookie
236
+ if @robots_socket_name.include? "tcp:"
237
+ af, port, daemon_name, daemon_addr = (Socket::getaddrinfo(@daemonhost, 2687)).first
238
+ ilog "Trying to get/hack remote cookie from: #{daemon_name}."
239
+ begin
240
+ cookiepath = "#{ENV['HOME']}/.dbus-keyrings/org_freedesktop_general"
241
+ #oki, the scp magic only works, if you use sshkeys
242
+ `scp #{daemon_addr}:.dbus-keyrings/org_freedesktop_general #{cookiepath}`
243
+ if File.exist? cookiepath
244
+ cookie = File.open(cookiepath)
245
+ dlog "Got cookie: #{cookie.gets}"
246
+ end
247
+ rescue
248
+ elog "Oops, something is wrong."
249
+ end
250
+ else
251
+ dlog "Nothing to hack, boring."
252
+ end
253
+ end
254
+
229
255
  #functions used by the module end here
230
256
 
231
257
  #dbus main loop
@@ -27,9 +27,9 @@ module RobotsXml
27
27
 
28
28
  #create an alive message
29
29
  def create_xml_alive_msg
30
- @hostname = "localhost" if @hostname.nil? #more fun with hostname
30
+ @localhost = "localhost" if @localhost.nil? #more fun with hostname
31
31
  @roboname = "Nameless" if @roboname.nil? #at least it's nameless
32
- robotsid = "#{@hostname}.#{@roboname.gsub(" ","_")}" #looks cooler
32
+ robotsid = "#{@localhost}.#{@roboname.gsub(" ","_")}" #looks cooler
33
33
  msg = create_xml_msg { |b| b.info("#{@roboname} alive","alive"=>"#{robotsid}","timestamp" => "#{Time.now}") }
34
34
  return msg
35
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pangdudu-robots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pangdudu
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-17 00:00:00 -07:00
12
+ date: 2009-07-27 00:00:00 -07:00
13
13
  default_executable: robots
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pangdudu-ruby-dbus-daemon
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: pangdudu-ruby-dbus
17
27
  type: :runtime
@@ -61,6 +71,7 @@ files:
61
71
  - funky-examples/memory-agent/memory_generator_agent.rb
62
72
  has_rdoc: true
63
73
  homepage: http://github.com/pangdudu/robots
74
+ licenses:
64
75
  post_install_message:
65
76
  rdoc_options: []
66
77
 
@@ -81,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
92
  requirements: []
82
93
 
83
94
  rubyforge_project: http://github.com/pangdudu/robots
84
- rubygems_version: 1.2.0
95
+ rubygems_version: 1.3.5
85
96
  signing_key:
86
97
  specification_version: 2
87
98
  summary: more robots!