~thelupine/pyconnmgr/trunk

« back to all changes in this revision

Viewing changes to src/pyconnmgr

  • 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:
2
2
 
3
3
"""
4
4
    title:          Python Connections Manager
5
 
    
 
5
 
6
6
    date:           10.14.2009
7
 
    
 
7
 
8
8
    author:         Lupine  - http://www.thelupine.com
9
 
    
 
9
 
10
10
    description:    Python/GTK/Glade frontend to the SSH, VNC and rdesktop
11
 
    
 
11
 
12
12
"""
13
13
 
14
 
import sys, os, signal, time, re, sqlite3, gtk
 
14
import sys, os, glob, signal, time, re, sqlite3
15
15
from subprocess import Popen, PIPE
 
16
from gi.repository import Gtk
16
17
 
17
18
APPNAME     = "pyconnmgr"
18
 
APPVERSION  = "3.0.0"
 
19
APPVERSION  = "3.0.3"
19
20
APPCONFDIR  = "/.pyconnmgr"
20
21
GLADE_FILE  = "/usr/share/pyconnmgr/pyconnmgr.glade"
21
22
#GLADE_FILE  = "glade/pyconnmgr.glade"
31
32
    def check_appconfig_dir(self):
32
33
        """
33
34
        This function will create the ENV HOME app config directory
34
 
        It will do so by first checking if the APPCONFDIR dir exists, 
 
35
        It will do so by first checking if the APPCONFDIR dir exists,
35
36
        if it does not it will be created, or give an error
36
37
        """
37
38
        appsettingsdir = os.environ["HOME"] + APPCONFDIR
114
115
            #check if "ftp" schema update has been done
115
116
            for col_name in col_name_list:
116
117
                if not re.search('20|ftpport|int|0||0', col_name):
117
 
                    print "Updating schema for FTP\n"
118
118
                    sqlcursor.execute('''ALTER TABLE hosts ADD ftpport int''')
119
119
                    sqlconn.commit()
120
120
                    sqlcursor.execute('''ALTER TABLE hosts ADD ftpuser text''')
137
137
                sqlconn = sqlite3.connect(HOSTSFILE)
138
138
                sqlcursor = sqlconn.cursor()
139
139
                sqlcursor.execute('''create table if not exists hosts
140
 
                                        (name text, 
141
 
                                        sshport int, 
 
140
                                        (name text,
 
141
                                        sshport int,
142
142
                                        sshuser text,
143
143
                                        sshopt text,
144
144
                                        vnctrucolor int,
162
162
                                        ftppath text)''')
163
163
                sqlconn.commit()
164
164
                sqlconn.close
165
 
        
 
165
 
166
166
    def read_hostsfile(self):
167
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 
 
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
170
        is up to date.  If not found, it will create a blank HOSTSFILE.
