gnms 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gnms might be problematic. Click here for more details.

Files changed (140) hide show
  1. data/LICENSE +459 -0
  2. data/README +29 -0
  3. data/bin/gnms +11 -0
  4. data/gnms.gemspec +70 -0
  5. data/lib/cmd_parse.rb +747 -0
  6. data/lib/config_global.rb +414 -0
  7. data/lib/contact.rb +171 -0
  8. data/lib/external/crypt/blowfish-tables.rb +190 -0
  9. data/lib/external/crypt/blowfish.rb +110 -0
  10. data/lib/external/crypt/cbc.rb +123 -0
  11. data/lib/external/crypt/stringxor.rb +27 -0
  12. data/lib/external/fog.rb +41 -0
  13. data/lib/external/jjmx.rb +45 -0
  14. data/lib/external/sms.rb +282 -0
  15. data/lib/external/xmpp4r-simple.rb +497 -0
  16. data/lib/format.rb +85 -0
  17. data/lib/gnms.rb +329 -0
  18. data/lib/gui/about_window.rb +177 -0
  19. data/lib/gui/adddelnode.rb +799 -0
  20. data/lib/gui/base_window.rb +789 -0
  21. data/lib/gui/canvas_map.rb +498 -0
  22. data/lib/gui/charts/gruff.rb +51 -0
  23. data/lib/gui/color_macro.rb +145 -0
  24. data/lib/gui/config_window.rb +2151 -0
  25. data/lib/gui/custom_plugin_window.rb +90 -0
  26. data/lib/gui/debug_window.rb +46 -0
  27. data/lib/gui/event_window.rb +469 -0
  28. data/lib/gui/find_node_window.rb +438 -0
  29. data/lib/gui/help_window.rb +47 -0
  30. data/lib/gui/ipcalculator.rb +147 -0
  31. data/lib/gui/jmx_ref_window.rb +309 -0
  32. data/lib/gui/link_view.rb +46 -0
  33. data/lib/gui/mib_browser.rb +585 -0
  34. data/lib/gui/node_host_property.rb +3712 -0
  35. data/lib/gui/node_host_view.rb +270 -0
  36. data/lib/gui/node_network_property.rb +1059 -0
  37. data/lib/gui/node_network_view.rb +186 -0
  38. data/lib/gui/node_view.rb +672 -0
  39. data/lib/gui/oid_ref_window.rb +288 -0
  40. data/lib/gui/snmptrap_ref_window.rb +288 -0
  41. data/lib/gui/sub/account_frame.rb +196 -0
  42. data/lib/gui/sub/contact_frame.rb +519 -0
  43. data/lib/gui/syslog_ref_window.rb +288 -0
  44. data/lib/gui/treenode_window.rb +320 -0
  45. data/lib/gui/update_window.rb +124 -0
  46. data/lib/gui/widgets.rb +169 -0
  47. data/lib/gui/wmi_ref_window.rb +286 -0
  48. data/lib/interface.rb +16 -0
  49. data/lib/ipcalc.rb +266 -0
  50. data/lib/link.rb +45 -0
  51. data/lib/main.rb +1091 -0
  52. data/lib/monitor/client/custom/custom_monitoring.rb +40 -0
  53. data/lib/monitor/client/jmx/jmx_attr_monitoring.rb +36 -0
  54. data/lib/monitor/client/jmx/jmx_monitoring.rb +83 -0
  55. data/lib/monitor/client/jmx/jmx_ref.rb +114 -0
  56. data/lib/monitor/client/snmp/mibs/SNMPv2-MIB.txt +854 -0
  57. data/lib/monitor/client/snmp/mibs/SNMPv2-SMI.txt +344 -0
  58. data/lib/monitor/client/snmp/oid_ref.rb +141 -0
  59. data/lib/monitor/client/snmp/snmp.rb +178 -0
  60. data/lib/monitor/client/snmp/snmp_monitoring.rb +58 -0
  61. data/lib/monitor/client/wmi/wmi.rb +139 -0
  62. data/lib/monitor/client/wmi/wmi_monitoring.rb +60 -0
  63. data/lib/monitor/client/wmi/wmi_ref.rb +141 -0
  64. data/lib/monitor/custom_plugin.rb +50 -0
  65. data/lib/monitor/server/msg_buffer.rb +39 -0
  66. data/lib/monitor/server/snmp/snmptrap_analyzer.rb +81 -0
  67. data/lib/monitor/server/snmp/snmptrap_capture.rb +26 -0
  68. data/lib/monitor/server/snmp/snmptrap_monitoring.rb +32 -0
  69. data/lib/monitor/server/snmp/snmptrap_ref.rb +135 -0
  70. data/lib/monitor/server/snmp/snmptrap_server.rb +50 -0
  71. data/lib/monitor/server/syslog/syslog_analyzer.rb +141 -0
  72. data/lib/monitor/server/syslog/syslog_capture.rb +28 -0
  73. data/lib/monitor/server/syslog/syslog_monitoring.rb +32 -0
  74. data/lib/monitor/server/syslog/syslog_ref.rb +136 -0
  75. data/lib/monitor/server/syslog/syslog_server.rb +43 -0
  76. data/lib/node.rb +1020 -0
  77. data/lib/node_db.rb +2668 -0
  78. data/lib/node_host.rb +215 -0
  79. data/lib/node_listener.rb +639 -0
  80. data/lib/node_network.rb +269 -0
  81. data/lib/node_property.rb +39 -0
  82. data/lib/notify/alarm.rb +247 -0
  83. data/lib/notify/irc_bot.rb +167 -0
  84. data/lib/notify/xmpp_bot.rb +107 -0
  85. data/lib/service.rb +36 -0
  86. data/lib/version.rb +8 -0
  87. data/pixmap/bg/map_bg.jpg +0 -0
  88. data/pixmap/bg/map_bg2.jpg +0 -0
  89. data/pixmap/logo.jpg +0 -0
  90. data/pixmap/logo_icon.png +0 -0
  91. data/pixmap/os/3com.png +0 -0
  92. data/pixmap/os/aix.gif +0 -0
  93. data/pixmap/os/amiga.png +0 -0
  94. data/pixmap/os/beos.png +0 -0
  95. data/pixmap/os/cisco.png +0 -0
  96. data/pixmap/os/freebsd.png +0 -0
  97. data/pixmap/os/hp.png +0 -0
  98. data/pixmap/os/hurd.gif +0 -0
  99. data/pixmap/os/irix.gif +0 -0
  100. data/pixmap/os/linux.png +0 -0
  101. data/pixmap/os/mac.png +0 -0
  102. data/pixmap/os/netbsd.gif +0 -0
  103. data/pixmap/os/netware.png +0 -0
  104. data/pixmap/os/openbsd.png +0 -0
  105. data/pixmap/os/os2warp.gif +0 -0
  106. data/pixmap/os/qnx.gif +0 -0
  107. data/pixmap/os/sco.gif +0 -0
  108. data/pixmap/os/sgi.xpm +111 -0
  109. data/pixmap/os/solaris.gif +0 -0
  110. data/pixmap/os/unix.gif +0 -0
  111. data/pixmap/os/unknown.png +0 -0
  112. data/pixmap/os/vms.xpm +345 -0
  113. data/pixmap/os/windows.png +0 -0
  114. data/pixmap/type/cloud.png +0 -0
  115. data/pixmap/type/device.png +0 -0
  116. data/pixmap/type/firewall.png +0 -0
  117. data/pixmap/type/gateway.png +0 -0
  118. data/pixmap/type/home.png +0 -0
  119. data/pixmap/type/host.png +0 -0
  120. data/pixmap/type/network.png +0 -0
  121. data/pixmap/type/printer.png +0 -0
  122. data/pixmap/type/router.png +0 -0
  123. data/pixmap/type/server.png +0 -0
  124. data/pixmap/type/switch.png +0 -0
  125. data/pixmap/type/vm.png +0 -0
  126. data/plugins/Defaultme.rb +7 -0
  127. data/plugins/DnsCheck.rb +46 -0
  128. data/plugins/FooMonitor.rb +26 -0
  129. data/plugins/HttpVirtualHostMonitor.rb +43 -0
  130. data/plugins/MysqlShowStatusMonitor.rb +64 -0
  131. data/plugins/PgsqlPercentConnectionMonitor.rb +72 -0
  132. data/plugins/SshCpuLoadMonitor.rb +85 -0
  133. data/plugins/SshDiskMonitor.rb +69 -0
  134. data/plugins/SshFgtAvExpiredMonitor.rb +75 -0
  135. data/plugins/SshPercentUsedRamMonitor.rb +74 -0
  136. data/plugins/TelnetCpuLoadMonitor.rb +69 -0
  137. data/plugins/example1.rb +15 -0
  138. data/plugins/example2.rb +7 -0
  139. data/sound/beep.wav +0 -0
  140. metadata +378 -0
