Commits

Paul McLanahan  committed 46faf83

Modified the method for getting the IP from the request to directly querying checkip.dyndns.org.

  • Participants
  • Parent commits 1abb871

Comments (0)

Files changed (1)

File slicehost.py

 import cgi
 import logging
 import os
+import re
+import sys
 import urlparse
 
 from ConfigParser import RawConfigParser
+from urllib2 import urlopen
 
 from pyactiveresource.activeresource import ActiveResource
 
     
     config = RawConfigParser({'names':None})
     config.read(cfg_file)
-    qs = os.environ.get('QUERY_STRING')
-    if qs:
-        data = urlparse.parse_qs(qs)
-        if 'ip' in data:
-            ip = data['ip'][0]
-            key = config.get('slicehost', 'api_key')
-            domain = config.get('slicehost', 'domain')
-            names = config.get('slicehost', 'names')
-            if names:
-                names = names.split()
-            logging.debug('ip=%s, domain=%s, names=%r, key=%s', ip, domain, names, key)
-            sh = Slicehost(key)
-            sh.set_zone_ip(domain, ip, names)
-            logging.info('set %s to %s', domain, ip)
-            print_result()
+    try:
+        html = urlopen('http://checkip.dyndns.org/').read()
+    except IOError:
+        print_result('error')
+    m = re.search(r'(\d{1,3}\.){3}(\d{1,3})', html)
+    if m:
+        ip = m.group(0)
+        key = config.get('slicehost', 'api_key')
+        domain = config.get('slicehost', 'domain')
+        names = config.get('slicehost', 'names')
+        if names:
+            names = names.split()
+        logging.debug('ip=%s, domain=%s, names=%r, key=%s', ip, domain, names, key)
+        sh = Slicehost(key)
+        sh.set_zone_ip(domain, ip, names)
+        logging.info('set %s to %s', domain, ip)
+        print_result()
     
     print_result('error')
 
 if __name__ == '__main__':
-    main()
+    main()
+