~thelupine/pyconnmgr/trunk

« back to all changes in this revision

Viewing changes to src/pyconnmgr-gtk2

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