Hi Ruben,
I had the same problem. Here is how I solved it...
1) I learned that the easiest way to grant admin access intially is to
give the anonymous user TRAC_ADMIN. So execute this command - trac-
admin /path/to/env permission add anonymous TRAC_ADMIN. Then you can
create new users and permissions using the graphical environment
(cklick Admin > Permissions)
2) the trac-digest.py file when downloaded has an indentation issue.
Here is the correct code...
from optparse import OptionParser
# The md5 module is deprecated in Python 2.5
try:
from hashlib import md5
except ImportError:
from md5 import md5
realm = 'trac'
# build the options
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-u", "--username",action="store", dest="username",
type = "string",
help="the username for whom to generate a password")
parser.add_option("-p", "--password",action="store", dest="password",
type = "string",
help="the password to use")
parser.add_option("-r", "--realm",action="store", dest="realm", type =
"string",
help="the realm in which to create the digest")
(options, args) = parser.parse_args()
# check options
if (options.username is None) or (options.password is None):
parser.error("You must supply both the username and password")
if (options.realm is not None):
realm = options.realm
# Generate the string to enter into the htdigest file
kd = lambda x: md5(':'.join(x)).hexdigest()
print ':'.join((options.username, realm, kd([options.username, realm,
options.password])))
3) before I discovered the indentation issue in trac-digest.py, I re-
wrote it so it worked like a combination of trac-digest & htdigest,
and would create and update the digest file. This one will produce a
file called trac.digest (the digest file). Command line is similar to
trac-digest.py except this one (TracDigest.py) will create it's own
digest file - trac.digest.
#TracDigest.py
"""
Simple python script to generate hashed passwords and a trac.digest
file for
trac and agilo.
Usage:
------
python trac-digest.py [-c] [-a] [-d] -u username -p password -f path -
r realm
required values:
username = the username to add to the file
password = the password to hash and add to the file
path = path to the user digest file (trac project folder;
file=trac.digest)
realm = the trac project the username/password is valid for
options:
a - append or update username/password to file (the default)
d - delete username/password from file
Note - username, password and path are required. Errors and usage
instructions dislay on the console.
The digest file is to be placed in the trac environment (project)
folder. There
can be one per project (leave realm blank and use the default) or one
per
trac environment (set the realm value). Also, if the username &
password
combination is the first in the file (new project), the file is
created.
Otherwise, the username/password is appended to the file (use -a).
Note - reference - http://trac.edgewall.org/wiki/TracStandalone
Outputs:
--------
The trac.digest file.
Each line in the file has this structure:
username:realm:hashed_password
bryan:trac:0896df5081b0c5824eefe39111a8dc35
Using the trac.digest file with tracd:
tracd --port 8000 --auth=proj_name,/path/trac.digest,realm /
path_to_proj
Functions:
main - main program
pwhash - returns hashed password
load - loads file into memory or creates one
update - updates or appends user to file
save - saves file
delete - deletes user from file
Test Cases:
1) command line with no options - test error handler
2) command line with -h - test parser help
3) command line no username or password - test parser error handler
4) command line no path or realm - test default values
5) command line a & d together - last one should win
6) command line a with invalid path - should create new one or exit
7) command line a with valid file (same file)
8) command line d with valid file (same file)
9) command line with valid realm and path
"""
__author__="bryan mckay"
__date__ ="$May 3, 2009 8:53:17 PM$"
__version__="1.0.0"
# Revision History
# Version 1.0.0 May 3, 2009 - Intial Release
# import required modules
from optparse import OptionParser #Powerful command-line parsing
library.
import os #Miscellaneous operating system interfaces.
import sys #Access system-specific parameters and functions.
# The md5 module is deprecated in Python 2.5, use hashlib
try:
from hashlib import md5
#sys.stderr.write("Debug: using hashlib module")
except ImportError:
try:
from md5 import md5
#sys.stderr.write("Debug: using md5 module")
except ImportError:
#sys.stderr.write("Aborting... Cannot find a hashlib or md5
module")
sys.exit("Aborting... Cannot find a hashlib or md5 module")
def main():
"""Create or update a trac.digest file
usage: python %prog [-a] [-c] [-d] -u username -p password -f path
-r realm
"""
# build the options
usage='%prog [-a] [-d] -u username -p password [-f path] [-r
realm]'
parser = OptionParser(usage=usage)
parser.add_option('-a', action='store_true', dest='append',
default=True,
help='Append or update username/password
[default]')
parser.add_option('-d', action='store_false', dest='append',
help='Remove the user from the digest file')
parser.add_option('-u', action='store', dest='username', type =
'string',
help='the username to add to the digest')
parser.add_option('-p', action='store', dest='password', type =
'string',
help='the password to be hashed and added to the
digest')
parser.add_option('-f', action='store', dest='path', type =
'string', default='./',
help='the path to the digest file
(file=trac.digest) [default=%default]')
parser.add_option('-r', action='store', dest='realm', type =
'string', default='trac',
help='the trac project for the username/password
[default=%default]')
(options, args) = parser.parse_args()
# Check options and agruments
if (options.username is None) or (options.password is None):
parser.error("You must supply both the username and password")
digest_entries = []
if options.append:
# Load file into memory and update or append user to file
digest_entries = load(options.path,options.append)
digest_entries = update(digest_entries,options.username,
options.realm, options.password)
save(options.path, digest_entries)
else:
# Load file into memory and delete user from file
digest_entries = load(options.path,options.append)
digest_entries = delete
(digest_entries,options.username,options.realm)
save(options.path, digest_entries)
def load(path,append):
"""Loads trac.digest file into memory"""
if (path == './'):
filename = path + 'trac.digest'
else:
filename = path + '/trac.digest'
if os.path.exists(filename):
lines = open(filename, 'r').readlines()
entries = []
for line in lines:
username, realm, password = line.split(':')
entry = [username, realm, password.rstrip()]
entries.append(entry)
return entries
else:
if append:
entries = []
return entries
else:
sys.exit("Aborting... %s does not exist" % filename)
def update(entries, username, realm, password):
"""Updates or appends user to trac.digest file in memory"""
matching_entries = [entry for entry in entries if entry[0] ==
username
and entry[1] == realm]
if matching_entries:
matching_entries[0][2] = pwhash(username,realm,password)
return entries
else:
entries.append([username, realm, pwhash
(username,realm,password)])
return entries
def save(path, entries):
"""Saves the trac.digest entries in memory to disk"""
if (path == './'):
filename = path + 'trac.digest'
else:
filename = path + '/trac.digest'
open(filename, 'w').writelines(["%s:%s:%s\n" % (entry[0], entry
[1], entry[2])
for entry in entries])
def delete(entries,username,realm):
"""Deletes the user from the trac.digest file"""
for entry in entries:
if (entry[0] == username and entry[1] == realm):
entries.remove(entry)
return entries
def pwhash(username, realm, password):
"""Generates the hash string to add to the trac.digest file"""
kd = lambda x: md5(':'.join(x)).hexdigest()
return kd([username, realm, password])
if __name__ == '__main__':
main()
References...
http://trac.edgewall.org/wiki/TracAdmin
http://trac.edgewall.org/wiki/TracPermissions
http://trac.edgewall.org/wiki/TracStandalone
On Jun 11, 7:24 am, Rubén <[email protected]> wrote:
> Hi, in Windows I am trying to create my Admin account. However I get
> the website but I cannot log in. I see my users.digest and this is
> empty.
>
> I have executed this line but the users.digest is still an empty
> file.
>
> C:\web>python c:\Python25\Scripts\trac-digest.py -u admin -p admin >>
> users.digest
>
> Do you know what it is going wrong?
>
> Regards
> Rubén
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Agilo for Scrum" group. This group is moderated by agile42 GmbH
http://www.agile42.com and is focused in supporting Agilo for Scrum users.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/agilo?hl=en
-~----------~----~----~----~------~----~------~--~---