Add Manager to Zope on Windows
This article shows how to add another Zope Manager to top acl_users folder. Under Linux you can use zopectl but this desn't work on Windows.
About
Some time ago it was possible to add Manager to Zope instance using inituser file. I'm not sure when or why this functionality was abandoned. But currently it is possible only using zopectl adduser command. There is a little problem on Windows. This script doesn't work on this system. I've looked inside code of Zope2/Startup/zopectl.py and it is really focused on Linux. So I had to find my own solution.
Instruction
Copy those 2 files described below to your /bin directory and run:
add_user.bat <username> <password>If user does not exist it will be added. Otherwise you will see message or error. It was tested on Zope 2.9
Shell script add_user.bat
First part is a shell script - .bat file. It sets some variables (copied from runzope.bat). But variables defined in runzope.bat were not enough. I was getting errors until I've defined ZOPE_CONFIG. This environment variable is used during startup to find config file.
@set PYTHON=C:\Program Files\Zope-2.9.6\Python\python.exe
@set INSTANCE_HOME=<YOUR INSTANCE>
@set SOFTWARE_HOME=C:\Program Files\Zope-2.9.6\Zope\lib\python
@set CONFIG_FILE=%INSTANCE_HOME%\etc\zope.conf
@set ZOPE_CONFIG=%CONFIG_FILE%
@set PYTHONPATH=%INSTANCE_HOME%\lib\python;%SOFTWARE_HOME%;%PYTHONPATH%
"%PYTHON%" add_user.py %1 %2
Python script add_user.py
And here is Python script that adds user. The most important fragment is copied from method do_adduser inside Zope2/Startup/zopectl.py. Then I've added few details like reading data from command line parameters, checking if user exists, nice messages.
import sys
if len(sys.argv)<3:
print "Bad syntax: add_user.py <username> <password>"
else:
LOGIN=sys.argv[1]
PASSWORD=sys.argv[2]
#Remove all arguments otherwise Zope.app() raise error
del sys.argv[2]
del sys.argv[1]
import Zope2
app = Zope2.app()
try:
acl_users = app.acl_users
if not acl_users.getUser(LOGIN):
acl_users._doAddUser(LOGIN,PASSWORD, ['Manager'], [])
import transaction
transaction.commit()
print "User '%s' added"%LOGIN
else:
print "User '%s' already exists, not added"%LOGIN
except:
print "User '%s' NOT added"%LOGIN
print "ERROR: %s-%s "%(sys.exc_info()[0],sys.exc_info()[1])
Easier but not exactly
subtransactions
transaction.savepoint(optimistic=True) in contexts where a subtransaction
abort will never occur, or sp=transaction.savepoint() if later rollback is
possible and then sp.rollback() instead of transaction.abort(1)
from:
http://archives.free.net.ph/message/20051103.152239.f4c5dcfc.en.html
just one to add one user with manager role
i just add some code into: ..\lib\python\Zope\App\startup.py
acl_users = app.acl_users
acl_users._doAddUser('nghia','password', ['Manager'], [])
but it's seem not working
Could you show me how to...
Thanks in advance
How to add manager
1. Log in to that machine
2. Find an "instance" folder. Something like '/var/lib/zope'. Inisde you'll find folders: bin, etc, Products, Extensions, log ect.
3. Go to bin: 'cd bin'
4. Stop instance: './zopectl stop'
5. Add manager: './zopectl adduser <username> <passwword>'
6. Start instance: './zopectl start'
If it doesn't work please dont hesitate to contact me:
http://www.llakomy.com/AboutMe/contact
New articles
Top downloads
| My CV | 1158 |
| FlashVideo-0.8.2.tar.gz | 785 |
| ZPTDebugger-1.1.2.tar.gz | 736 |
| ZProtx-1.0.tar.gz | 391 |
| TextIndexNG2-win-py2.4.zip | 19 |
There is always the easiest way - google :) try: http://plope.com/Books/2_7Edition/Security.stx#3-31