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.
- data/LICENSE +459 -0
- data/README +29 -0
- data/bin/gnms +11 -0
- data/gnms.gemspec +70 -0
- data/lib/cmd_parse.rb +747 -0
- data/lib/config_global.rb +414 -0
- data/lib/contact.rb +171 -0
- data/lib/external/crypt/blowfish-tables.rb +190 -0
- data/lib/external/crypt/blowfish.rb +110 -0
- data/lib/external/crypt/cbc.rb +123 -0
- data/lib/external/crypt/stringxor.rb +27 -0
- data/lib/external/fog.rb +41 -0
- data/lib/external/jjmx.rb +45 -0
- data/lib/external/sms.rb +282 -0
- data/lib/external/xmpp4r-simple.rb +497 -0
- data/lib/format.rb +85 -0
- data/lib/gnms.rb +329 -0
- data/lib/gui/about_window.rb +177 -0
- data/lib/gui/adddelnode.rb +799 -0
- data/lib/gui/base_window.rb +789 -0
- data/lib/gui/canvas_map.rb +498 -0
- data/lib/gui/charts/gruff.rb +51 -0
- data/lib/gui/color_macro.rb +145 -0
- data/lib/gui/config_window.rb +2151 -0
- data/lib/gui/custom_plugin_window.rb +90 -0
- data/lib/gui/debug_window.rb +46 -0
- data/lib/gui/event_window.rb +469 -0
- data/lib/gui/find_node_window.rb +438 -0
- data/lib/gui/help_window.rb +47 -0
- data/lib/gui/ipcalculator.rb +147 -0
- data/lib/gui/jmx_ref_window.rb +309 -0
- data/lib/gui/link_view.rb +46 -0
- data/lib/gui/mib_browser.rb +585 -0
- data/lib/gui/node_host_property.rb +3712 -0
- data/lib/gui/node_host_view.rb +270 -0
- data/lib/gui/node_network_property.rb +1059 -0
- data/lib/gui/node_network_view.rb +186 -0
- data/lib/gui/node_view.rb +672 -0
- data/lib/gui/oid_ref_window.rb +288 -0
- data/lib/gui/snmptrap_ref_window.rb +288 -0
- data/lib/gui/sub/account_frame.rb +196 -0
- data/lib/gui/sub/contact_frame.rb +519 -0
- data/lib/gui/syslog_ref_window.rb +288 -0
- data/lib/gui/treenode_window.rb +320 -0
- data/lib/gui/update_window.rb +124 -0
- data/lib/gui/widgets.rb +169 -0
- data/lib/gui/wmi_ref_window.rb +286 -0
- data/lib/interface.rb +16 -0
- data/lib/ipcalc.rb +266 -0
- data/lib/link.rb +45 -0
- data/lib/main.rb +1091 -0
- data/lib/monitor/client/custom/custom_monitoring.rb +40 -0
- data/lib/monitor/client/jmx/jmx_attr_monitoring.rb +36 -0
- data/lib/monitor/client/jmx/jmx_monitoring.rb +83 -0
- data/lib/monitor/client/jmx/jmx_ref.rb +114 -0
- data/lib/monitor/client/snmp/mibs/SNMPv2-MIB.txt +854 -0
- data/lib/monitor/client/snmp/mibs/SNMPv2-SMI.txt +344 -0
- data/lib/monitor/client/snmp/oid_ref.rb +141 -0
- data/lib/monitor/client/snmp/snmp.rb +178 -0
- data/lib/monitor/client/snmp/snmp_monitoring.rb +58 -0
- data/lib/monitor/client/wmi/wmi.rb +139 -0
- data/lib/monitor/client/wmi/wmi_monitoring.rb +60 -0
- data/lib/monitor/client/wmi/wmi_ref.rb +141 -0
- data/lib/monitor/custom_plugin.rb +50 -0
- data/lib/monitor/server/msg_buffer.rb +39 -0
- data/lib/monitor/server/snmp/snmptrap_analyzer.rb +81 -0
- data/lib/monitor/server/snmp/snmptrap_capture.rb +26 -0
- data/lib/monitor/server/snmp/snmptrap_monitoring.rb +32 -0
- data/lib/monitor/server/snmp/snmptrap_ref.rb +135 -0
- data/lib/monitor/server/snmp/snmptrap_server.rb +50 -0
- data/lib/monitor/server/syslog/syslog_analyzer.rb +141 -0
- data/lib/monitor/server/syslog/syslog_capture.rb +28 -0
- data/lib/monitor/server/syslog/syslog_monitoring.rb +32 -0
- data/lib/monitor/server/syslog/syslog_ref.rb +136 -0
- data/lib/monitor/server/syslog/syslog_server.rb +43 -0
- data/lib/node.rb +1020 -0
- data/lib/node_db.rb +2668 -0
- data/lib/node_host.rb +215 -0
- data/lib/node_listener.rb +639 -0
- data/lib/node_network.rb +269 -0
- data/lib/node_property.rb +39 -0
- data/lib/notify/alarm.rb +247 -0
- data/lib/notify/irc_bot.rb +167 -0
- data/lib/notify/xmpp_bot.rb +107 -0
- data/lib/service.rb +36 -0
- data/lib/version.rb +8 -0
- data/pixmap/bg/map_bg.jpg +0 -0
- data/pixmap/bg/map_bg2.jpg +0 -0
- data/pixmap/logo.jpg +0 -0
- data/pixmap/logo_icon.png +0 -0
- data/pixmap/os/3com.png +0 -0
- data/pixmap/os/aix.gif +0 -0
- data/pixmap/os/amiga.png +0 -0
- data/pixmap/os/beos.png +0 -0
- data/pixmap/os/cisco.png +0 -0
- data/pixmap/os/freebsd.png +0 -0
- data/pixmap/os/hp.png +0 -0
- data/pixmap/os/hurd.gif +0 -0
- data/pixmap/os/irix.gif +0 -0
- data/pixmap/os/linux.png +0 -0
- data/pixmap/os/mac.png +0 -0
- data/pixmap/os/netbsd.gif +0 -0
- data/pixmap/os/netware.png +0 -0
- data/pixmap/os/openbsd.png +0 -0
- data/pixmap/os/os2warp.gif +0 -0
- data/pixmap/os/qnx.gif +0 -0
- data/pixmap/os/sco.gif +0 -0
- data/pixmap/os/sgi.xpm +111 -0
- data/pixmap/os/solaris.gif +0 -0
- data/pixmap/os/unix.gif +0 -0
- data/pixmap/os/unknown.png +0 -0
- data/pixmap/os/vms.xpm +345 -0
- data/pixmap/os/windows.png +0 -0
- data/pixmap/type/cloud.png +0 -0
- data/pixmap/type/device.png +0 -0
- data/pixmap/type/firewall.png +0 -0
- data/pixmap/type/gateway.png +0 -0
- data/pixmap/type/home.png +0 -0
- data/pixmap/type/host.png +0 -0
- data/pixmap/type/network.png +0 -0
- data/pixmap/type/printer.png +0 -0
- data/pixmap/type/router.png +0 -0
- data/pixmap/type/server.png +0 -0
- data/pixmap/type/switch.png +0 -0
- data/pixmap/type/vm.png +0 -0
- data/plugins/Defaultme.rb +7 -0
- data/plugins/DnsCheck.rb +46 -0
- data/plugins/FooMonitor.rb +26 -0
- data/plugins/HttpVirtualHostMonitor.rb +43 -0
- data/plugins/MysqlShowStatusMonitor.rb +64 -0
- data/plugins/PgsqlPercentConnectionMonitor.rb +72 -0
- data/plugins/SshCpuLoadMonitor.rb +85 -0
- data/plugins/SshDiskMonitor.rb +69 -0
- data/plugins/SshFgtAvExpiredMonitor.rb +75 -0
- data/plugins/SshPercentUsedRamMonitor.rb +74 -0
- data/plugins/TelnetCpuLoadMonitor.rb +69 -0
- data/plugins/example1.rb +15 -0
- data/plugins/example2.rb +7 -0
- data/sound/beep.wav +0 -0
- metadata +378 -0
@@ -0,0 +1,196 @@
|
|
1
|
+
frame_account = Gtk::Frame::new
|
2
|
+
frame_account.border_width=10
|
3
|
+
frame_account.show
|
4
|
+
|
5
|
+
vbox = Gtk::VBox::new
|
6
|
+
vbox.show
|
7
|
+
frame_account.add vbox
|
8
|
+
|
9
|
+
account_ls = Gtk::ListStore.new(String, String, String)
|
10
|
+
@account_view = Gtk::TreeView.new(account_ls)
|
11
|
+
|
12
|
+
def cell_edited(cell, path_string, new_text, col, node)
|
13
|
+
iter = @account_view.model.get_iter(path_string)
|
14
|
+
#check if account id does not already exist for the host
|
15
|
+
if (node.ip != ROOTMAPADDR) && (iter[0] != "snmp")
|
16
|
+
#None is a special entry
|
17
|
+
if (col == 0) && ((node.account_exist?(new_text)) || (new_text.upcase == "NONE") || (new_text.upcase == ""))
|
18
|
+
return
|
19
|
+
end
|
20
|
+
#we have to store the modified value
|
21
|
+
if col == 0
|
22
|
+
login, password = node.get_account_id(iter[0])
|
23
|
+
node.del_account(iter[0])
|
24
|
+
node.add_account(new_text, login, password)
|
25
|
+
elsif col == 1
|
26
|
+
node.set_account_login(iter[0], new_text)
|
27
|
+
elsif col == 2
|
28
|
+
node.set_account_password(iter[0], new_text)
|
29
|
+
end
|
30
|
+
iter[col] = new_text
|
31
|
+
else
|
32
|
+
errorEntry(@window, "'snmp' account has to be configured in Option>Preference>SNMP tab")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
tr0=Gtk::CellRendererText.new
|
37
|
+
tr0.editable=true
|
38
|
+
tr0.mode=Gtk::CellRenderer::MODE_EDITABLE
|
39
|
+
tr0.signal_connect("edited") { |renderer, iter, var|
|
40
|
+
cell_edited(renderer, iter, var, 0, node)
|
41
|
+
}
|
42
|
+
column1 = Gtk::TreeViewColumn.new("ID Name", tr0, {:text => 0})
|
43
|
+
column1.set_sort_column_id(0)
|
44
|
+
|
45
|
+
tr1=Gtk::CellRendererText.new
|
46
|
+
tr1.editable=true
|
47
|
+
tr1.mode=Gtk::CellRenderer::MODE_EDITABLE
|
48
|
+
tr1.signal_connect("edited") { |renderer, iter, var|
|
49
|
+
cell_edited(renderer, iter, var, 1, node)
|
50
|
+
}
|
51
|
+
column2 = Gtk::TreeViewColumn.new("Login", tr1, {:text => 1})
|
52
|
+
column2.set_sort_column_id(1)
|
53
|
+
|
54
|
+
tr2=Gtk::CellRendererText.new
|
55
|
+
tr2.editable=true
|
56
|
+
tr2.mode=Gtk::CellRenderer::MODE_EDITABLE
|
57
|
+
tr2.signal_connect("edited") { |renderer, iter, var|
|
58
|
+
cell_edited(renderer, iter, var, 2, node)
|
59
|
+
}
|
60
|
+
column3 = Gtk::TreeViewColumn.new("Password", tr2, {:text => 2})
|
61
|
+
column3.set_sort_column_id(2)
|
62
|
+
|
63
|
+
#by default we hide password column
|
64
|
+
column3.set_visible(false)
|
65
|
+
|
66
|
+
@account_view.append_column(column1)
|
67
|
+
@account_view.append_column(column2)
|
68
|
+
@account_view.append_column(column3)
|
69
|
+
@account_view.show
|
70
|
+
|
71
|
+
def insert_account_entry(node)
|
72
|
+
if !node.account_exist?("default")
|
73
|
+
iter=@account_view.model.append
|
74
|
+
iter[0] = "default"
|
75
|
+
iter[1] = "value1"
|
76
|
+
iter[2] = "value2"
|
77
|
+
node.add_account(iter[0], iter[1], iter[2])
|
78
|
+
else
|
79
|
+
errorEntry(@window, "'default' account already exists")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_selected_account_entry(node)
|
84
|
+
if @account_view.selection.selected
|
85
|
+
if (node.ip != ROOTMAPADDR) && (@account_view.model.get_value(@account_view.selection.selected,0)!= "snmp")
|
86
|
+
node.del_account(@account_view.model.get_value(@account_view.selection.selected,0))
|
87
|
+
@account_view.model.remove(@account_view.selection.selected)
|
88
|
+
else
|
89
|
+
errorEntry(@window, "'snmp' account can't be deleted")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
@account_view.signal_connect("key_press_event") {|w,e|
|
95
|
+
if e.keyval == Gdk::Keyval::GDK_Delete
|
96
|
+
remove_selected_account_entry(node)
|
97
|
+
elsif e.keyval == Gdk::Keyval::GDK_Insert
|
98
|
+
insert_account_entry(node)
|
99
|
+
end
|
100
|
+
}
|
101
|
+
|
102
|
+
#load existing entries
|
103
|
+
nbaccounts=0
|
104
|
+
node.get_all_account().each_pair {|id, table|
|
105
|
+
iter=@account_view.model.append
|
106
|
+
iter[0] = id
|
107
|
+
iter[1] = table[0]
|
108
|
+
iter[2] = table[1]
|
109
|
+
nbaccounts+=1
|
110
|
+
}
|
111
|
+
|
112
|
+
if nbaccounts == 0
|
113
|
+
#load default entries if needed
|
114
|
+
for id in ["wmi","snmp","telnet", "ssh", "custom", "mysql", "oracle", "ipmi"]
|
115
|
+
if !node.account_exist_nr?(id)
|
116
|
+
#add a default one
|
117
|
+
iter=@account_view.model.append
|
118
|
+
iter[0] = id
|
119
|
+
if id == "snmp"
|
120
|
+
iter[1] = $config.read_community
|
121
|
+
iter[2] = $config.write_community
|
122
|
+
elsif id == "wmi"
|
123
|
+
iter[1] = "administrator"
|
124
|
+
iter[2] = "administrator"
|
125
|
+
elsif (id == "telnet") || (id == "ssh") || (id == "mysql") || (id == "ipmi")
|
126
|
+
iter[1] = "root"
|
127
|
+
iter[2] = "root"
|
128
|
+
else
|
129
|
+
iter[1] = "value1"
|
130
|
+
iter[2] = "value2"
|
131
|
+
end
|
132
|
+
node.add_account(id, iter[1], iter[2])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Create a popup menu
|
138
|
+
menu_account = Gtk::Menu.new
|
139
|
+
|
140
|
+
item_add_account = Gtk::ImageMenuItem.new("Add account")
|
141
|
+
image_item_add_account = Gtk::Image.new()
|
142
|
+
image_item_add_account.set_stock(Gtk::Stock::ADD)
|
143
|
+
item_add_account.set_image(image_item_add_account)
|
144
|
+
item_add_account.signal_connect("activate") {
|
145
|
+
insert_account_entry(node)
|
146
|
+
}
|
147
|
+
menu_account.append(item_add_account)
|
148
|
+
|
149
|
+
item_del_account = Gtk::ImageMenuItem.new("Delete account")
|
150
|
+
image_item_del_account = Gtk::Image.new()
|
151
|
+
image_item_del_account.set_stock(Gtk::Stock::REMOVE)
|
152
|
+
item_del_account.set_image(image_item_del_account)
|
153
|
+
item_del_account.signal_connect("activate") {|renderer, iter, var|
|
154
|
+
remove_selected_account_entry(node)
|
155
|
+
}
|
156
|
+
menu_account.append(item_del_account)
|
157
|
+
|
158
|
+
item_switch_password = Gtk::ImageMenuItem.new("Show password")
|
159
|
+
image_item_switch_password = Gtk::Image.new()
|
160
|
+
image_item_switch_password.set_stock(Gtk::Stock::DIALOG_WARNING)
|
161
|
+
item_switch_password.set_image(image_item_switch_password)
|
162
|
+
item_switch_password.signal_connect("activate") {|renderer, iter, var|
|
163
|
+
if @account_view.get_column(2).visible?
|
164
|
+
item_switch_password.label="Show password"
|
165
|
+
else
|
166
|
+
item_switch_password.label="Hide password"
|
167
|
+
end
|
168
|
+
@account_view.get_column(2).visible=!@account_view.get_column(2).visible?
|
169
|
+
}
|
170
|
+
menu_account.append(item_switch_password)
|
171
|
+
|
172
|
+
menu_account.show_all
|
173
|
+
|
174
|
+
@account_view.signal_connect("button_press_event") do |widget, event|
|
175
|
+
if event.kind_of? Gdk::EventButton and event.button == 3
|
176
|
+
menu_account.popup(nil, nil, event.button, event.time)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
hbox = Gtk::HBox.new(FALSE, 1)
|
181
|
+
hbox.add Gtk::Image.new(Gtk::Stock::EDIT, Gtk::IconSize::MENU)
|
182
|
+
hbox.add Gtk::Label::new("Account")
|
183
|
+
hbox.show_all
|
184
|
+
|
185
|
+
scrollhbox = Gtk::HBox::new
|
186
|
+
scrollhbox.show
|
187
|
+
scrollhbox.add(@account_view)
|
188
|
+
|
189
|
+
scrolled = Gtk::ScrolledWindow.new(nil, nil)
|
190
|
+
scrolled.border_width=0
|
191
|
+
scrolled.set_policy(Gtk::POLICY_NEVER,Gtk::POLICY_AUTOMATIC)
|
192
|
+
scrolled.add_with_viewport(scrollhbox)
|
193
|
+
scrolled.show
|
194
|
+
|
195
|
+
vbox.add(scrolled)
|
196
|
+
notebook.append_page frame_account, hbox
|
@@ -0,0 +1,519 @@
|
|
1
|
+
#provide contact details as: firstname lastname email phone mobile im pager location note
|
2
|
+
|
3
|
+
frame_contact = Gtk::Frame::new
|
4
|
+
frame_contact.border_width=10
|
5
|
+
frame_contact.show
|
6
|
+
|
7
|
+
vbox = Gtk::VBox::new
|
8
|
+
vbox.show
|
9
|
+
frame_contact.add vbox
|
10
|
+
|
11
|
+
contact_ls = Gtk::ListStore.new(String, String, String)
|
12
|
+
@contact_view = Gtk::TreeView.new(contact_ls)
|
13
|
+
|
14
|
+
def cell_edited(cell, path_string, new_text, col)
|
15
|
+
iter = @contact_view.model.get_iter(path_string)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
tr0=Gtk::CellRendererText.new
|
20
|
+
#prenom
|
21
|
+
column1 = Gtk::TreeViewColumn.new("First Name", tr0, {:text => 0})
|
22
|
+
column1.set_sort_column_id(0)
|
23
|
+
|
24
|
+
tr1=Gtk::CellRendererText.new
|
25
|
+
#nom
|
26
|
+
column2 = Gtk::TreeViewColumn.new("Last Name", tr1, {:text => 1})
|
27
|
+
column2.set_sort_column_id(1)
|
28
|
+
|
29
|
+
@contact_view.append_column(column1)
|
30
|
+
@contact_view.append_column(column2)
|
31
|
+
@contact_view.show
|
32
|
+
|
33
|
+
def add_contact_entry()
|
34
|
+
add_contact_entry_details(true)
|
35
|
+
if @cb_mail
|
36
|
+
@cb_mail.set_sensitive(@button_mail.active?)
|
37
|
+
@cb_im.set_sensitive(@button_im.active?)
|
38
|
+
@cb_sms.set_sensitive(@entry_sms_device.text != "")
|
39
|
+
@entry_mail_button.set_sensitive(@cb_mail.active?)
|
40
|
+
@entry_im_button.set_sensitive(@cb_im.active?)
|
41
|
+
@entry_sms_button.set_sensitive(@cb_sms.active?)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def edit_contact_entry(ref)
|
46
|
+
add_contact_entry_details(false, ref)
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_contact_entry_details(add_boolean, ref=nil)
|
50
|
+
window=Gtk::Window.new
|
51
|
+
window.set_modal(true)
|
52
|
+
lbl="Edit Contact Entry"
|
53
|
+
if add_boolean
|
54
|
+
lbl="Add Contact Entry"
|
55
|
+
end
|
56
|
+
|
57
|
+
window.set_title(lbl)
|
58
|
+
window.set_size_request(460, 380)
|
59
|
+
|
60
|
+
window.signal_connect("key_press_event") {|w,e|
|
61
|
+
if e.keyval == Gdk::Keyval::GDK_Escape
|
62
|
+
window.destroy
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
frame = Gtk::Frame::new
|
67
|
+
frame.border_width=10
|
68
|
+
frame.show
|
69
|
+
vbox_root=Gtk::VBox::new
|
70
|
+
vbox_root.show
|
71
|
+
window.add vbox_root
|
72
|
+
vbox_root.add frame
|
73
|
+
|
74
|
+
vbox = Gtk::VBox.new
|
75
|
+
vbox.show
|
76
|
+
frame.add vbox
|
77
|
+
|
78
|
+
table = Gtk::Table.new(11,2,false)
|
79
|
+
table.show
|
80
|
+
|
81
|
+
label_fname = Gtk::Label.new "First Name"
|
82
|
+
label_fname.show
|
83
|
+
if add_boolean
|
84
|
+
entry_fname = Gtk::Entry.new
|
85
|
+
else
|
86
|
+
entry_fname = Gtk::Entry.new
|
87
|
+
entry_fname.set_editable false
|
88
|
+
entry_fname.set_text(ref[0])
|
89
|
+
end
|
90
|
+
entry_fname.show
|
91
|
+
table.attach(label_fname,0,1,0,1)
|
92
|
+
table.attach(entry_fname,1,2,0,1)
|
93
|
+
|
94
|
+
label_lname = Gtk::Label.new "Last Name"
|
95
|
+
label_lname.show
|
96
|
+
if add_boolean
|
97
|
+
entry_lname = Gtk::Entry.new
|
98
|
+
else
|
99
|
+
entry_lname = Gtk::Entry.new
|
100
|
+
entry_lname.set_editable false
|
101
|
+
entry_lname.set_text(ref[1])
|
102
|
+
end
|
103
|
+
entry_lname.show
|
104
|
+
table.attach(label_lname,0,1,1,2)
|
105
|
+
table.attach(entry_lname,1,2,1,2)
|
106
|
+
|
107
|
+
label_email = Gtk::Label.new "Email"
|
108
|
+
label_email.show
|
109
|
+
if add_boolean
|
110
|
+
entry_email = Gtk::Entry.new
|
111
|
+
else
|
112
|
+
entry_email = Gtk::Entry.new
|
113
|
+
entry_email.set_text($contact["#{ref[0]}|#{ref[1]}"].email)
|
114
|
+
end
|
115
|
+
entry_email.show
|
116
|
+
table.attach(label_email,0,1,2,3)
|
117
|
+
table.attach(entry_email,1,2,2,3)
|
118
|
+
|
119
|
+
label_phone = Gtk::Label.new "Phone"
|
120
|
+
label_phone.show
|
121
|
+
if add_boolean
|
122
|
+
entry_phone = Gtk::Entry.new
|
123
|
+
else
|
124
|
+
entry_phone = Gtk::Entry.new
|
125
|
+
entry_phone.set_text($contact["#{ref[0]}|#{ref[1]}"].phone)
|
126
|
+
end
|
127
|
+
entry_phone.show
|
128
|
+
table.attach(label_phone,0,1,3,4)
|
129
|
+
table.attach(entry_phone,1,2,3,4)
|
130
|
+
|
131
|
+
label_mobile = Gtk::Label.new "Mobile"
|
132
|
+
label_mobile.show
|
133
|
+
if add_boolean
|
134
|
+
entry_mobile = Gtk::Entry.new
|
135
|
+
else
|
136
|
+
entry_mobile = Gtk::Entry.new
|
137
|
+
entry_mobile.set_text($contact["#{ref[0]}|#{ref[1]}"].mobile)
|
138
|
+
end
|
139
|
+
entry_mobile.show
|
140
|
+
table.attach(label_mobile,0,1,4,5)
|
141
|
+
table.attach(entry_mobile,1,2,4,5)
|
142
|
+
|
143
|
+
label_pager = Gtk::Label.new "Pager"
|
144
|
+
label_pager.show
|
145
|
+
if add_boolean
|
146
|
+
entry_pager = Gtk::Entry.new
|
147
|
+
else
|
148
|
+
entry_pager = Gtk::Entry.new
|
149
|
+
entry_pager.set_text($contact["#{ref[0]}|#{ref[1]}"].pager)
|
150
|
+
end
|
151
|
+
entry_pager.show
|
152
|
+
table.attach(label_pager,0,1,5,6)
|
153
|
+
table.attach(entry_pager,1,2,5,6)
|
154
|
+
|
155
|
+
label_im = Gtk::Label.new "IM"
|
156
|
+
label_im.show
|
157
|
+
if add_boolean
|
158
|
+
entry_im = Gtk::Entry.new
|
159
|
+
else
|
160
|
+
entry_im = Gtk::Entry.new
|
161
|
+
entry_im.set_text($contact["#{ref[0]}|#{ref[1]}"].im)
|
162
|
+
end
|
163
|
+
entry_im.show
|
164
|
+
table.attach(label_im,0,1,6,7)
|
165
|
+
table.attach(entry_im,1,2,6,7)
|
166
|
+
|
167
|
+
label_title = Gtk::Label.new "Title"
|
168
|
+
label_title.show
|
169
|
+
if add_boolean
|
170
|
+
entry_title = Gtk::Entry.new
|
171
|
+
else
|
172
|
+
entry_title = Gtk::Entry.new
|
173
|
+
entry_title.set_text($contact["#{ref[0]}|#{ref[1]}"].title)
|
174
|
+
end
|
175
|
+
entry_title.show
|
176
|
+
table.attach(label_title,0,1,7,8)
|
177
|
+
table.attach(entry_title,1,2,7,8)
|
178
|
+
|
179
|
+
label_organization = Gtk::Label.new "Organization"
|
180
|
+
label_organization.show
|
181
|
+
if add_boolean
|
182
|
+
entry_organization = Gtk::Entry.new
|
183
|
+
else
|
184
|
+
entry_organization = Gtk::Entry.new
|
185
|
+
entry_organization.set_text($contact["#{ref[0]}|#{ref[1]}"].organization)
|
186
|
+
end
|
187
|
+
entry_organization.show
|
188
|
+
table.attach(label_organization,0,1,8,9)
|
189
|
+
table.attach(entry_organization,1,2,8,9)
|
190
|
+
|
191
|
+
label_location = Gtk::Label.new "Location"
|
192
|
+
label_location.show
|
193
|
+
if add_boolean
|
194
|
+
entry_location = Gtk::Entry.new
|
195
|
+
else
|
196
|
+
entry_location = Gtk::Entry.new
|
197
|
+
entry_location.set_text($contact["#{ref[0]}|#{ref[1]}"].location)
|
198
|
+
end
|
199
|
+
entry_location.show
|
200
|
+
table.attach(label_location,0,1,9,10)
|
201
|
+
table.attach(entry_location,1,2,9,10)
|
202
|
+
|
203
|
+
label_note = Gtk::Label.new "Note"
|
204
|
+
label_note.show
|
205
|
+
if add_boolean
|
206
|
+
entry_note = Gtk::Entry.new
|
207
|
+
else
|
208
|
+
entry_note = Gtk::Entry.new
|
209
|
+
entry_note.set_text($contact["#{ref[0]}|#{ref[1]}"].note)
|
210
|
+
end
|
211
|
+
entry_note.show
|
212
|
+
table.attach(label_note,0,1,10,11)
|
213
|
+
table.attach(entry_note,1,2,10,11)
|
214
|
+
|
215
|
+
bbox =Gtk::HBox::new(FALSE, 10)
|
216
|
+
bbox.border_width=10
|
217
|
+
bbox.show
|
218
|
+
|
219
|
+
ok_button = Gtk::Button.new(Gtk::Stock::OK)
|
220
|
+
ok_button.show
|
221
|
+
ok_button.signal_connect("clicked") {
|
222
|
+
if add_boolean
|
223
|
+
#new entry!
|
224
|
+
if !Contact::contact_exist?(entry_fname.text(),entry_lname.text())
|
225
|
+
Contact::add_contact(entry_fname.text(), entry_lname.text(), entry_email.text(), entry_phone.text(), entry_mobile.text(), entry_pager.text(), entry_im.text(), entry_title.text(), entry_organization.text(), entry_location.text(), entry_note.text())
|
226
|
+
iter = @contact_view.model.append
|
227
|
+
iter[0] = entry_fname.text()
|
228
|
+
iter[1] = entry_lname.text()
|
229
|
+
window.destroy
|
230
|
+
else
|
231
|
+
dialog = Gtk::MessageDialog.new(window, Gtk::Dialog::DESTROY_WITH_PARENT,
|
232
|
+
Gtk::MessageDialog::ERROR,
|
233
|
+
Gtk::MessageDialog::BUTTONS_OK,
|
234
|
+
"Contact '#{entry_fname.text()} #{entry_lname.text()}' already exists!")
|
235
|
+
dialog.run
|
236
|
+
dialog.destroy
|
237
|
+
end
|
238
|
+
else
|
239
|
+
#modify existing entry
|
240
|
+
Contact::set_email(entry_fname.text(),entry_lname.text(),entry_email.text())
|
241
|
+
Contact::set_phone(entry_fname.text(),entry_lname.text(),entry_phone.text())
|
242
|
+
Contact::set_mobile(entry_fname.text(),entry_lname.text(),entry_mobile.text())
|
243
|
+
Contact::set_pager(entry_fname.text(),entry_lname.text(),entry_pager.text())
|
244
|
+
Contact::set_im(entry_fname.text(),entry_lname.text(),entry_im.text())
|
245
|
+
Contact::set_title(entry_fname.text(),entry_lname.text(),entry_title.text())
|
246
|
+
Contact::set_organization(entry_fname.text(),entry_lname.text(),entry_organization.text())
|
247
|
+
Contact::set_location(entry_fname.text(),entry_lname.text(),entry_location.text())
|
248
|
+
Contact::set_note(entry_fname.text(),entry_lname.text(),entry_note.text())
|
249
|
+
|
250
|
+
# @contact_view.each do |model,path,iter|
|
251
|
+
# if (iter[0] == entry_fname.text()) && (iter[1] == entry_lname.text())
|
252
|
+
# break
|
253
|
+
# end
|
254
|
+
#end
|
255
|
+
window.destroy
|
256
|
+
end
|
257
|
+
}
|
258
|
+
|
259
|
+
cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
|
260
|
+
cancel_button.show
|
261
|
+
cancel_button.signal_connect("clicked") {
|
262
|
+
window.destroy
|
263
|
+
}
|
264
|
+
|
265
|
+
ok_button.set_flags(Gtk::Widget::CAN_DEFAULT)
|
266
|
+
bbox.pack_start(ok_button, TRUE, TRUE, 0)
|
267
|
+
cancel_button.set_flags(Gtk::Widget::CAN_DEFAULT)
|
268
|
+
bbox.pack_start(cancel_button, TRUE, TRUE, 0)
|
269
|
+
vbox.add table
|
270
|
+
separator = Gtk::HSeparator::new()
|
271
|
+
separator.show
|
272
|
+
vbox_root.pack_start(separator, FALSE, TRUE, 0)
|
273
|
+
vbox_root.pack_start(bbox, FALSE, TRUE, 0)
|
274
|
+
window.show
|
275
|
+
end
|
276
|
+
|
277
|
+
def fill_contact_entry()
|
278
|
+
window=Gtk::Window.new
|
279
|
+
window.set_modal(true)
|
280
|
+
|
281
|
+
window.set_title("Fill Contact using LDAP directory")
|
282
|
+
window.set_size_request(360, 240)
|
283
|
+
|
284
|
+
window.signal_connect("key_press_event") {|w,e|
|
285
|
+
if e.keyval == Gdk::Keyval::GDK_Escape
|
286
|
+
window.destroy
|
287
|
+
end
|
288
|
+
}
|
289
|
+
|
290
|
+
frame = Gtk::Frame::new
|
291
|
+
frame.border_width=10
|
292
|
+
frame.show
|
293
|
+
vbox_root=Gtk::VBox::new
|
294
|
+
vbox_root.show
|
295
|
+
window.add vbox_root
|
296
|
+
vbox_root.add frame
|
297
|
+
|
298
|
+
vbox = Gtk::VBox.new
|
299
|
+
vbox.show
|
300
|
+
frame.add vbox
|
301
|
+
|
302
|
+
table = Gtk::Table.new(3,2,false)
|
303
|
+
table.show
|
304
|
+
|
305
|
+
label_host = Gtk::Label.new "Host"
|
306
|
+
label_host.show
|
307
|
+
entry_host = Gtk::Entry.new
|
308
|
+
entry_host.show
|
309
|
+
table.attach(label_host,0,1,0,1)
|
310
|
+
table.attach(entry_host,1,2,0,1)
|
311
|
+
|
312
|
+
label_port = Gtk::Label.new "Port"
|
313
|
+
label_port.show
|
314
|
+
entry_port = Gtk::Entry.new
|
315
|
+
entry_port.set_text(LDAP::LDAP_PORT.to_s)
|
316
|
+
entry_port.show
|
317
|
+
table.attach(label_port,0,1,1,2)
|
318
|
+
table.attach(entry_port,1,2,1,2)
|
319
|
+
|
320
|
+
label_base = Gtk::Label.new "Base"
|
321
|
+
label_base.show
|
322
|
+
entry_base = Gtk::Entry.new
|
323
|
+
entry_base.show
|
324
|
+
table.attach(label_base,0,1,2,3)
|
325
|
+
table.attach(entry_base,1,2,2,3)
|
326
|
+
|
327
|
+
|
328
|
+
bbox =Gtk::HBox::new(FALSE, 10)
|
329
|
+
bbox.border_width=10
|
330
|
+
bbox.show
|
331
|
+
|
332
|
+
ok_button = Gtk::Button.new(Gtk::Stock::REFRESH)
|
333
|
+
ok_button.show
|
334
|
+
ok_button.signal_connect("clicked") {
|
335
|
+
host = entry_host.text
|
336
|
+
port = entry_port.text
|
337
|
+
#SSLPORT = LDAP::LDAPS_PORT
|
338
|
+
base = entry_base.text
|
339
|
+
if host!="" && port!="" && base!=""
|
340
|
+
scope = LDAP::LDAP_SCOPE_SUBTREE
|
341
|
+
filter = '(objectclass=person)'
|
342
|
+
attrs = ['cn', 'sn', 'givenName', 'mail', 'telephoneNumber', 'mobile', 'title', 'o']
|
343
|
+
|
344
|
+
begin
|
345
|
+
Thread.start {
|
346
|
+
conn = LDAP::Conn.new(host, port.to_i)
|
347
|
+
#conn.bind(dn=nil, password=nil, method=LDAP::LDAP_AUTH_SIMPLE)
|
348
|
+
#conn.perror("bind")
|
349
|
+
conn.search(base, scope, filter, attrs) { |entry|
|
350
|
+
# print distinguished name
|
351
|
+
#p entry.dn
|
352
|
+
# print all attribute names
|
353
|
+
#p entry.attrs
|
354
|
+
# print values of attribute 'sn'
|
355
|
+
# print entry as Hash
|
356
|
+
$log.debug(entry.to_hash)
|
357
|
+
firstname=entry.to_hash["givenName"]
|
358
|
+
lastname=entry.to_hash["sn"]
|
359
|
+
#seems all values are returned in an array
|
360
|
+
if firstname && lastname && !Contact::contact_exist?(firstname.first, lastname.first)
|
361
|
+
Contact::add_contact(firstname.first, lastname.first, (entry.to_hash["mail"] && entry.to_hash["mail"].first) || "", (entry.to_hash["telephoneNumber"] && entry.to_hash["telephoneNumber"].first) || "", (entry.to_hash["mobile"] && entry.to_hash["mobile"].first) || "", "", "", (entry.to_hash["title"] && entry.to_hash["title"].first) || "", (entry.to_hash["o"] && entry.to_hash["o"].first) || "", "", "")
|
362
|
+
Gtk.thread_protect do
|
363
|
+
if @contact_view
|
364
|
+
iter = @contact_view.model.append
|
365
|
+
iter[0] = firstname.first
|
366
|
+
iter[1] = lastname.first
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
}
|
371
|
+
}
|
372
|
+
rescue LDAP::ResultError
|
373
|
+
$log.error("Can't search for contact with given arguments")
|
374
|
+
rescue Exception => msg
|
375
|
+
$log.error("LDAP searching error #{msg}")
|
376
|
+
end
|
377
|
+
#conn.perror("search")
|
378
|
+
#conn.unbind
|
379
|
+
end
|
380
|
+
}
|
381
|
+
|
382
|
+
cancel_button = Gtk::Button.new(Gtk::Stock::CLOSE)
|
383
|
+
cancel_button.show
|
384
|
+
cancel_button.signal_connect("clicked") {
|
385
|
+
window.destroy
|
386
|
+
}
|
387
|
+
|
388
|
+
ok_button.set_flags(Gtk::Widget::CAN_DEFAULT)
|
389
|
+
bbox.pack_start(ok_button, TRUE, TRUE, 0)
|
390
|
+
cancel_button.set_flags(Gtk::Widget::CAN_DEFAULT)
|
391
|
+
bbox.pack_start(cancel_button, TRUE, TRUE, 0)
|
392
|
+
vbox.add table
|
393
|
+
separator = Gtk::HSeparator::new()
|
394
|
+
separator.show
|
395
|
+
vbox_root.pack_start(separator, FALSE, TRUE, 0)
|
396
|
+
vbox_root.pack_start(bbox, FALSE, TRUE, 0)
|
397
|
+
window.show
|
398
|
+
end
|
399
|
+
|
400
|
+
def del_selected_contact_entry(win)
|
401
|
+
if @contact_view.selection.selected
|
402
|
+
firstname=@contact_view.selection.selected[0]
|
403
|
+
lastname=@contact_view.selection.selected[1]
|
404
|
+
if !Contact::used?(firstname, lastname)
|
405
|
+
@contact_view.model.remove(@contact_view.selection.selected)
|
406
|
+
Contact::del_contact(firstname, lastname)
|
407
|
+
if Contact::contact_nb_entry() == 0
|
408
|
+
if @cb_mail
|
409
|
+
@cb_mail.set_sensitive(false)
|
410
|
+
@cb_im.set_sensitive(false)
|
411
|
+
@cb_sms.set_sensitive(false)
|
412
|
+
@entry_mail_button.set_sensitive(false)
|
413
|
+
@entry_im_button.set_sensitive(false)
|
414
|
+
@entry_sms_button.set_sensitive(false)
|
415
|
+
end
|
416
|
+
end
|
417
|
+
else
|
418
|
+
errorEntry(win, "Contact #{firstname} #{lastname} is in used #{$contact["#{firstname}|#{lastname}"].nb_use} time(s)")
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
@contact_view.signal_connect("key_press_event") {|w,e|
|
424
|
+
if e.keyval == Gdk::Keyval::GDK_Delete
|
425
|
+
del_selected_contact_entry(window)
|
426
|
+
elsif e.keyval == Gdk::Keyval::GDK_Insert
|
427
|
+
add_contact_entry()
|
428
|
+
end
|
429
|
+
}
|
430
|
+
@contact_view.signal_connect("button_press_event") do |widget, event|
|
431
|
+
if (@contact_view.selection.selected!=nil) && (event.event_type == Gdk::Event::BUTTON2_PRESS)
|
432
|
+
edit_contact_entry(@contact_view.selection.selected)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
|
437
|
+
#load existing entries
|
438
|
+
$contact.each_key {|id|
|
439
|
+
iter=@contact_view.model.append
|
440
|
+
iter[0] = $contact[id].firstname
|
441
|
+
iter[1] = $contact[id].lastname
|
442
|
+
} unless !$contact
|
443
|
+
|
444
|
+
# Create a popup menu
|
445
|
+
menu_contact = Gtk::Menu.new
|
446
|
+
|
447
|
+
item_add_contact = Gtk::ImageMenuItem.new("Add contact")
|
448
|
+
image_item_add_contact = Gtk::Image.new()
|
449
|
+
image_item_add_contact.set_stock(Gtk::Stock::ADD)
|
450
|
+
item_add_contact.set_image(image_item_add_contact)
|
451
|
+
item_add_contact.signal_connect("activate") {
|
452
|
+
add_contact_entry()
|
453
|
+
}
|
454
|
+
menu_contact.append(item_add_contact)
|
455
|
+
|
456
|
+
item_del_contact = Gtk::ImageMenuItem.new("Delete contact")
|
457
|
+
image_item_del_contact = Gtk::Image.new()
|
458
|
+
image_item_del_contact.set_stock(Gtk::Stock::REMOVE)
|
459
|
+
item_del_contact.set_image(image_item_del_contact)
|
460
|
+
item_del_contact.signal_connect("activate") {|renderer, iter, var|
|
461
|
+
del_selected_contact_entry(window)
|
462
|
+
}
|
463
|
+
menu_contact.append(item_del_contact)
|
464
|
+
|
465
|
+
item_edit_contact = Gtk::ImageMenuItem.new("Edit contact")
|
466
|
+
image_item_edit_contact = Gtk::Image.new()
|
467
|
+
image_item_edit_contact.set_stock(Gtk::Stock::EDIT)
|
468
|
+
item_edit_contact.set_image(image_item_edit_contact)
|
469
|
+
item_edit_contact.signal_connect("activate") {
|
470
|
+
if @contact_view.selection.selected != nil
|
471
|
+
edit_contact_entry(@contact_view.selection.selected)
|
472
|
+
end
|
473
|
+
}
|
474
|
+
menu_contact.append(item_edit_contact)
|
475
|
+
|
476
|
+
item_fill_contact = Gtk::ImageMenuItem.new("Fill contact using LDAP")
|
477
|
+
image_item_fill_contact = Gtk::Image.new()
|
478
|
+
image_item_fill_contact.set_stock(Gtk::Stock::COPY)
|
479
|
+
item_fill_contact.set_image(image_item_fill_contact)
|
480
|
+
item_fill_contact.signal_connect("activate") {
|
481
|
+
fill_contact_entry()
|
482
|
+
}
|
483
|
+
if $ldap_library_missing
|
484
|
+
item_fill_contact.set_sensitive(false)
|
485
|
+
end
|
486
|
+
menu_contact.append(item_fill_contact)
|
487
|
+
|
488
|
+
menu_contact.show_all
|
489
|
+
|
490
|
+
@contact_view.signal_connect("button_press_event") do |widget, event|
|
491
|
+
if event.kind_of? Gdk::EventButton and event.button == 3
|
492
|
+
if @contact_view.selection.selected
|
493
|
+
item_del_contact.set_sensitive(true)
|
494
|
+
item_edit_contact.set_sensitive(true)
|
495
|
+
else
|
496
|
+
item_del_contact.set_sensitive(false)
|
497
|
+
item_edit_contact.set_sensitive(false)
|
498
|
+
end
|
499
|
+
menu_contact.popup(nil, nil, event.button, event.time)
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
hbox = Gtk::HBox.new(FALSE, 1)
|
504
|
+
hbox.add Gtk::Image.new(Gtk::Stock::ORIENTATION_PORTRAIT, Gtk::IconSize::MENU)
|
505
|
+
hbox.add Gtk::Label::new("Contact")
|
506
|
+
hbox.show_all
|
507
|
+
|
508
|
+
scrollhbox = Gtk::HBox::new
|
509
|
+
scrollhbox.show
|
510
|
+
scrollhbox.add(@contact_view)
|
511
|
+
|
512
|
+
scrolled = Gtk::ScrolledWindow.new(nil, nil)
|
513
|
+
scrolled.border_width=0
|
514
|
+
scrolled.set_policy(Gtk::POLICY_NEVER,Gtk::POLICY_AUTOMATIC)
|
515
|
+
scrolled.add_with_viewport(scrollhbox)
|
516
|
+
scrolled.show
|
517
|
+
|
518
|
+
vbox.add(scrolled)
|
519
|
+
notebook.append_page frame_contact, hbox
|