~thelupine/pyconnmgr/trunk

« back to all changes in this revision

Viewing changes to src/pyconnmgr-gtk3

  • Committer: Danny Bray
  • Date: 2012-12-29 15:31:13 UTC
  • Revision ID: danny@ssh.thelupine.com-20121229153113-br9v62bojjzb1c4u
fixed m$ license rdesktop issue; last gtk2 update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
    title:          Python Connections Manager
 
5
 
 
6
    date:           10.14.2009
 
7
 
 
8
    author:         Lupine  - http://www.thelupine.com
 
9
 
 
10
    description:    Python/GTK/Glade frontend to the SSH, VNC and rdesktop
 
11
 
 
12
"""
 
13
 
 
14
import sys, os, glob, signal, time, re, sqlite3
 
15
from subprocess import Popen, PIPE
 
16
from gi.repository import Gtk
 
17
 
 
18
APPNAME     = "pyconnmgr"
 
19
APPVERSION  = "3.0.3"
 
20
APPCONFDIR  = "/.pyconnmgr"
 
21
GLADE_FILE  = "/usr/share/pyconnmgr/pyconnmgr.glade"
 
22
#GLADE_FILE  = "glade/pyconnmgr.glade"
 
23
HOSTSFILE   = os.environ["HOME"] + APPCONFDIR + "/hostsfile.db"
 
24
 
 
25
print "\n\n" + APPNAME + " version " + APPVERSION + ", Copyright (C) 2008\n"
 
26
print APPNAME + " comes with ABSOLUTELY NO WARRANTY, is licensed under the"
 
27
print "GNU GENERAL PUBLIC LICENSE and is free and open source software."
 
28
print "http://www.thelupine.com\n\n"
 
29
 
 
30
class ConnectionManager:
 
31
 
 
32
    def check_appconfig_dir(self):
 
33
        """
 
34
        This function will create the ENV HOME app config directory
 
35
        It will do so by first checking if the APPCONFDIR dir exists,
 
36
        if it does not it will be created, or give an error
 
37
        """
 
38
        appsettingsdir = os.environ["HOME"] + APPCONFDIR
 
39
        if not os.path.isdir(appsettingsdir):
 
40
            try:
 
41
                os.mkdir(appsettingsdir)
 
42
            except OSError:
 
43
                errormessage = 'Unable to create configuration directory:\n' \
 
44
                                + appsettingsdir + \
 
45
                                '\nYou will not be able to save hosts.\n\n'
 
46
                print errormessage
 
47
                self.error_message_label.set_text(errormessage)
 
48
                self.error_dialog.show()
 
49
        return appsettingsdir
 
50
 
 
51
    def check_sqlitedb(self):
 
52
        """
 
53
        This function will check for the sqlite3 file, and if not exist
 
54
        it will create it.  If it does exist, it will perform any DB
 
55
        updates that are needed.
 
56
        """
 
57
        if os.path.isfile(HOSTSFILE):
 
58
            sqlconn = sqlite3.connect(HOSTSFILE)
 
59
            sqlcursor = sqlconn.cursor()
 
60
            sqlcursor.execute('''pragma table_info('hosts')''')
 
61
            """
 
62
            # this is what the current schema should look like
 
63
            0|name|text|0||0
 
64
            1|sshport|int|0||0
 
65
            2|sshuser|text|0||0
 
66
            3|sshopt|text|0||0
 
67
            4|vnctrucolor|int|0||0
 
68
            5|vncbgr|int|0||0
 
69
            6|vncquality|int|0||0
 
70
            7|vnccompresslevel|int|0||0
 
71
            8|vncport|int|0||0
 
72
            9|vncpassword|text|0||0
 
73
            10|vncx11cur|int|0||0
 
74
            11|rdpgeom|text|0||0
 
75
            12|rdpuser|text|0||0
 
76
            13|rdpdom|text|0||0
 
77
            14|tab|int|0||0
 
78
            15|sftpport|int|0||0
 
79
            16|sftpuser|text|0||0
 
80
            17|sftppath|text|0||0
 
81
            18|smbuser|text|0||0
 
82
            19|smbpath|text|0||0
 
83
            20|ftpport|int|0||0
 
84
            21|ftpuser|text|0||0
 
85
            22|ftppath|text|0||0
 
