Merge lp:~lqb/update-notifier/kdeproxy+kwallet-support into lp:update-notifier/ubuntu
- kdeproxy+kwallet-support
- Merge into ubuntu
Status: | Work in progress |
---|---|
Proposed branch: | lp:~lqb/update-notifier/kdeproxy+kwallet-support |
Merge into: | lp:update-notifier/ubuntu |
Diff against target: |
597 lines (+457/-9) 7 files modified
TODO (+7/-1) data/kwalletdbuscli.py (+94/-0) data/org.freedesktop.policykit.pkexec.package-data-downloader.policy (+19/-0) data/package-data-downloader (+318/-6) debian/changelog (+11/-1) debian/control (+5/-1) debian/update-notifier-common.install (+3/-0) |
To merge this branch: | bzr merge lp:~lqb/update-notifier/kdeproxy+kwallet-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sebastien Bacher | Needs Fixing | ||
Review via email: mp+153420@code.launchpad.net |
Commit message
Description of the change
- Added proxy support configured in kde
- Added kwallet support
- Added simple GUI Password dialog for proxy authentification
Lorenz (lqb) wrote : | # |
> thank you for your work, the current version of the merge request has
> conflicts (in data/package-
> resolve those and resubmit it?
My try to do that failed. I have to find out what I made wrong. Perhaps you might give me a hint.
Thanks
Sebastien Bacher (seb128) wrote : | # |
Not sure what happened, in case there were need commits in the vcs since you did the change you might want to "bzr merge lp:update-notifier" in your branch, then resolve the conflicts and use "bzr resolve <files_
Lorenz (lqb) wrote : | # |
> Not sure what happened, in case there were need commits in the vcs since you
> did the change you might want to "bzr merge lp:update-notifier" in your
> branch, then resolve the conflicts and use "bzr resolve
> <files_
That is not realy what I wanted but it works.
Thanks
Unmerged revisions
- 710. By Lorenz
-
bufix for password dialog problem
- 709. By Lorenz
-
merged with trunk
- 708. By Lorenz
-
merge with trunk
- 707. By Lorenz
-
merged data/package-
data-downloader - 706. By Lorenz
-
* resolved conflict debian/control
* resolved conflict data/package-data-downloader - 705. By Lorenz
-
* added policykit rule to allow pkexec to use the GUI
* Enhanced proxy support for kde with kwallet support
* added partial autoconfiguration support (if configured in kde)
* added gui prompt for proxy password
* added passwordcache - 704. By Lorenz
-
Merged from lp:~lqb/update-notifier/bug1152203
Preview Diff
1 | === modified file 'TODO' | |||
2 | --- TODO 2007-07-27 21:00:33 +0000 | |||
3 | +++ TODO 2013-04-11 13:43:22 +0000 | |||
4 | @@ -6,4 +6,10 @@ | |||
5 | 6 | * use a g_hash_table for hook_files | 6 | * use a g_hash_table for hook_files |
6 | 7 | * remove hook-files that are no longer in the HOOK_DIR | 7 | * remove hook-files that are no longer in the HOOK_DIR |
7 | 8 | from the hook_seen file (by discarding them when building | 8 | from the hook_seen file (by discarding them when building |
8 | 9 | the hook_files list) | ||
9 | 10 | \ No newline at end of file | 9 | \ No newline at end of file |
10 | 10 | the hook_files list) | ||
11 | 11 | |||
12 | 12 | get_kde_proxy_servers: | ||
13 | 13 | get wpad autoconfiguration from DHCP | ||
14 | 14 | |||
15 | 15 | get_gconf_proxy_servers: | ||
16 | 16 | implement this function | ||
17 | 11 | 17 | ||
18 | === added file 'data/kwalletdbuscli.py' | |||
19 | --- data/kwalletdbuscli.py 1970-01-01 00:00:00 +0000 | |||
20 | +++ data/kwalletdbuscli.py 2013-04-11 13:43:22 +0000 | |||
21 | @@ -0,0 +1,94 @@ | |||
22 | 1 | #!/usr/bin/python | ||
23 | 2 | |||
24 | 3 | import sys | ||
25 | 4 | import os | ||
26 | 5 | import subprocess | ||
27 | 6 | import shlex | ||
28 | 7 | import argparse | ||
29 | 8 | import dbus | ||
30 | 9 | from pprint import pprint | ||
31 | 10 | |||
32 | 11 | appid='Python KWallet D-Bus CLI' | ||
33 | 12 | wallet='kdewallet' | ||
34 | 13 | |||
35 | 14 | sOK=0 | ||
36 | 15 | sError=1 | ||
37 | 16 | sCancel=10 | ||
38 | 17 | |||
39 | 18 | def askpass(title="KWallet DBUS CLI",text="Enter username and password"): | ||
40 | 19 | appid="test" | ||
41 | 20 | description="desc" | ||
42 | 21 | realm="re" | ||
43 | 22 | cmd='zenity --title="'+title+'" --forms --text="'+text+'" --add-entry=username --add-password=password' | ||
44 | 23 | p=subprocess.Popen(args=shlex.split(cmd),stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) | ||
45 | 24 | ret=p.wait() | ||
46 | 25 | out,err=p.communicate() | ||
47 | 26 | if ret != 0: | ||
48 | 27 | return None | ||
49 | 28 | user,password=out.split('|') | ||
50 | 29 | return user+':'+password | ||
51 | 30 | |||
52 | 31 | |||
53 | 32 | def main(): | ||
54 | 33 | global appid | ||
55 | 34 | STATUS=sOK | ||
56 | 35 | parser=argparse.ArgumentParser() | ||
57 | 36 | parser.add_argument('-a','--app',default=appid,dest='appid') | ||
58 | 37 | |||
59 | 38 | subparsers=parser.add_subparsers(dest='parser_name') | ||
60 | 39 | |||
61 | 40 | pclose=subparsers.add_parser('close') | ||
62 | 41 | |||
63 | 42 | pget=subparsers.add_parser('get') | ||
64 | 43 | pget.add_argument('-f','--folder', required=True) | ||
65 | 44 | pget.add_argument('-e','--entry', required=True) | ||
66 | 45 | |||
67 | 46 | pset=subparsers.add_parser('set') | ||
68 | 47 | pset.add_argument('-f','--folder', required=True) | ||
69 | 48 | pset.add_argument('-e','--entry', required=True) | ||
70 | 49 | pset.add_argument('-p','--password', required=True) | ||
71 | 50 | |||
72 | 51 | pset=subparsers.add_parser('ask') | ||
73 | 52 | pset.add_argument('-f','--folder', required=True) | ||
74 | 53 | pset.add_argument('-e','--entry', required=True) | ||
75 | 54 | pset.add_argument('-t','--text',default='Enter username and password', required=False) | ||
76 | 55 | |||
77 | 56 | args=parser.parse_args() | ||
78 | 57 | |||
79 | 58 | appid=args.appid | ||
80 | 59 | bus=dbus.SessionBus() | ||
81 | 60 | remote_object = bus.get_object('org.kde.kwalletd', '/modules/kwalletd' ) | ||
82 | 61 | iface = dbus.Interface(remote_object, 'org.kde.KWallet') | ||
83 | 62 | |||
84 | 63 | if args.parser_name == 'close': | ||
85 | 64 | iface.disconnectApplication(wallet, appid) | ||
86 | 65 | if args.parser_name == 'get': | ||
87 | 66 | wid=iface.open(wallet, 0, appid) | ||
88 | 67 | password=iface.readPasswordList(wid, args.folder, args.entry, appid) | ||
89 | 68 | if len(password.keys()) != 0: | ||
90 | 69 | password=password[args.entry] | ||
91 | 70 | print password | ||
92 | 71 | else: | ||
93 | 72 | STATUS=sError | ||
94 | 73 | if args.parser_name == 'ask': | ||
95 | 74 | password=askpass(appid,args.text) | ||
96 | 75 | if password is None: | ||
97 | 76 | print >> sys.stderr, "askpass canceled" | ||
98 | 77 | STATUS=sCancel | ||
99 | 78 | else: | ||
100 | 79 | wid=iface.open(wallet, 0, appid) | ||
101 | 80 | iface.writePassword(wid, args.folder, args.entry, password, appid) | ||
102 | 81 | print password | ||
103 | 82 | if args.parser_name == 'set': | ||
104 | 83 | wid=iface.open(wallet, 0, appid) | ||
105 | 84 | password=args.password | ||
106 | 85 | iface.writePassword(wid, args.folder, args.entry, password, appid) | ||
107 | 86 | print password | ||
108 | 87 | sys.exit(STATUS) | ||
109 | 88 | |||
110 | 89 | |||
111 | 90 | if __name__ == "__main__": | ||
112 | 91 | main() | ||
113 | 92 | |||
114 | 93 | |||
115 | 94 | |||
116 | 0 | 95 | ||
117 | === added file 'data/org.freedesktop.policykit.pkexec.package-data-downloader.policy' | |||
118 | --- data/org.freedesktop.policykit.pkexec.package-data-downloader.policy 1970-01-01 00:00:00 +0000 | |||
119 | +++ data/org.freedesktop.policykit.pkexec.package-data-downloader.policy 2013-04-11 13:43:22 +0000 | |||
120 | @@ -0,0 +1,19 @@ | |||
121 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
122 | 2 | <!DOCTYPE policyconfig PUBLIC | ||
123 | 3 | "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" | ||
124 | 4 | "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> | ||
125 | 5 | <policyconfig> | ||
126 | 6 | |||
127 | 7 | <action id="org.freedesktop.policykit.pkexec.run-package-data-downloader"> | ||
128 | 8 | <description>Run package-data-downloader</description> | ||
129 | 9 | <message>Authentication is required to run package-data-downloader</message> | ||
130 | 10 | <defaults> | ||
131 | 11 | <allow_any>no</allow_any> | ||
132 | 12 | <allow_inactive>no</allow_inactive> | ||
133 | 13 | <allow_active>auth_admin_keep</allow_active> | ||
134 | 14 | </defaults> | ||
135 | 15 | <annotate key="org.freedesktop.policykit.exec.path">/usr/lib/update-notifier/package-data-downloader</annotate> | ||
136 | 16 | <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate> | ||
137 | 17 | </action> | ||
138 | 18 | |||
139 | 19 | </policyconfig> | ||
140 | 0 | 20 | ||
141 | === modified file 'data/package-data-downloader' | |||
142 | --- data/package-data-downloader 2012-08-25 14:18:38 +0000 | |||
143 | +++ data/package-data-downloader 2013-04-11 13:43:22 +0000 | |||
144 | @@ -27,7 +27,18 @@ | |||
145 | 27 | import string | 27 | import string |
146 | 28 | import apt | 28 | import apt |
147 | 29 | import debconf | 29 | import debconf |
148 | 30 | import pacparser | ||
149 | 31 | import pwd | ||
150 | 32 | import shlex | ||
151 | 33 | import getpass | ||
152 | 34 | import tempfile | ||
153 | 35 | import socket | ||
154 | 30 | from datetime import datetime | 36 | from datetime import datetime |
155 | 37 | try: | ||
156 | 38 | import configparser as config_parser | ||
157 | 39 | except: | ||
158 | 40 | import ConfigParser as config_parser | ||
159 | 41 | |||
160 | 31 | 42 | ||
161 | 32 | DATADIR = "/usr/share/package-data-downloads/" | 43 | DATADIR = "/usr/share/package-data-downloads/" |
162 | 33 | STAMPDIR = "/var/lib/update-notifier/package-data-downloads/" | 44 | STAMPDIR = "/var/lib/update-notifier/package-data-downloads/" |
163 | @@ -39,6 +50,274 @@ | |||
164 | 39 | failures = [] | 50 | failures = [] |
165 | 40 | permanent_failures = [] | 51 | permanent_failures = [] |
166 | 41 | 52 | ||
167 | 53 | PROGNAME="update-notifier-downloader" | ||
168 | 54 | |||
169 | 55 | class PasswordCache(): | ||
170 | 56 | __data={} | ||
171 | 57 | def set(self, key, user, password): | ||
172 | 58 | self.__data[key]={'user':user,'password':password} | ||
173 | 59 | def get(self, key=None): | ||
174 | 60 | if key is None: | ||
175 | 61 | return self.__data | ||
176 | 62 | else: | ||
177 | 63 | if key in self.__data.keys(): | ||
178 | 64 | return self.__data[key] | ||
179 | 65 | else: | ||
180 | 66 | return None | ||
181 | 67 | |||
182 | 68 | |||
183 | 69 | |||
184 | 70 | class kwalletFancyURLopener(urllib.FancyURLopener): | ||
185 | 71 | appid=PROGNAME | ||
186 | 72 | """Inheriited from urllib.FancyURLopener to add kwallet communication. | ||
187 | 73 | Communication with kwallet over dbus seems to work only if DISPLAY is set. | ||
188 | 74 | If TERM is set, we can communicate with the user. | ||
189 | 75 | If neither DISPLAY or TERM is set communication might not be possible. | ||
190 | 76 | """ | ||
191 | 77 | count=0 | ||
192 | 78 | |||
193 | 79 | def prompt_user_passwd(self, realm, description): | ||
194 | 80 | self.count+=1 | ||
195 | 81 | if self.count > 20: | ||
196 | 82 | sys.exit(1) | ||
197 | 83 | appid=kwalletFancyURLopener.appid | ||
198 | 84 | kwallet_bin='/usr/lib/update-notifier/kwalletdbuscli.py' | ||
199 | 85 | key=realm + "-" + description | ||
200 | 86 | TERM=os.getenv('TERM',None) | ||
201 | 87 | DISPLAY=os.getenv('DISPLAY',None) | ||
202 | 88 | user=None | ||
203 | 89 | password=None | ||
204 | 90 | pwcache=PasswordCache() | ||
205 | 91 | |||
206 | 92 | uid=os.getenv('PKEXEC_UID',None) | ||
207 | 93 | if uid==None: | ||
208 | 94 | uid=os.getenv('SUDO_UID',None) | ||
209 | 95 | if uid==None: | ||
210 | 96 | if 'USER' in os.environ: | ||
211 | 97 | uid=int(pwd.getpwnam(os.environ['USER']).pw_uid) | ||
212 | 98 | if uid==None: | ||
213 | 99 | uid=os.getuid() | ||
214 | 100 | |||
215 | 101 | credentials=pwcache.get(key) | ||
216 | 102 | #if credentials is not None: | ||
217 | 103 | if credentials is not None and self.count < 2: | ||
218 | 104 | return (credentials['user'], credentials['password']) | ||
219 | 105 | else: | ||
220 | 106 | if (TERM == None or DISPLAY == None): | ||
221 | 107 | return ('','') | ||
222 | 108 | else: | ||
223 | 109 | out='' | ||
224 | 110 | if DISPLAY != None: | ||
225 | 111 | print "Accessing kwallet" | ||
226 | 112 | cmd='sudo -u "#'+str(uid)+'" '+kwallet_bin+' -a "'+appid+'" get -f "'+appid+'" -e "'+key+'"' | ||
227 | 113 | p=subprocess.Popen(args=shlex.split(cmd),stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) | ||
228 | 114 | ret=p.wait() | ||
229 | 115 | out,err=p.communicate() | ||
230 | 116 | out=out.strip() | ||
231 | 117 | if ret != 0 or self.count > 2 or (out=="" or out==":"): # No entry in wallet or wrong credentials or empty credentials | ||
232 | 118 | cmd='sudo -u "#'+str(uid)+'" '+kwallet_bin+' -a "'+appid+'" ask -f "'+appid+'" -e "'+key+'" -t "Enter credentials for '+description.replace('&','&')+' at '+realm+'"' | ||
233 | 119 | p=subprocess.Popen(args=shlex.split(cmd),stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) | ||
234 | 120 | ret=p.wait() | ||
235 | 121 | out,err=p.communicate() | ||
236 | 122 | out=out.strip() | ||
237 | 123 | if ret==10: | ||
238 | 124 | return (None,None) # Don't ask again | ||
239 | 125 | elif ret != 0: | ||
240 | 126 | return ("\n","\n") # Force to ask again | ||
241 | 127 | elif out=="" or out==":": | ||
242 | 128 | return ("\n","\n") # Force to ask again. Treats empty credentials as error | ||
243 | 129 | user,password=out.split(':') | ||
244 | 130 | pwcache.set(key, user, password) | ||
245 | 131 | credentials=pwcache.get(key) | ||
246 | 132 | return (user, password) | ||
247 | 133 | |||
248 | 134 | |||
249 | 135 | def get_gconf_proxy_servers(url,uid=None): | ||
250 | 136 | """Get proxy server from (system) gconf settings.""" | ||
251 | 137 | print "Not yet Implemented!" | ||
252 | 138 | return {} | ||
253 | 139 | |||
254 | 140 | |||
255 | 141 | def get_kde_proxy_servers(url,uid=None): | ||
256 | 142 | """Get proxy server from kde settings""" | ||
257 | 143 | proxies={} | ||
258 | 144 | kioslave=config_parser.ConfigParser(allow_no_value=True) | ||
259 | 145 | if uid is not None: | ||
260 | 146 | home=pwd.getpwuid(int(uid)).pw_dir | ||
261 | 147 | #print "HOME="+home | ||
262 | 148 | config_files=['/etc/kde4/kioslaverc',home+'/.kde/share/config/kioslaverc'] | ||
263 | 149 | else: | ||
264 | 150 | config_files=['/etc/kde4/kioslaverc'] | ||
265 | 151 | |||
266 | 152 | for config_file in config_files: | ||
267 | 153 | try: | ||
268 | 154 | fh=open(config_file) | ||
269 | 155 | line=fh.readline() # discard first lines until line contains "[" | ||
270 | 156 | while not '[' in line: | ||
271 | 157 | line=fh.readline() | ||
272 | 158 | if line=='': | ||
273 | 159 | break | ||
274 | 160 | fh.seek(-1 * len(line), 1) # rewind file pointer | ||
275 | 161 | kioslave.readfp(fh) | ||
276 | 162 | except: | ||
277 | 163 | pass | ||
278 | 164 | |||
279 | 165 | if not kioslave.has_section('Proxy Settings'): | ||
280 | 166 | return proxies | ||
281 | 167 | |||
282 | 168 | if (kioslave.get('Proxy Settings','ProxyType') == '0'): # No Proxy | ||
283 | 169 | proxies={} | ||
284 | 170 | |||
285 | 171 | if (kioslave.get('Proxy Settings','ProxyType') == '1'): # Use manually specified proxy configuration | ||
286 | 172 | proxies['http']=kioslave.get('Proxy Settings','httpProxy').replace(' ',':') | ||
287 | 173 | proxies['ftp']=kioslave.get('Proxy Settings','ftpProxy').replace(' ',':') | ||
288 | 174 | proxies['socks']=kioslave.get('Proxy Settings','socksProxy').replace(' ',':') | ||
289 | 175 | proxies['https']=kioslave.get('Proxy Settings','httpsProxy').replace(' ',':') | ||
290 | 176 | proxies['no']=kioslave.get('Proxy Settings','NoProxyFor') # does this work? | ||
291 | 177 | |||
292 | 178 | if (kioslave.get('Proxy Settings','ProxyType') == '2'): # Use proxy auto configuration URL | ||
293 | 179 | pacurl=kioslave.get('Proxy Settings','Proxy Config Script') | ||
294 | 180 | if pacurl is None: | ||
295 | 181 | return {} | ||
296 | 182 | tmpfn=tempfile.mkstemp(prefix="proxy_",suffix=".pac")[1] | ||
297 | 183 | urlh=urllib.urlopen(pacurl,proxies={}) # Force direct download | ||
298 | 184 | tmph=open(tmpfn,"w") | ||
299 | 185 | for line in urlh: | ||
300 | 186 | tmph.write(line) | ||
301 | 187 | tmph.close() | ||
302 | 188 | proxy_string=pacparser.just_find_proxy(tmpfn, url) | ||
303 | 189 | os.remove(tmpfn) | ||
304 | 190 | proxylist = proxy_string.split(";") | ||
305 | 191 | proxies = None | ||
306 | 192 | while proxylist: | ||
307 | 193 | proxy = proxylist.pop(0).strip() | ||
308 | 194 | if 'DIRECT' in proxy: | ||
309 | 195 | proxies = {} | ||
310 | 196 | break | ||
311 | 197 | if proxy[0:5].upper() == 'PROXY': | ||
312 | 198 | proxy = proxy[6:].strip() | ||
313 | 199 | proxies = {'http': 'http://%s' % proxy} | ||
314 | 200 | |||
315 | 201 | if (kioslave.get('Proxy Settings','ProxyType') == '3'): # Detect proxy configuration automatically | ||
316 | 202 | # usually a DHCPINFORM shoud be used first to determine the proxy pac url but I currently can't test, so I don't implement that yet | ||
317 | 203 | pacurl=None | ||
318 | 204 | tmpfn=None | ||
319 | 205 | fqdn=socket.getfqdn() | ||
320 | 206 | domparts=fqdn.split('.') | ||
321 | 207 | proxylist=None | ||
322 | 208 | while len(domparts) > 2: | ||
323 | 209 | domparts.remove(domparts[0]) | ||
324 | 210 | pacurl="http://wpad."+string.join(domparts,".")+"/wpad.dat" | ||
325 | 211 | tmpfn=tempfile.mkstemp(prefix="proxy_",suffix=".pac")[1] | ||
326 | 212 | try: | ||
327 | 213 | urlh=urllib.urlopen(pacurl,proxies={}) # Force direct download | ||
328 | 214 | except: | ||
329 | 215 | continue | ||
330 | 216 | tmph=open(tmpfn,"w") | ||
331 | 217 | if urlh.info().gettype() == 'application/x-ns-proxy-autoconfig': | ||
332 | 218 | for line in urlh: | ||
333 | 219 | tmph.write(line) | ||
334 | 220 | tmph.close() | ||
335 | 221 | proxy_string=pacparser.just_find_proxy(tmpfn, url) | ||
336 | 222 | proxylist = proxy_string.split(";") | ||
337 | 223 | os.remove(tmpfn) | ||
338 | 224 | if proxylist==None: | ||
339 | 225 | print "No WPAD configuration found. Using direct access" | ||
340 | 226 | proxies = {} | ||
341 | 227 | while proxylist: | ||
342 | 228 | proxy = proxylist.pop(0).strip() | ||
343 | 229 | if 'DIRECT' in proxy: | ||
344 | 230 | proxies = {} | ||
345 | 231 | break | ||
346 | 232 | if proxy[0:5].upper() == 'PROXY': | ||
347 | 233 | proxy = proxy[6:].strip() | ||
348 | 234 | proxies = {'http': 'http://%s' % proxy} | ||
349 | 235 | |||
350 | 236 | |||
351 | 237 | if (kioslave.get('Proxy Settings','ProxyType') == '4'): # Use system proxy configuration | ||
352 | 238 | for varname in kioslave.get('Proxy Settings','httpProxy').split(','): | ||
353 | 239 | try: | ||
354 | 240 | proxies['http']=os.environ[varname] | ||
355 | 241 | except: | ||
356 | 242 | pass | ||
357 | 243 | if 'http' in proxies.keys(): | ||
358 | 244 | break | ||
359 | 245 | for varname in kioslave.get('Proxy Settings','ftpProxy').split(','): | ||
360 | 246 | try: | ||
361 | 247 | proxies['ftp']=os.environ[varname] | ||
362 | 248 | except: | ||
363 | 249 | pass | ||
364 | 250 | if 'ftp' in proxies.keys(): | ||
365 | 251 | break | ||
366 | 252 | for varname in kioslave.get('Proxy Settings','httpsProxy').split(','): | ||
367 | 253 | try: | ||
368 | 254 | proxies['https']=os.environ[varname] | ||
369 | 255 | except: | ||
370 | 256 | pass | ||
371 | 257 | if 'https' in proxies.keys(): | ||
372 | 258 | break | ||
373 | 259 | for varname in kioslave.get('Proxy Settings','socksProxy').split(','): | ||
374 | 260 | try: | ||
375 | 261 | proxies['socks']=os.environ[varname] | ||
376 | 262 | except: | ||
377 | 263 | pass | ||
378 | 264 | if 'socks' in proxies.keys(): | ||
379 | 265 | break | ||
380 | 266 | for varname in kioslave.get('Proxy Settings','NoProxyFor').split(','): # does this work? | ||
381 | 267 | try: | ||
382 | 268 | proxies['no']=os.environ[varname] | ||
383 | 269 | except: | ||
384 | 270 | pass | ||
385 | 271 | if 'no' in proxies.keys(): | ||
386 | 272 | break | ||
387 | 273 | return proxies | ||
388 | 274 | |||
389 | 275 | |||
390 | 276 | def get_env_proxy_servers(): | ||
391 | 277 | """Get proxy server from environment settings""" | ||
392 | 278 | # Get our proxy settings from the environment | ||
393 | 279 | proxies = {} | ||
394 | 280 | try: | ||
395 | 281 | for proto in ('http','https','ftp','no'): | ||
396 | 282 | try: | ||
397 | 283 | proxies[proto] = os.environ[proto+"_proxy"] | ||
398 | 284 | except KeyError: | ||
399 | 285 | pass | ||
400 | 286 | except Exception: | ||
401 | 287 | pass | ||
402 | 288 | return proxies | ||
403 | 289 | |||
404 | 290 | def get_proxy_servers(url): | ||
405 | 291 | """Get proxy settings dependent on environment and call | ||
406 | 292 | |||
407 | 293 | This script could be called through different ways. | ||
408 | 294 | It is not possible to fetch proxy setting e.g. from kde | ||
409 | 295 | settings if this script was called from a cronjob | ||
410 | 296 | """ | ||
411 | 297 | |||
412 | 298 | UID=os.getuid() | ||
413 | 299 | PKEXEC_UID=os.getenv('PKEXEC_UID',None) | ||
414 | 300 | SUDO_UID=os.getenv('SUDO_UID',None) | ||
415 | 301 | proxies={} | ||
416 | 302 | |||
417 | 303 | if (PKEXEC_UID != None) and (PKEXEC_UID != 0): | ||
418 | 304 | proxies=get_kde_proxy_servers(url,PKEXEC_UID) | ||
419 | 305 | elif (SUDO_UID != None) and (SUDO_UID != 0): | ||
420 | 306 | proxies=get_kde_proxy_servers(url,SUDO_UID) | ||
421 | 307 | elif (UID != None) and (UID != 0): | ||
422 | 308 | proxies=get_kde_proxy_servers(url,UID) | ||
423 | 309 | else: | ||
424 | 310 | proxies=get_kde_proxy_servers(url) | ||
425 | 311 | |||
426 | 312 | if not proxies: | ||
427 | 313 | proxies=get_gconf_proxy_servers(url) | ||
428 | 314 | |||
429 | 315 | if not proxies: | ||
430 | 316 | proxies=get_env_proxy_servers() | ||
431 | 317 | |||
432 | 318 | return proxies | ||
433 | 319 | |||
434 | 320 | |||
435 | 42 | def create_or_update_stampfile(file): | 321 | def create_or_update_stampfile(file): |
436 | 43 | """Create or update the indicated stampfile, and remove failure flags""" | 322 | """Create or update the indicated stampfile, and remove failure flags""" |
437 | 44 | 323 | ||
438 | @@ -145,8 +424,9 @@ | |||
439 | 145 | sys.exit(1) | 424 | sys.exit(1) |
440 | 146 | 425 | ||
441 | 147 | packages = [os.path.basename(failure) for failure in failures] | 426 | packages = [os.path.basename(failure) for failure in failures] |
442 | 427 | |||
443 | 148 | output_file.write( | 428 | output_file.write( |
445 | 149 | string.Template(input).substitute( | 429 | string.Template(input).safe_substitute( |
446 | 150 | {'packages' : ", ".join(packages)})) | 430 | {'packages' : ", ".join(packages)})) |
447 | 151 | output_file.close() | 431 | output_file.close() |
448 | 152 | 432 | ||
449 | @@ -160,6 +440,17 @@ | |||
450 | 160 | res.append(relfile) | 440 | res.append(relfile) |
451 | 161 | return res | 441 | return res |
452 | 162 | 442 | ||
453 | 443 | def mktmp4url(url): | ||
454 | 444 | import tempfile | ||
455 | 445 | garbage, path = urllib.splittype(url) | ||
456 | 446 | garbage, path = urllib.splithost(path or "") | ||
457 | 447 | path, garbage = urllib.splitquery(path or "") | ||
458 | 448 | path, garbage = urllib.splitattr(path or "") | ||
459 | 449 | suffix = os.path.splitext(path)[1] | ||
460 | 450 | (fd, filename) = tempfile.mkstemp(suffix) | ||
461 | 451 | return (fd, filename) | ||
462 | 452 | |||
463 | 453 | |||
464 | 163 | def process_download_requests(): | 454 | def process_download_requests(): |
465 | 164 | """Process requests to download package data files | 455 | """Process requests to download package data files |
466 | 165 | 456 | ||
467 | @@ -182,7 +473,6 @@ | |||
468 | 182 | proxies[proto] = os.environ[proto+"_proxy"] | 473 | proxies[proto] = os.environ[proto+"_proxy"] |
469 | 183 | except KeyError: | 474 | except KeyError: |
470 | 184 | pass | 475 | pass |
471 | 185 | |||
472 | 186 | if proxies: | 476 | if proxies: |
473 | 187 | urllib._urlopener = urllib.FancyURLopener(proxies) | 477 | urllib._urlopener = urllib.FancyURLopener(proxies) |
474 | 188 | except Exception: | 478 | except Exception: |
475 | @@ -214,6 +504,7 @@ | |||
476 | 214 | record_failure(relfile) | 504 | record_failure(relfile) |
477 | 215 | break | 505 | break |
478 | 216 | command = [para['script']] | 506 | command = [para['script']] |
479 | 507 | tmpfiles=[] | ||
480 | 217 | 508 | ||
481 | 218 | if 'should-download' in para: | 509 | if 'should-download' in para: |
482 | 219 | db = debconf.DebconfCommunicator('update-notifier') | 510 | db = debconf.DebconfCommunicator('update-notifier') |
483 | @@ -231,7 +522,12 @@ | |||
484 | 231 | try: | 522 | try: |
485 | 232 | for i in range(len(files)): | 523 | for i in range(len(files)): |
486 | 233 | print "%s: downloading %s" % (relfile, files[i]) | 524 | print "%s: downloading %s" % (relfile, files[i]) |
488 | 234 | dest_file = urllib.urlretrieve(files[i])[0] | 525 | proxies=get_proxy_servers(files[i]) # Get our proxy settings for each url |
489 | 526 | if proxies: | ||
490 | 527 | urllib._urlopener = kwalletFancyURLopener(proxies) | ||
491 | 528 | (fd,filename)=mktmp4url(files[i]) | ||
492 | 529 | tmpfiles.append(filename) | ||
493 | 530 | dest_file = urllib.urlretrieve(files[i], filename)[0] | ||
494 | 235 | output = subprocess.check_output(["sha256sum", dest_file]) | 531 | output = subprocess.check_output(["sha256sum", dest_file]) |
495 | 236 | output = output.split(' ')[0] | 532 | output = output.split(' ')[0] |
496 | 237 | if output == sums[i]: | 533 | if output == sums[i]: |
497 | @@ -241,7 +537,6 @@ | |||
498 | 241 | break | 537 | break |
499 | 242 | if relfile in failures + permanent_failures: | 538 | if relfile in failures + permanent_failures: |
500 | 243 | break | 539 | break |
501 | 244 | |||
502 | 245 | sys.stdout.flush() | 540 | sys.stdout.flush() |
503 | 246 | result = subprocess.call(command) | 541 | result = subprocess.call(command) |
504 | 247 | if result: | 542 | if result: |
505 | @@ -252,7 +547,6 @@ | |||
506 | 252 | break | 547 | break |
507 | 253 | except Exception: | 548 | except Exception: |
508 | 254 | traceback.print_exc(file=sys.stderr) | 549 | traceback.print_exc(file=sys.stderr) |
509 | 255 | |||
510 | 256 | record_failure(relfile) | 550 | record_failure(relfile) |
511 | 257 | # The 'script' is always the last stanza | 551 | # The 'script' is always the last stanza |
512 | 258 | break | 552 | break |
513 | @@ -266,7 +560,11 @@ | |||
514 | 266 | traceback.print_exc(file=sys.stderr) | 560 | traceback.print_exc(file=sys.stderr) |
515 | 267 | record_failure(relfile) | 561 | record_failure(relfile) |
516 | 268 | break | 562 | break |
518 | 269 | 563 | for f in tmpfiles: | |
519 | 564 | try: | ||
520 | 565 | os.remove(f) | ||
521 | 566 | except: | ||
522 | 567 | pass | ||
523 | 270 | previous_failures = existing_permanent_failures() | 568 | previous_failures = existing_permanent_failures() |
524 | 271 | 569 | ||
525 | 272 | # We only report about "permanent" failures when there are new ones, | 570 | # We only report about "permanent" failures when there are new ones, |
526 | @@ -294,3 +592,17 @@ | |||
527 | 294 | 592 | ||
528 | 295 | if __name__ == "__main__": | 593 | if __name__ == "__main__": |
529 | 296 | process_download_requests() | 594 | process_download_requests() |
530 | 595 | |||
531 | 596 | |||
532 | 597 | # close wallet | ||
533 | 598 | uid=os.getenv('PKEXEC_UID',None) | ||
534 | 599 | if uid==None: | ||
535 | 600 | uid=os.getenv('SUDO_UID',None) | ||
536 | 601 | if uid==None: | ||
537 | 602 | uid=os.getuid() | ||
538 | 603 | if uid!=0: | ||
539 | 604 | cmd='sudo -u "#'+str(uid)+'" /usr/lib/update-notifier/kwalletdbuscli.py -a "'+PROGNAME+'" close' | ||
540 | 605 | p=subprocess.Popen(args=shlex.split(cmd),stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE) | ||
541 | 606 | p.wait() | ||
542 | 607 | |||
543 | 608 | print PROGNAME+" finished" | ||
544 | 297 | 609 | ||
545 | === modified file 'debian/changelog' | |||
546 | --- debian/changelog 2013-04-09 10:31:08 +0000 | |||
547 | +++ debian/changelog 2013-04-11 13:43:22 +0000 | |||
548 | @@ -218,10 +218,20 @@ | |||
549 | 218 | 218 | ||
550 | 219 | update-notifier (0.119ubuntu10) quantal; urgency=low | 219 | update-notifier (0.119ubuntu10) quantal; urgency=low |
551 | 220 | 220 | ||
552 | 221 | [ Steve Langasek ] | ||
553 | 221 | * Merge in changes from 0.119ubuntu8.1 which had been uploaded to | 222 | * Merge in changes from 0.119ubuntu8.1 which had been uploaded to |
554 | 222 | precise-proposed. | 223 | precise-proposed. |
555 | 223 | 224 | ||
557 | 224 | -- Steve Langasek <steve.langasek@ubuntu.com> Tue, 15 May 2012 16:20:43 -0700 | 225 | [ Lorenz ] |
558 | 226 | * Fix Translation error and use safe_substitute instead of substitute on | ||
559 | 227 | template substitution. LP: #1152203 | ||
560 | 228 | * added policykit rule to allow pkexec to use the GUI | ||
561 | 229 | * Enhanced proxy support for kde with kwallet support | ||
562 | 230 | * added partial autoconfiguration support (if configured in kde) | ||
563 | 231 | * added gui prompt for proxy password | ||
564 | 232 | * added passwordcache | ||
565 | 233 | |||
566 | 234 | -- Lorenz <lqb@gmx.de> Tue, 12 Mar 2013 18:44:45 +0100 | ||
567 | 225 | 235 | ||
568 | 226 | update-notifier (0.119ubuntu9) quantal; urgency=low | 236 | update-notifier (0.119ubuntu9) quantal; urgency=low |
569 | 227 | 237 | ||
570 | 228 | 238 | ||
571 | === modified file 'debian/control' | |||
572 | --- debian/control 2013-04-09 10:07:10 +0000 | |||
573 | +++ debian/control 2013-04-11 13:43:22 +0000 | |||
574 | @@ -47,7 +47,11 @@ | |||
575 | 47 | Depends: ${shlibs:Depends}, | 47 | Depends: ${shlibs:Depends}, |
576 | 48 | ${misc:Depends}, | 48 | ${misc:Depends}, |
577 | 49 | python, | 49 | python, |
579 | 50 | python-apt (>= 0.6.12), python-debian, debconf, patch | 50 | python-apt (>= 0.6.12), |
580 | 51 | python-debian, | ||
581 | 52 | debconf, | ||
582 | 53 | patch, | ||
583 | 54 | python-pacparser | ||
584 | 51 | Recommends: libpam-modules (>= 1.0.1-9ubuntu3) | 55 | Recommends: libpam-modules (>= 1.0.1-9ubuntu3) |
585 | 52 | Suggests: policykit-1 | 56 | Suggests: policykit-1 |
586 | 53 | Description: Files shared between update-notifier and other packages | 57 | Description: Files shared between update-notifier and other packages |
587 | 54 | 58 | ||
588 | === modified file 'debian/update-notifier-common.install' | |||
589 | --- debian/update-notifier-common.install 2013-02-01 15:13:06 +0000 | |||
590 | +++ debian/update-notifier-common.install 2013-04-11 13:43:22 +0000 | |||
591 | @@ -12,3 +12,6 @@ | |||
592 | 12 | usr/lib/update-notifier/ | 12 | usr/lib/update-notifier/ |
593 | 13 | usr/share/locale | 13 | usr/share/locale |
594 | 14 | debian/update-manager-downloader-fix2.diff usr/share/update-notifier/upgrader-patches | 14 | debian/update-manager-downloader-fix2.diff usr/share/update-notifier/upgrader-patches |
595 | 15 | data/org.freedesktop.policykit.pkexec.package-data-downloader.policy usr/share/polkit-1/actions/ | ||
596 | 16 | data/kwalletdbuscli.py usr/lib/update-notifier | ||
597 | 17 |
thank you for your work, the current version of the merge request has conflicts (in data/package- data-downloader and debian/control), could you resolve those and resubmit it?