171
171
        """
172
172
        hostnames = []
180
180
                        hostnames.append(hostname)
181
181
            sqlconn.close
182
182
        return hostnames
183
 
    
 
183
 
184
184
    def on_del_menu_activate(self, action):
185
185
        """This function will remove a host entry from the HOSTSFILE"""
186
186
        host = self.host_entry.get_text()
207
207
 
208
208
            if (row[1]):
209
209
                hostsshport = row[1]
210
 
            else:                
 
210
            else:
211
211
                hostsshport = 22
212
 
                
 
212
 
213
213
            if (row[2]):
214
214
                hostsshuser = row[2]
215
215
            else:
216
216
                hostsshuser = ""
217
 
                
 
217
 
218
218
            if (row[3]):
219
219
                hostsshopt = row[3]
220
220
            else:
221
221
                hostsshopt = ""
222
 
            
 
222
 
223
223
            if (row[4]):
224
224
                hostvnctrucolor = row[4]
225
225
            else:
229
229
                hostvncbgr = row[5]
230
230
            else:
231
231
                hostvncbgr = ""
232
 
                
 
232
 
233
233
            if (row[6]):
234
234
                hostvncquality = row[6]
235
235
            else:
236
236
                hostvncquality = 9
237
 
                
 
237
 
238
238
            if (row[7]):
239
239
                hostvnccompresslevel = row[7]
240
240
            else:
241
241
                hostvnccompresslevel = 9
242
 
                
 
242
 
243
243
            if (row[8]):
244
244
                hostvncport = row[8]
245
245
            else:
246
246
                hostvncport = 5900
247
 
                
 
247
 
248
248
            if (row[9]):
249
249
                hostvncpassword = row[9]
250
250
            else:
251
251
                hostvncpassword = ""
252
 
                
 
252
 
253
253
            if (row[10]):
254
254
                hostvncx11cur = row[10]
255
255
            else:
256
256
                hostvncx11cur = ""
257
 
            
 
257
 
258
258
            if (row[11]):
259
259
                hostrdpgeom = row[11]
260
260
            else:
261
261
                hostrdpgeom = ""
262
 
                
 
262
 
263
263
            if (row[12]):
264
264
                hostrdpuser = row[12]
265
265
            else:
269
269
                hostrdpdom = row[13]
270
270
            else:
271
271
                hostrdpdom = ""
272
 
            
 
272
 
273
273
            if (row[14]):
274
274
                tabposition = row[14]
275
275
            else:
279
279
                hostsftpport = row[15]
280
280
            else:
281
281
                hostsftpport = 22
282
 
                
 
282
 
283
283
            if (row[16]):
284
284
                hostsftpuser = row[16]
285
285
            else:
289
289
                hostsftppath = row[17]
290
290
            else:
291
291
                hostsftppath = ""
292
 
                
 
292
 
293
293
            if (row[18]):
294
294
                hostsmbuser = row[18]
295
295
            else:
304
304
                hostftpport = row[20]
305
305
            else:
306
306
                hostftpport = 21
307
 
                
 
307
 
308
308
            if (row[21]):
309
309
                hostftpuser = row[21]
310
310
            else:
314
314
                hostftppath = row[22]
315
315
            else:
316
316
                hostftppath = ""
317
 
            
318
 
            #next, if a proper host is entered, update the widgets with the 
319
 
            #above variables                
 
317
 
 
318
            #next, if a proper host is entered, update the widgets with the
 
319
            #above variables
320
320
            if hostname == host:
321
321
                self.tabbed_notebook.set_current_page(tabposition)
322
322
                #SSH
362
362
                self.ftp_user_entry.set_text(hostftpuser)
363
363
                self.ftp_path_entry.set_text(hostftppath)
364
364
        sqlconn.close
365
 
        
 
365
 
366
366
    def on_host_entry_changed(self, action):
367
367
        """This function will call to the update_host_settings function"""
368
368
        self.update_host_settings()
387
387
                        sftpport,sftpuser,sftppath,smbuser,smbpath, \
388
388
                        ftpport,ftpuser,ftppath,host)
389
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=?, 
 
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
403
                                rdpdom=?,
404
404
                                tab=?,
405
405
                                sftpport=?,
423
423
        sqlconn.commit()
424
424
        sqlconn.close()
425
425
 
426
 
    def populate_rdp_geometry_cmbox(self):
427
 
        """Write defaults values for rdp_geometry_cmbox"""
428
 
        gemotryvalues = ['640x480', '800x600', '1024x768', '1280x1024']
429
 
        gemotryliststore = gtk.ListStore(str)
430
 
        for gemotryvalue in gemotryvalues:
431
 
            gemotryliststore.append ([gemotryvalue])
432
 
        self.rdp_geometry_cmbox.set_model(gemotryliststore)
433
 
        self.rdp_geometry_cmbox.set_text_column(0)
434
 
 
435
426
    def populate_cmbox_hostlist(self):
436
427
        """Read in the HOSTSFILE and populate the drop down hosts list"""
437
428
        hostnames = self.read_hostsfile()
438
 
        hosts = gtk.ListStore(str)
 
429
        hosts = Gtk.ListStore(str)
439
430
        for hostname in hostnames:
440
431
            hosts.prepend ([hostname])
441
432
        self.host_entry_cmbox.set_model(hosts)
442
 
        self.host_entry_cmbox.set_text_column(0)
 
433
        self.host_entry_cmbox.set_entry_text_column(0)
443
434
 
444
435
    def populate_cmbox_hostlist_entry_completion(self):
445
436
        """Read in the HOSTSFILE and populate the entry completion"""
446
437
        hostnames = self.read_hostsfile()
447
 
        completion = gtk.EntryCompletion()
448
 
        hosts = gtk.ListStore(str)
 
438
        completion = Gtk.EntryCompletion()
 
439
        hosts = Gtk.ListStore(str)
449
440
        for hostname in hostnames:
450
441
            iter = hosts.append()
451
442
            hosts.set(iter, 0, hostname)
476
467
        txtbuffer = self.hosts_txtview.get_buffer()
477
468
        found_tag = txtbuffer.create_tag(foreground='red', background='black')
478
469
        start = txtbuffer.get_start_iter()
479
 
        first, last = start.forward_search(findentry, gtk.TEXT_SEARCH_TEXT_ONLY)
 
470
        first, last = start.forward_search(findentry, Gtk.TEXT_SEARCH_TEXT_ONLY)
480
471
        if first:
481
472
            self.hosts_txtview.scroll_to_iter(first, 0.0)
482
473
            txtbuffer.place_cursor(first)
491
482
    def on_hosts_menu_copy_activate(self, action):
492
483
        """This will copy an entry"""
493
484
        buffer = self.hosts_txtview.get_buffer()
494
 
        buffer.copy_clipboard (gtk.clipboard_get());
 
485
        buffer.copy_clipboard (Gtk.clipboard_get());
495
486
 
496
487
    def on_hosts_menu_paste_activate(self, action):
497
488
        """This will paste an entry"""
498
489
        buffer = self.hosts_txtview.get_buffer()
499
 
        buffer.paste_clipboard (gtk.clipboard_get(), None, True);
 
490
        buffer.paste_clipboard (Gtk.clipboard_get(), None, True);
500
491
 
501
492
    def on_hosts_menu_delete_activate(self, action):
502
493
        """This will paste an entry"""
535
526
        self.populate_cmbox_hostlist()
536
527
        self.populate_cmbox_hostlist_entry_completion()
537
528
        self.hosts_dialog.hide()
538
 
    
 
529
 
539
530
    def on_about_menu_activate(self, widget, data=None):
540
531
        """This will show the ABOUT dialog"""
541
532
        self.label_version.set_markup('<span weight="bold" size="larger"> ' \
555
546
    def on_error_button_clicked(self, action):
556
547
        """This will close the Error dialog"""
557
548
        self.error_dialog.hide()
558
 
        
 
549
 
559
550
    def on_error_dialog_delete_event(self, widget, event=None):
560
551
        """This will close the Error dialog"""
561
552
        self.error_dialog.hide()
577
568
        self.hosts_dialog.show()
578
569
 
579
570
    def on_connect_btn_clicked(self, child):
580
 
        """This will first determine what tab you are on, and then 
 