86
            """
 
87
            col_name_list = [tuple[0] for tuple in sqlcursor.description]
 
88
            #check if "tab" schema update has been done
 
89
            for col_name in col_name_list:
 
90
                if not re.search('14|tab|int|0||0', col_name):
 
91
                    sqlcursor.execute('''ALTER TABLE hosts ADD tab int''')
 
92
                    sqlconn.commit()
 
93
                else:
 
94
                    break
 
95
            #check if "sftp" schema update has been done
 
96
            for col_name in col_name_list:
 
97
                if not re.search('15|sftpport|int|0||0', col_name):
 
98
                    sqlcursor.execute('''ALTER TABLE hosts ADD sftpport int''')
 
99
                    sqlconn.commit()
 
100
                    sqlcursor.execute('''ALTER TABLE hosts ADD sftpuser text''')
 
101
                    sqlconn.commit()
 
102
                    sqlcursor.execute('''ALTER TABLE hosts ADD sftppath text''')
 
103
                    sqlconn.commit()
 
104
                else:
 
105
                    break
 
106
            #check if "smb" schema update has been done
 
107
            for col_name in col_name_list:
 
108
                if not re.search('19|smbpath|text|0||0', col_name):
 
109
                    sqlcursor.execute('''ALTER TABLE hosts ADD smbuser text''')
 
110
                    sqlconn.commit()
 
111
                    sqlcursor.execute('''ALTER TABLE hosts ADD smbpath text''')
 
112
                    sqlconn.commit()
 
113
                else:
 
114
                    break
 
115
            #check if "ftp" schema update has been done
 
116
            for col_name in col_name_list:
 
117
                if not re.search('20|ftpport|int|0||0', col_name):
 
118
                    sqlcursor.execute('''ALTER TABLE hosts ADD ftpport int''')
 
119
                    sqlconn.commit()
 
120
                    sqlcursor.execute('''ALTER TABLE hosts ADD ftpuser text''')
 
121
                    sqlconn.commit()
 
122
                    sqlcursor.execute('''ALTER TABLE hosts ADD ftppath text''')
 
123
                    sqlconn.commit()
 
124
                else:
 
125
                    break
 
126
        else:
 
127
            try:
 
128
                sqlite3.connect(HOSTSFILE)
 
129
            except:
 
130
                errormessage = 'Unable to connect to sqlite3 file:\n' \
 
131
                                + HOSTSFILE + \
 
132
                                '\nYou will not be able to save hosts.\n\n'
 
133
                print errormessage
 
134
                self.error_message_label.set_text(errormessage)
 
135
                self.error_dialog.show()
 
136
            else:
 
137
                sqlconn = sqlite3.connect(HOSTSFILE)
 
138
                sqlcursor = sqlconn.cursor()
 
139
                sqlcursor.execute('''create table if not exists hosts
 
140
                                        (name text,
 
141
                                        sshport int,
 
142
                                        sshuser text,
 
143
                                        sshopt text,
 
144
                                        vnctrucolor int,
 
145
                                        vncbgr int,
 
146
                                        vncquality int,
 
147
                                        vnccompresslevel int,
 
148
                                        vncport int,
 
149
                                        vncpassword text,
 
150
                                        vncx11cur int,
 
151
                                        rdpgeom text,
 
152
                                        rdpuser text,
 
153
                                        rdpdom text,
 
154
                                        tab int,
 
155
                                        sftpport int,
 
156
                                        sftpuser text,
 
157
                                        sftppath text,
 
158
                                        smbuser text,
 
159
                                        smbpath text,
 
160
                                        ftpport int,
 
161
                                        ftpuser text,
 
162
                                        ftppath text)''')
 
163
                sqlconn.commit()
 
164
                sqlconn.close
 
165
 
 
166
    def read_hostsfile(self):
 
167
        """
 
168
        This function will check for the existence of a HOSTSFILE and if found,
 
169
        read in it's contents into an array after checking the table structure
 
170
        is up to date.  If not found, it will create a blank HOSTSFILE.
 
