summaryrefslogtreecommitdiffstats
path: root/actions
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2005-10-02 00:13:49 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2005-10-02 00:13:49 +0000
commitc69a69f7b314aaa4b1fb265232ae420d076ad245 (patch)
tree7e5f47a6e30458ec393319fb5a7dc767eab5eb42 /actions
parent693768da1faf295fd580bd4b2acfdef958daa0c0 (diff)
* remove support for shell scripts (too dangerous)
* add support for python modules for servicetype's actions (not finnished) git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@23 3be567f1-68ff-0310-b24a-ad7cc433fd2f
Diffstat (limited to 'actions')
-rw-r--r--actions/Makefile.am2
-rw-r--r--actions/services/Makefile.am5
-rwxr-xr-xactions/services/__init__.py112
3 files changed, 119 insertions, 0 deletions
diff --git a/actions/Makefile.am b/actions/Makefile.am
new file mode 100644
index 0000000..a829c18
--- /dev/null
+++ b/actions/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = \
+ services \ No newline at end of file
diff --git a/actions/services/Makefile.am b/actions/services/Makefile.am
new file mode 100644
index 0000000..2a28c48
--- /dev/null
+++ b/actions/services/Makefile.am
@@ -0,0 +1,5 @@
+servicesdir = $(ACTIONSDIR)/services
+services_SCRIPTS = \
+ __init__.py
+
+EXTRA_DIST = $(services_SCRIPTS)
diff --git a/actions/services/__init__.py b/actions/services/__init__.py
new file mode 100755
index 0000000..bb51b49
--- /dev/null
+++ b/actions/services/__init__.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+
+import subprocess
+import gnome
+
+def pair_to_dict(l):
+ res = dict()
+ for el in l:
+ if "=" not in el:
+ res[el]=''
+ else:
+ tmp = el.split('=',1)
+ if len(tmp[0]) > 0:
+ res[tmp[0]] = tmp[1]
+ return res
+
+
+def build_url(uri = "http", hostname="127.0.0.1", port = None, path = None, username = None, password = None):
+ if path and path != None:
+ if path[0] == "/":
+ path = path[1:]
+ else:
+ path = ""
+
+ if username:
+ if password:
+ username="%s:%s@" % (username,password)
+ else:
+ username="%s@" % (username)
+ else:
+ username=""
+ if port and port != None:
+ hostname="%s:%i" % (hostname,port)
+ return "%s://%s%s/%s" % (uri,username,hostname,path)
+
+def get_txt_value(txts, txt):
+ if txts.has_key(txt):
+ return txts[txt]
+ else:
+ return None
+
+
+def _http_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("http",address,port, path, username,password)
+ gnome.url_show(url)
+
+def _https_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("https",address,port, path, username,password)
+ gnome.url_show(url)
+
+def _ftp_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 _ssh_tcp(name, hostname, address, port, txts):
+ if txts.has_key("u"):
+ sshline = "ssh -l %s -p %i %s" % (txts["u"], 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
+
+def _sftp-ssh_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)
+ return
+ if stype == "_https._tcp":
+ _https_tcp(name, hostname, address, port, txts)
+ return
+ if stype == "_ftp._tcp":
+ _ftp_tcp(name, hostname, address, port, txts)
+ return
+ if stype == "_ssh._tcp":
+ _ssh_tcp(name, hostname, address, port, txts)
+ return
+ if stype == "_sftp-ssh._tcp":
+ _sftp-ssh_tcp(name, hostname, address, port, txts)
+ return
+
+
+if __name__ == "__main__":
+ print build_url()
+ print build_url("ftp")
+ print build_url("https","www.google.com")
+ print build_url("https","www.google.com",80)
+ print build_url("https","www.google.com",80)
+ print build_url("https","www.google.com",80,"test")
+ print build_url("https","www.google.com",80,"/test")
+ print build_url("https","www.google.com",80,"/test", "user")
+ print build_url("https","www.google.com",0, "", None, "pass")
+ print build_url("https","www.google.com",80,"/test", "user", "pass")