Home Articles Add Manager to Zope on Windows
Document Actions

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 way

Posted by Anonymous User Anonymous User at 2007-06-21 14:36

There is always the easiest way - google :) try: http://plope.com/Books/2_7Edition/Security.stx#3-31


Easier but not exactly

Posted by lukasz at 2007-06-21 14:42
Not exactly. First of all Emergency user cannot do anything except adding a Manager. Secondly, using zpasswd.py script you are creating files 'inituser' or 'access'. They are then imported to Zope during start up. But the problem is that 'inituser' is not imported when there is more than 1 user in acl_users. Using above script you can add as many Managers as you want :)

subtransactions

Posted by yurj at 2008-01-07 09:51
subtransactions are deprecated; instead of transaction.commit(1), use
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

Posted by nghiavt at 2008-07-23 09:11
Could you tell me how to add one user manager into zope site cause i have just taken over a zope system but i don't have any account to manage it.

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

Posted by Lukasz Lakomy at 2008-07-23 09:23
This article describes how to add one in Windows. So I assume you have Unix/Linux machine. What you have to do is:
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

Sponsor me

I'll run London Marathon on 26th of April 2009. Please help me with fundraising for Sense - charity for deafblind people. Justgiving - SPONSOR ME

Tags