171
        """
 
172
        hostnames = []
 
173
        if os.path.isfile(HOSTSFILE):
 
174
            sqlconn = sqlite3.connect(HOSTSFILE)
 
175
            #select all hostnames, and read into an array
 
176
            for row in sqlconn.execute("SELECT name FROM hosts \
 
177
                                        ORDER BY name DESC"):
 
178
                for hostname in row:
 
179
                    if hostname:
 
180
                        hostnames.append(hostname)
 
181
            sqlconn.close
 
182
        return hostnames
 
183
 
 
184
    def on_del_menu_activate(self, action):
 
185
        """This function will remove a host entry from the HOSTSFILE"""
 
186
        host = self.host_entry.get_text()
 
187
        sqlconn = sqlite3.connect(HOSTSFILE)
 
188
        sqlcursor = sqlconn.cursor()
 
189
        sqlcursor.execute('DELETE FROM hosts WHERE name=?', (host,))
 
190
        sqlconn.commit()
 
191
        sqlconn.close()
 
192
        self.host_entry.set_text('')
 
193
        self.populate_cmbox_hostlist()
 
194
        self.populate_cmbox_hostlist_entry_completion()
 
195
 
 
196
    def update_host_settings(self):
 
197
        """This function will read HOSTSFILE, and populate the proper fields"""
 
198
        host = self.host_entry.get_text()
 
199
        sqlconn = sqlite3.connect(HOSTSFILE)
 
200
        sqlcursor = sqlconn.cursor()
 
201
        #first look through the sqlite db, and assign values to variables
 
202
        for row in sqlcursor.execute("SELECT * FROM hosts"):
 
203
            if (row[0]):
 
204
                hostname = row[0]
 
205
            else:
 
206
                hostname = ""
 
207
 
 
208
            if (row[1]):
 
209
                hostsshport = row[1]
 
210
            else:
 
211
                hostsshport = 22
 
212
 
 
213
            if (row[2]):
 
214
                hostsshuser = row[2]
 
215
            else:
 
216
                hostsshuser = ""
 
217
 
 
218
            if (row[3]):
 
219
                hostsshopt = row[3]
 
220
            else:
 
221
                hostsshopt = ""
 
222
 
 
223
            if (row[4]):
 
224
                hostvnctrucolor = row[4]
 
225
            else:
 
226
                hostvnctrucolor = ""
 
227
 
 
228
            if (row[5]):
 
229
                hostvncbgr = row[5]
 
230
            else:
 
231
                hostvncbgr = ""
 
232
 
 
233
            if (row[6]):
 
234
                hostvncquality = row[6]
 
235
            else:
 
236
                hostvncquality = 9
 
237
 
 
238
            if (row[7]):
 
239
                hostvnccompresslevel = row[7]
 
240
            else:
 
241
                hostvnccompresslevel = 9
 
242
 
 
243
            if (row[8]):
 
244
                hostvncport = row[8]
 
245
            else:
 
246
                hostvncport = 5900
 
247
 
 
248
            if (row[9]):
 
249
                hostvncpassword = row[9]
 
250
            else:
 
251
                hostvncpassword = ""
 
252
 
 
253
            if (row[10]):
 
254
                hostvncx11cur = row[10]
 
255
            else:
 
256
                hostvncx11cur = ""
 
257
 
 
258
            if (row[11]):
 
259
                hostrdpgeom = row[11]
 
260
            else:
 
261
                hostrdpgeom = ""
 
262
 
 
263
            if (row[12]):
 
264
                hostrdpuser = row[12]
 
265
            else:
 
266
                hostrdpuser = ""
 
267
 
 
268
            if (row[13]):
 
269
                hostrdpdom = row[13]
 
270
            else:
 
271
                hostrdpdom = ""
 
272
 
 
273
            if (row[14]):
 
274
                tabposition = row[14]
 
275
            else:
 
276
                tabposition = 0
 
277
 
 
278
            if (row[15]):
 
279
                hostsftpport = row[15]
 
280
            else:
 
281
                hostsftpport = 22
 
282
 
 
283
            if (row[16]):
 
284
                hostsftpuser = row[16]
 
285
            else:
 
286
                hostsftpuser = ""
 
287
 
 
288
            if (row[17]):
 
289
                hostsftppath = row[17]
 
290
            else:
 
291
                hostsftppath = ""
 
292
 
 
293
            if (row[18]):
 
294
                hostsmbuser = row[18]
 
295
            else:
 
296
                hostsmbuser = ""
 
297
 
 
298
            if (row[19]):
 
299
                hostsmbpath = row[19]
 
300
            else:
 
301
                hostsmbpath = ""
 
302
 
 
303
            if (row[20]):
 
304
                hostftpport = row[20]
 
305
            else:
 
306
                hostftpport = 21
 
307
 
 
308
            if (row[21]):
 
309
                hostftpuser = row[21]
 
310
            else:
 
311
                hostftpuser = ""
 
312
 
 
313
            if (row[22]):
 
314
                hostftppath = row[22]
 
315
            else:
 
316
                hostftppath = ""
 
317
 
 
318
            #next, if a proper host is entered, update the widgets with the
 
319
            #above variables
 
320
            if hostname == host:
 
321
                self.tabbed_notebook.set_current_page(tabposition)
 
322
                #SSH
 
323
                self.ssh_port_sbtn.set_text(str(hostsshport))
 
324
                self.ssh_port_sbtn.set_value(hostsshport)
 
325
                self.ssh_user_entry.set_text(hostsshuser)
 
326
                self.ssh_options_entry.set_text(hostsshopt)
 
327
                #SFTP
 
328
                self.sftp_port_sbtn.set_text(str(hostsftpport))
 
329
                self.sftp_port_sbtn.set_value(hostsftpport)
 
330
                self.sftp_user_entry.set_text(hostsftpuser)
 
331
                self.sftp_path_entry.set_text(hostsftppath)
 
332
                #VNC
 
333
                self.vnc_quality_sbtn.set_text(str(hostvncquality))
 
334
                self.vnc_quality_sbtn.set_value(hostvncquality)
 
335
                self.vnc_compress_sbtn.set_text(str(hostvnccompresslevel))
 
336
                self.vnc_compress_sbtn.set_value(hostvnccompresslevel)
 
337
                self.vnc_port_sbtn.set_text(str(hostvncport))
 
338
                self.vnc_port_sbtn.set_value(hostvncport)
 
339
                self.vnc_password_entry.set_text(hostvncpassword)
 
340
                if hostvncx11cur == 1:
 
341
                    self.vnc_x11cur_chkbox.set_active(1)
 
342
                else:
 
343
                    self.vnc_x11cur_chkbox.set_active(0)
 
344
                if hostvnctrucolor == 1:
 
345
                    self.vnc_trucolor_rbtn.set_active(1)
 
346
                else:
 
347
                    self.vnc_trucolor_rbtn.set_active(0)
 
348
                if hostvncbgr == 1:
 
349
                    self.vnc_bgr233_rbtn.set_active(1)
 
350
                else:
 
351
                    self.vnc_bgr233_rbtn.set_active(0)
 
352
                #RDP
 
353
                self.rdp_geometry_entry.set_text(hostrdpgeom)
 
354
                self.rdp_user_entry.set_text(hostrdpuser)
 
355
                self.rdp_domain_entry.set_text(hostrdpdom)
 
356
                #SMB
 
357
                self.smb_user_entry.set_text(hostsmbuser)
 
358
                self.smb_path_entry.set_text(hostsmbpath)
 
359
                #FTP
 
360
                self.ftp_port_sbtn.set_text(str(hostftpport))
 
361
                self.ftp_port_sbtn.set_value(hostftpport)
 
362
                self.ftp_user_entry.set_text(hostftpuser)
 
363
                self.ftp_path_entry.set_text(hostftppath)
 
364
        sqlconn.close
 
365
 
 
366
    def on_host_entry_changed(self, action):
 
367
        """This function will call to the update_host_settings function"""
 
368
        self.update_host_settings()
 
369
 
 
370
    def update_host_info(self,host,sshport,sshuser,sshoptions,vnctrucolor, \
 
371
        vncbgr,vncquality,vnccompresslevel,vncport,vncpasswd,vncx11cur, \
 
372
        rdpgeometry,rdpuser,rdpdomain,selectedtab,sftpport,sftpuser,sftppath, \
 
373
        smbuser,smbpath,ftpport,ftpuser,ftppath):
 
374
        """This function will update host information to the HOSTSFILE"""
 
375
        sqlconn = sqlite3.connect(HOSTSFILE)
 
376
        sqlcursor = sqlconn.cursor()
 
377
        #we'll need to determine if this will be a sql UPDATE or sql INSERT
 
378
        foundhost = "no"
 
379
        hostnames = self.read_hostsfile()
 
380
        for hostname in hostnames:
 
381
            if hostname == host:
 
382
                foundhost = "yes"
 
383
                #host already exist, so update information
 
384
                values = (sshport,sshuser,sshoptions,vnctrucolor,vncbgr, \
 
385
                        vncquality,vnccompresslevel,vncport,vncpasswd, \
 
386
                        vncx11cur,rdpgeometry,rdpuser,rdpdomain,selectedtab, \
 
387
                        sftpport,sftpuser,sftppath,smbuser,smbpath, \
 
388
                        ftpport,ftpuser,ftppath,host)
 
389
                sqlcursor.execute('''
 
390
                        UPDATE hosts SET
 
391
                                sshport=?,
 
392
                                sshuser=?,
 
393
                                sshopt=?,
 
394
                                vnctrucolor=?,
 
395
                                vncbgr=?,
 
396
                                vncquality=?,
 
397
                                vnccompresslevel=?,
 
398
                                vncport=?,
 
399
                                vncpassword=?,
 
400
                                vncx11cur=?,
 
401
                                rdpgeom=?,
 
402
                                rdpuser=?,
 
403
                                rdpdom=?,
 
404
                                tab=?,
 
405
                                sftpport=?,
 
406
                                sftpuser=?,
 
407
                                sftppath=?,
 
408
                                smbuser=?,
 
409
                                smbpath=?,
 
410
                                ftpport=?,
 
411
                                ftpuser=?,
 
412
                                ftppath=?
 
413
                        WHERE name=? ''', values)
 
414
        if foundhost == "no":
 
415
            #host didn't exist, so insert new host information
 
416
            sqlcursor.execute('''
 
417
                    INSERT INTO hosts VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
 
418
                    ''',(host,sshport,sshuser,sshoptions,vnctrucolor,vncbgr, \
 
419
                    vncquality,vnccompresslevel,vncport,vncpasswd,vncx11cur, \
 
420
                    rdpgeometry,rdpuser,rdpdomain,selectedtab,sftpport,sftpuser, \
 
421
                    sftppath,smbuser,smbpath,ftpport,ftpuser,ftppath) )
 
422
        #update and close the database
 
423
        sqlconn.commit()
 
424
        sqlconn.close()
 
425
 
 
426
    def populate_cmbox_hostlist(self):
 
427
        """Read in the HOSTSFILE and populate the drop down hosts list"""
 
428
        hostnames = self.read_hostsfile()
 
429
        hosts = Gtk.ListStore(str)
 
430
        for hostname in hostnames:
 
431
            hosts.prepend ([hostname])
 
432
        self.host_entry_cmbox.set_model(hosts)
 
433
        self.host_entry_cmbox.set_entry_text_column(0)
 
434
 
 
435
    def populate_cmbox_hostlist_entry_completion(self):
 
436
        """Read in the HOSTSFILE and populate the entry completion"""
 
437
        hostnames = self.read_hostsfile()
 
438
        completion = Gtk.EntryCompletion()
 
439
        hosts = Gtk.ListStore(str)
 
440
        for hostname in hostnames:
 
441
            iter = hosts.append()
 
442
            hosts.set(iter, 0, hostname)
 
443
        self.host_entry.set_completion(completion)
 
444
        completion.set_model(hosts)
 
445
        completion.set_text_column(0)
 
446
 
 
447
    def on_hosts_dialog_delete_event(self, widget, event=None):
 
448
        """This will hide the Edit -> Hosts dialog"""
 
449
        self.hosts_dialog.hide()
 
450
        return True
 
451
 
 
452
    def on_hosts_cancel_btn_clicked(self, widget, data=None):
 
453
        """This will hide the Edit -> Hosts dialog"""
 
454
        self.hosts_dialog.hide()
 
455
 
 
456
    def on_hosts_menu_find_activate(self, action):
 
457
        """This will display the hosts->find dialog"""
 
458
        self.find_dialog_find_entry.set_text('')
 
459
        txtbuffer = self.hosts_txtview.get_buffer()
 
460
        start, end = txtbuffer.get_bounds()
 
461
        txtbuffer.remove_all_tags(start, end)
 
462
        self.find_dialog.show()
 
463
 
 
464
    def on_find_dialog_ok_button_clicked(self, action):
 
465
        """This will highlight each found entry"""
 
466
        findentry = self.find_dialog_find_entry.get_text()
 
467
        txtbuffer = self.hosts_txtview.get_buffer()
 
468
        found_tag = txtbuffer.create_tag(foreground='red', background='black')
 
469
        start = txtbuffer.get_start_iter()
 
470
        first, last = start.forward_search(findentry, Gtk.TEXT_SEARCH_TEXT_ONLY)
 
471
        if first:
 
472
            self.hosts_txtview.scroll_to_iter(first, 0.0)
 
473
            txtbuffer.place_cursor(first)
 
474
            txtbuffer.apply_tag(found_tag, first, last)
 
475
        self.find_dialog.hide()
 
476
 
 
477
    def on_hosts_menu_cut_activate(self, action):
 
478
        """This will cut an entry"""
 
479
        buffer = self.hosts_txtview.get_buffer()
 
480
        buffer.cut_clipboard(clipboard, self.hosts_txtview.get_editable());
 
481
 
 
482
    def on_hosts_menu_copy_activate(self, action):
 
483
        """This will copy an entry"""
 
484
        buffer = self.hosts_txtview.get_buffer()
 
485
        buffer.copy_clipboard (Gtk.clipboard_get());
 
486
 
 
487
    def on_hosts_menu_paste_activate(self, action):
 
488
        """This will paste an entry"""
 
489
        buffer = self.hosts_txtview.get_buffer()
 
490
        buffer.paste_clipboard (Gtk.clipboard_get(), None, True);
 
491
 
 
492
    def on_hosts_menu_delete_activate(self, action):
 
493
        """This will paste an entry"""
 
494
        buffer = self.hosts_txtview.get_buffer()
 
495
        buffer.delete_selection (False, True);
 
496
 
 
497
    def on_find_dialog_cancel_button_clicked(self, action):
 
498
        """This will hide the hosts->find dialog"""
 
499
        self.find_dialog.hide()
 
500
 
 
501
    def on_find_dialog_delete_event(self, widget, event=None):
 
502
        """This will hide the hosts->find dialog"""
 
503
        self.find_dialog.hide()
 
504
        return True
 
505
 
 
506
    def on_hosts_apply_btn_clicked(self, child):
 
507
        """This will update the HOSTSFILE with everything in the TextView"""
 
508
        hostnames = self.read_hostsfile()
 
509
        hosts = self.hosts_txtview.get_buffer()
 
510
        bufferhostnames = hosts.get_text(hosts.get_start_iter(), \
 
511
                            hosts.get_end_iter())
 
512
        newhostnames = bufferhostnames.split('\n')
 
513
        ##dual-forloops to check the hostnames against the newhostnames
 
514
        for hostname in hostnames:
 
515
            foundnewhostname = 0
 
516
            for newhostname in newhostnames:
 
517
                if re.search(hostname, newhostname):
 
518
                    foundnewhostname = 1
 
519
            if not foundnewhostname:
 
520
                print "Deleteing " + hostname + " from sqlite3\n"
 
521
                sqlconn = sqlite3.connect(HOSTSFILE)
 
522
                sqlcursor = sqlconn.cursor()
 
523
                sqlcursor.execute('DELETE FROM hosts WHERE name=?', (hostname,))
 
524
                sqlconn.commit()
 
525
                sqlconn.close()
 
526
        self.populate_cmbox_hostlist()
 
527
        self.populate_cmbox_hostlist_entry_completion()
 
528
        self.hosts_dialog.hide()
 
529
 
 
530
    def on_about_menu_activate(self, widget, data=None):
 
531
        """This will show the ABOUT dialog"""
 
532
        self.label_version.set_markup('<span weight="bold" size="larger"> ' \
 
533
                                        + APPNAME + ' ' + 'v' + APPVERSION \
 
534
                                        + '</span>')
 
535
        self.about_dialog.show()
 
536
 
 
537
    def on_about_dialog_delete_event(self, widget, event=None):
 
538
        """This will close the ABOUT dialog"""
 
539
        self.about_dialog.hide()
 
540
        return True
 
541
 
 
542
    def on_about_close_button_clicked(self, widget, data=None):
 
543
        """This will close the ABOUT dialog"""
 
544
        self.about_dialog.hide()
 
545
 
 
546
    def on_error_button_clicked(self, action):
 
547
        """This will close the Error dialog"""
 
548
        self.error_dialog.hide()
 
549
 
 
550
    def on_error_dialog_delete_event(self, widget, event=None):
 
551
        """This will close the Error dialog"""
 
552
        self.error_dialog.hide()
 
553
        return True
 
554
 
 
555
    def on_hosts_menu_activate(self, action):
 
556
        """This function will activate the Edit -> Hosts menu item"""
 
557
        self.hosts_txtview.set_buffer(None)
 
558
        sqlconn = sqlite3.connect(HOSTSFILE)
 
559
        dbhosts = []
 
560
        for row in sqlconn.execute("SELECT name FROM hosts ORDER BY name ASC"):
 
561
            for hostname in row:
 
562
                dbhosts.append(hostname + "\n")
 
563
            sqlconn.close
 
564
        hosts = self.hosts_txtview.get_buffer()
 
565
        iter = hosts.get_iter_at_offset(0)
 
566
        for dbhost in dbhosts:
 
567
            hosts.insert(iter, dbhost)
 
568
        self.hosts_dialog.show()
 
569
 
 
570
    def on_connect_btn_clicked(self, child):
 
571
        """This will first determine what tab you are on, and then
 