@@ -0,0 +1,51 @@
1
+ #
2
+ # this file contains all method to drawing charts
3
+ #
4
+
5
+ def network_status_pie(node, size=400)
6
+
7
+ g=Gruff::Pie.new(size)
8
+ begin
9
+ #this method depends on gruff version
10
+ g.legend_at_bottom=true
11
+ rescue
12
+ end
13
+
14
+ g.theme = {
15
+ :marker_color => 'black',
16
+ :font_color => 'black',
17
+ :background_colors => 'transparent'
18
+ }
19
+
20
+ sev_stat=Array.new($status_value.size,0)
21
+
22
+ node.get_node().each_value do |n|
23
+ sev_stat[$status_value.index(n.status)]+=1
24
+ end
25
+
26
+ status_index=0
27
+ $status.each do |stat|
28
+
29
+ sev_percent=0
30
+ if node.nb_node>0
31
+ sev_percent=(sev_stat[status_index]*100)/node.nb_node.to_f()
32
+ end
33
+ if sev_stat[status_index] > 0
34
+ g.data(sev_stat[status_index].to_s()+" "+stat.capitalize(), [sev_percent.round()], hexa_to_rgb_color_str($status_color[status_index]))
35
+ end
36
+ status_index+=1
37
+ end
38
+
39
+ #g.hide_legend=true
40
+ #g.data("Critical", [1])
41
+ #g.data("Major", [1])
42
+ #g.data("Warning", [1])
43
+ #g.data("Minor", [1])
44
+ #g.data("Normal", [1])
45
+ #g.data("Unmanaged", [1])
46
+ #g.data("Unkown", [1])
47
+
48
+ #g.write('my_test.png')
49
+ return g.to_blob { self.format='PNG' }
50
+
51
+ end
@@ -0,0 +1,145 @@
1
+ #
2
+ # this file contain color variable and function both for node class and other files
3
+ #
4
+
5
+
6
+ #
7
+ # load image, return a pixmap
8
+ #
9
+ def load_image (file, keepisgeometry="")
10
+ if file[0,1] == '/'
11
+ rfile = file
12
+ else
13
+ rfile = "#{PIXMAP_PATH}/#{file}"
14
+ end
15
+ if FileTest.exist? rfile
16
+ im = Gtk::Image.new(rfile)
17
+ else
18
+ print "#{rfile} doesnt exist!","\n"
19
+ load_image "type/pc.gif"
20
+ end
21
+ end
22
+
23
+
24
+ def find_extension (file)
25
+ if FileTest.exist?("#{PIXMAP_PATH}/#{file}.png")
26
+ return "#{file}.png"
27
+ elsif FileTest.exist?("#{PIXMAP_PATH}/#{file}.gif")
28
+ return "#{file}.gif"
29
+ elsif FileTest.exist?("#{PIXMAP_PATH}/#{file}.jpg")
30
+ return "#{file}.jpg"
31
+ elsif FileTest.exist?("#{PIXMAP_PATH}/#{file}.xpm")
32
+ return "#{file}.xpm"
33
+ else
34
+ return "null"
35
+ end
36
+ end
37
+
38
+ #
39
+ # convert rgb to hex color str
40
+ #
41
+ def rgb_to_hex_color(rgb)
42
+ if rgb.class == Gdk::Color
43
+ r,g,b=rgb.to_a()
44
+ r=(r-1)/256 unless r==0
45
+ g=(g-1)/256 unless g==0
46
+ b=(b-1)/256 unless b==0
47
+ hex_result=""
48
+ [r,g,b].each do |comp|
49
+ hex=sprintf("%x",comp)
50
+ if hex == '0'
51
+ hex_result+="00"
52
+ else
53
+ hex_result+=hex
54
+ end
55
+ end
56
+ return hex_result
57
+ end
58
+ end
59
+
60
+ #
61
+ # convert hexa value to a rgb Gdk::Color
62
+ #
63
+ def hexa_to_rgb_color(rgb)
64
+ hexa_str=sprintf("%8x",rgb)
65
+ tab=hexa_str.match(/(.{2})(.{2})(.{2}).{2}/)
66
+ r=tab[1]
67
+ g=tab[2]
68
+ b=tab[3]
69
+
70
+ if r== " "
71
+ r="00"
72
+ elsif b==" "
73
+ b="00"
74
+ end
75
+
76
+ rd=sprintf("%d","0x#{r}")
77
+ gd=sprintf("%d","0x#{g}")
78
+ bd=sprintf("%d","0x#{b}")
79
+
80
+ return Gdk::Color.new(rd.to_i()*256,gd.to_i()*256,bd.to_i()*256)
81
+ end
82
+
83
+ def hexa_to_rgb_color_str(rgb)
84
+
85
+ hexa_str=sprintf("%06x",rgb)
86
+ hexa_str=hexa_str.chop()
87
+ hexa_str=hexa_str.chop()
88
+ if hexa_str.length < 6
89
+ hexa_str="00"+hexa_str
90
+ end
91
+ return "##{hexa_str}"
92
+ end
93
+
94
+ #color
95
+
96
+ $red = hexa_to_rgb_color($status_color[$status.index("CRITICAL")])
97
+ $orange = hexa_to_rgb_color($status_color[$status.index("MAJOR")])
98
+ $yellow = hexa_to_rgb_color($status_color[$status.index("WARNING")])
99
+ $blue = hexa_to_rgb_color($status_color[$status.index("MINOR")])
100
+ $green = hexa_to_rgb_color($status_color[$status.index("NORMAL")])
101
+ $grey = Gdk::Color.new(49151, 49151, 49151)
102
+ $purple = Gdk::Color.new(37888, 26880, 58880)
103
+ #for tooltips background
104
+ $light_yellow = Gdk::Color.new(64515, 62985, 50745)
105
+
106
+ #color style
107
+
108
+ $red_style = Gtk::Style.new
109
+ $orange_style = Gtk::Style.new
110
+ $green_style = Gtk::Style.new
111
+ $grey_style = Gtk::Style.new
112
+ $yellow_style = Gtk::Style.new
113
+ $blue_style = Gtk::Style.new
114
+
115
+ $red_style.set_text(Gtk::STATE_NORMAL, $red.red, $red.green, $red.blue)
116
+ $red_style.set_text(Gtk::STATE_ACTIVE, $red.red, $red.green, $red.blue)
117
+ $red_style.set_bg(Gtk::STATE_NORMAL, $orange.red, $orange.green, $orange.blue)
118
+ $red_style.set_bg(Gtk::STATE_ACTIVE, $orange.red, $orange.green, $orange.blue)
119
+ $red_style.set_bg(Gtk::STATE_PRELIGHT, $orange.red, $orange.green, $orange.blue)
120
+
121
+ $orange_style.set_text(Gtk::STATE_NORMAL, $orange.red, $orange.green, $orange.blue)
122
+ $orange_style.set_text(Gtk::STATE_ACTIVE, $orange.red, $orange.green, $orange.blue)
123
+ $orange_style.set_bg(Gtk::STATE_NORMAL, $orange.red, $orange.green, $orange.blue)
124
+ $orange_style.set_bg(Gtk::STATE_ACTIVE, $orange.red, $orange.green, $orange.blue)
125
+ $orange_style.set_bg(Gtk::STATE_PRELIGHT, $orange.red, $orange.green, $orange.blue)
126
+
127
+ $yellow_style.set_text(Gtk::STATE_NORMAL, $yellow.red, $yellow.green, $yellow.blue)
128
+ $yellow_style.set_text(Gtk::STATE_ACTIVE, $yellow.red, $yellow.green, $yellow.blue)
129
+ $yellow_style.set_bg(Gtk::STATE_NORMAL, $yellow.red, $yellow.green, $yellow.blue)
130
+ $yellow_style.set_bg(Gtk::STATE_ACTIVE, $yellow.red, $yellow.green, $yellow.blue)
131
+ $yellow_style.set_bg(Gtk::STATE_PRELIGHT, $yellow.red, $yellow.green, $yellow.blue)
132
+
133
+ $blue_style.set_text(Gtk::STATE_NORMAL, $blue.red, $blue.green, $blue.blue)
134
+ $blue_style.set_text(Gtk::STATE_ACTIVE, $blue.red, $blue.green, $blue.blue)
135
+ $blue_style.set_bg(Gtk::STATE_NORMAL, $blue.red, $blue.green, $blue.blue)
136
+ $blue_style.set_bg(Gtk::STATE_ACTIVE, $blue.red, $blue.green, $blue.blue)
137
+ $blue_style.set_bg(Gtk::STATE_PRELIGHT, $blue.red, $blue.green, $blue.blue)
138
+
139
+ $green_style.set_bg(Gtk::STATE_NORMAL, $green.red, $green.green, $green.blue)
140
+ $green_style.set_bg(Gtk::STATE_ACTIVE, $green.red, $green.green, $green.blue)
141
+ $green_style.set_bg(Gtk::STATE_PRELIGHT, $green.red, $green.green, $green.blue)
142
+
143
+ $grey_style.set_bg(Gtk::STATE_NORMAL, 49151, 49151, 49151)
144
+ $grey_style.set_bg(Gtk::STATE_ACTIVE, 49151, 49151, 49151)
145
+ $grey_style.set_bg(Gtk::STATE_PRELIGHT, 49151, 49151, 49151)
@@ -0,0 +1,2151 @@
1
+ class ConfigWindow
2
+
3
+ def initialize(cfg)
4
+ @config=cfg
5
+ @old_sev_level=@config.level
6
+ @old_contact=nil
7
+ end
8
+
9
+ #
10
+ # save configuration file as YAML
11
+ #
12
+ def save_config_yaml()
13
+
14
+ fic_tmp=Tempfile.new(File.basename(GLOBAL_CONF_FILE))
15
+
16
+ general = {
17
+ 'default_width' => get_map_width(),
18
+ 'default_height' => get_map_height(),
19
+ 'default_map' => $map,
20
+ 'host_label_view' => $config.host_label_view,
21
+ 'host_icon_view' => $config.host_icon_view,
22
+ 'network_label_view' => $config.network_label_view,
23
+ 'network_icon_view' => $config.network_icon_view,
24
+ 'map_display_view' => $config.map_display_view,
25
+ 'show_label' => @button_show_label.active?,
26
+ 'noshow_fqdn' => @button_noshow_fqdn.active?,
27
+ 'show_tooltips' => @button_show_tooltips.active?,
28
+ 'confirm_delete' => @button_confirm_delete.active?,
29
+ 'confirm_quit' => @button_confirm_quit.active?,
30
+ 'auto_save_map' => @button_auto_save_map.active?,
31
+ 'auto_save_map_value' => @entry_auto_save_map.text.to_i,
32
+ 'log_level' => @combo_log_level.active_text,
33
+ 'mail_server' => @button_mail.active?,
34
+ 'sms_device' => @entry_sms_device.text,
35
+ 'im_daemon' => @button_im.active?,
36
+ 'im_login' => @entry_im_login.text,
37
+ 'im_password' => Base64.encode64(blowfish_encode(@entry_im_password.text)),
38
+ 'irc_daemon' => @button_irc.active?,
39
+ 'irc_server' => @entry_irc_server.text,
40
+ 'irc_port' => @entry_irc_port.text,
41
+ 'irc_channel' => @entry_irc_channel.text
42
+ }
43
+ snmp = {
44
+ 'read_community' => @entry_read_community.text,
45
+ 'write_community' => @entry_write_community.text,
46
+ 'snmp_version' => @combo_snmp_version.active_text,
47
+ 'snmp_port' => @port_spinner.value_as_int,
48
+ 'snmp_timeout' => @timeout_spinner.value_as_int,
49
+ 'snmp_retry' => @retry_spinner.value_as_int
50
+ }
51
+
52
+ notification = {
53
+ 'level_alert_type' => $level_alert_type,
54
+ 'level' => @entry_level.active_text,
55
+ 'mail' => @config.mail_by_level,
56
+ 'sound_file_path' => @config.sound_file_path_by_level,
57
+ 'sms_num' => @config.sms_num_by_level,
58
+ 'im_dest' => @config.im_dest_by_level,
59
+ 'script_name' => @config.script_name_by_level
60
+ }
61
+
62
+ scan = {
63
+ 'broadcast_ping' => {
64
+ 'state' => @button_bp.active?,
65
+ 'delay' => @entry_delay_bp.text.to_i,
66
+ },
67
+ 'mac' => {
68
+ 'state' => @button_macf.active?,
69
+ 'delay' => @entry_delay_macf.text.to_i,
70
+ 'lock' => @button_macl.active?,
71
+ 'manufacturer' => {
72
+ 'state' => @button_macm.active?
73
+ }
74
+ },
75
+ 'node_resolving' => {
76
+ 'state' => @button_nr.active?,
77
+ 'delay' => @entry_delay_nr.text.to_i
78
+ },
79
+ 'port' => {
80
+ 'state' => @button_pm.active?,
81
+ 'delay' => @entry_delay_pm.text.to_i
82
+ },
83
+ 'snmp' => {
84
+ 'state' => @button_snmp.active?,
85
+ 'delay' => @entry_delay_snmp.text.to_i
86
+ },
87
+ 'wmi' => {
88
+ 'state' => @button_wmi.active?,
89
+ 'delay' => @entry_delay_wmi.text.to_i
90
+ },
91
+ 'custom' => {
92
+ 'state' => @button_custom.active?,
93
+ 'delay' => @entry_delay_custom.text.to_i
94
+ },
95
+ 'jmx' => {
96
+ 'state' => @button_jmx.active?,
97
+ 'delay' => @entry_delay_jmx.text.to_i
98
+ },
99
+
100
+ 'syslog' => {
101
+ 'state' => @button_syslog_daemon.active?,
102
+ 'port' => @entry_syslog_daemon_port.text.to_i
103
+ },
104
+ 'snmptrap' => {
105
+ 'state' => @button_snmptrap_daemon.active?,
106
+ 'port' => @entry_snmptrap_daemon_port.text.to_i,
107
+ 'community' => @entry_snmptrap_daemon_community.text
108
+ }
109
+ }
110
+
111
+ path = {
112
+ 'ping' => @entry_ping.text,
113
+ 'nmap' => @entry_nmap.text,
114
+ 'ssh' => @entry_ssh.text,
115
+ 'telnet' => @entry_telnet.text,
116
+ 'browser' => @entry_browser.text,
117
+ 'vncviewer' => @entry_vncviewer.text,
118
+ 'rdesktop' => @entry_rdesktop.text,
119
+ 'terminal' => @entry_xterm.text,
120
+ 'nmblookup' => @entry_nmblookup.text,
121
+ 'xprobe' => @entry_xprobe.text,
122
+ 'wmic' => @entry_wmic.text
123
+ }
124
+
125
+ if @colorchk.active?
126
+ color="color"
127
+ else
128
+ color="image"
129
+ end
130
+
131
+ colors = {
132
+ 'pixmap_size' => @entry_pixmap_size.text.to_i,
133
+ 'bg_type' => color,
134
+ 'label_text' => @cp_label_text.color.to_a(),
135
+ 'label_bg' => @cp_label_bg.color.to_a(),
136
+ 'rgb' => @cp.color.to_a(),
137
+ 'image_path' => @entry_image.filename
138
+ }
139
+
140
+ YAML::dump(general)
141
+ YAML::dump(snmp)
142
+ YAML::dump(notification)
143
+ YAML::dump(scan)
144
+ YAML::dump(path)
145
+ YAML::dump(colors)
146
+
147
+ db = YAML::Store.new(fic_tmp.path)
148
+ db.transaction{
149
+ db['general'] = general
150
+ db['snmp'] = snmp
151
+ db['notification'] = notification
152
+ db['scan'] = scan
153
+ db['path'] = path
154
+ db['colors'] = colors
155
+ }
156
+
157
+ if File.stat(fic_tmp.path).size?
158
+ FileUtils.move(fic_tmp.path, GLOBAL_CONF_FILE)
159
+ $log.info("Configuration file saved as #{GLOBAL_CONF_FILE}")
160
+ @config.read_config_yaml()
161
+ end
162
+ end
163
+
164
+
165
+ #
166
+ # toggle contact selection in contact selection window
167
+ #
168
+ def toggle_contact_selection(path=0)
169
+ #switch all port
170
+ @contact_treeview.model.each {|model, path, iter|
171
+ fixed =iter[0]
172
+ fixed ^= 1
173
+ @contact_selection[path.to_str().to_i()]=fixed
174
+ iter[0] = fixed
175
+ }
176
+ end
177
+
178
+ #
179
+ # list all contact in a treeview and return an array of contact id selected
180
+ #
181
+ def ConfigWindow::contact_selection_window(alarm, contact_selected_array, contact_button)
182
+ @contact_selection=[]
183
+ contact_window=Gtk::Window.new
184
+ contact_window.set_title("Select contact for #{alarm} notifications")
185
+ contact_window.set_size_request(250, 200)
186
+ contact_window.set_modal(true)
187
+
188
+ ls = Gtk::ListStore.new(Integer, String, String)
189
+ @contact_treeview = Gtk::TreeView.new(ls)
190
+
191
+ renderer = Gtk::CellRendererToggle.new
192
+ renderer.signal_connect('toggled') do |cell, path|
193
+ # get toggled iter
194
+ iter = @contact_treeview.model.get_iter(path)
195
+ fixed =iter[0]
196
+ # do something with the value
197
+ fixed ^= 1
198
+ @contact_selection[path.to_i()]=fixed
199
+ # set new value
200
+ iter[0] = fixed
201
+ end
202
+
203
+ column1 = Gtk::TreeViewColumn.new("Selected",
204
+ renderer, {:active => 0})
205
+ column1.set_clickable(true)
206
+ column2 = Gtk::TreeViewColumn.new("FirstName",
207
+ Gtk::CellRendererText.new, {:text => 1})
208
+ column2.set_sort_column_id(1)
209
+ column3 = Gtk::TreeViewColumn.new("LastName",
210
+ Gtk::CellRendererText.new, {:text => 2})
211
+ column3.set_sort_column_id(2)
212
+
213
+ column1.signal_connect("clicked") do |column|
214
+ toggle_contact_selection()
215
+ end
216
+
217
+ @contact_treeview.append_column(column1)
218
+ @contact_treeview.append_column(column2)
219
+ @contact_treeview.append_column(column3)
220
+ @contact_treeview.show
221
+
222
+ #load existing entries
223
+ #copy contact hash
224
+ contact_hash_dup=$contact.dup
225
+ contact_selected_array.each {|contact|
226
+ iter=ls.append
227
+ iter[0] = 1
228
+ iter[1] = contact.firstname
229
+ iter[2] = contact.lastname
230
+ contact_hash_dup.delete("#{contact.firstname}|#{contact.lastname}")
231
+ }
232
+ #add remaining contacts
233
+ contact_hash_dup.each_key {|id|
234
+ iter=ls.append
235
+ iter[0] = 0
236
+ iter[1] = contact_hash_dup[id].firstname
237
+ iter[2] = contact_hash_dup[id].lastname
238
+ } unless !contact_hash_dup
239
+
240
+
241
+ vbox_root = Gtk::VBox::new
242
+ contact_window.add vbox_root
243
+ vbox_root.show
244
+
245
+ vbox_root.add @contact_treeview
246
+ bbox =Gtk::HBox::new(FALSE, 10)
247
+ bbox.border_width=10
248
+ bbox.show
249
+
250
+ ok_button = Gtk::Button.new(Gtk::Stock::OK)
251
+ ok_button.show
252
+ ok_button.signal_connect("clicked") {
253
+ #return an array of selected contact
254
+ old_contact_selected_array=contact_selected_array.dup
255
+ contact_selected_array.clear
256
+ contact_str="Selected contact(s):\n"
257
+ @contact_treeview.model.each {|model, path, iter|
258
+ selected = iter[0]
259
+ firstname = iter[1]
260
+ lastname = iter[2]
261
+
262
+ if selected.to_i == 1
263
+ contact_str+=firstname+" "+lastname+"\n"
264
+ contact_selected_array.push(Contact_selected_info.new(firstname,lastname))
265
+ end
266
+ }
267
+ old_contact_selected_array.each {|contact|
268
+ if !contact_selected_array.include?(contact)
269
+ #so the contact has been removed
270
+ Contact::del_use(contact.firstname, contact.lastname)
271
+ end
272
+
273
+ }
274
+ contact_selected_array.each {|contact|
275
+ if !old_contact_selected_array.include?(contact)
276
+ #so the contact has been added
277
+ Contact::add_use(contact.firstname, contact.lastname)
278
+ end
279
+
280
+ }
281
+ #update the tooltips
282
+ if contact_selected_array.size > 0
283
+ case alarm.downcase
284
+ when "mail" then
285
+ contact_button.set_tooltip_text(contact_str)
286
+ when "sms" then
287
+ contact_button.set_tooltip_text(contact_str)
288
+ when "im" then
289
+ contact_button.set_tooltip_text(contact_str)
290
+ end
291
+ else
292
+ case alarm.downcase
293
+ when "mail" then
294
+ contact_button.set_tooltip_text("")
295
+ when "sms" then
296
+ contact_button.set_tooltip_text("")
297
+ when "im" then
298
+ contact_button.set_tooltip_text("")
299
+ end
300
+ end
301
+ contact_window.destroy
302
+ }
303
+
304
+ cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
305
+ cancel_button.show
306
+ cancel_button.signal_connect("clicked") {
307
+ contact_window.destroy
308
+ }
309
+
310
+ ok_button.set_flags(Gtk::Widget::CAN_DEFAULT)
311
+ bbox.pack_start(ok_button, TRUE, TRUE, 0)
312
+ cancel_button.set_flags(Gtk::Widget::CAN_DEFAULT)
313
+ bbox.pack_start(cancel_button, TRUE, TRUE, 0)
314
+
315
+ separator = Gtk::HSeparator::new()
316
+ separator.show
317
+ vbox_root.pack_start(separator, FALSE, TRUE, 0)
318
+ vbox_root.pack_start(bbox, FALSE, TRUE, 0)
319
+ contact_window.show
320
+ end
321
+
322
+
323
+
324
+ #
325
+ # main config window will all the frames
326
+ #
327
+ def show()
328
+ window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
329
+ window.set_title("Preference")
330
+ window.set_size_request(580,560)
331
+ window.border_width=0
332
+ window.set_modal true
333
+ window.resizable=false
334
+
335
+ #window.set_allow_shrink true
336
+ #window.set_allow_grow false
337
+ window.signal_connect("key_press_event") {|w,e|
338
+ if e.keyval == Gdk::Keyval::GDK_Escape
339
+ cancel_action(window)
340
+ end
341
+ }
342
+
343
+ #init contact
344
+ @old_contact=Hash.new
345
+ $contact.each_key {|id|
346
+ @old_contact[id]=$contact[id].dup
347
+ } unless !$contact
348
+
349
+ box1 = Gtk::VBox.new(FALSE, 0)
350
+ window.add(box1)
351
+ box1.show
352
+
353
+ box2 = Gtk::VBox.new(FALSE, 10)
354
+ box2.border_width=10
355
+ box1.pack_start(box2, TRUE, TRUE, 0)
356
+ box2.show
357
+
358
+ notebook = Gtk::Notebook.new()
359
+ notebook.set_tab_pos(Gtk::POS_TOP)
360
+ box2.pack_start(notebook, TRUE, TRUE, 0)
361
+ notebook.show
362
+
363
+ #onglet 0
364
+ frame = Gtk::Frame::new("Overview")
365
+ frame.border_width=10
366
+ frame.set_size_request(200, 150)
367
+ frame.show
368
+
369
+ table = Gtk::Table.new(13,2,false)
370
+ table.show
371
+ frame.add table
372
+
373
+ @button_show_label = Gtk::CheckButton.new "Display label"
374
+ @button_show_label.set_size_request 10,-1
375
+ @button_show_label.set_active @config.show_label
376
+ @button_show_label.show
377
+ table.attach(@button_show_label,0,1,1,2)
378
+ @button_noshow_fqdn = Gtk::CheckButton.new "Display hostname instead of FQDN"
379
+ @button_noshow_fqdn.set_size_request 10,-1
380
+ @button_noshow_fqdn.set_active @config.noshow_fqdn && @button_show_label.active?
381
+ @button_noshow_fqdn.set_sensitive @config.noshow_fqdn && @button_show_label.active?
382
+ @button_noshow_fqdn.show
383
+ table.attach(@button_noshow_fqdn,0,1,2,3)
384
+
385
+ @button_show_tooltips = Gtk::CheckButton.new "Display node tooltips"
386
+ @button_show_tooltips.set_size_request 10,-1
387
+ @button_show_tooltips.set_active @config.show_tooltips
388
+ @button_show_tooltips.show
389
+ table.attach(@button_show_tooltips,0,1,3,4)
390
+
391
+ @button_confirm_delete = Gtk::CheckButton.new "Confirm before removing node(s)"
392
+ @button_confirm_delete.set_size_request 10,-1
393
+ @button_confirm_delete.set_active @config.confirm_delete
394
+ @button_confirm_delete.show
395
+ table.attach(@button_confirm_delete,0,1,4,5)
396
+
397
+ @button_confirm_quit = Gtk::CheckButton.new "Confirm before quit"
398
+ @button_confirm_quit.set_size_request 10,-1
399
+ @button_confirm_quit.set_active @config.confirm_quit
400
+ @button_confirm_quit.show
401
+ table.attach(@button_confirm_quit,0,1,5,6)
402
+
403
+ label_log_level = Gtk::Label.new "Set log level to "
404
+ @combo_log_level = Gtk::ComboBox.new
405
+ levels = ["Debug", "Info", "Warning", "Error"]
406
+ levels.each { |levl|
407
+ @combo_log_level.append_text(levl)
408
+ }
409
+ ind = levels.index(@config.log_level)
410
+ @combo_log_level.set_active(ind) if ind
411
+
412
+ hbox=Gtk::HBox.new(false)
413
+ hbox.pack_start label_log_level,false,true,0
414
+ hbox.pack_start @combo_log_level,false,false,0
415
+ hbox.show_all
416
+ table.attach(hbox,0,1,6,7)
417
+
418
+ @button_auto_save_map = Gtk::CheckButton.new "Autosave map frequency (in m)"
419
+ @button_auto_save_map.set_active @config.auto_save_map
420
+ hbbox=Gtk::HButtonBox.new()
421
+ @entry_auto_save_map = Gtk::Entry.new
422
+ @entry_auto_save_map.set_size_request(5,-1)
423
+ @entry_auto_save_map.set_max_length 5
424
+ @entry_auto_save_map.set_text(@config.auto_save_map_value.to_s)
425
+ @entry_auto_save_map.set_sensitive @button_auto_save_map.active?
426
+ hbbox.add @entry_auto_save_map
427
+
428
+ @button_auto_save_map.signal_connect("toggled") {
429
+ @entry_auto_save_map.set_sensitive @button_auto_save_map.active?
430
+ }
431
+
432
+ hbox=Gtk::HBox.new()
433
+ hbox.add @button_auto_save_map
434
+ hbox.add hbbox
435
+ hbox.show_all
436
+ table.attach(hbox,0,1,7,8)
437
+
438
+ @button_mail = Gtk::CheckButton.new "Configure mail server"
439
+ @button_mail.set_active @config.mail_server
440
+ hbbox=Gtk::VBox.new(false)
441
+ hbbox.pack_start @button_mail,false,false,0
442
+
443
+ label_mail_server_addr = Gtk::Label.new "Mail server addr"
444
+ label_mail_server_addr.show
445
+ @entry_mail_server_addr = Gtk::Entry.new
446
+ @entry_mail_server_addr.set_editable(true)
447
+ if @config.mail_server_addr == nil
448
+ @entry_mail_server_addr.set_text ConfigGlobal::DEFAULT_MAIL_SERVER
449
+ else
450
+ @entry_mail_server_addr.set_text @config.mail_server_addr
451
+ end
452
+ @entry_mail_server_addr.set_sensitive @button_mail.active?
453
+ @entry_mail_server_addr.show
454
+ bhbox_mail_server_addr=Gtk::HBox.new(true)
455
+ bhbox_mail_server_addr.show
456
+ bhbox_mail_server_addr.pack_start label_mail_server_addr,false,false,0
457
+ bhbox_mail_server_addr.pack_start @entry_mail_server_addr,false,false,0
458
+ hbbox.pack_start bhbox_mail_server_addr,false,false,0
459
+
460
+ label_mail_server_port = Gtk::Label.new "Mail server port"
461
+ label_mail_server_port.show
462
+ @entry_mail_server_port = Gtk::Entry.new
463
+ @entry_mail_server_port.set_editable(true)
464
+ if @config.mail_server_port == nil
465
+ @entry_mail_server_port.set_text ConfigGlobal::DEFAULT_MAIL_SERVER_PORT
466
+ else
467
+ @entry_mail_server_port.set_text @config.mail_server_port.to_s
468
+ end
469
+
470
+ @entry_mail_server_port.set_sensitive @button_mail.active?
471
+ @entry_mail_server_port.show
472
+ bhbox_mail_server_port=Gtk::HBox.new(true)
473
+ bhbox_mail_server_port.show
474
+ bhbox_mail_server_port.pack_start label_mail_server_port,false,false,0
475
+ bhbox_mail_server_port.pack_start @entry_mail_server_port,false,false,0
476
+ hbbox.pack_start bhbox_mail_server_port,false,false,0
477
+ hbbox.show_all
478
+ table.attach(hbbox,0,1,8,9)
479
+
480
+ label_sms_device = Gtk::Label.new "Set SMS device "
481
+ hbox=Gtk::HBox.new(false)
482
+ hbox.pack_start label_sms_device,false,true,0
483
+ @entry_sms_device = Gtk::Entry.new
484
+ if (@config.sms_device!=nil)&&(@entry_sms_device!="")
485
+ @entry_sms_device.set_text(@config.sms_device)
486
+ end
487
+ hbox.pack_start @entry_sms_device,false,false,0
488
+ hbox.show_all
489
+ table.attach(hbox,0,1,9,10)
490
+ ######################################### Instant Messaging part #########################################
491
+ @button_im = Gtk::CheckButton.new "Configure IM bot (login and password)"
492
+ @button_im.set_active @config.im_daemon
493
+ hbbox=Gtk::VBox.new(false)
494
+ hbbox.pack_start @button_im,false,false,0
495
+
496
+ hbox=Gtk::HBox.new(true)
497
+ @entry_im_login = Gtk::Entry.new
498
+
499
+ if (@config.im_login!=nil) && (@config.im_login!="")
500
+ @entry_im_login.set_text(@config.im_login)
501
+ end
502
+ @entry_im_login.set_sensitive @button_im.active?
503
+ hbox.pack_start @entry_im_login,false,false,0
504
+ @entry_im_password = Gtk::Entry.new
505
+ @entry_im_password.visibility=false
506
+ if (@config.im_password!=nil) && (@config.im_password!="")
507
+ @entry_im_password.set_text(@config.im_password)
508
+ end
509
+ @entry_im_password.set_sensitive @button_im.active?
510
+ hbox.pack_start @entry_im_password,false,false,0
511
+ hbbox.pack_start hbox,false,false,0
512
+ hbbox.show_all
513
+ table.attach(hbbox,0,1,10,11)
514
+
515
+ ######################################### IRC part #########################################
516
+ @button_irc = Gtk::CheckButton.new "Configure IRC bot (server, port, channel)"
517
+ @button_irc.set_active @config.irc_daemon
518
+ hbbox=Gtk::VBox.new(false)
519
+ hbbox.add @button_irc
520
+
521
+ hbox=Gtk::HBox.new(true)
522
+ @entry_irc_server = Gtk::Entry.new
523
+ if (@config.irc_server!=nil) && (@config.irc_server!="")
524
+ @entry_irc_server.set_text(@config.irc_server)
525
+ end
526
+ @entry_irc_server.set_sensitive @button_irc.active?
527
+ hbox.add @entry_irc_server
528
+ @entry_irc_port = Gtk::Entry.new
529
+ if (@config.irc_port!=nil) && (@config.irc_port!="")
530
+ @entry_irc_port.set_text(@config.irc_port)
531
+ else
532
+ @entry_irc_port.set_text("6667")
533
+ end
534
+ @entry_irc_port.set_sensitive @button_irc.active?
535
+ hbox.add @entry_irc_port
536
+
537
+ @entry_irc_channel = Gtk::Entry.new
538
+ if (@config.irc_channel!=nil) && (@config.irc_channel!="")
539
+ @entry_irc_channel.set_text(@config.irc_channel)
540
+ end
541
+ @entry_irc_channel.set_sensitive @button_irc.active?
542
+ hbox.add @entry_irc_channel
543
+ hbbox.pack_start hbox,false,false,0
544
+ hbbox.show_all
545
+ table.attach(hbbox,0,1,11,12)
546
+
547
+ ######################################### END IRC part #####################################
548
+
549
+ hbox = Gtk::HBox.new(FALSE, 1)
550
+ hbox.add Gtk::Image.new(Gtk::Stock::PROPERTIES, Gtk::IconSize::MENU)
551
+ hbox.add Gtk::Label::new("General")
552
+ hbox.show_all
553
+ notebook.append_page frame, hbox
554
+
555
+ #onglet 1
556
+
557
+ frame = Gtk::Frame.new("Configuration")
558
+ frame.border_width=10
559
+ frame.set_size_request(300, 300)
560
+ frame.show
561
+
562
+ #read_community write_community version port timeout retry
563
+
564
+ table = Gtk::Table.new(6,2,false)
565
+ table.show
566
+ frame.add table
567
+ label_read_community = Gtk::Label.new "Read community"
568
+ label_read_community.show
569
+ @entry_read_community = Gtk::Entry.new
570
+ if @config.read_community == "" || @config.read_community == nil
571
+ @entry_read_community.set_text "public"
572
+ else
573
+ @entry_read_community.set_text @config.read_community
574
+ end
575
+ @entry_read_community.set_size_request(100,-1)
576
+ @entry_read_community.show
577
+ bbox=Gtk::HButtonBox.new
578
+ bbox.show
579
+ bbox.add @entry_read_community
580
+
581
+ table.attach(label_read_community,0,1,0,1)
582
+ table.attach(bbox,1,2,0,1)
583
+
584
+ label_write_community = Gtk::Label.new "Write community"
585
+ label_write_community.show
586
+ @entry_write_community = Gtk::Entry.new
587
+ if @config.write_community == "" || @config.write_community == nil
588
+ @entry_write_community.set_text "private"
589
+ else
590
+ @entry_write_community.set_text @config.write_community
591
+ end
592
+ @entry_write_community.set_size_request(100,-1)
593
+ @entry_write_community.show
594
+ bbox=Gtk::HButtonBox.new
595
+ bbox.show
596
+ bbox.add @entry_write_community
597
+
598
+ table.attach(label_write_community,0,1,1,2)
599
+ table.attach(bbox,1,2,1,2)
600
+
601
+ label_snmp_version = Gtk::Label.new "SNMP version"
602
+ label_snmp_version.show
603
+ @combo_snmp_version = Gtk::ComboBox.new
604
+ @combo_snmp_version.append_text(SNMPv1)
605
+ @combo_snmp_version.append_text(SNMPv2)
606
+ if @config.snmp_version == "" || @config.snmp_version == nil || @config.snmp_version == "1"
607
+ @combo_snmp_version.set_active(0)
608
+ else
609
+ @combo_snmp_version.set_active(1)
610
+ end
611
+ @combo_snmp_version.set_size_request(100,-1)
612
+ @combo_snmp_version.show
613
+ bbox=Gtk::HButtonBox.new
614
+ bbox.show
615
+ bbox.add @combo_snmp_version
616
+
617
+ table.attach(label_snmp_version,0,1,2,3)
618
+ table.attach(bbox,1,2,2,3)
619
+
620
+ label_snmp_port = Gtk::Label.new "Port"
621
+ label_snmp_port.show
622
+ if @config.snmp_port == "" || @config.snmp_port == nil
623
+ adj = Gtk::Adjustment::new(161.0, 1.0, 65534.0, 1.0, 5.0, 0.0)
624
+ else
625
+ adj = Gtk::Adjustment::new(@config.snmp_port.to_f, 1.0, 65534.0, 1.0, 5.0, 0.0)
626
+ end
627
+ @port_spinner = Gtk::SpinButton::new(adj, 0, 0)
628
+ @port_spinner.set_wrap(true)
629
+ @port_spinner.show
630
+ bbox=Gtk::HButtonBox.new
631
+ bbox.show
632
+ bbox.add @port_spinner
633
+
634
+ table.attach(label_snmp_port,0,1,3,4)
635
+ table.attach(bbox,1,2,3,4)
636
+
637
+ label_snmp_timeout = Gtk::Label.new "Timeout (in s)"
638
+ label_snmp_timeout.show
639
+ if @config.snmp_timeout == "" || @config.snmp_timeout == nil
640
+ adj = Gtk::Adjustment::new(10.0, 1.0, 3600.0, 1.0, 5.0, 0.0)
641
+ else
642
+ adj = Gtk::Adjustment::new(@config.snmp_timeout.to_f, 1.0, 3600.0, 1.0, 5.0, 0.0)
643
+ end
644
+ @timeout_spinner = Gtk::SpinButton::new(adj, 0, 0)
645
+ @timeout_spinner.set_wrap(true)
646
+ @timeout_spinner.show
647
+ bbox=Gtk::HButtonBox.new
648
+ bbox.show
649
+ bbox.add @timeout_spinner
650
+
651
+ table.attach(label_snmp_timeout,0,1,4,5)
652
+ table.attach(bbox,1,2,4,5)
653
+
654
+ label_snmp_retry = Gtk::Label.new "Retry"
655
+ label_snmp_retry.show
656
+ if @config.snmp_retry == "" || @config.snmp_retry == nil
657
+ adj = Gtk::Adjustment::new(1.0, 1.0, 3600.0, 1.0, 5.0, 0.0)
658
+ else
659
+ adj = Gtk::Adjustment::new(@config.snmp_retry.to_f, 1.0, 3600.0, 1.0, 5.0, 0.0)
660
+ end
661
+ @retry_spinner = Gtk::SpinButton::new(adj, 0, 0)
662
+ @retry_spinner.set_wrap(true)
663
+ @retry_spinner.show
664
+ bbox=Gtk::HButtonBox.new
665
+ bbox.show
666
+ bbox.add @retry_spinner
667
+
668
+ table.attach(label_snmp_retry,0,1,5,6)
669
+ table.attach(bbox,1,2,5,6)
670
+
671
+ hbox = Gtk::HBox.new(FALSE, 1)
672
+ hbox.add Gtk::Image.new(Gtk::Stock::EDIT, Gtk::IconSize::MENU)
673
+ hbox.add Gtk::Label::new("SNMP")
674
+ hbox.show_all
675
+ notebook.append_page frame, hbox
676
+
677
+ #tab 2###############################################################################################
678
+ frame = Gtk::Frame::new("Notification based security level")
679
+ frame.border_width=10
680
+ frame.set_size_request(200, 150)
681
+ frame.show
682
+
683
+ @entry_level = Gtk::ComboBox.new
684
+ for l in $LEVEL
685
+ @entry_level.append_text(l)
686
+ end
687
+
688
+ if @config.level == "" || @config.level == nil
689
+ @entry_level.set_active(0)
690
+ else
691
+ @entry_level.set_active($LEVEL.index(@config.level))
692
+ end
693
+ @old_sev_level=@entry_level.active_text
694
+ @entry_level.show
695
+
696
+ bbox=Gtk::VButtonBox.new
697
+ bbox.show
698
+ bbox.add @entry_level
699
+
700
+ frame.add bbox
701
+ chbutton = []
702
+
703
+ for alert_type in $talert_type
704
+ pos=$talert_type.index(alert_type)
705
+
706
+ cb_t=Gtk::CheckButton.new alert_type.capitalize()
707
+ cb_t.set_active($level_alert_type[@entry_level.active_text][pos])
708
+ cb_t.show
709
+ chbutton.push cb_t
710
+ if alert_type == "mail"
711
+ cb_t.set_label("Mail recipient")
712
+ @entry_mail = []
713
+ @entry_mail_button = Gtk::Button.new("Configure contacts")
714
+ if @config.mail_by_level[@config.level]
715
+ @entry_mail=@config.mail_by_level[@config.level]
716
+ end
717
+ @entry_mail_button.set_sensitive(cb_t.active? && @button_mail.active? && (Contact::contact_nb_entry()>0))
718
+ if @entry_mail.size > 0
719
+ contact_str="Selected contact(s):\n"
720
+ @entry_mail.each {|contact|
721
+ contact_str+=contact.firstname+" "+contact.lastname+"\n"
722
+ }
723
+ @entry_mail_button.set_tooltip_text(contact_str)
724
+ end
725
+
726
+ @entry_mail_button.signal_connect("clicked") {
727
+ ConfigWindow::contact_selection_window("Mail",@entry_mail,@entry_mail_button)
728
+ }
729
+
730
+ @entry_mail_button.show
731
+
732
+ bhbox_mail=Gtk::HButtonBox.new
733
+ bhbox_mail.add cb_t
734
+ bhbox_mail.add @entry_mail_button
735
+ bhbox_mail.show
736
+ cb_t.set_sensitive(@button_mail.active? && (Contact::contact_nb_entry()>0))
737
+ @cb_mail=cb_t
738
+ bbox.add bhbox_mail
739
+ elsif alert_type == "beep"
740
+ label_soundfile = Gtk::Label.new "Sound file"
741
+ label_soundfile.show
742
+ @entry_soundfile = Gtk::ComboBox.new
743
+ @entry_soundfile.set_size_request 140,-1
744
+ files=Array.new
745
+ if File.exists?(SOUND_DIR)
746
+ files_tmp=Dir.entries(SOUND_DIR)
747
+ files_tmp << ConfigGlobal::DEFAULT_SOUND_FILE
748
+ files_tmp.each do |val|
749
+ if val.match('[^.]')
750
+ files << val
751
+ @entry_soundfile.append_text(val)
752
+ end
753
+ end
754
+ end
755
+ current_level=@entry_level.active_text
756
+ if @config.sound_file_path_by_level[current_level] != nil
757
+ iter=files.index(@config.sound_file_path_by_level[current_level])
758
+ if iter == nil
759
+ @entry_soundfile.set_active(files.size()-1)
760
+ else
761
+ @entry_soundfile.set_active(iter)
762
+ end
763
+ else
764
+ @entry_soundfile.set_active(files.size()-1)
765
+ end
766
+ @entry_soundfile.show
767
+ bhbox_sound_file=Gtk::HButtonBox.new
768
+ bhbox_sound_file.add cb_t
769
+ bhbox_sound_file.add label_soundfile
770
+ bhbox_sound_file.add @entry_soundfile
771
+ @entry_soundfile.set_sensitive(cb_t.active?)
772
+ label_soundfile.set_sensitive(cb_t.active?)
773
+ bhbox_sound_file.show
774
+ bbox.add bhbox_sound_file
775
+ elsif alert_type == "sms"
776
+ cb_t.set_label("SMS mobile number")
777
+ @entry_sms = []
778
+ @entry_sms_button = Gtk::Button.new("Configure contacts")
779
+ if @config.sms_num_by_level[@config.level]
780
+ @entry_sms=@config.sms_num_by_level[@config.level]
781
+ end
782
+ @entry_sms_button.set_sensitive(cb_t.active? && (Contact::contact_nb_entry()>0) && (@entry_sms_device.text != ""))
783
+ if @entry_sms.size > 0
784
+ contact_str="Selected contact(s):\n"
785
+ @entry_sms.each {|contact|
786
+ contact_str+=contact.firstname+" "+contact.lastname+"\n"
787
+ }
788
+ @entry_sms_button.set_tooltip_text(contact_str)
789
+ end
790
+ @entry_sms_button.signal_connect("clicked") {
791
+ ConfigWindow::contact_selection_window("SMS",@entry_sms, @entry_sms_button)
792
+ }
793
+ @entry_sms_button.show
794
+ bhbox_sms=Gtk::HButtonBox.new
795
+ bhbox_sms.add cb_t
796
+ bhbox_sms.add @entry_sms_button
797
+ bhbox_sms.show
798
+ @cb_sms=cb_t
799
+ @cb_sms.set_sensitive((@entry_sms_device.text != "") && (Contact::contact_nb_entry()>0))
800
+ bbox.add bhbox_sms
801
+ elsif alert_type == "im"
802
+ cb_t.set_label("IM Recipient")
803
+ @entry_im = []
804
+ @entry_im_button = Gtk::Button.new("Configure contacts")
805
+ if @config.im_dest_by_level[@config.level]
806
+ @entry_im=@config.im_dest_by_level[@config.level]
807
+ end
808
+ @entry_im_button.set_sensitive(cb_t.active? && @button_im.active? && (Contact::contact_nb_entry()>0))
809
+ if @entry_im.size > 0
810
+ contact_str="Selected contact(s):\n"
811
+ @entry_im.each {|contact|
812
+ contact_str+=contact.firstname+" "+contact.lastname+"\n"
813
+ }
814
+ @entry_im_button.set_tooltip_text(contact_str)
815
+ end
816
+ @entry_im_button.signal_connect("clicked") {
817
+ ConfigWindow::contact_selection_window("IM",@entry_im, @entry_im_button)
818
+ }
819
+ @entry_im_button.show
820
+ bhbox_im=Gtk::HButtonBox.new
821
+ bhbox_im.add cb_t
822
+ bhbox_im.add @entry_im_button
823
+ bhbox_im.show
824
+ cb_t.set_sensitive(@button_im.active? && (Contact::contact_nb_entry()>0))
825
+ @cb_im=cb_t
826
+ bbox.add bhbox_im
827
+ elsif alert_type == "script"
828
+ cb_t.set_label("Script path to execute")
829
+ @entry_script = Gtk::Entry.new
830
+ @entry_script.show
831
+ if @config.script_name_by_level != nil && @config.script_name_by_level[@config.level] != nil && @config.script_name_by_level[@config.level] != ""
832
+ @entry_script.set_text(@config.script_name_by_level[@config.level])
833
+ cb_t.active=true
834
+ end
835
+ bhbox_script=Gtk::HButtonBox.new
836
+ bhbox_script.add cb_t
837
+ bhbox_script.add @entry_script
838
+ bhbox_script.show
839
+ @entry_script.set_sensitive(cb_t.active?)
840
+ @cb_script=cb_t
841
+ bbox.add bhbox_script
842
+ elsif alert_type == "irc"
843
+ cb_t.set_sensitive(@button_irc.active?)
844
+ @cb_irc=cb_t
845
+ bbox.add cb_t
846
+ else
847
+ bbox.add cb_t
848
+ end
849
+
850
+ cb_t.signal_connect("clicked") {|s|
851
+ lbl=s.label.downcase.gsub(/\s.*/,"")
852
+ pos=$talert_type.index(lbl)
853
+
854
+ $level_alert_type[@entry_level.active_text][pos] = s.active?
855
+ if lbl == "mail"
856
+ @entry_mail_button.set_sensitive(s.active? && (Contact::contact_nb_entry()>0))
857
+ elsif lbl == "beep"
858
+ @entry_soundfile.set_sensitive(s.active?)
859
+ label_soundfile.set_sensitive(s.active?)
860
+ elsif lbl == "sms"
861
+ @entry_sms_button.set_sensitive(s.active? && (Contact::contact_nb_entry()>0))
862
+ elsif lbl == "im"
863
+ @entry_im_button.set_sensitive(s.active? && (Contact::contact_nb_entry()>0))
864
+ elsif lbl == "script"
865
+ @entry_script.set_sensitive(s.active?)
866
+ end
867
+ @config.level = @entry_level.active_text
868
+ }
869
+
870
+ end
871
+
872
+ @button_im.signal_connect("toggled") {
873
+ @entry_im_login.set_sensitive @button_im.active?
874
+ @entry_im_password.set_sensitive @button_im.active?
875
+ if (Contact::contact_nb_entry()==0)
876
+ @cb_im.set_sensitive false
877
+ else
878
+ @cb_im.set_sensitive @button_im.active?
879
+ end
880
+ if !@button_im.active?
881
+ @entry_im_button.set_sensitive @button_im.active?
882
+ end
883
+ }
884
+
885
+ @button_irc.signal_connect("toggled") {
886
+ @entry_irc_server.set_sensitive @button_irc.active?
887
+ @entry_irc_port.set_sensitive @button_irc.active?
888
+ @entry_irc_channel.set_sensitive @button_irc.active?
889
+ @cb_irc.set_sensitive @button_irc.active?
890
+ }
891
+
892
+ @button_mail.signal_connect("toggled") {
893
+ @entry_mail_server_addr.set_sensitive @button_mail.active?
894
+ @entry_mail_server_port.set_sensitive @button_mail.active?
895
+ if (Contact::contact_nb_entry()==0)
896
+ @cb_mail.set_sensitive false
897
+ else
898
+ @cb_mail.set_sensitive @button_mail.active?
899
+ end
900
+ if !@button_mail.active?
901
+ @entry_mail_button.set_sensitive @button_mail.active?
902
+ end
903
+ }
904
+
905
+ @entry_soundfile.signal_connect("changed") {
906
+ if @entry_soundfile.active_text == ConfigGlobal::DEFAULT_SOUND_FILE
907
+ @config.sound_file_path_by_level[@entry_level.active_text] = nil
908
+ else
909
+ @config.sound_file_path_by_level[@entry_level.active_text] = @entry_soundfile.active_text
910
+ end
911
+ }
912
+
913
+ @entry_level.signal_connect("changed") {
914
+ if (@entry_level.active_text != "")
915
+ #store old level info
916
+ @config.mail_by_level[@old_sev_level]=@entry_mail
917
+ if @entry_soundfile.active_text == ConfigGlobal::DEFAULT_SOUND_FILE
918
+ @config.sound_file_path_by_level[@old_sev_level] = nil
919
+ else
920
+ @config.sound_file_path_by_level[@old_sev_level] = @entry_soundfile.active_text
921
+ end
922
+ @config.script_name_by_level[@old_sev_level] = @entry_script.text
923
+ @config.sms_num_by_level[@old_sev_level] = @entry_sms
924
+ @config.im_dest_by_level[@old_sev_level] = @entry_im
925
+
926
+ #reload checkbox depending on level selected
927
+ i=0
928
+ current_level=@entry_level.active_text
929
+ for cb in chbutton
930
+ cb.set_active($level_alert_type[current_level][i])
931
+ i+=1
932
+ end
933
+ #reload specific entry
934
+ if @config.mail_by_level[current_level]
935
+ @entry_mail=@config.mail_by_level[current_level]
936
+ else
937
+ @entry_mail.clear
938
+ end
939
+ if @button_mail.active? && @cb_mail.active? && (Contact::contact_nb_entry()>0)
940
+ @entry_mail_button.set_sensitive true
941
+ else
942
+ @entry_mail_button.set_sensitive false
943
+ end
944
+
945
+ if @config.sound_file_path_by_level[current_level] != nil
946
+ iter=files.index(@config.sound_file_path_by_level[current_level])
947
+ if iter == nil
948
+ @entry_soundfile.set_active(files.size()-1)
949
+ else
950
+ @entry_soundfile.set_active(iter)
951
+ end
952
+ else
953
+ @entry_soundfile.set_active(files.size()-1)
954
+ end
955
+
956
+ if @config.script_name_by_level[current_level] && (@config.script_name_by_level[current_level] != "")
957
+ @entry_script.set_text @config.script_name_by_level[current_level]
958
+ else
959
+ @entry_script.set_text("")
960
+ @cb_script.active=false
961
+ end
962
+
963
+ if @config.sms_num_by_level[current_level]
964
+ @entry_sms=@config.sms_num_by_level[current_level]
965
+ else
966
+ @entry_sms.clear
967
+ end
968
+
969
+ if (@entry_sms_device.text != "") && @cb_sms.active? && (Contact::contact_nb_entry()>0)
970
+ @entry_sms_button.set_sensitive(true)
971
+ else
972
+ @entry_sms_button.set_sensitive(false)
973
+ end
974
+
975
+ if @config.im_dest_by_level[current_level] != nil
976
+ @entry_im=@config.im_dest_by_level[current_level]
977
+ else
978
+ @entry_im.clear
979
+ end
980
+ if @button_im.active? && @cb_im.active? && (Contact::contact_nb_entry()>0)
981
+ @entry_im_button.set_sensitive(true)
982
+ else
983
+ @entry_im_button.set_sensitive(false)
984
+ end
985
+
986
+
987
+ @old_sev_level=current_level
988
+ end
989
+ }
990
+ hbox = Gtk::HBox.new(FALSE, 1)
991
+ hbox.add Gtk::Image.new(Gtk::Stock::FIND_AND_REPLACE, Gtk::IconSize::MENU)
992
+ hbox.add Gtk::Label::new("Alert")
993
+ hbox.show_all
994
+ notebook.signal_connect("switch-page") do |slf, page, page_num|
995
+ #here page number 2 is the third page appended so it's "alert"
996
+ if (page_num == 2)
997
+ val=true
998
+ if (Contact::contact_nb_entry()==0) || (@entry_sms_device.text == "")
999
+ val=false
1000
+ end
1001
+ @cb_sms.set_sensitive(val)
1002
+ @entry_sms_button.set_sensitive(val && @cb_sms.active?)
1003
+ end
1004
+ end
1005
+
1006
+ notebook.append_page frame, hbox
1007
+
1008
+ ##################################contact tab######################################################
1009
+
1010
+ begin
1011
+ eval IO.read("#{GNMSLIB}"+'/gui/sub/contact_frame.rb')
1012
+ rescue Exception => msg
1013
+ $log.error("Can't load contact frame #{msg}")
1014
+ end
1015
+
1016
+ ###################################active monitoring####################################################
1017
+ vbox_frame=Gtk::VBox.new
1018
+ vbox_frame.show
1019
+ frame = Gtk::Frame::new("Active")
1020
+ frame.border_width=10
1021
+ #frame.set_size_request(200, 150)
1022
+ frame.show
1023
+ vbox_frame.add frame
1024
+ table = Gtk::Table.new(5,2,false)
1025
+ table.show
1026
+ frame.add table
1027
+
1028
+ #find hosts using broadcast ping, and if possible arp+lldp sniffing
1029
+ @button_bp = Gtk::CheckButton.new "Find hosts in local segment delay (in s)"
1030
+ @button_bp.set_size_request 10,-1
1031
+ @button_bp.set_active @config.broadcast_ping_state
1032
+ @button_bp.show
1033
+
1034
+ @entry_delay_bp = Gtk::Entry.new
1035
+ @entry_delay_bp.show
1036
+ @entry_delay_bp.set_size_request 5,-1
1037
+ if @config.broadcast_ping_delay == "" || @config.broadcast_ping_delay == nil
1038
+ @entry_delay_bp.set_text "300"
1039
+ else
1040
+ @entry_delay_bp.set_text @config.broadcast_ping_delay.to_s
1041
+ end
1042
+ @entry_delay_bp.set_sensitive @button_bp.active?
1043
+
1044
+ @button_bp.signal_connect("toggled") {
1045
+ @entry_delay_bp.set_sensitive @button_bp.active?
1046
+ }
1047
+
1048
+ table.attach(@button_bp,0,1,2,3)
1049
+ table.attach(@entry_delay_bp,1,2,2,3)
1050
+
1051
+ @button_macf = Gtk::CheckButton.new "Find MAC address delay (in s)"
1052
+ @button_macf.set_active @config.mac_state
1053
+ @button_macf.show
1054
+
1055
+ @entry_delay_macf = Gtk::Entry.new
1056
+ @entry_delay_macf.show
1057
+ @entry_delay_macf.set_size_request 5,-1
1058
+ if @config.mac_delay == "" || @config.mac_delay == nil
1059
+ @entry_delay_macf.set_text "60"
1060
+ else
1061
+ @entry_delay_macf.set_text @config.mac_delay.to_s
1062
+ end
1063
+ @entry_delay_macf.set_sensitive @button_macf.active?
1064
+
1065
+
1066
+ table.attach(@button_macf,0,1,3,4)
1067
+ table.attach(@entry_delay_macf,1,2,3,4)
1068
+
1069
+ @button_macl = Gtk::CheckButton.new "Lock MAC address"
1070
+ @button_macl.set_active @config.mac_lock
1071
+ @button_macl.show
1072
+
1073
+ table.attach(@button_macl,0,1,4,5)
1074
+
1075
+ vbox_macm=Gtk::VBox.new
1076
+
1077
+ @button_macm = Gtk::CheckButton.new "Show manufacturer MAC address"
1078
+ @button_macm.set_active @config.mac_manufacturer
1079
+ @button_macm.show
1080
+ vbox_macm.add @button_macm
1081
+ if !mac_manufacturer_list_exist?()
1082
+ @button_macm.set_active false
1083
+ @button_macm.set_sensitive false
1084
+ #put a download OUIs button
1085
+ @button_macm_dl = Gtk::Button.new("Download MAC manufacturer")
1086
+ @button_macm_dl.signal_connect("clicked"){
1087
+ Thread.start {
1088
+ Gtk.thread_protect do
1089
+ @button_macm_dl.label="Processing OUIs from IEEE"
1090
+ if get_mac_manufacturer_list() == 0
1091
+ @button_macm.set_sensitive(true) unless !@button_macm
1092
+ @button_macm.set_active @config.mac_manufacturer unless !@button_macm
1093
+ @button_macm_dl.hide()
1094
+ else
1095
+ @button_macm_dl.label="Error when processing OUIs from IEEE"
1096
+ end
1097
+ end
1098
+ }
1099
+ }
1100
+ @button_macm_dl.show
1101
+ vbox_macm.add @button_macm_dl
1102
+ end
1103
+ vbox_macm.show
1104
+ table.attach(vbox_macm,0,1,5,6)
1105
+
1106
+ @button_macf.signal_connect("toggled") {
1107
+ @entry_delay_macf.set_sensitive @button_macf.active?
1108
+ @button_macl.set_sensitive @button_macf.active?
1109
+ @button_macm.set_sensitive @button_macf.active? unless !mac_manufacturer_list_exist?()
1110
+ }
1111
+
1112
+ @button_nr = Gtk::CheckButton.new "Node Resolving delay (in s)"
1113
+ @button_nr.set_active @config.node_resolving
1114
+ @button_nr.show
1115
+
1116
+ @entry_delay_nr = Gtk::Entry.new
1117
+ @entry_delay_nr.show
1118
+ @entry_delay_nr.set_size_request 5,-1
1119
+ if @config.node_resolving_delay == "" || @config.node_resolving_delay == nil
1120
+ @entry_delay_nr.set_text "120"
1121
+ else
1122
+ @entry_delay_nr.set_text @config.node_resolving_delay.to_s
1123
+ end
1124
+ if ENV["USER"] != "root"
1125
+ @button_nr.set_active false
1126
+ @button_nr.set_sensitive false
1127
+ @entry_delay_nr.set_sensitive false
1128
+ else
1129
+ @entry_delay_nr.set_sensitive @button_nr.active?
1130
+ end
1131
+
1132
+ @button_nr.signal_connect("toggled") {
1133
+ @entry_delay_nr.set_sensitive @button_nr.active?
1134
+ }
1135
+ table.attach(@button_nr,0,1,6,7)
1136
+ table.attach(@entry_delay_nr,1,2,6,7)
1137
+
1138
+ @button_pm = Gtk::CheckButton.new "Host/Port Monitoring delay (in s)"
1139
+ if @config.nmap_path == ""
1140
+ @button_pm.set_active false
1141
+ else
1142
+ @button_pm.set_active @config.port_mon
1143
+ end
1144
+ @button_pm.show
1145
+
1146
+ @entry_delay_pm = Gtk::Entry.new
1147
+ @entry_delay_pm.show
1148
+ @entry_delay_pm.set_size_request 5,-1
1149
+ if @config.port_mon_delay == "" || @config.port_mon_delay == nil
1150
+ @entry_delay_pm.set_text "60"
1151
+ else
1152
+ @entry_delay_pm.set_text @config.port_mon_delay.to_s
1153
+ end
1154
+ @entry_delay_pm.set_sensitive @button_pm.active?
1155
+
1156
+ if ENV["USER"] != "root"
1157
+ @button_pm.set_active false
1158
+ @button_pm.set_sensitive false
1159
+ @entry_delay_pm.set_sensitive false
1160
+ else
1161
+ @entry_delay_pm.set_sensitive @button_pm.active?
1162
+ end
1163
+
1164
+ @button_pm.signal_connect("toggled") {
1165
+ if @config.nmap_path != ""
1166
+ @entry_delay_pm.set_sensitive @button_pm.active?
1167
+ end
1168
+ }
1169
+ table.attach(@button_pm,0,1,8,9)
1170
+ table.attach(@entry_delay_pm,1,2,8,9)
1171
+
1172
+ @button_snmp = Gtk::CheckButton.new "SNMP monitoring"
1173
+ @button_snmp.set_active @config.snmp_mon
1174
+ @button_snmp.show
1175
+ @entry_delay_snmp = Gtk::Entry.new
1176
+ @entry_delay_snmp.show
1177
+ @entry_delay_snmp.set_size_request 5,-1
1178
+ if @config.snmp_mon_delay == "" || @config.snmp_mon_delay == nil
1179
+ @entry_delay_snmp.set_text "60"
1180
+ else
1181
+ @entry_delay_snmp.set_text @config.snmp_mon_delay.to_s
1182
+ end
1183
+ @entry_delay_snmp.set_sensitive @button_snmp.active?
1184
+
1185
+ @button_snmp.signal_connect("toggled") {
1186
+ @entry_delay_snmp.set_sensitive @button_snmp.active?
1187
+ }
1188
+
1189
+ table.attach(@button_snmp,0,1,9,10)
1190
+ table.attach(@entry_delay_snmp,1,2,9,10)
1191
+
1192
+ @button_wmi = Gtk::CheckButton.new "WMI monitoring"
1193
+ @button_wmi.set_active @config.wmi_mon
1194
+ @button_wmi.show
1195
+ @entry_delay_wmi = Gtk::Entry.new
1196
+ @entry_delay_wmi.show
1197
+ @entry_delay_wmi.set_size_request 5,-1
1198
+ if @config.wmi_mon_delay == "" || @config.wmi_mon_delay == nil
1199
+ @entry_delay_wmi.set_text "60"
1200
+ else
1201
+ @entry_delay_wmi.set_text @config.wmi_mon_delay.to_s
1202
+ end
1203
+ @entry_delay_wmi.set_sensitive @button_wmi.active?
1204
+
1205
+ @button_wmi.signal_connect("toggled") {
1206
+ @entry_delay_wmi.set_sensitive @button_wmi.active?
1207
+ }
1208
+
1209
+ table.attach(@button_wmi,0,1,10,11)
1210
+ table.attach(@entry_delay_wmi,1,2,10,11)
1211
+
1212
+ @button_custom = Gtk::CheckButton.new "Custom monitoring"
1213
+ @button_custom.set_active @config.custom_mon
1214
+ @button_custom.show
1215
+ @entry_delay_custom = Gtk::Entry.new
1216
+ @entry_delay_custom.show
1217
+ @entry_delay_custom.set_size_request 5,-1
1218
+ if @config.custom_mon_delay == "" || @config.custom_mon_delay == nil
1219
+ @entry_delay_custom.set_text "60"
1220
+ else
1221
+ @entry_delay_custom.set_text @config.custom_mon_delay.to_s
1222
+ end
1223
+ @entry_delay_custom.set_sensitive @button_custom.active?
1224
+
1225
+ @button_custom.signal_connect("toggled") {
1226
+ @entry_delay_custom.set_sensitive @button_custom.active?
1227
+ }
1228
+ table.attach(@button_custom,0,1,11,12)
1229
+ table.attach(@entry_delay_custom,1,2,11,12)
1230
+
1231
+ @button_jmx = Gtk::CheckButton.new "JMX monitoring"
1232
+ @button_jmx.set_active @config.jmx_mon
1233
+ @button_jmx.show
1234
+ @entry_delay_jmx = Gtk::Entry.new
1235
+ @entry_delay_jmx.show
1236
+ @entry_delay_jmx.set_size_request 5,-1
1237
+ if @config.jmx_mon_delay == "" || @config.jmx_mon_delay == nil
1238
+ @entry_delay_jmx.set_text "60"
1239
+ else
1240
+ @entry_delay_jmx.set_text @config.jmx_mon_delay.to_s
1241
+ end
1242
+ @entry_delay_jmx.set_sensitive @button_jmx.active?
1243
+
1244
+ @button_jmx.signal_connect("toggled") {
1245
+ @entry_delay_jmx.set_sensitive @button_jmx.active?
1246
+ }
1247
+ table.attach(@button_jmx,0,1,12,13)
1248
+ table.attach(@entry_delay_jmx,1,2,12,13)
1249
+
1250
+ #passive monitoring
1251
+
1252
+ frame_passive = Gtk::Frame::new("Passive")
1253
+ frame_passive.border_width=10
1254
+ frame_passive.show
1255
+ vbox_frame.add frame_passive
1256
+ table_passive = Gtk::Table.new(1,2,false)
1257
+ table_passive.show
1258
+ frame_passive.add table_passive
1259
+
1260
+ @button_syslog_daemon = Gtk::CheckButton.new "Syslog server port"
1261
+ @button_syslog_daemon.set_active @config.syslog_mon
1262
+ @button_syslog_daemon.show
1263
+
1264
+ @entry_syslog_daemon_port = Gtk::Entry.new
1265
+ @entry_syslog_daemon_port.show
1266
+ @entry_syslog_daemon_port.set_size_request 5,-1
1267
+ @entry_syslog_daemon_port.set_max_length 5
1268
+ if @config.syslog_port == "" || @config.syslog_port == nil
1269
+ @entry_syslog_daemon_port.set_text "514"
1270
+ else
1271
+ @entry_syslog_daemon_port.set_text @config.syslog_port.to_s
1272
+ end
1273
+ @entry_syslog_daemon_port.set_sensitive @button_syslog_daemon.active?
1274
+
1275
+ @button_syslog_daemon.signal_connect("toggled") {
1276
+ @entry_syslog_daemon_port.set_sensitive @button_syslog_daemon.active?
1277
+ }
1278
+
1279
+ table_passive.attach(@button_syslog_daemon,0,1,0,1)
1280
+ table_passive.attach(@entry_syslog_daemon_port,1,2,0,1)
1281
+
1282
+ @button_snmptrap_daemon = Gtk::CheckButton.new "SNMP Trap server port"
1283
+ @button_snmptrap_daemon.set_active @config.snmptrap_mon
1284
+ @button_snmptrap_daemon.show
1285
+
1286
+ @entry_snmptrap_daemon_port = Gtk::Entry.new
1287
+ @entry_snmptrap_daemon_port.show
1288
+ @entry_snmptrap_daemon_port.set_size_request 5,-1
1289
+ @entry_snmptrap_daemon_port.set_max_length 5
1290
+ if @config.snmptrap_port == "" || @config.snmptrap_port == nil
1291
+ @entry_snmptrap_daemon_port.set_text "162"
1292
+ else
1293
+ @entry_snmptrap_daemon_port.set_text @config.snmptrap_port.to_s
1294
+ end
1295
+
1296
+ label_snmptrap_daemon_community=Gtk::Label.new("Community")
1297
+ label_snmptrap_daemon_community.set_alignment(0.2,0)
1298
+ label_snmptrap_daemon_community.show
1299
+ @entry_snmptrap_daemon_community = Gtk::Entry.new
1300
+ @entry_snmptrap_daemon_community.show
1301
+ @entry_snmptrap_daemon_community.set_size_request 5,-1
1302
+ if @config.snmptrap_community == "" || @config.snmptrap_community == nil
1303
+ @entry_snmptrap_daemon_community.set_text "public"
1304
+ else
1305
+ @entry_snmptrap_daemon_community.set_text @config.snmptrap_community
1306
+ end
1307
+
1308
+ @entry_snmptrap_daemon_port.set_sensitive @button_snmptrap_daemon.active?
1309
+ @entry_snmptrap_daemon_community.set_sensitive @button_snmptrap_daemon.active?
1310
+ @button_snmptrap_daemon.signal_connect("toggled") {
1311
+ @entry_snmptrap_daemon_port.set_sensitive @button_snmptrap_daemon.active?
1312
+ label_snmptrap_daemon_community.set_sensitive @button_snmptrap_daemon.active?
1313
+ @entry_snmptrap_daemon_community.set_sensitive @button_snmptrap_daemon.active?
1314
+ }
1315
+
1316
+ table_passive.attach(@button_snmptrap_daemon,0,1,1,2)
1317
+ table_passive.attach(@entry_snmptrap_daemon_port,1,2,1,2)
1318
+ table_passive.attach(label_snmptrap_daemon_community,0,1,2,3)
1319
+ table_passive.attach(@entry_snmptrap_daemon_community,1,2,2,3)
1320
+
1321
+ hbox = Gtk::HBox.new(FALSE, 1)
1322
+ hbox.add Gtk::Image.new(Gtk::Stock::EXECUTE, Gtk::IconSize::MENU)
1323
+ hbox.add Gtk::Label::new("Monitoring")
1324
+ hbox.show_all
1325
+ notebook.append_page vbox_frame, hbox
1326
+
1327
+ #onglet 4 - need to be coded !
1328
+ #
1329
+ # frame = Gtk::Frame::new("Where to store nodes")
1330
+ # frame.border_width=10
1331
+ # frame.set_size_request(200, 150)
1332
+ # frame.show
1333
+ #
1334
+ # vbox = Gtk::VButtonBox.new
1335
+ # vbox.show
1336
+ # frame.add vbox
1337
+ # cbfile = Gtk::CheckButton.new("In file, support for 1 network")
1338
+ # cbfile.show
1339
+ # vbox.add cbfile
1340
+ # cbdb = Gtk::CheckButton.new("In DB, support for many networks/subnetworks")
1341
+ # cbdb.show
1342
+ # vbox.add cbdb
1343
+ #
1344
+ # label = Gtk::Label::new("Database")
1345
+ # notebook.append_page frame, label
1346
+ #
1347
+ #onglet 5
1348
+ frame = Gtk::Frame::new("Executable File Path")
1349
+ frame.border_width=10
1350
+ frame.set_size_request(200, 150)
1351
+ frame.show
1352
+
1353
+ table = Gtk::Table.new(5,2,false)
1354
+ table.show
1355
+ frame.add table
1356
+
1357
+ label_ping = Gtk::Label.new "ping"
1358
+ label_ping.show
1359
+ @entry_ping = Gtk::Entry.new
1360
+ if @config.ping_path == "" || @config.ping_path == nil
1361
+ ou=`/usr/bin/which ping | /bin/grep \/`
1362
+ @entry_ping.set_text ou.chomp
1363
+ else
1364
+ @entry_ping.set_text @config.ping_path
1365
+ end
1366
+ @entry_ping.set_size_request(140,-1)
1367
+ @entry_ping.show
1368
+
1369
+ bbox=Gtk::HButtonBox.new
1370
+ bbox.show
1371
+ bbox.add @entry_ping
1372
+
1373
+ table.attach(label_ping,0,1,0,1)
1374
+ table.attach(bbox,1,2,0,1)
1375
+
1376
+ label_nmap = Gtk::Label.new "nmap"
1377
+ label_nmap.show
1378
+ @entry_nmap = Gtk::Entry.new
1379
+
1380
+ if @config.nmap_path == "" || @config.nmap_path == nil
1381
+ ou=`/usr/bin/which nmap | /bin/grep \/`
1382
+ @entry_nmap.set_text ou.chomp
1383
+ else
1384
+ @entry_nmap.set_text @config.nmap_path
1385
+ end
1386
+ @entry_nmap.set_size_request(140,-1)
1387
+ @entry_nmap.show
1388
+
1389
+ bbox=Gtk::HButtonBox.new
1390
+ bbox.show
1391
+ bbox.add @entry_nmap
1392
+
1393
+ table.attach(label_nmap,0,1,2,3)
1394
+ table.attach(bbox,1,2,2,3)
1395
+
1396
+ label_ssh = Gtk::Label.new "ssh"
1397
+ label_ssh.show
1398
+ @entry_ssh = Gtk::Entry.new
1399
+
1400
+ if @config.ssh_path == "" || @config.ssh_path == nil
1401
+ ou=`/usr/bin/which ssh | /bin/grep \/`
1402
+ @entry_ssh.set_text ou.chomp
1403
+ else
1404
+ @entry_ssh.set_text @config.ssh_path
1405
+ end
1406
+ @entry_ssh.set_size_request(140,-1)
1407
+ @entry_ssh.show
1408
+
1409
+ bbox=Gtk::HButtonBox.new
1410
+ bbox.show
1411
+ bbox.add @entry_ssh
1412
+
1413
+ table.attach(label_ssh,0,1,3,4)
1414
+ table.attach(bbox,1,2,3,4)
1415
+
1416
+ label_telnet = Gtk::Label.new "telnet"
1417
+ label_telnet.show
1418
+ @entry_telnet = Gtk::Entry.new
1419
+
1420
+ if @config.telnet_path == "" || @config.telnet_path == nil
1421
+ ou=`/usr/bin/which telnet | /bin/grep \/`
1422
+ @entry_telnet.set_text ou.chomp
1423
+ else
1424
+ @entry_telnet.set_text @config.telnet_path
1425
+ end
1426
+ @entry_telnet.set_size_request(140,-1)
1427
+ @entry_telnet.show
1428
+
1429
+ bbox=Gtk::HButtonBox.new
1430
+ bbox.show
1431
+ bbox.add @entry_telnet
1432
+
1433
+ table.attach(label_telnet,0,1,4,5)
1434
+ table.attach(bbox,1,2,4,5)
1435
+
1436
+ label_browser = Gtk::Label.new "browser"
1437
+ label_browser.show
1438
+ @entry_browser = Gtk::Entry.new
1439
+
1440
+ if @config.browser_path == "" || @config.browser_path == nil
1441
+ for br in ["firefox", "mozilla", "netscape", "konqueror", "galeon"]
1442
+ ou=`/usr/bin/which #{br} | /bin/grep \/`
1443
+ if ou != ""
1444
+ break
1445
+ end
1446
+ end
1447
+ @entry_browser.set_text ou.chomp
1448
+ else
1449
+ @entry_browser.set_text @config.browser_path
1450
+ end
1451
+ @entry_browser.set_size_request(140,-1)
1452
+ @entry_browser.show
1453
+
1454
+ bbox=Gtk::HButtonBox.new
1455
+ bbox.show
1456
+ bbox.add @entry_browser
1457
+
1458
+ table.attach(label_browser,0,1,5,6)
1459
+ table.attach(bbox,1,2,5,6)
1460
+
1461
+ label_vncviewer = Gtk::Label.new "VNC client"
1462
+ label_vncviewer.show
1463
+ @entry_vncviewer = Gtk::Entry.new
1464
+
1465
+ if @config.vncviewer_path == "" || @config.vncviewer_path == nil
1466
+ ou=`/usr/bin/which vncviewer | /bin/grep \/`
1467
+ @entry_vncviewer.set_text ou.chomp
1468
+ else
1469
+ @entry_vncviewer.set_text @config.vncviewer_path
1470
+ end
1471
+ @entry_vncviewer.set_size_request(140,-1)
1472
+ @entry_vncviewer.show
1473
+
1474
+ bbox=Gtk::HButtonBox.new
1475
+ bbox.show
1476
+ bbox.add @entry_vncviewer
1477
+
1478
+ table.attach(label_vncviewer,0,1,6,7)
1479
+ table.attach(bbox,1,2,6,7)
1480
+
1481
+ label_rdesktop = Gtk::Label.new "RDP client"
1482
+ label_rdesktop.show
1483
+ @entry_rdesktop = Gtk::Entry.new
1484
+
1485
+ if @config.rdesktop_path == "" || @config.rdesktop_path == nil
1486
+ ou=`/usr/bin/which rdesktop | /bin/grep \/`
1487
+ @entry_rdesktop.set_text ou.chomp
1488
+ else
1489
+ @entry_rdesktop.set_text @config.rdesktop_path
1490
+ end
1491
+ @entry_rdesktop.set_size_request(140,-1)
1492
+ @entry_rdesktop.show
1493
+
1494
+ bbox=Gtk::HButtonBox.new
1495
+ bbox.show
1496
+ bbox.add @entry_rdesktop
1497
+
1498
+ table.attach(label_rdesktop,0,1,7,8)
1499
+ table.attach(bbox,1,2,7,8)
1500
+
1501
+ label_xterm = Gtk::Label.new "terminal launcher"
1502
+ label_xterm.show
1503
+ @entry_xterm = Gtk::Entry.new
1504
+
1505
+ if @config.xterm_path == "" || @config.xterm_path == nil
1506
+ ou=`/usr/bin/which xterm | /bin/grep \/`
1507
+ if ou
1508
+ @entry_xterm.set_text "#{ou.chomp} -e "
1509
+ end
1510
+ else
1511
+ @entry_xterm.set_text @config.xterm_path
1512
+ end
1513
+ @entry_xterm.set_size_request(140,-1)
1514
+ @entry_xterm.show
1515
+
1516
+ bbox=Gtk::HButtonBox.new
1517
+ bbox.show
1518
+ bbox.add @entry_xterm
1519
+
1520
+ table.attach(label_xterm,0,1,8,9)
1521
+ table.attach(bbox,1,2,8,9)
1522
+
1523
+ label_nmblookup = Gtk::Label.new "nmblookup"
1524
+ label_nmblookup.show
1525
+ @entry_nmblookup = Gtk::Entry.new
1526
+
1527
+ if @config.nmblookup_path == "" || @config.nmblookup_path == nil
1528
+ ou=`/usr/bin/which nmblookup | /bin/grep \/`
1529
+ @entry_nmblookup.set_text ou.chomp
1530
+ else
1531
+ @entry_nmblookup.set_text @config.nmblookup_path
1532
+ end
1533
+ @entry_nmblookup.set_size_request(140,-1)
1534
+ @entry_nmblookup.show
1535
+
1536
+ bbox=Gtk::HButtonBox.new
1537
+ bbox.show
1538
+ bbox.add @entry_nmblookup
1539
+
1540
+ table.attach(label_nmblookup,0,1,9,10)
1541
+ table.attach(bbox,1,2,9,10)
1542
+
1543
+ label_xprobe = Gtk::Label.new "xprobe2"
1544
+ label_xprobe.show
1545
+ @entry_xprobe = Gtk::Entry.new
1546
+ if @config.xprobe_path == "" || @config.xprobe_path == nil
1547
+ ou=`/usr/bin/which xprobe2 | /bin/grep \/`
1548
+ @entry_xprobe.set_text ou.chomp
1549
+ else
1550
+ @entry_xprobe.set_text @config.xprobe_path
1551
+ end
1552
+ @entry_xprobe.set_size_request(140,-1)
1553
+ @entry_xprobe.show
1554
+
1555
+ bbox=Gtk::HButtonBox.new
1556
+ bbox.show
1557
+ bbox.add @entry_xprobe
1558
+
1559
+ table.attach(label_xprobe,0,1,10,11)
1560
+ table.attach(bbox,1,2,10,11)
1561
+
1562
+ label_wmic = Gtk::Label.new "wmic"
1563
+ label_wmic.show
1564
+ @entry_wmic = Gtk::Entry.new
1565
+ if @config.wmic_path == "" || @config.wmic_path == nil
1566
+ ou=`/usr/bin/which wmic | /bin/grep \/`
1567
+ @entry_wmic.set_text ou.chomp
1568
+ else
1569
+ @entry_wmic.set_text @config.wmic_path
1570
+ end
1571
+ @entry_wmic.set_size_request(140,-1)
1572
+ @entry_wmic.show
1573
+
1574
+ bbox=Gtk::HButtonBox.new
1575
+ bbox.show
1576
+ bbox.add @entry_wmic
1577
+
1578
+ table.attach(label_wmic,0,1,11,12)
1579
+ table.attach(bbox,1,2,11,12)
1580
+
1581
+
1582
+ #end path elf
1583
+
1584
+ hbox = Gtk::HBox.new(FALSE, 1)
1585
+ hbox.add Gtk::Image.new(Gtk::Stock::INDEX, Gtk::IconSize::MENU)
1586
+ hbox.add Gtk::Label::new("Path")
1587
+ hbox.show_all
1588
+
1589
+ notebook.append_page frame, hbox
1590
+
1591
+ #onglet 6
1592
+ frame = Gtk::Frame::new("Accelerator")
1593
+ frame.border_width=10
1594
+ frame.set_size_request(200, 150)
1595
+ frame.show
1596
+
1597
+ label = Gtk::Label.new("keys are not yet dynamic")
1598
+ label.show
1599
+ frame.add label
1600
+
1601
+ hbox = Gtk::HBox.new(FALSE, 1)
1602
+ hbox.add Gtk::Image.new(Gtk::Stock::SELECT_FONT, Gtk::IconSize::MENU)
1603
+ hbox.add Gtk::Label::new("Keys")
1604
+ hbox.show_all
1605
+ notebook.append_page frame, hbox
1606
+
1607
+ #onglet 7
1608
+ frame = Gtk::Frame::new("Default")
1609
+ frame.border_width=10
1610
+ frame.set_size_request(200, 150)
1611
+ frame.show
1612
+
1613
+ vbox = Gtk::VButtonBox.new
1614
+ vbox.set_layout_style(Gtk::ButtonBox::SPREAD)
1615
+ vbox.show
1616
+ frame.add vbox
1617
+
1618
+ hbox = Gtk::HButtonBox.new
1619
+ hbox.set_layout_style(Gtk::ButtonBox::EDGE)
1620
+ hbox.show
1621
+ vbox.add hbox
1622
+
1623
+ button_ps = Gtk::CheckButton.new "Resize node icon"
1624
+ button_ps.show
1625
+ hbox.add button_ps
1626
+
1627
+ @entry_pixmap_size = Gtk::Entry.new
1628
+ @entry_pixmap_size.show
1629
+ @entry_pixmap_size.set_size_request 3,-1
1630
+ if @config.pixmap_size == "" || @config.pixmap_size == nil
1631
+ @entry_pixmap_size.set_text "35"
1632
+ else
1633
+ @entry_pixmap_size.set_text(@config.pixmap_size.to_s())
1634
+ end
1635
+ if @config.pixmap_size == "0"
1636
+ button_ps.set_active false
1637
+ else
1638
+ button_ps.set_active true
1639
+ end
1640
+ @entry_pixmap_size.set_sensitive button_ps.active?
1641
+
1642
+ button_ps.signal_connect("toggled") {
1643
+ if !button_ps.active?
1644
+ @entry_pixmap_size.set_sensitive false
1645
+ @entry_pixmap_size.set_text "0"
1646
+ else
1647
+ @entry_pixmap_size.set_sensitive true
1648
+ @entry_pixmap_size.set_text(@config.pixmap_size.to_s())
1649
+ end
1650
+ }
1651
+ hbox.add @entry_pixmap_size
1652
+
1653
+ hbbl1=Gtk::HButtonBox.new
1654
+ hbbl1.set_layout_style(Gtk::ButtonBox::EDGE)
1655
+ hbbl1.show
1656
+
1657
+ colorchk_label_text = Gtk::Label.new("Node text label color")
1658
+ colorchk_label_text.set_sensitive @button_show_label.active?
1659
+ colorchk_label_text.show
1660
+ hbbl1.add colorchk_label_text
1661
+
1662
+ @cp_label_text = Gtk::ColorButton.new
1663
+ @cp_label_text.set_use_alpha(false)
1664
+ @cp_label_text.set_sensitive @button_show_label.active?
1665
+ gdk_color=nil
1666
+ if @config.label_text == nil
1667
+ gdk_color=Gdk::Color.new(0, 0, 0)
1668
+ else
1669
+ gdk_color=Gdk::Color.new(@config.label_text[0].to_f, @config.label_text[1].to_f, @config.label_text[2].to_f)
1670
+ end
1671
+ @cp_label_text.set_color(gdk_color)
1672
+ hbbl1.add @cp_label_text
1673
+ vbox.add hbbl1
1674
+ @cp_label_text.show
1675
+
1676
+ hbbl2=Gtk::HButtonBox.new
1677
+ hbbl2.set_layout_style(Gtk::ButtonBox::EDGE)
1678
+ hbbl2.show
1679
+
1680
+ colorchk_bg_label = Gtk::Label.new("Node background label color")
1681
+ colorchk_bg_label.set_sensitive @button_show_label.active?
1682
+ colorchk_bg_label.show
1683
+ hbbl2.add colorchk_bg_label
1684
+
1685
+ @cp_label_bg = Gtk::ColorButton.new
1686
+ @cp_label_bg.set_use_alpha(false)
1687
+ @cp_label_bg.set_sensitive @button_show_label.active?
1688
+ gdk_color=nil
1689
+ if @config.label_bg == nil
1690
+ gdk_color=Gdk::Color.new(65535, 65535, 65535)
1691
+ else
1692
+ gdk_color=Gdk::Color.new(@config.label_bg[0].to_f, @config.label_bg[1].to_f, @config.label_bg[2].to_f)
1693
+ end
1694
+ @cp_label_bg.set_color(gdk_color)
1695
+ hbbl2.add @cp_label_bg
1696
+ vbox.add hbbl2
1697
+ @cp_label_bg.show
1698
+
1699
+ @button_show_label.signal_connect("clicked") {
1700
+ @button_noshow_fqdn.set_sensitive(@button_show_label.active?)
1701
+ colorchk_label_text.set_sensitive(@button_show_label.active?)
1702
+ colorchk_bg_label.set_sensitive(@button_show_label.active?)
1703
+ @cp_label_text.set_sensitive(@button_show_label.active?)
1704
+ @cp_label_bg.set_sensitive(@button_show_label.active?)
1705
+ }
1706
+
1707
+ hbb=Gtk::HButtonBox.new
1708
+ hbb.set_layout_style(Gtk::ButtonBox::EDGE)
1709
+ hbb.show
1710
+
1711
+ @colorchk = Gtk::CheckButton.new("Map background color")
1712
+ @colorchk.show
1713
+ hbb.add @colorchk
1714
+
1715
+ @cp = Gtk::ColorButton.new
1716
+ @cp.set_use_alpha(false)
1717
+ if @config.bg_type != nil
1718
+ if @config.bg_type == "color"
1719
+ @colorchk.set_active true
1720
+ @cp.set_sensitive true
1721
+ else
1722
+ @colorchk.set_active false
1723
+ @cp.set_sensitive false
1724
+ end
1725
+ end
1726
+ gdk_color=nil
1727
+ if @config.rgb == nil
1728
+ gdk_color=Gdk::Color.new(65535, 65535, 65535)
1729
+ else
1730
+ gdk_color=Gdk::Color.new(@config.rgb[0].to_f, @config.rgb[1].to_f, @config.rgb[2].to_f)
1731
+ end
1732
+ @cp.set_color(gdk_color)
1733
+ hbb.add @cp
1734
+ vbox.add hbb
1735
+ @cp.show
1736
+
1737
+ hbb2=Gtk::HButtonBox.new
1738
+ hbb2.set_layout_style(Gtk::ButtonBox::EDGE)
1739
+ hbb2.show
1740
+
1741
+ imagechk = Gtk::CheckButton.new("Map background image")
1742
+ imagechk.show
1743
+ hbb2.add imagechk
1744
+
1745
+ #remove dir name and file format from file bg path
1746
+ file_ng = nil
1747
+ if @config.image_path
1748
+ file_bg = @config.image_path[1+ String.new("bg").size, @config.image_path.size - 2 - String.new("bg").size - String.new("jpg").size]
1749
+ end
1750
+ @entry_image = Gtk::ImageComboList.new("bg", file_bg, "jpg")
1751
+ @entry_image.show
1752
+ hbb2.add @entry_image
1753
+ vbox.add hbb2
1754
+ if @config.bg_type != nil
1755
+ if @config.bg_type == "image"
1756
+ imagechk.set_active(true)
1757
+ @entry_image.set_sensitive true
1758
+ else
1759
+ imagechk.set_active(false)
1760
+ @entry_image.set_sensitive false
1761
+ end
1762
+ end
1763
+ @colorchk.signal_connect("toggled") {
1764
+ if @colorchk.active?
1765
+ @cp.set_sensitive(true)
1766
+ imagechk.set_active(false)
1767
+ @entry_image.set_sensitive(false)
1768
+ else
1769
+ @cp.set_sensitive(false)
1770
+ imagechk.set_active(true)
1771
+ @entry_image.set_sensitive(true)
1772
+ end
1773
+
1774
+ }
1775
+ imagechk.signal_connect("clicked") {
1776
+ if imagechk.active?
1777
+ @entry_image.set_sensitive(true)
1778
+ @colorchk.set_active(false)
1779
+ @cp.set_sensitive(false)
1780
+ else
1781
+ @entry_image.set_sensitive(false)
1782
+ @colorchk.set_active(true)
1783
+ @cp.set_sensitive(true)
1784
+ end
1785
+ }
1786
+
1787
+ hbox = Gtk::HBox.new(FALSE, 1)
1788
+ hbox.add Gtk::Image.new(Gtk::Stock::SELECT_COLOR, Gtk::IconSize::MENU)
1789
+ hbox.add Gtk::Label::new("Display")
1790
+ hbox.show_all
1791
+ notebook.append_page frame, hbox
1792
+ #end
1793
+
1794
+ separator = Gtk::HSeparator::new()
1795
+ box1.pack_start(separator, FALSE, TRUE, 0)
1796
+ separator.show
1797
+
1798
+ box2 = Gtk::HBox::new(FALSE, 10)
1799
+ box2.border_width=10
1800
+ box1.pack_start(box2, FALSE, TRUE, 0)
1801
+ box2.show
1802
+
1803
+ button = Gtk::Button::new(Gtk::Stock::SAVE)
1804
+ button.signal_connect("clicked") do
1805
+ #save contacts
1806
+ $contact.each_key {|id|
1807
+ #for each entry we insert or update the db
1808
+ db_write_contact($contact[id].firstname, $contact[id].lastname, $contact[id].email, $contact[id].phone, $contact[id].mobile, $contact[id].pager, $contact[id].im, $contact[id].title, $contact[id].organization, $contact[id].location, $contact[id].note)
1809
+ @old_contact.delete(id) unless !@old_contact
1810
+ }
1811
+ #id in old_contact are delete entries
1812
+ if @old_contact
1813
+ @old_contact.each_key {|id|
1814
+ db_del_contact(@old_contact[id].firstname, @old_contact[id].lastname)
1815
+ }
1816
+ end
1817
+ #test if current map as color or image already set
1818
+ if get_map() and !$network[get_map()].map_bg_type
1819
+ if @colorchk.active? == true
1820
+ $canvas.unset_background_image()
1821
+ set_background_color(@cp.color())
1822
+ else
1823
+ if @entry_image.filename!=nil && (FileTest.exist?("#{PIXMAP_PATH}"+"/"+@entry_image.filename))
1824
+ $canvas.set_background_image("#{PIXMAP_PATH}"+"/"+@entry_image.filename)
1825
+ else
1826
+ $log.error("Warning: Image background #{PIXMAP_PATH}/#{@entry_image.filename} doesn't exist")
1827
+ #give focus to color
1828
+ imagechk.set_active(false)
1829
+ @colorchk.set_active(true)
1830
+ @config.bg_type="color"
1831
+ end
1832
+ end
1833
+ end
1834
+
1835
+ old_config_show_label=@config.show_label
1836
+ old_config_noshow_fqdn=@config.noshow_fqdn
1837
+ old_config_show_tooltips=@config.show_tooltips
1838
+ old_config_log_level=@config.log_level
1839
+ old_config_pixmap_size=@config.pixmap_size
1840
+ old_config_label_text=@config.label_text
1841
+ old_config_label_bg=@config.label_bg
1842
+
1843
+ #thread management
1844
+ old_port_mon=@config.port_mon
1845
+ old_snmp_mon=@config.snmp_mon
1846
+ old_wmi_mon=@config.wmi_mon
1847
+ old_jmx_mon=@config.jmx_mon
1848
+ old_custom_mon=@config.custom_mon
1849
+ old_ping_state=@config.broadcast_ping_state
1850
+ old_mac_state=@config.mac_state
1851
+ old_node_resolving=@config.node_resolving
1852
+ old_syslog_mon=@config.syslog_mon
1853
+ old_syslog_mon_port=@config.syslog_port.to_i()
1854
+ old_snmptrap_mon=@config.snmptrap_mon
1855
+ old_snmptrap_mon_port=@config.snmptrap_port.to_i()
1856
+ old_auto_save_map=@config.auto_save_map
1857
+ old_auto_save_map_value=@config.auto_save_map_value
1858
+ old_im_daemon=@config.im_daemon
1859
+ old_im_login=@config.im_login
1860
+ old_im_password=@config.im_password
1861
+ old_irc_daemon=@config.irc_daemon
1862
+ old_irc_server=@config.irc_server
1863
+ old_irc_port=@config.irc_port
1864
+ old_irc_channel=@config.irc_channel
1865
+
1866
+
1867
+ #notification: store mail information for current severity
1868
+ @config.mail_by_level[@config.level]=@entry_mail
1869
+
1870
+ #notification: store script name
1871
+ if @config.script_name_by_level == nil
1872
+ @config.init_script_name()
1873
+ end
1874
+ @config.script_name_by_level[@config.level]=@entry_script.text
1875
+ @config.sms_num_by_level[@config.level]=@entry_sms
1876
+ @config.im_dest_by_level[@config.level]=@entry_im
1877
+
1878
+ if isInteger(@entry_delay_bp.text) && @entry_delay_bp.text.to_i > 5 &&
1879
+ isInteger(@entry_delay_macf.text) && @entry_delay_macf.text.to_i > 5 &&
1880
+ isInteger(@entry_delay_nr.text) && @entry_delay_nr.text.to_i > 5 &&
1881
+ isInteger(@entry_delay_pm.text) && @entry_delay_pm.text.to_i > 5 &&
1882
+ isInteger(@entry_delay_snmp.text) && @entry_delay_snmp.text.to_i > 5 &&
1883
+ isInteger(@entry_delay_wmi.text) && @entry_delay_wmi.text.to_i > 5 &&
1884
+ isInteger(@entry_delay_jmx.text) && @entry_delay_jmx.text.to_i > 5 &&
1885
+ isInteger(@entry_delay_custom.text) && @entry_delay_custom.text.to_i > 5 &&
1886
+ isInteger(@entry_auto_save_map.text) && @entry_auto_save_map.text.to_i > 5
1887
+ if isValidPort(@entry_syslog_daemon_port.text.to_i())
1888
+ if isValidPort(@entry_snmptrap_daemon_port.text.to_i())
1889
+ if @entry_auto_save_map.text.to_i > 1
1890
+ if (@entry_mail_server_addr.text == "") || (@entry_mail_server_port.text == "")
1891
+ #we can't enable mail notification is a parameter is missing
1892
+ @button_mail.set_active(false)
1893
+ end
1894
+ save_config_yaml()
1895
+
1896
+ #reload label colors
1897
+ if (old_config_label_text != @config.label_text) or (old_config_label_bg != @config.label_bg)
1898
+ if $map.nil?
1899
+ #it's only root map
1900
+ $network[get_map()].node_view.reload_label_colors()
1901
+ else
1902
+ $network[get_map()].get_node().each_value {|n|
1903
+ n.node_view.reload_label_colors()
1904
+ }
1905
+ end
1906
+ end
1907
+
1908
+ #once save, try to find nmap version
1909
+ check_scanner_version()
1910
+ #update snmp conf for root node
1911
+ $network[ROOTMAPADDR].set_snmp_conf(@entry_read_community.text, @entry_write_community.text, @combo_snmp_version.active_text, @port_spinner.value_as_int, @timeout_spinner.value_as_int, @retry_spinner.value_as_int, 1) unless !$network[ROOTMAPADDR]
1912
+ if old_port_mon != @button_pm.active?
1913
+ if @button_pm.active?
1914
+ add_monitoring_thread("Port monitoring",tmonitorport())
1915
+ else
1916
+ del_monitoring_thread("Port monitoring")
1917
+ end
1918
+ end
1919
+ if old_snmp_mon != @button_snmp.active?
1920
+ if @button_snmp.active?
1921
+ add_monitoring_thread("Snmp monitoring",tmonitorsnmp())
1922
+ else
1923
+ del_monitoring_thread("Snmp monitoring")
1924
+ end
1925
+ end
1926
+ if old_wmi_mon != @button_wmi.active?
1927
+ if @button_wmi.active?
1928
+ add_monitoring_thread("WMI monitoring",tmonitorwmi())
1929
+ else
1930
+ del_monitoring_thread("WMI monitoring")
1931
+ end
1932
+ end
1933
+ if old_custom_mon != @button_custom.active?
1934
+ if @button_custom.active?
1935
+ add_monitoring_thread("Custom monitoring",tmonitorcustom())
1936
+ else
1937
+ del_monitoring_thread("Custom monitoring")
1938
+ end
1939
+ end
1940
+ if old_jmx_mon != @button_jmx.active?
1941
+ if @button_jmx.active?
1942
+ add_monitoring_thread("JMX monitoring",tmonitorjmx())
1943
+ else
1944
+ del_monitoring_thread("JMX monitoring")
1945
+ end
1946
+ end
1947
+ if old_ping_state != @button_bp.active?
1948
+ if @button_bp.active?
1949
+ add_monitoring_thread("Local ping", t_find_local_segment_pinging())
1950
+ add_monitoring_thread("Local sniffing", t_find_local_segment_sniffing())
1951
+ add_monitoring_thread("Remote ping", t_find_remote_new_host())
1952
+ else
1953
+ del_monitoring_thread("Local ping")
1954
+ del_monitoring_thread("Local sniffing")
1955
+ del_monitoring_thread("Remote ping")
1956
+ end
1957
+ end
1958
+ if old_mac_state != @button_macf.active?
1959
+ if @button_macf.active?
1960
+ add_monitoring_thread("Find mac",tmacip())
1961
+ else
1962
+ del_monitoring_thread("Find mac")
1963
+ end
1964
+ end
1965
+ if old_node_resolving != @button_nr.active?
1966
+ if @button_nr.active?
1967
+ add_monitoring_thread("Resolve ip to name",tresolvip())
1968
+ add_monitoring_thread("Resolve ip to netbios",tresolvnetbiosname())
1969
+ add_monitoring_thread("Find os",tresolvos())
1970
+ else
1971
+ del_monitoring_thread("Resolve ip to name")
1972
+ del_monitoring_thread("Resolve ip to netbios")
1973
+ del_monitoring_thread("Find os")
1974
+ end
1975
+ end
1976
+
1977
+ if old_syslog_mon != @button_syslog_daemon.active?
1978
+ if @button_syslog_daemon.active?
1979
+ $syslog_capture=SyslogCapture.new()
1980
+ else
1981
+ if $syslog_capture != nil
1982
+ $syslog_capture.stop()
1983
+ end
1984
+ end
1985
+ elsif @button_syslog_daemon.active? && (old_syslog_mon_port != @entry_syslog_daemon_port.text.to_i())
1986
+ $syslog_capture.stop()
1987
+ #and restart with new port
1988
+ sleep(1)
1989
+ $syslog_capture=SyslogCapture.new()
1990
+ end
1991
+
1992
+ if @entry_im_login.text != ""
1993
+ if old_im_daemon != @button_im.active?
1994
+ if @button_im.active?
1995
+ $im_daemon=XmppBot.new()
1996
+ else
1997
+ if $im_daemon != nil
1998
+ $im_daemon.stop()
1999
+ $im_daemon = nil
2000
+ end
2001
+ end
2002
+ elsif @button_im.active? && ((old_im_login != @entry_im_login.text)||(old_im_password != @entry_im_password.text))
2003
+ if $im_daemon
2004
+ $im_daemon.stop()
2005
+ $im_daemon = nil
2006
+ #and restart with new conf
2007
+ sleep(1)
2008
+ end
2009
+ $im_daemon=XmppBot.new()
2010
+ end
2011
+ else
2012
+ #no login so we desactivate the button
2013
+ $log.error("IM login not set, so IM notification is disabled") if @button_im.active?
2014
+ @button_im.set_active(false)
2015
+ if $im_daemon != nil
2016
+ $im_daemon.stop()
2017
+ $im_daemon = nil
2018
+ end
2019
+ end
2020
+
2021
+ if (@entry_irc_server.text != "") and (@entry_irc_channel.text != "")
2022
+ if old_irc_daemon != @button_irc.active?
2023
+ if @button_irc.active?
2024
+ $irc_daemon=IrcBot.new()
2025
+ else
2026
+ if $irc_daemon != nil
2027
+ $irc_daemon.stop()
2028
+ $irc_daemon = nil
2029
+ end
2030
+ end
2031
+ elsif @button_irc.active? && ((old_irc_server != @entry_irc_server.text)||(old_irc_port != @entry_irc_port.text)||(old_irc_channel != @entry_irc_channel.text))
2032
+ if $irc_daemon
2033
+ $irc_daemon.stop()
2034
+ $irc_daemon = nil
2035
+ #and restart with new conf
2036
+ sleep(1)
2037
+ end
2038
+ $irc_daemon=IrcBot.new()
2039
+ end
2040
+ else
2041
+ #no server or no channel so we desactivate the button
2042
+ $log.error("IRC server or channel is not set, so IRC notification is disabled") if @button_irc.active?
2043
+ @button_irc.set_active(false)
2044
+ if $irc_daemon != nil
2045
+ $irc_daemon.stop()
2046
+ $irc_daemon = nil
2047
+ end
2048
+ end
2049
+
2050
+ if old_snmptrap_mon != @button_snmptrap_daemon.active?
2051
+ if @button_snmptrap_daemon.active?
2052
+ $snmptrap_capture=SnmpTrapCapture.new()
2053
+ else
2054
+ if $snmptrap_capture != nil
2055
+ $snmptrap_capture.stop()
2056
+ end
2057
+ end
2058
+ elsif @button_snmptrap_daemon.active? && (old_snmptrap_mon_port != @entry_snmptrap_daemon_port.text.to_i())
2059
+ $snmptrap_capture.stop()
2060
+ #and restart with new port
2061
+ sleep(1)
2062
+ $snmptrap_capture=SnmpTrapCapture.new()
2063
+ end
2064
+
2065
+ if old_config_show_label != @button_show_label.active?
2066
+ #remove label from nodes
2067
+ if $map.nil?
2068
+ #it's only root map
2069
+ $network[get_map()].set_label_visibility()
2070
+ else
2071
+ $network[get_map()].get_node().each_value {|n|
2072
+ n.set_label_visibility()
2073
+ }
2074
+ end
2075
+ end
2076
+ if old_config_noshow_fqdn != @button_noshow_fqdn.active?
2077
+ #only show fqdn on node host
2078
+ $network[get_map()].get_node().each_value {|n|
2079
+ if n.class == Host
2080
+ n.refresh_dns_name()
2081
+ end
2082
+ }
2083
+ end
2084
+ if old_config_log_level != @entry_level.active_text
2085
+ $log.level=txtlvl_to_loggerlvl(@config.log_level)
2086
+ end
2087
+ if old_config_pixmap_size.to_i() != @entry_pixmap_size.text.to_i()
2088
+ $network[get_map()].get_node().each_value {|n|
2089
+ n.node_view.resize()
2090
+ }
2091
+ end
2092
+ if (old_auto_save_map != @button_auto_save_map.active?) && @button_auto_save_map.active?
2093
+ if !exist_monitoring_thread("Map autosaving")
2094
+ add_monitoring_thread("Map autosaving",tauto_save_map())
2095
+ else
2096
+ $log.info("Thread autosave map already active")
2097
+ end
2098
+ end
2099
+ window.destroy
2100
+ else
2101
+ errorEntry(window, "Bad auto save value need to be greater than 1")
2102
+ end
2103
+ else
2104
+ errorEntry(window, "Bad SNMP trap server port")
2105
+ end
2106
+ else
2107
+ errorEntry(window, "Bad Syslog server port")
2108
+ end
2109
+ else
2110
+ errorEntry(window, "Bad delay value")
2111
+ end
2112
+ end
2113
+
2114
+ box2.pack_start(button, TRUE, TRUE, 0)
2115
+ button.set_flags(Gtk::Widget::CAN_DEFAULT);
2116
+ button.grab_default
2117
+ button.show
2118
+
2119
+ button = Gtk::Button::new(Gtk::Stock::CANCEL)
2120
+ button.signal_connect("clicked") do
2121
+ cancel_action(window)
2122
+ end
2123
+ box2.pack_start(button, TRUE, TRUE, 0)
2124
+ button.set_flags(Gtk::Widget::CAN_DEFAULT);
2125
+ button.grab_default
2126
+ button.show
2127
+
2128
+ window.show
2129
+
2130
+ end
2131
+
2132
+ def cancel_action(win)
2133
+ #restore accounts
2134
+ contact_temp=$contact.dup
2135
+ $contact.clear
2136
+ $contact=@old_contact
2137
+ $contact.each_key {|id|
2138
+ if contact_temp.include?(id)
2139
+ $contact[id].nb_use=contact_temp[id].nb_use
2140
+ else
2141
+ #if it does not exist so it had been deleted
2142
+ $contact[id].nb_use=0
2143
+ end
2144
+ }
2145
+
2146
+ if FileTest.exist?(GLOBAL_CONF_FILE)
2147
+ win.destroy
2148
+ end
2149
+ end
2150
+
2151
+ end