571
        """This will first determine what tab you are on, and then
581
572
            launch the necessary app"""
582
573
        selectedtab = self.tabbed_notebook.get_current_page()
583
574
        host = self.host_entry.get_text()
602
593
        vncpasswd = self.vnc_password_entry.get_text()
603
594
        rdpgeometry = self.rdp_geometry_entry.get_text()
604
595
        rdpuser = self.rdp_user_entry.get_text()
605
 
        rdpdomain = self.rdp_domain_entry.get_text() 
 
596
        rdpdomain = self.rdp_domain_entry.get_text()
606
597
        smbuser = self.smb_user_entry.get_text()
607
598
        smbpath = self.smb_path_entry.get_text()
608
599
        ftpport = self.ftp_port_sbtn.get_text()
651
642
                    pyrdpdomain= '-d' + rdpdomain
652
643
                    command.append(pyrdpdomain)
653
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)
654
649
                commandspawn = Popen(command)
655
650
            elif selectedtab == 4:
656
651
                #we are on the SMB tab
682
677
        child = subprocess.Popen([command, parms])
683
678
 
684
679
    def __init__(self):
685
 
        gtkbuilder = gtk.Builder()
 
680
        gtkbuilder = Gtk.Builder()
686
681
        gtkbuilder.add_from_file(GLADE_FILE)
687
 
        
 
682
 
688
683
        #initialize the glade objects
689
684
        self.label_version = gtkbuilder.get_object('label_version')
690
685
        self.about_dialog = gtkbuilder.get_object('about_dialog')
691
686
        self.host_entry = gtkbuilder.get_object('host_entry')
692
687
        self.host_entry_cmbox = gtkbuilder.get_object('host_entry_cmbox')
 
688
        self.host_entrycompletion = gtkbuilder.get_object \
 
689
                                                ('host_entrycompletion')
693
690
        self.ssh_port_sbtn = gtkbuilder.get_object('ssh_port_sbtn')
694
691
        self.ssh_user_entry = gtkbuilder.get_object('ssh_user_entry')
695
692
        self.ssh_options_entry = gtkbuilder.get_object('ssh_options_entry')
726
723
        self.check_appconfig_dir()
727
724
        self.check_sqlitedb()
728
725
        self.read_hostsfile()
729
 
        
730
 
        signals = { 
731
 
            'on_main_dialog_destroy' : gtk.main_quit,
732
 
            'on_cancel_btn_clicked' : gtk.main_quit,
733
 
            'on_quit_menu_activate' : gtk.main_quit,
 
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,
734
731
            'on_hosts_menu_quit_activate' : self.on_hosts_cancel_btn_clicked,
735
732
            'on_connect_btn_clicked' : self.on_connect_btn_clicked,
736
733
            'on_host_entry_activate' : self.on_connect_btn_clicked,
778
775
            'on_error_dialog_delete_event' : self.on_error_dialog_delete_event,
779
776
            'on_host_entry_changed' : self.on_host_entry_changed}
780
777
        gtkbuilder.connect_signals(signals)
781
 
        self.populate_rdp_geometry_cmbox()
782
778
        self.populate_cmbox_hostlist()
783
779
        self.populate_cmbox_hostlist_entry_completion()
784
780
 
785
781
if __name__ == "__main__":
786
 
    display = gtk.gdk.display_manager_get().get_default_display()
787
 
    clipboard = gtk.Clipboard(display, 'CLIPBOARD')
788
782
    connectionmanager = ConnectionManager()
789
 
    try:
790
 
        gtk.gdk.threads_init()
791
 
    except:
792
 
        print "No threading was enabled when you compiled pyGTK!"
793
 
        sys.exit(1)
794
 
    gtk.gdk.threads_enter()
795
 
    gtk.main()
796
 
    gtk.gdk.threads_leave()
 
783
    Gtk.main()
797
784