summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2005-10-05 00:12:25 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2005-10-05 00:12:25 +0000
commit6ee652a01d48cba70413c31b0b86e0fc98146040 (patch)
tree89b20afb0c2e8f2b3cf845a49d3e59f84f6d1cba
parent62173f2e3cd486569b16a0ebe1cff52fa95807b7 (diff)
* add preliminary support for plugin (ssh)
* add support a small ui for ssh login git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@36 3be567f1-68ff-0310-b24a-ad7cc433fd2f
-rwxr-xr-xactions/services/__init__.py.in83
-rw-r--r--actions/services/_ssh_tcp.py87
2 files changed, 162 insertions, 8 deletions
diff --git a/actions/services/__init__.py.in b/actions/services/__init__.py.in
index dc64db4..b0f3871 100755
--- a/actions/services/__init__.py.in
+++ b/actions/services/__init__.py.in
@@ -12,6 +12,11 @@
# $id$
#
+import pygtk
+pygtk.require('2.0')
+import gtk
+import os
+import pwd
import subprocess
import gnome
@@ -73,9 +78,78 @@ def _ftp_tcp(name, hostname, address, port, txts):
url = build_url("ftp",address,port, path, username,password)
gnome.url_show(url)
+def _sftpssh_tcp(name, hostname, address, port, txts):
+ path = get_txt_value(txts,"path")
+ username = get_txt_value(txts,"u")
+ password = get_txt_value(txts,"p")
+ url = build_url("ftp",address,port, path, username,password)
+ gnome.url_show(url)
+
+def enter_callback(widget, win):
+ win.destroy()
+
+def SshLogin(hostname, username = None):
+ global win
+ win = gtk.Dialog("Ssh Connection", None,
+ gtk.DIALOG_MODAL,
+ (gtk.STOCK_OK, gtk.RESPONSE_OK))
+
+ vbox = gtk.VBox(False, 5)
+ win.vbox.pack_start(vbox, True, True, 0)
+ vbox.set_border_width(5)
+
+ label = gtk.Label()
+ label.set_markup("Connecting to <b>%s</b>.\nPlease enter your <b>login</b>:" % (hostname))
+
+ vbox.pack_start(label, False, False, 0)
+
+ # Create our entry
+ entry = gtk.Entry()
+ if username!= None:
+ entry.set_text(username)
+ entry.connect("activate", enter_callback, win)
+ vbox.pack_start(entry, False, False, 0)
+
+ # Create the completion object
+ completion = gtk.EntryCompletion()
+
+ # Assign the completion to the entry
+ entry.set_completion(completion)
+
+ # Create a tree model and use it as the completion model
+ completion_model = __create_completion_model()
+ completion.set_model(completion_model)
+
+ # Use model column 0 as the text column
+ completion.set_text_column(0)
+
+ win.show_all()
+ win.run()
+ return entry.get_text()
+
+def __create_completion_model():
+ ''' Creates a tree model containing the completions.
+ '''
+ store = gtk.ListStore(str)
+
+ iter = store.append()
+ store.set(iter, 0, "root")
+
+ current_user = pwd.getpwuid(os.getuid())[0]
+ iter = store.append()
+ store.set(iter, 0, current_user)
+
+ return store
+
def _ssh_tcp(name, hostname, address, port, txts):
+
if txts.has_key("u"):
- sshline = "ssh -l %s -p %i %s" % (txts["u"], port, address)
+ username = SshLogin(name, txts["u"])
+ else:
+ username = SshLogin(name)
+
+ if username != "":
+ sshline = "ssh -l %s -p %i %s" % (username, port, address)
else:
sshline = "ssh -p %i %s" % (port, address)
@@ -86,13 +160,6 @@ def _ssh_tcp(name, hostname, address, port, txts):
cmdline.append("-e %s" % sshline)
pid = subprocess.Popen(cmdline).pid
-def _sftpssh_tcp(name, hostname, address, port, txts):
- path = get_txt_value(txts,"path")
- username = get_txt_value(txts,"u")
- password = get_txt_value(txts,"p")
- url = build_url("ftp",address,port, path, username,password)
- gnome.url_show(url)
-
def handle(name, stype, hostname, address, port, txts):
if stype == "_http._tcp":
_http_tcp(name, hostname, address, port, txts)
diff --git a/actions/services/_ssh_tcp.py b/actions/services/_ssh_tcp.py
new file mode 100644
index 0000000..1465275
--- /dev/null
+++ b/actions/services/_ssh_tcp.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import os
+import pwd
+
+def enter_callback(widget, win):
+ win.destroy()
+
+def SshLogin(hostname, username = None):
+ global win
+ win = gtk.Dialog("Ssh Connection", None,
+ gtk.DIALOG_MODAL,
+ (gtk.STOCK_OK, gtk.RESPONSE_OK))
+
+ vbox = gtk.VBox(False, 5)
+ win.vbox.pack_start(vbox, True, True, 0)
+ vbox.set_border_width(5)
+
+ label = gtk.Label()
+ label.set_markup("Connecting to <b>%s</b>.\nPlease enter your <b>login</b>:" % (hostname))
+
+ vbox.pack_start(label, False, False, 0)
+
+ # Create our entry
+ entry = gtk.Entry()
+ if username!= None:
+ entry.set_text(username)
+ entry.connect("activate", enter_callback, win)
+ vbox.pack_start(entry, False, False, 0)
+
+ # Create the completion object
+ completion = gtk.EntryCompletion()
+
+ # Assign the completion to the entry
+ entry.set_completion(completion)
+
+ # Create a tree model and use it as the completion model
+ completion_model = __create_completion_model()
+ completion.set_model(completion_model)
+
+ # Use model column 0 as the text column
+ completion.set_text_column(0)
+
+ win.show_all()
+ win.run()
+ return entry.get_text()
+
+def __create_completion_model():
+ ''' Creates a tree model containing the completions.
+ '''
+ store = gtk.ListStore(str)
+
+ iter = store.append()
+ store.set(iter, 0, "root")
+
+ current_user = pwd.getpwuid(os.getuid())[0]
+ iter = store.append()
+ store.set(iter, 0, current_user)
+
+ return store
+
+def _ssh_tcp(name, hostname, address, port, txts):
+
+ if txts.has_key("u"):
+ username = SshLogin(name, txts["u"])
+ else:
+ username = SshLogin(name)
+
+ if username != "":
+ sshline = "ssh -l %s -p %i %s" % (username, port, address)
+ else:
+ sshline = "ssh -p %i %s" % (port, address)
+
+ cmdline = []
+ cmdline.append("gnome-terminal")
+ cmdline.append("--tab")
+ cmdline.append("-t %s" % name)
+ cmdline.append("-e %s" % sshline)
+ pid = subprocess.Popen(cmdline).pid
+
+if __name__ == '__main__':
+# res = SshLogin("localhost", "robert")
+# print res
+ _ssh_tcp(name, hostname, address, port, txts)