Modify

Opened 15 years ago

Closed 6 years ago

Last modified 6 years ago

#5856 closed defect (fixed)

Image() URLs fail due to lack of ATTACHMENT_VIEW permissions, crashes WikiToPDF

Reported by: bugs@… Owned by: Ryan J Ollos
Priority: highest Component: TracWikiToPdfPlugin
Severity: critical Keywords:
Cc: Trac Release: 0.11

Description

I think this one is more a Trac flaw, due to their addition of more granular image access.

But it does result in breaking this plugin. If you upload an image to the page and link using the short form recommended in the wiki formatting guide, the WikiToPDF plugin crashes.

A workaround is to explicitly specify wiki:PageName:MyImage.png?

Although this is a bit convoluted. I'm not sure what the solution is, just documenting it here for other users of the plugin.

Attachments (0)

Change History (7)

comment:1 Changed 14 years ago by anonymous

Priority: normalhighest
Severity: normalcritical

same Problem here.

WikiToPdf plugin tries to get the images as user anonymous. I do not want to give WIKI_VIEW/ATTACHMENT_VIEW to the anonymous user!

LegacyAttachmentPolicy denies anonymous performing ATTACHMENT_VIEW on <Resource u'wiki:Features, attachment:grad.png'>

Please fix this, or give us a workaround.

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

comment:2 Changed 14 years ago by anonymous

I still get the following error: (I think this is due to the 401 - unauthorized) can you point me towards a solution? is this due to missconfiguration, or a bug?

(i had to replace all occurences of "http" with "tthp" for beeing able to post this)

