mò
1Ú2Cc           @   s  d  Z  d k Z d k Z e i i d d ƒ e i i d d ƒ e i i d d ƒ d Z d k Td k l Z l	 Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d a a a a d a a a h  a h  a h  a h  a d „  Z e d j o e ƒ  n d S(   sË  
MoinMoin - check / process user accounts tool
GPL code written by Thomas Waldmann, 20031005

Why is this needed?
===================
When using ACLs, a wiki user name has to be unique, there must not be
multiple accounts having the same username. The problem is, that this
was possible before the introduction of ACLs and many users, who forgot
their ID, simply created a new ID using the same user name.

Because access rights (when using ACLs) depend on the NAME (not the ID),
this must be cleaned up before using ACLs or users will have difficulties
changing settings and saving their account data (system won't accept the
save, if the user name and email is not unique).

How to use this tool?
=====================

0. Check the settings at top of the code!
   Making a backup of your wiki might be also a great idea.
   
1. Best is to first look at duplicate user names:
    --usersunique

   If everything looks OK there, you may save that to disk:
    --usersunique --save

2. Now, check also for duplicate email addresses:
    --emailsunique

   If everything looks OK, you may save that to disk:
    --emailsunique --save

3. If the announced action is incorrect, you may choose to better manually
disable some accounts:
    --disableuser 1234567.8.90 --save

4. After cleaning up, do 1. and 2. again. There should be no output now, if
   everything is OK.
   
5. Optionally you may want to make wikinames out of the user names
    --wikinames
    --wikinames --save
    
Ni    s"   /home/twaldmann/moincvs/moin--mains   /org/org.linuxwiki/cgi-bins	   /org/wikit   DieserAccountIstRichtig(   t   *(   s   configs   wikiutilc          C   së   xä t  t ƒ D]Ö }  t d  |  ƒ } | t |  <t i | i	 ƒ o t | i	 i
 |  ƒ n |  g t | i	 <| i o? t i | i ƒ o t | i i
 |  ƒ q° |  g t | i <n | i p t i d | i ƒ o | i	 t |  <q q Wd  S(   Ns	   .*@.*\..*(   t   getUserListt   requestt   uidt   Usert   Nonet   ut   userst   namest   has_keyt   namet   appendt   emailt   emailst   ret   matcht   uids_noemail(   R   R   (    (    t[   /p/gems/public/moin/lib/python2.4/site-packages/MoinMoin/scripts/accounts/moin_usercheck.pyt   collect_dataM   s     

"c         C   s    t  |  } | i i t ƒ d j S(   Ni    (   R   R   R   t   subscribed_pagest   findt	   magicpage(   R   R   (    (    R   t   hasmagicpagec   s    
c         C   sÄ   t  |  } d |  | i | i f Gt |  ƒ } | o d GH| i ƒ  nz | i po d | _ d | i |  f | _ | i o d | i |  f | _ n d | _	 t o | i ƒ  d GHqÀ d GHn d  S(   Ns    %-20s %-25s %-35ss   - keeping (magicpage)!i   s   %s-%st    s   - disabled.s   - would be disabled.(
   R   R   R   R   R   R   t   keepthist   savet   disabledR   (   R   R   R   (    (    R   t   disableUserg   s     

	
	
	c         C   st   t  | i ƒ } t o | SnS y2 t  t i i t i i t	 i
 |  d ƒ ƒ ƒ } Wn t j
 o | } n X| Sd  S(   Ns   .trail(   t   floatt   usert
   last_savedt   t_lst	   lastsavedt   ost   patht   getmtimet   joint   configt   user_dirR   t   t_lut   OSError(   R   R   R    R(   (    (    R   t   getsortvaluez   s    2c         C   s·   g  } x4 |  D], } t | } | i t | | ƒ | f ƒ q W| i ƒ  x" | d  D] \ } } t	 | ƒ qR W| d d } t | } d | | i
 | i t | ƒ o d p d f GHd  S(   Niÿÿÿÿi   s    %-20s %-25s %-35s - keeping%s!s    (magicpage)R   (   t   sortlistt   uidlistR   R   R   R   R*   t   sortt   tR   R   R   R   (   R,   R+   R   R.   R   (    (    R   t   process…   s     
 
 
c          C   sD   x= t  i ƒ  D]/ }  t t  |  ƒ d j o t t  |  ƒ q q Wd  S(   Ni   (   R	   t   keysR   t   lenR/   (   R   (    (    R   t   make_users_unique”   s     c          C   sD   x= t  i ƒ  D]/ }  t t  |  ƒ d j o t t  |  ƒ q q Wd  S(   Ni   (   R   R0   R   R1   R/   (   R   (    (    R   t   make_emails_unique™   s     c          C   sÙ   d  k  } xÉ t i ƒ  D]» } t | } | i o q n t i | i ƒ p‡ | i	 | i ƒ i
 d d ƒ i
 d d ƒ }  t i |  ƒ p d | | i f GHqÑ d | | i |  f GHt o |  | _ | i ƒ  qÑ q q Wd  S(   Nt    R   t   -s%    %-20s %-25s - no WikiName, giving ups     %-20s %-25s - no WikiName -> %s(   t   stringR   R0   R   R   R   t   wikiutilt   isStrictWikinameR   t   capwordst   replacet   newnameR   (   R;   R   R   R6   (    (    R   t   make_WikiNamesŸ   s    	 

 *	c          C   sL   xE t  i ƒ  D]7 } t  | }  t o  d | |  i f GH|  i ƒ  q q Wd  S(   Ns    %-20s %-25s - saving(   R   R0   R   R   R   R   (   R   R   (    (    R   t   do_removepasswords®   s     
c           C   se  d t  i j o
 d a n d t  i j o
 d a n d t  i j o
 d a n d t  i j o
 d a n d t  i j o
 d a n d t  i j o
 d a n d t  i j o
 d a n t o8 t o0 t o( t o  t o d	 t  i d
 GHd  Sn t	 ƒ  t o t
 ƒ  n t o t ƒ  n t o t t  i d ƒ n t o t ƒ  n t o t ƒ  n d  S(   Ns   --usersuniquei   s   --emailsuniques   --lastsaveds   --wikinamess   --removepasswordss   --saves   --disableusersd  %s
    Options:
        --usersunique       makes user names unique (by appending the ID to
                            name and email, disabling subscribed pages and
                            disabling all, but the latest saved user account)
                            default is to SHOW what will be happening, you
                            need to give the --save option to really do it.

        --emailsunique      makes user emails unique
                            default is to show, use --save to save it.

        --lastsaved         normally the account most recently USED will
                            survive and the others will be disabled.
                            using --lastsaved, the account most recently
                            SAVED will survive.

        --disableuser uid   disable the user with user id uid
                            this can't be combined with the options above!
                            
        --wikinames         try to make "WikiNames" out of "user names"
        --removepasswords   remove pre-1.1 cleartext passwords from accounts
        
        --save              if specified as LAST option, will allow the other
                            options to save user accounts back to disk.
                            if not specified, no settings will be permanently
                            changed.

    i    i   (   t   syst   argvt   usersuniquet   emailsuniqueR!   t	   wikinamest   removepasswordsR   t   disableuserR   R2   R3   R   R<   R=   (    (    (    R   t   runÄ   s<       
 
 
 
 
 
 
(     t   __main__(    t   __doc__R>   R   R#   t   insertR   t   MoinMoin.usert   MoinMoinR&   R7   R   R   R   R*   R/   R2   R3   R<   R=   R@   RA   R!   R   RD   RB   RC   R   R	   R   R   RE   t   __name__(   R/   R   R*   R<   R   R   R3   R   R&   RE   R>   R   R2   R7   R=   (    (    R   t   ?0   s2   										4