changeset 71:6318de36e334

pics2: limit access to index
author paulo
date Wed, 28 Oct 2015 00:57:23 -0700
parents 3456dd3e8660
children c7bbd3805509
files pics2/pics_app.py
diffstat 1 files changed, 25 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/pics2/pics_app.py	Wed Jul 29 00:20:39 2015 -0600
     1.2 +++ b/pics2/pics_app.py	Wed Oct 28 00:57:23 2015 -0700
     1.3 @@ -10,12 +10,23 @@
     1.4  
     1.5  import logging
     1.6  logging.basicConfig(
     1.7 -	level=logging.DEBUG,
     1.8 +	level=logging.INFO,
     1.9  	filename="_LOG",
    1.10  	format="%(asctime)s %(levelname)-8s %(message)s",
    1.11  )
    1.12  
    1.13  
    1.14 +def _lahat():
    1.15 +	ret = None
    1.16 +
    1.17 +	try:
    1.18 +		with open("_lahat") as lahat_f:
    1.19 +			ret = lahat_f.read().strip()
    1.20 +	except IOError:
    1.21 +		pass
    1.22 +
    1.23 +	return ret
    1.24 +
    1.25  
    1.26  def _is_pics_dir(dirpath):
    1.27  	return os.path.exists(os.path.join(dirpath, "_picsroot"))
    1.28 @@ -120,6 +131,7 @@
    1.29  	def __init__(self, environ):
    1.30  		self._environ = environ
    1.31  		self._page_func = None
    1.32 +		self._show_index = False
    1.33  	
    1.34  		#logging.debug("environ = %s" % (sorted(self._environ.items(), key=lambda x: x[0]),))
    1.35  		logging.debug("environ['PATH_INFO'] = %s" % self._environ["PATH_INFO"])
    1.36 @@ -133,12 +145,17 @@
    1.37  		if len(ppi) < 1 or ppi[0] != '':
    1.38  			raise AssertionError("Parsed path length must start empty: " + pi)
    1.39  	
    1.40 +		self._qs = urlparse.parse_qs(self._environ["QUERY_STRING"])
    1.41 +		logging.debug("self._qs = %s" % self._qs)
    1.42 +		if self._qs.get("lahat", [''])[0] == _lahat():
    1.43 +			self._show_index = True
    1.44 +
    1.45  		if len(ppi) >= 2 and _is_pics_dir(ppi[1]):
    1.46  			if len(ppi) == 2:
    1.47  				self._page_func = self.page_thumbs
    1.48  			elif len(ppi) >= 4 and ppi[2] == "browse" and os.path.exists(os.path.join(*ppi)):
    1.49  				self._page_func = self.page_browse
    1.50 -		elif len(ppi) == 1:
    1.51 +		elif len(ppi) == 1 and self._show_index:
    1.52  			self._page_func = self.page_index
    1.53  	
    1.54  		if self._page_func is None:
    1.55 @@ -183,10 +200,9 @@
    1.56  		d = os.path.join(*ppi)
    1.57  		(html_root, html_header, html_body) = self._get_standard_html_doc(d)
    1.58  
    1.59 -		qs = urlparse.parse_qs(self._environ["QUERY_STRING"])
    1.60  		from_img = None
    1.61 -		if "from" in qs:
    1.62 -			from_img = qs["from"][0]
    1.63 +		if "from" in self._qs:
    1.64 +			from_img = self._qs["from"][0]
    1.65  	
    1.66  		html_p = html_body.p
    1.67  		for (t, b) in _get_images(d):
    1.68 @@ -195,7 +211,10 @@
    1.69  			else:
    1.70  				self._go_thumbnail_links_to_browse_imgs_html_body(html_p, t, b)
    1.71  	
    1.72 -		html_body.a("(Other pictures)", href=self._get_app_url(''))
    1.73 +		# TODO: fix me
    1.74 +		#if self._show_index:
    1.75 +		#	html_body.a("(Other pictures)", href=self._get_app_url(''))
    1.76 +
    1.77  		return html_root
    1.78  	
    1.79