# File "build/bdist.linux-i686/egg/trac/web/main.py", line 513, in _dispatch_request
Local variables:
NameValue
dispatcher File<trac.web.main.RequestDispatcher object at 0xa6811cc>
e FileEOFError('EOF when reading a line',)
env File<trac.env.Environment object at 0xa1da6ac>
env_error FileNone
req File<Request "GET '/wiki/test_mediawiki'">
resp File[]
# File "build/bdist.linux-i686/egg/trac/web/main.py", line 235, in dispatch
Local variables:
NameValueValue
chosen_handler File<trac.wiki.web_ui.WikiModule object at 0xa68ed0c>
chrome File<trac.web.chrome.Chrome object at 0xa6813ec>
err File(<type 'exceptions.EOFError'>, EOFError('EOF when reading a line',), ...
handler File<trac.wiki.web_ui.WikiModule object at 0xa68ed0c>
req File<Request "GET '/wiki/test_mediawiki'">
self File<trac.web.main.RequestDispatcher object at 0xa6811cc>
# File "build/bdist.linux-i686/egg/trac/wiki/web_ui.py", line 172, in process_request
Local variables:
NameValueValue
action File'view'
format Fileu'pdf'
old_version FileNone
page File<trac.wiki.model.WikiPage object at 0xa6492ec>
pagename Fileu'test_mediawiki'
req File<Request "GET '/wiki/test_mediawiki'">
self File<trac.wiki.web_ui.WikiModule object at 0xa68ed0c>
version FileNone
versioned_page File<trac.wiki.model.WikiPage object at 0xa68102c>
# File "build/bdist.linux-i686/egg/trac/mimeview/api.py", line 982, in send_converted
Local variables:
NameValueValue
RequestDone File<class 'trac.web.api.RequestDone'>
content Fileu"{{{\r\n#!mediawiki\r\n\r\n__TOC__\r\n\r\n= 1 =\r\n== 1.1 ==\r\n== 1.2 ...
filename Fileu'test_mediawiki'
in_type File'text/x-trac-wiki'
req File<Request "GET '/wiki/test_mediawiki'">
selector Fileu'pdf'
self File<trac.mimeview.api.Mimeview object at 0xa67ee0c>
# File "build/bdist.linux-i686/egg/trac/mimeview/api.py", line 681, in convert_content
Local variables:
NameValueValue
c File('pdf', 'PDF', 'pdf', 'text/x-trac-wiki', 'application/pdf', 7, ...
candidates File[('pdf', 'PDF', 'pdf', 'text/x-trac-wiki', 'application/pdf', 7, ...
ck File'pdf'
content Fileu"{{{\r\n#!mediawiki\r\n\r\n__TOC__\r\n\r\n= 1 =\r\n== 1.1 ==\r\n== 1.2 ...
converter File<wikitopdf.wikitopdf.WikiToPdfPage object at 0xa6830cc>
ext File'pdf'
filename FileNone
full_mimetype File'text/x-trac-wiki'
input_mimettype File'text/x-trac-wiki'
key Fileu'pdf'
mimetype File'text/x-trac-wiki'
name File'PDF'
output_mimetype File'application/pdf'
quality File7
req File<Request "GET '/wiki/test_mediawiki'">
self File<trac.mimeview.api.Mimeview object at 0xa67ee0c>
url FileNone
# File "build/bdist.linux-x86_64/egg/wikitopdf/wikitopdf.py", line 224, in convert_content
Local variables:
NameValueValue
base_dir Fileu'/var/lib/trac/demo/htdocs'
codepage Fileu'iso-8859-15'
input_type File'text/x-trac-wiki'
output_type File'pdf'
req File<Request "GET '/wiki/test_mediawiki'">
self File<wikitopdf.wikitopdf.WikiToPdfPage object at 0xa6830cc>
text Fileu"{{{\r\n#!mediawiki\r\n\r\n__TOC__\r\n\r\n= 1 =\r\n== 1.1 ==\r\n== 1.2 ...
# File "build/bdist.linux-x86_64/egg/wikitopdf/wikitopdf.py", line 94, in wiki_to_pdf
Local variables:
NameValueValue
addrpos File1201
base_dir Fileu'/var/lib/trac/demo/htdocs'
codepage Fileu'iso-8859-15'
env File<trac.env.Environment object at 0xa1da6ac>
file File<closed file '<fdopen>', mode 'w' at 0xa7a08d8>
imgcounter File0
imgpos File1185
newimg Fileu'/var/lib/trac/demo/wikitopdf/167a_/0_r-Mq2S'
page Fileu'<table id="toc" class="toc" summary="Contents"><tr><td><div ...
r File<_sre.SRE_Pattern object at 0xa78cd40>
req File<Request "GET '/wiki/test_mediawiki'">
text Fileu"{{{\r\n#!mediawiki\r\n\r\n__TOC__\r\n\r\n= 1 =\r\n== 1.1 ==\r\n== 1.2 ...
theimg Fileu'tthp//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd ...
thepos File85
tmp_dir Fileu'/var/lib/trac/demo/wikitopdf/167a_'
tracuri Fileu'tthp//trac'
# File "/usr/lib/python2.5/urllib.py", line 89, in urlretrieve
Code fragment:
Line
84return opener.open(url, data)
85def urlretrieve(url, filename=None, reporthook=None, data=None):
86global _urlopener
87if not _urlopener:
8859_urlopener = FancyURLopener()
89return _urlopener.retrieve(url, filename, reporthook, data)
90def urlcleanup():
91if _urlopener:
92_urlopener.cleanup()
93 
94# exception raised when downloaded size does not match content-length
Local variables:
NameValueValue
data FileNone
filename Fileu'/var/lib/trac/demo/wikitopdf/167a_/0_r-Mq2S'
reporthook FileNone
url Fileu'tthp//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd ...
# File "/usr/lib/python2.5/urllib.py", line 222, in retrieve
Code fragment:
Line
217hdrs = fp.info()
218del fp
219return url2pathname(splithost(url1)[1]), hdrs
220except IOError, msg:
221pass
222fp = self.open(url, data)
223headers = fp.info()
224if filename:
225tfp = open(filename, 'wb')
226else:
227import tempfile
Local variables:
NameValueValue
data FileNone
filename Fileu'/var/lib/trac/demo/wikitopdf/167a_/0_r-Mq2S'
reporthook FileNone
self File<urllib.FancyURLopener instance at 0xa68120c>
type File'http'
url File'tthp//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd9 ...
url1 File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
# File "/usr/lib/python2.5/urllib.py", line 190, in open
Code fragment:
Line
185return self.open_unknown_proxy(proxy, fullurl, data)
186else:
187return self.open_unknown(fullurl, data)
188try:
189if data is None:
190return getattr(self, name)(url)
191else:
192return getattr(self, name)(url, data)
193except socket.error, msg:
194raise IOError, ('socket error', msg), sys.exc_info()[2]
195 
Local variables:
NameValueValue
data FileNone
fullurl File'tthp//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd9 ...
name File'open_http'
proxy FileNone
self File<urllib.FancyURLopener instance at 0xa68120c>
url File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
urltype File'http'
# File "/usr/lib/python2.5/urllib.py", line 338, in open_http
Code fragment:
Line
333fp = h.getfile()
334if errcode == 200:
335return addinfourl(fp, headers, "tthp" + url)
336else:
337if data is None:
338return self.http_error(url, fp, errcode, errmsg, headers)
339else:
340return self.http_error(url, fp, errcode, errmsg, headers, data)
341 
342def http_error(self, url, fp, errcode, errmsg, headers, data=None):
343"""Handle http errors.
Local variables:
NameValueValue
args File('User-Agent', 'Python-urllib/1.17')
auth FileNone
data FileNone
errcode File401
errmsg File'Authorization Required'
fp File<socket._fileobject object at 0xa7a59cc>
h File<httplib.HTTP instance at 0xa68a7ac>
headers File<httplib.HTTPMessage instance at 0xa68aaac>
host File'trac'
httplib File<module 'httplib' from '/usr/lib/python2.5/httplib.pyc'>
proxy_auth FileNone
proxy_passwd FileNone
realhost File'trac'
selector File'/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e1c.png ...
self File<urllib.FancyURLopener instance at 0xa68120c>
url File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
user_passwd FileNone
# File "/usr/lib/python2.5/urllib.py", line 351, in http_error
Code fragment:
Line
346# First check if there's a specific handler for this error
347name = 'http_error_%d' % errcode
348if hasattr(self, name):
349method = getattr(self, name)
350if data is None:
351result = method(url, fp, errcode, errmsg, headers)
352else:
353result = method(url, fp, errcode, errmsg, headers, data)
354if result: return result
355return self.http_error_default(url, fp, errcode, errmsg, headers)
356 
Local variables:
NameValueValue
data FileNone
errcode File401
errmsg File'Authorization Required'
fp File<socket._fileobject object at 0xa7a59cc>
headers File<httplib.HTTPMessage instance at 0xa68aaac>
method File<bound method FancyURLopener.http_error_401 of <urllib.FancyURLopener ...
name File'http_error_401'
self File<urllib.FancyURLopener instance at 0xa68120c>
url File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
# File "/usr/lib/python2.5/urllib.py", line 680, in http_error_401
Code fragment:
Line
675if scheme.lower() != 'basic':
676URLopener.http_error_default(self, url, fp,
677errcode, errmsg, headers)
678name = 'retry_' + self.type + '_basic_auth'
679if data is None:
680return getattr(self,name)(url, realm)
681else:
682return getattr(self,name)(url, realm, data)
683 
684def http_error_407(self, url, fp, errcode, errmsg, headers, data=None):
685"""Error 407 -- proxy authentication required.
Local variables:
NameValueValue
data FileNone
errcode File401
errmsg File'Authorization Required'
fp File<socket._fileobject object at 0xa7a59cc>
headers File<httplib.HTTPMessage instance at 0xa68aaac>
match File<_sre.SRE_Match object at 0xa7a09b0>
name File'retry_http_basic_auth'
re File<module 're' from '/usr/lib/python2.5/re.pyc'>
realm File'Trac Project'
scheme File'Basic'
self File<urllib.FancyURLopener instance at 0xa68120c>
stuff File'Basic realm="Trac Project"'
url File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
# File "/usr/lib/python2.5/urllib.py", line 744, in retry_http_basic_auth
Code fragment:
Line
739 
740def retry_http_basic_auth(self, url, realm, data=None):
741host, selector = splithost(url)
742i = host.find('@') + 1
743host = host[i:]
744user, passwd = self.get_user_passwd(host, realm, i)
745if not (user or passwd): return None
746host = quote(user, safe='') + ':' + quote(passwd, safe='') + '@' + host
747newurl = 'tthp//' + host + selector
748if data is None:
749return self.open(newurl)
Local variables:
NameValueValue
data FileNone
host File'trac'
i File0
realm File'Trac Project'
selector File'/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e1c.png ...
self File<urllib.FancyURLopener instance at 0xa68120c>
url File'//trac/projects/demo/login/tracmath/da1c76cfc5919c0aea6d9c58c65037cd94868e ...
# File "/usr/lib/python2.5/urllib.py", line 773, in get_user_passwd
Code fragment:
Line
768if key in self.auth_cache:
769if clear_cache:
770del self.auth_cache[key]
771else:
772return self.auth_cache[key]
773user, passwd = self.prompt_user_passwd(host, realm)
774if user or passwd: self.auth_cache[key] = (user, passwd)
775return user, passwd
776 
777def prompt_user_passwd(self, host, realm):
778"""Override this in a GUI environment!"""
Local variables:
NameValueValue
clear_cache File0
host File'trac'
key File'Trac Project@trac'
realm File'Trac Project'
self File<urllib.FancyURLopener instance at 0xa68120c>
# File "/usr/lib/python2.5/urllib.py", line 782, in prompt_user_passwd 

comment:3 Changed 6 years ago by Ryan J Ollos

Owner: Diorgenes Felipe Grzesiuk deleted

comment:4 Changed 6 years ago by Ryan J Ollos

Owner: set to Ryan J Ollos
Status: newaccepted

comment:5 Changed 6 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 17340:

TracWikiToPdfPlugin 3.0.0dev: Fix failure retrieving images

Retrieving images would fail when anonymous lacked
WIKI_VIEW.

Fixes #5856.

comment:6 Changed 6 years ago by Ryan J Ollos

In 17341:

TracWikiToPdfPlugin 3.0.0dev: Fix failure of r17340 with subpages

Refs #5856.

comment:7 Changed 6 years ago by Ryan J Ollos

This is more complicated than I initially thought. We'll probably needs to use urlretrieve for external images.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.