ó
@ü½cc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l Td d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z e j Z e j e j f Z d „  Z d d „ Z d d „ Z d S(   sC   Script which implements admin editing of the list's html templates.iÿÿÿÿN(   t   Utils(   t   MailList(   t   *(   t   HTMLFormatter(   t   Errors(   t   Auth(   t   syslog(   t   i18n(   t
   csrf_checkc          C   sj  d „  }  d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d	 ƒ f d
 |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d |  d ƒ f d  |  d! ƒ f d" |  d# ƒ f f } t  j }  t ƒ  } t  j t j ƒ | j t j ƒ t j ƒ  } | s}| j t	 d$ |  d% ƒ ƒ ƒ | j
 ƒ  GHd  S| d& j ƒ  } y t j | d' d& ƒ} Wne t j k
 r} t j | ƒ } | j t	 d$ |  d( ƒ ƒ ƒ d) GH| j
 ƒ  GHt d* d+ | | ƒ d  SXt  j | j ƒ | j | j ƒ t j ƒ  } y | j d, d- ƒ WnW t k
 r§| j t	 d$ |  d. ƒ ƒ ƒ | j t |  d/ ƒ ƒ ƒ d0 GH| j
 ƒ  GHd  SXd1 d, d2 g }	 | j ƒ  }
 t |
 ƒ t |	 ƒ r÷t | | j d3 ƒ d4 ƒ } n t } | j d, ƒ r"d- t j d5 <t } n  | j t j t j f | j d, d- ƒ ƒ så| j  d2 ƒ rÅt t! d6 |  d7 ƒ ƒ ƒ j
 ƒ  } t j j" d8 t j j" d9 t j j" d: d; ƒ ƒ ƒ } t d< d= | | ƒ n d- } t# j$ | d4 d> | ƒd  S| j d? d- ƒ } | | j% ƒ  k r| j } n  t  j | ƒ | j | ƒ | j& } t' | ƒ d@ k rý| d@ } x|| D]; \ } } | | k r[|  | ƒ } | j( |  dA ƒ ƒ Pq[q[Wt j | ƒ } | j( |  dB ƒ ƒ | j t	 d$ |  dC ƒ ƒ ƒ | j | j) ƒ  ƒ | j
 ƒ  GHd  SnÖ | j( |  dD ƒ ƒ | j t	 d@ |  dD ƒ ƒ ƒ | j t	 d$ |  dE ƒ ƒ ƒ t* ƒ  } xG | D]? \ } } t+ | j, dF ƒ dG | |  | ƒ ƒ } | j | ƒ qXW| j t! dH | ƒ ƒ | j | j) ƒ  ƒ | j
 ƒ  GHd  Szq | j ƒ  r*| j  dI ƒ r*| rt- | | | | dJ | ƒq*| j. |  dK ƒ ƒ n  t/ | | | | dJ | ƒWd  | j | j) ƒ  ƒ | j
 ƒ  GHXd  S(L   Nc         S   s   |  S(   N(    (   t   s(    (    s3   /export/web/mailman/mailman/Mailman/Cgi/edithtml.pyt   _,   s    s   listinfo.htmls   General list information pages   subscribe.htmls   Subscribe results pages   options.htmls   User specific options pages   subscribeack.txts   Welcome email text files   masthead.txts   Digest mastheads   postheld.txts   User notice of held posts   approve.txts    User notice of held subscriptions
   refuse.txts#   Notice of post refused by moderators
   invite.txts   Invitation to join lists
   verify.txts   Request to confirm subscriptions	   unsub.txts!   Request to confirm unsubscriptions   nomoretoday.txts!   User notice of autoresponse limits   postack.txts   User post acknowledgements   disabled.txts'   Subscription disabled by bounce warnings   admlogin.htmls   Admin/moderator login pages   private.htmls   Private archive login pages   userpass.txts   On demand password reminderi   s   List name is required.i    t   locks&   No such list <em>%(safelistname)s</em>s   Status: 404 Not Foundt   errors   edithtml: No such list "%s": %st   adminpwt    t   Errors   Invalid options to CGI script.s   Status: 400 Bad Requestt   VARHELPt   admlogint
   csrf_tokent   admint   HTTP_COOKIEs   +1s   Authorization failed.t   HTTP_FORWARDED_FORt   HTTP_X_FORWARDED_FORt   REMOTE_ADDRs   unidentified origint   securitys3   Authorization failed (edithtml): list=%s: remote=%st   msgt   languagei   s/   %(realname)s -- Edit html for %(template_info)ss   Edit HTML : Errors&   %(safetemplatename)s: Invalid templates!   %(realname)s -- HTML Page Editings   Select page to edit:t   edithtmlt   /s   +2t   langformt   langs6   The form lifetime has expired. (request forgery check)(0   R   R
   t   Documentt   set_languaget   mm_cfgt   DEFAULT_SERVER_LANGUAGER    t   GetPathPiecest   AddItemt   Headert   Formatt   lowerR   R   t   MMListErrort   websafeR   t   preferred_languaget   cgit   FieldStoraget   getfirstt	   TypeErrort   Boldt   keyst   setR   t   Truet   ost   environt   WebAuthenticatet   AuthListAdmint   AuthSiteAdmint   has_keyt   FontSizet   getR   t	   loginpaget   GetAvailableLanguagest	   real_namet   lent   SetTitlet   GetMailmanFootert   UnorderedListt   Linkt   GetScriptURLt
   ChangeHTMLt   addErrort
   FormatHTML(   R
   t   template_datat   doct   partst   listnamet   mlistt   et   safelistnamet   cgidatat   safe_paramst   paramst   csrf_checkedR   t   remoteR   t   realnamet   template_namet   templatet   infot   template_infot   safetemplatenamet   template_listt   l(    (    s3   /export/web/mailman/mailman/Mailman/Cgi/edithtml.pyt   main)   sà    					!	
	
	&c         C   s€  | |  j  ƒ  k r |  j } n  t j | ƒ } | j t d d |  j ƒ ƒ | j t d | ƒ ƒ | j d ƒ t |  j d ƒ t	 d ƒ ƒ } t |  j d ƒ t	 d ƒ ƒ } | j t
 d | ƒ ƒ | j d	 ƒ | j t
 d | ƒ ƒ | j d
 ƒ | j d ƒ t |  j  ƒ  ƒ d k r¨t |  j d ƒ d | d |  d t ƒ} | j |  j d d t	 d ƒ ƒƒ | j |  j | ƒ ƒ | j t d d ƒ ƒ | j | ƒ | j d ƒ n  t |  j d ƒ d | d |  d t ƒ}	 t j | d d d | d |  ƒ}
 |	 j t d |
 d d d d ƒƒ |	 j d
 t	 d ƒ ƒ | |  j k rS|	 j t d | ƒ ƒ n  |	 j t d t	 d ƒ ƒ ƒ | j |	 ƒ d  S(   Ni   s   %s:s   <hr>R   s0   View or edit the list configuration information.R   s)   Edit the public HTML pages and text filess   +1s   <br>s   <p>R   RK   t   contextss   editlang-buttont   texts   Edit this template forR   R2   t   rawR   t	   html_codet   rowsi(   t   colsiK   s#   When you are done making changes...R   t   submits   Submit Changes(   R<   R*   R    t
   GetCharSetR$   R%   R=   RB   RC   R
   R9   R>   t   Formt   AUTH_CONTEXTSt   FormatButtont   GetLangSelectBoxt   Hiddent   maketextt   TextAreat   SubmitButton(   RK   RH   RT   RW   R   t   lcsett   linkt   backlinkR   t   formR]   (    (    s3   /export/web/mailman/mailman/Mailman/Cgi/edithtml.pyRF   Á   sD    !"c   
      C   sõ  | |  j  ƒ  k r |  j } n  | j d ƒ sv | j t d t d ƒ ƒ ƒ | j t d t d ƒ ƒ ƒ | j d ƒ d  S| d j } t j | ƒ r
| j t d t d ƒ ƒ ƒ | j t d ƒ ƒ | j t	 d t d	 ƒ ƒ ƒ | j t d t d
 ƒ ƒ ƒ | j d ƒ d  St
 j j |  j ƒ  | ƒ } t
 j d ƒ } zF y t
 j | d ƒ Wn+ t k
 rx} | j t j k ry‚  qyn XWd  t
 j | ƒ Xt t
 j j | | ƒ d ƒ }	 z |	 j | ƒ Wd  |	 j ƒ  X| j t d t d ƒ ƒ ƒ | j d ƒ d  S(   NR_   i   s   Can't have empty html page.s   HTML Unchanged.s   <hr>s
  The page you saved contains suspicious HTML that could
potentially expose your users to cross-site scripting attacks.  This change
has therefore been rejected.  If you still want to make these changes, you
must have shell access to your Mailman server.
             s   See s   http://wiki.list.org/x/jYA9s	   FAQ 4.48.s   Page Unchanged.i    iý  t   ws   HTML successfully updated.(   R<   R*   R8   R$   R%   R
   t   valueR    t   suspiciousHTMLRB   R3   t   patht   joint   fullpatht   umaskt   mkdirt   OSErrort   errnot   EEXISTt   opent   writet   close(
   RK   t   cgi_infoRT   RH   R   t   codet   langdirt   omaskRL   t   fp(    (    s3   /export/web/mailman/mailman/Mailman/Cgi/edithtml.pyRD   ê   sD    	 (   t   __doc__R3   R+   Ry   t   ret   MailmanR    R   t   Mailman.htmlformatt   Mailman.HTMLFormatterR   R   t   Mailman.CgiR   t   Mailman.Logging.SyslogR   R   t   Mailman.CSRFcheckR   R
   R!   R6   R7   Re   R[   t   NoneRF   RD   (    (    (    s3   /export/web/mailman/mailman/Mailman/Cgi/edithtml.pyt   <module>   s$   
		˜)