The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

user-simple-admin - Example script to administer a User::Simple database

SYNOPSIS

What you always have to specify: - How to get to the information: a DSN (--dsn), the table name (--tbl), and probably the database user (--dbuser) and password (--dbpass) - An action to perform: --new_user, --mod_user, --remove_user - The attributes needed for your query (--login, --name, --level, --password) - Optionally, to get a listing of the users in the database, use --dump_users

Table creation: user-simple-admin --dsn 'dbi:Pg:dbname=database;host=some.host.org' --table user_simple --dbuser useradmin --dbpass s3kr3t --create_plain user-simple-admin --dsn 'dbi:Pg:dbname=database;host=some.host.org' --table user_simple --dbuser useradmin --dbpass s3kr3t --create_rdbms

User creation example: user-simple-admin --dsn 'dbi:Pg:dbname=database;host=some.host.org' --table user_simple --dbuser useradmin --dbpass s3kr3t --new_user --login joe --name 'Joe Schmoe' --passwd mys3kr17 --level 5

User remotion: user-simple-admin --dsn 'dbi:Pg:dbname=database;host=some.host.org' --table user_simple--dbuser useradmin --dbpass s3kr3t --remove_user --login john

User modification: user-simple-admin --dsn 'dbi:Pg:dbname=database;host=some.host.org' --table user_simple --dbuser useradmin --dbpass s3kr3t --new_user --login joe --name 'Joe A. Schmoe' --passwd dont_forget_it --level 2

DESCRIPTION

This script gives you access from the command line to the main User::Simple::Admin functionality. Please note that it has been written more as an example than as a script you will use in your day to day administration - But if it suits you, well... :)

The script is made to be run non-interactively, taking all of its input via the command line (using the standard Getopts::Long syntax), and signalling either success or failure as the exit code (as always, 0 means success, and any other thing means failure).

About the Getopts::Long syntax, in a nutshell: You can specify the options to the script in any order, as long as you keep the switches next to their values (that is, --tbl tablename --dump_users is the same as --dump_users --tbl tablename, but it is not the same as --tbl --dump_users tablename. You can use the shortest possible not ambiguous string for each of the switches (i.e. --remove_user is equivalent to --r).

First of all, you have to get the script to get to the users' data - In order to do so, you have to specify a DSN (a DBI Data Source Name - A bit obscure, yes, I should replace it to something more intuitive as soon as I have some time to do so) and the name of the table where the information is located. This should be done with the --dsn and --tbl options. Probably you will also specify a database user name and password - do so using the --dbuser and --dbpass options.

Table creation

If you specify --create_plain or --create_rdbms, the User::Admin::Simple object will be instantiated by creating (instead of just accessing) the specified table. Beware, as attempting to create an already existing table will not work!

--create_rdbms should be used whenever possible (this is, whenever you are using a real RDBMS behind User::Simple, in contraposition to a simple file-based structure such as DBD::XBase, DBD::CSV or similar ones). If you are using a file-based structure, use --create_plain instead. For further details, refer to the User::Simple::Admin manual.

User creation

To create a new user, specify --new_user and give the desired user information - The only required option is --login, as it is the unique descriptor for this user - The other available switches are --name, --passwd and --level. Again, refer to User::Simple::Admin for further details.

If you do not specify a password upon user creation, the account will be created but access to it will be disabled until a password is set.

User remotion

Use --remove_user. You have to specify the --login you will be removing - Don't specify any other data; the script will refuse to work if you specify any of the other data options.

User modification

Use --mod_user. You need to specify the --login you are referring to. You cannot change a user's login, it is an immutable field. You can specify one or more of the --name, --passwd and --level data options.

Querying

If you specify --dump_users, a user listing will be returned to you. Please note that you can ask for --dump_users when performing other opertions (i.e. creation, remotion) - It will be run as the last operation, however, if the operation fails, the users list will not be dumped.

Other switches

--quiet supresses all output (including errors produced by this script, the errors generated by User::Simple::Admin, DBI or whatever else will still be sent) - Only the users dump will be printed.

--verbose will give status debug information you will very seldom require.

Examples

Create a table in a remote PostgreSQL database and insert a user in it:

    user-simple-admin --dsn 'dbi:Pg:dbname=userdb;host=dbserver' --dbuser dbadmin --dbpass dbs3kr37 --tbl test --create_rdbms --new_user --login someone --name 'A random user' 

Change that user's password in order to enable the account

    user-simple-admin --dsn 'dbi:Pg:dbname=userdb;host=dbserver' --dbuser dbadmin --dbpass dbs3kr37 --tbl test --mod_user --login someone --passwd thepassword

Remove that user

    user-simple-admin --dsn 'dbi:Pg:dbname=userdb;host=dbserver' --dbuser dbadmin --dbpass dbs3kr37 --tbl test --remove_user --login someone 

Get the users listing in a DBD::XBase database

    user-simple-admin --dsn 'dbi:XBase:/home/user/databases/users' --tbl user_simple --dump_users

DEPENDS ON

DBI (and a suitable DBD backend)

Getopt::Long

User::Simple::Admin

SEE ALSO

User::Simple and User::Simple::Admin

AUTHOR

Gunnar Wolf <gwolf@gwolf.org>

COPYRIGHT

Copyright 2005 Gunnar Wolf / Instituto de Investigaciones Económicas UNAM This module is Free Software, it can be redistributed under the same terms as Perl.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 151:

Non-ASCII character seen before =encoding in 'Económicas'. Assuming UTF-8