572
            launch the necessary app"""
 
573
        selectedtab = self.tabbed_notebook.get_current_page()
 
574
        host = self.host_entry.get_text()
 
575
        sshport = self.ssh_port_sbtn.get_text()
 
576
        sshuser = self.ssh_user_entry.get_text()
 
577
        sshoptions = self.ssh_options_entry.get_text()
 
578
        sftpport = self.sftp_port_sbtn.get_text()
 
579
        sftpuser = self.sftp_user_entry.get_text()
 
580
        sftppath = self.sftp_path_entry.get_text()
 
581
        vnctrucolor = 0
 
582
        if self.vnc_trucolor_rbtn.get_active():
 
583
            vnctrucolor = 1
 
584
        vncbgr = 0
 
585
        if self.vnc_bgr233_rbtn.get_active():
 
586
            vncbgr = 1
 
587
        vncx11cur = 0
 
588
        if self.vnc_x11cur_chkbox.get_active():
 
589
            vncx11cur = 1
 
590
        vncquality = self.vnc_quality_sbtn.get_text()
 
591
        vnccompresslevel = self.vnc_compress_sbtn.get_text()
 
592
        vncport = self.vnc_port_sbtn.get_text()
 
593
        vncpasswd = self.vnc_password_entry.get_text()
 
594
        rdpgeometry = self.rdp_geometry_entry.get_text()
 
595
        rdpuser = self.rdp_user_entry.get_text()
 
596
        rdpdomain = self.rdp_domain_entry.get_text()
 
597
        smbuser = self.smb_user_entry.get_text()
 
598
        smbpath = self.smb_path_entry.get_text()
 
599
        ftpport = self.ftp_port_sbtn.get_text()
 
600
        ftpuser = self.ftp_user_entry.get_text()
 
601
        ftppath = self.ftp_path_entry.get_text()
 
602
        if len(host) != 0:
 
603
            if selectedtab == 0:
 
604
                #we are on the SSH tab
 
605
                sshuserhost = 'ssh ' + sshoptions + ' -p ' + sshport + \
 
606
                                ' ' + sshuser + "@" + host
 
607
                command = ['gnome-terminal', '--geometry', '110x25', \
 
608
                            '-t', host, '-e', sshuserhost]
 
609
                commandspawn = Popen(command)
 
610
            elif selectedtab == 1:
 
611
                #we are on the SFTP tab
 
612
                nautilusURI = 'sftp://' + sftpuser + '@' + host + ":" + \
 
613
                                sftpport + sftppath
 
614
                command = ['nautilus', nautilusURI]
 
615
                commandspawn = Popen(command)
 
616
            elif selectedtab == 2:
 
617
                #we are on the VNC tab
 
618
                vnchostport = host + ":" + vncport
 
619
                command = ['vncviewer', '-autopass', \
 
620
                            '-quality', vncquality, \
 
621
                            '-compresslevel', vnccompresslevel]
 
622
                if vnctrucolor == 1:
 
623
                    command.append('-truecolour')
 
624
                if vncbgr == 1:
 
625
                    command.append('-bgr233')
 
626
                if vncx11cur == 1:
 
627
                    command.append('-x11cursor')
 
628
                pwordcommand = ['echo', vncpasswd]
 
629
                command.append(vnchostport)
 
630
                #finally, spawn the vnccommand with all parms
 
631
                pwordspwan = Popen(pwordcommand,stdout=PIPE)
 
632
                commandspawn = Popen(command, \
 
633
                                            stdin=pwordspwan.stdout,stdout=PIPE)
 
634
                pwordspwan.stdout.close()
 
635
            elif selectedtab == 3:
 
636
                #we are on the RDP tab
 
637
                command = ['rdesktop','-b','-g',rdpgeometry]
 
638
                if len(rdpuser) != 0:
 
639
                    pyrdpuser = '-u' + rdpuser
 
640
                    command.append(pyrdpuser)
 
641
                if len(rdpdomain) != 0:
 
642
                    pyrdpdomain= '-d' + rdpdomain
 
643
                    command.append(pyrdpdomain)
 
644
                command.append(host)
 
645
                #due to m$ licsening change for 2008+ servers, we now need this:
 
646
                mslicfile = os.environ["HOME"] + "/.rdesktop/licence.*"
 
647
                for x in glob.glob(mslicfile):
 
648
                    os.unlink(x)
 
649
                commandspawn = Popen(command)
 
650
            elif selectedtab == 4:
 
651
                #we are on the SMB tab
 
652
                nautilusURI = 'smb://' + smbuser + '@' + host + "/" + smbpath
 
653
                command = ['nautilus', nautilusURI]
 
654
                commandspawn = Popen(command)
 
655
            elif selectedtab == 5:
 
656
                #we are on the FTP tab
 
657
                nautilusURI = 'ftp://' + ftpuser + '@' + host + ":" + \
 
658
                                ftpport + ftppath
 
659
                command = ['nautilus', nautilusURI]
 
660
                commandspawn = Popen(command)
 
661
            #now that the command has launched, update the sqlite db
 
662
            self.update_host_info(host,sshport,sshuser,sshoptions,vnctrucolor, \
 
663
                vncbgr,vncquality,vnccompresslevel,vncport,vncpasswd, \
 
664
                vncx11cur,rdpgeometry,rdpuser,rdpdomain,selectedtab, \
 
665
                sftpport,sftpuser,sftppath,smbuser,smbpath,ftpport,ftpuser,ftppath)
 
666
            self.populate_cmbox_hostlist()
 
667
            self.populate_cmbox_hostlist_entry_completion()
 
668
        else:
 
669
            errormessage = 'I need a host!!!  Please enter the IP or \
 
670
                            DNS name of a host in the HOST: field.'
 
671
            print errormessage
 
672
            self.error_message_textview.set_text(errormessage)
 
673
            self.error_dialog.show()
 
674
 
 
675
    def spawn_child(self, command, parms):
 
676
        """This function will spawn the child process"""
 
677
        child = subprocess.Popen([command, parms])
 
678
 
 
679
    def __init__(self):
 
680
        gtkbuilder = Gtk.Builder()
 
681
        gtkbuilder.add_from_file(GLADE_FILE)
 
682
 
 
683
        #initialize the glade objects
 
684
        self.label_version = gtkbuilder.get_object('label_version')
 
685
        self.about_dialog = gtkbuilder.get_object('about_dialog')
 
686
        self.host_entry = gtkbuilder.get_object('host_entry')
 
687
        self.host_entry_cmbox = gtkbuilder.get_object('host_entry_cmbox')
 
688
        self.host_entrycompletion = gtkbuilder.get_object \
 
689
                                                ('host_entrycompletion')
 
690
        self.ssh_port_sbtn = gtkbuilder.get_object('ssh_port_sbtn')
 
691
        self.ssh_user_entry = gtkbuilder.get_object('ssh_user_entry')
 
692
        self.ssh_options_entry = gtkbuilder.get_object('ssh_options_entry')
 
693
        self.sftp_port_sbtn = gtkbuilder.get_object('sftp_port_sbtn')
 
694
        self.sftp_user_entry = gtkbuilder.get_object('sftp_user_entry')
 
695
        self.sftp_path_entry = gtkbuilder.get_object('sftp_path_entry')
 
696
        self.vnc_quality_sbtn = gtkbuilder.get_object('vnc_quality_sbtn')
 
697
        self.vnc_compress_sbtn = gtkbuilder.get_object('vnc_compress_sbtn')
 
698
        self.vnc_port_sbtn = gtkbuilder.get_object('vnc_port_sbtn')
 
699
        self.vnc_password_entry = gtkbuilder.get_object('vnc_password_entry')
 
700
        self.vnc_x11cur_chkbox = gtkbuilder.get_object('vnc_x11cur_chkbox')
 
701
        self.vnc_trucolor_rbtn = gtkbuilder.get_object('vnc_trucolor_rbtn')
 
702
        self.vnc_bgr233_rbtn = gtkbuilder.get_object('vnc_bgr233_rbtn')
 
703
        self.rdp_geometry_cmbox = gtkbuilder.get_object('rdp_geometry_cmbox')
 
704
        self.rdp_geometry_entry = gtkbuilder.get_object('rdp_geometry_entry')
 
705
        self.rdp_user_entry = gtkbuilder.get_object('rdp_user_entry')
 
706
        self.rdp_domain_entry = gtkbuilder.get_object('rdp_domain_entry')
 
707
        self.smb_user_entry = gtkbuilder.get_object('smb_user_entry')
 
708
        self.smb_path_entry = gtkbuilder.get_object('smb_path_entry')
 
709
        self.ftp_port_sbtn = gtkbuilder.get_object('ftp_port_sbtn')
 
710
        self.ftp_user_entry = gtkbuilder.get_object('ftp_user_entry')
 
711
        self.ftp_path_entry = gtkbuilder.get_object('ftp_path_entry')
 
712
        self.hosts_dialog = gtkbuilder.get_object('hosts_dialog')
 
713
        self.hosts_txtview = gtkbuilder.get_object('hosts_txtview')
 
714
        self.find_dialog_find_entry = gtkbuilder.get_object \
 
715
                                                ('find_dialog_find_entry')
 
716
        self.find_dialog = gtkbuilder.get_object('find_dialog')
 
717
        self.error_dialog = gtkbuilder.get_object('error_dialog')
 
718
        self.error_message_label = gtkbuilder.get_object('error_message_label')
 
719
        self.error_dialog = gtkbuilder.get_object('error_dialog')
 
720
        self.tabbed_notebook = gtkbuilder.get_object('tabbed_notebook')
 
721
 
 
722
        #perform some initialization functions
 
723
        self.check_appconfig_dir()
 
724
        self.check_sqlitedb()
 
725
        self.read_hostsfile()
 
726
 
 
727
        signals = {
 
728
            'on_main_dialog_destroy' : Gtk.main_quit,
 
729
            'on_cancel_btn_clicked' : Gtk.main_quit,
 
730
            'on_quit_menu_activate' : Gtk.main_quit,
 
731
            'on_hosts_menu_quit_activate' : self.on_hosts_cancel_btn_clicked,
 
732
            'on_connect_btn_clicked' : self.on_connect_btn_clicked,
 
733
            'on_host_entry_activate' : self.on_connect_btn_clicked,
 
734
            'on_ssh_user_entry_activate' : self.on_connect_btn_clicked,
 
735
            'on_ssh_options_entry_activate' : self.on_connect_btn_clicked,
 
736
            'on_ssh_port_sbtn_activate' : self.on_connect_btn_clicked,
 
737
            'on_sftp_user_entry_activate' : self.on_connect_btn_clicked,
 
738
            'on_sftp_port_sbtn_activate' : self.on_connect_btn_clicked,
 
739
            'on_sftp_path_entry_activate' : self.on_connect_btn_clicked,
 
740
            'on_vnc_password_entry_activate' : self.on_connect_btn_clicked,
 
741
            'on_vnc_port_sbtn_activate' : self.on_connect_btn_clicked,
 
742
            'on_vnc_quality_sbtn_activate' : self.on_connect_btn_clicked,
 
743
            'on_vnc_compress_sbtn_activate' : self.on_connect_btn_clicked,
 
744
            'on_rdp_user_entry_activate' : self.on_connect_btn_clicked,
 
745
            'on_rdp_domain_entry_activate' : self.on_connect_btn_clicked,
 
746
            'on_rdp_geometry_entry_activate' : self.on_connect_btn_clicked,
 
747
            'on_smb_user_entry_activate' : self.on_connect_btn_clicked,
 
748
            'on_smb_path_entry_activate' : self.on_connect_btn_clicked,
 
749
            'on_ftp_user_entry_activate' : self.on_connect_btn_clicked,
 
750
            'on_ftp_port_sbtn_activate' : self.on_connect_btn_clicked,
 
751
            'on_ftp_path_entry_activate' : self.on_connect_btn_clicked,
 
752
            'on_hosts_cancel_btn_clicked' : self.on_hosts_cancel_btn_clicked,
 
753
            'on_hosts_apply_btn_clicked' : self.on_hosts_apply_btn_clicked,
 
754
            'on_hosts_menu_find_activate' : self.on_hosts_menu_find_activate,
 
755
            'on_hosts_menu_cut_activate' : self.on_hosts_menu_cut_activate,
 
756
            'on_hosts_menu_copy_activate' : self.on_hosts_menu_copy_activate,
 
757
            'on_hosts_menu_paste_activate' : self.on_hosts_menu_paste_activate,
 
758
            'on_hosts_menu_delete_activate' : \
 
759
                                    self.on_hosts_menu_delete_activate,
 
760
            'on_del_menu_activate' : self.on_del_menu_activate,
 
761
            'on_hosts_menu_activate' : self.on_hosts_menu_activate,
 
762
            'on_hosts_dialog_delete_event' : self.on_hosts_dialog_delete_event,
 
763
            'on_about_menu_activate' : self.on_about_menu_activate,
 
764
            'on_about_close_button_clicked' : \
 
765
                                    self.on_about_close_button_clicked,
 
766
            'on_about_dialog_delete_event' : self.on_about_dialog_delete_event,
 
767
            'on_find_dialog_ok_button_clicked' : \
 
768
                                    self.on_find_dialog_ok_button_clicked,
 
769
            'on_find_dialog_find_entry_activate' : \
 
770
                                    self.on_find_dialog_ok_button_clicked,
 
771
            'on_find_dialog_cancel_button_clicked' : \
 
772
                                    self.on_find_dialog_cancel_button_clicked,
 
773
            'on_find_dialog_delete_event' : self.on_find_dialog_delete_event,
 
774
            'on_error_button_clicked' : self.on_error_button_clicked,
 
775
            'on_error_dialog_delete_event' : self.on_error_dialog_delete_event,
 
776
            'on_host_entry_changed' : self.on_host_entry_changed}
 
777
        gtkbuilder.connect_signals(signals)
 
778
        self.populate_cmbox_hostlist()
 
779
        self.populate_cmbox_hostlist_entry_completion()
 
780
 
 
781
if __name__ == "__main__":
 
782
    connectionmanager = ConnectionManager()
 
783
    Gtk.main()
 
784