Mailing List Archive

script to manage users / calendars from the command line
On Fri, 2009-11-20 at 16:18 +0100, Norbert P?schel wrote:
> Hello,
>
> does anybody have a shell script that allows the creation of new users
> and their calendars from the shell?

I don't, but if you're looking at writing one I would write it so that
it called a PHP script for the actual creation.

In the PHP script I would include auth-functions.php and then construct
a $usr object so I could make a call to:

UpdateUserFromExternal( $usr );

which would do the updating, calendar creation and so forth.


The problem with writing it directly in a shell script is that it might
not continue to do the right thing as fields get added to the database
over time.

In particular, 0.9.8 will add a 'resourcetype' column to the collection
table, and the default value for that is not the appropriate value for a
calendar collection.

Similarly, at some point in the future a default addressbook collection
will be added to the stuff that gets created by default, and a user
creation shell script would again need to be updated to add that, unless
it called the PHP to do the update.

Cheers,
Andrew.

------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
He is now rising from affluence to poverty.
-- Mark Twain
------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20091121/3e8f7486/attachment.pgp>
-------------- next part --------------
script to manage users / calendars from the command line [ In reply to ]
Hello Andrew,

thanks for your help. Looking at UpdateUserFromExternal() let me realize
I didn't need that command line script after all - my real problem was
that LDAP-authenticated users didn't get their home calendars created
automatically!

Debugging this I found the following statement in two places in
auth_functions.php:

if ( isset($usr->active) && $usr->active == 'f' ) return false;

As far as I understand the code (which is not very far, probably ;-) )
$usr->active is a bool, so the second part of the comparison is bad. I
changed the lines to

if ( isset($usr->active) && !$usr->active) return false;

and everything works as expected!

Also, the infamous line

if ( function_exists('CreateHomeCalendar') ) return(true);

at the beginning of auth_functions still breaks LDAP users, so I had to
comment it out.

Patch for this is attached. For good measure I also added a patch for
dba/create-database.sh - this is a bash script and breaks on systems
where /bin/sh is not a bash (like mine - I work on Solaris).

Regards,

Norbert P?schel

Andrew McMillan schrieb:
> On Fri, 2009-11-20 at 16:18 +0100, Norbert P?schel wrote:
>> Hello,
>>
>> does anybody have a shell script that allows the creation of new users
>> and their calendars from the shell?
>
> I don't, but if you're looking at writing one I would write it so that
> it called a PHP script for the actual creation.
>
> In the PHP script I would include auth-functions.php and then construct
> a $usr object so I could make a call to:
>
> UpdateUserFromExternal( $usr );
>
> which would do the updating, calendar creation and so forth.
>
>
> The problem with writing it directly in a shell script is that it might
> not continue to do the right thing as fields get added to the database
> over time.
>
> In particular, 0.9.8 will add a 'resourcetype' column to the collection
> table, and the default value for that is not the appropriate value for a
> calendar collection.
>
> Similarly, at some point in the future a default addressbook collection
> will be added to the stuff that gets created by default, and a user
> creation shell script would again need to be updated to add that, unless
> it called the PHP to do the update.
>
> Cheers,
> Andrew.
>
> ------------------------------------------------------------------------
> andrew (AT) morphoss (DOT) com +64(272)DEBIAN
> He is now rising from affluence to poverty.
> -- Mark Twain
> ------------------------------------------------------------------------
>
>
>
> ------------------------------------------------------------------------
>

--
networker, projektberatung GmbH
Kirchstr. 11a
53604 Bad Honnef

Tel.: 02224/986158
Fax: 02224/986174
Mobil: 0163/5768493

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: create-database.sh.diff
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20091123/c50142d4/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: auth_functions.php.diff
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20091123/c50142d4/attachment-0001.asc>
-------------- next part --------------