1
/* Copyright (C) 2000-2006 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: UserFactory.pike,v 1.4 2006/08/10 08:08:50 astra Exp $
20
constant cvs_version="$Id: UserFactory.pike,v 1.4 2006/08/10 08:08:50 astra Exp $";
22
inherit "/factories/ContainerFactory";
30
#include <attributes.h>
34
static int iActivation = 0;
37
* Initialize the factory with its default attributes.
39
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
41
static void init_factory()
44
init_class_attribute(USER_ADRESS, CMD_TYPE_STRING, "user adress",
45
0, EVENT_ATTRIBUTES_CHANGE, 0,
46
CONTROL_ATTR_USER, "");
47
init_class_attribute(USER_MODE, CMD_TYPE_INT, "user mode",
48
0, EVENT_ATTRIBUTES_CHANGE, 0,
49
CONTROL_ATTR_CLIENT, 0);
50
init_class_attribute(USER_UMASK, CMD_TYPE_MAPPING, "user umask",
51
EVENT_ATTRIBUTES_QUERY, EVENT_ATTRIBUTES_CHANGE,0,
52
CONTROL_ATTR_USER, ([ ]));
53
init_class_attribute(USER_MODE_MSG, CMD_TYPE_STRING,
54
"user mode message", 0,
55
EVENT_ATTRIBUTES_CHANGE, 0,CONTROL_ATTR_USER,"");
56
init_class_attribute(USER_EMAIL, CMD_TYPE_STRING, "email",
57
0, EVENT_ATTRIBUTES_CHANGE,0,
58
CONTROL_ATTR_USER, "");
59
init_class_attribute(USER_FULLNAME, CMD_TYPE_STRING, "user fullname",0,
60
EVENT_ATTRIBUTES_CHANGE, 0,CONTROL_ATTR_USER, "");
61
init_class_attribute(USER_WORKROOM, CMD_TYPE_OBJECT, "workroom", 0,
62
EVENT_ATTRIBUTES_CHANGE, 0,CONTROL_ATTR_USER, 0);
63
init_class_attribute(USER_LOGOUT_PLACE, CMD_TYPE_OBJECT, "logout-env",
64
0, EVENT_ATTRIBUTES_CHANGE, 0,
65
CONTROL_ATTR_USER, 0);
66
init_class_attribute(USER_LAST_LOGIN, CMD_TYPE_TIME, "last-login",
67
0, EVENT_ATTRIBUTES_CHANGE, 0,
68
CONTROL_ATTR_SERVER, 0);
69
init_class_attribute(USER_BOOKMARKROOM, CMD_TYPE_OBJECT, "bookmark room",0,
70
EVENT_ATTRIBUTES_CHANGE, 0,CONTROL_ATTR_USER, 0);
71
init_class_attribute(USER_FORWARD_MSG, CMD_TYPE_INT, "forward message",
72
0, EVENT_ATTRIBUTES_CHANGE, 0,
73
CONTROL_ATTR_USER, 1);
74
init_class_attribute(USER_FAVOURITES, CMD_TYPE_ARRAY, "favourites list",
75
0, EVENT_ATTRIBUTES_CHANGE, 0,
76
CONTROL_ATTR_USER, ({ }) );
77
init_class_attribute(USER_CALENDAR, CMD_TYPE_OBJECT, "calendar", 0,
78
EVENT_ATTRIBUTES_CHANGE, 0, CONTROL_ATTR_SERVER,0);
79
init_class_attribute(USER_MONITOR, CMD_TYPE_OBJECT, "monitor", 0,
80
EVENT_ATTRIBUTES_CHANGE, 0, CONTROL_ATTR_SERVER,0);
81
init_class_attribute(USER_ID, CMD_TYPE_STRING, "user id",
82
EVENT_ATTRIBUTES_QUERY,
83
EVENT_ATTRIBUTES_CHANGE,
84
0,CONTROL_ATTR_USER, "");
88
* Create a new user object with the following vars:
89
* name - the users name (nickname is possible too).
90
* email - the users email adress.
91
* pw - the users initial password.
92
* fullname - the full name of the user.
93
* firstname - the last name of the user.
95
* @param mapping vars - variables for execution.
96
* @return the objectp of the new user if successfully, or 0 (no access or user
98
* @author Thomas Bopp (astra@upb.de)
100
object execute(mapping vars)
105
if ( stringp(vars["nickname"]) )
106
name = lower_case(vars["nickname"]);
110
obj = MODULE_USERS->lookup(name);
112
steam_error("user_create(): User does already exist.");
113
obj = MODULE_GROUPS->lookup(name);
115
steam_error("user_create(): Group with this name already exist.");
118
object ouid = seteuid(USER("root"));
119
obj = user_create(vars);
123
// try to find the user and remove
124
obj = MODULE_USERS->lookup(name);
125
if ( objectp(obj) ) {
133
private static object user_create(mapping vars)
138
try_event(EVENT_EXECUTE, CALLER, obj);
141
if ( stringp(vars["nickname"]) )
142
name = lower_case(vars["nickname"]);
146
if ( search(name, " ") >= 0 )
147
steam_error("Whitespaces in Usernames are not allowed");
149
string pw = vars["pw"];
150
string email = vars["email"];
152
if ( stringp(vars->fullname) && !xml.utf8_check(vars->fullname) )
153
steam_error("Failed utf8-check for firstname or fullname !");
155
if ( stringp(vars->firstname) && !xml.utf8_check(vars->firstname) )
156
steam_error("Failed utf8-check for firstname or fullname !");
158
obj = object_create(name, CLASS_NAME_USER, 0, vars["attributes"],
159
vars["attributesAcquired"], vars["attributesLocked"]);
160
obj->lock_attribute(OBJ_NAME);
161
if ( !objectp(obj) ) {
162
SECURITY_LOG("Creation of user " + name + " failed...");
163
return null; // creation failed...
167
if (stringp(vars["language"]))
168
language=vars["language"];
170
obj->set_user_password(pw);
171
obj->set_user_name(name);
172
obj->set_attribute(USER_EMAIL, email);
173
obj->set_attribute(USER_FULLNAME, vars["fullname"]);
174
obj->set_attribute(USER_FIRSTNAME, vars["firstname"]);
175
if (stringp(language)) obj->set_attribute(USER_LANGUAGE, language);
176
obj->set_creator(_ROOT);
178
if ( objectp(this_user()) && this_user() != _GUEST )
179
obj->sanction_object(this_user(), SANCTION_ALL);
181
if ( stringp(vars["description"]) )
182
obj->set_attribute(OBJ_DESC, vars["description"]);
183
if ( stringp(vars["contact"]) )
184
obj->set_attribute(USER_ADRESS, vars["contact"]);
186
object workroom, factory, calendar;
188
factory = _Server->get_factory(CLASS_ROOM);
190
workroom = factory->execute((["name":name+"'s workarea",]));
192
obj->set_attribute(USER_WORKROOM, workroom);
193
obj->lock_attribute(USER_WORKROOM);
194
workroom->set_attribute(OBJ_DESC, name+"s workroom.");
195
workroom->set_creator(obj->this());
196
workroom->set_attribute(OBJ_OWNER, obj->this());
197
workroom->sanction_object(obj->this(), SANCTION_ALL);
198
workroom->sanction_object_meta(obj->this(), SANCTION_ALL);
200
object bookmarkroom = factory->execute((["name":name+"'s bookmarks",]));
201
obj->set_attribute(USER_BOOKMARKROOM, bookmarkroom);
202
obj->lock_attribute(USER_BOOKMARKROOM);
203
bookmarkroom->set_creator(obj->this());
204
bookmarkroom->sanction_object(obj->this(), SANCTION_ALL);
205
bookmarkroom->sanction_object_meta(obj->this(), SANCTION_ALL);
207
factory = _Server->get_factory(CLASS_TRASHBIN);
208
object trashbin = factory->execute((["name":"trashbin", ]));
209
trashbin->set_attribute(OBJ_DESC, "Trashbin");
210
trashbin->move(workroom->this());
211
trashbin->set_creator(obj->this());
212
trashbin->sanction_object(obj->this(), SANCTION_ALL);
213
trashbin->sanction_object_meta(obj->this(), SANCTION_ALL);
214
trashbin->sanction_object(_STEAMUSER, SANCTION_INSERT);
215
trashbin->set_acquire(0);
217
obj->set_attribute(USER_TRASHBIN, trashbin);
219
calendar = _Server->get_factory(CLASS_CALENDAR)->execute((["name":name+"'s calendar"]) );
220
obj->set_attribute(USER_CALENDAR, calendar);
221
obj->lock_attribute(USER_CALENDAR);
222
calendar->set_creator(obj->this());
223
calendar->sanction_object(obj->this(), SANCTION_ALL);
224
calendar->sanction_object_meta(obj->this(), SANCTION_ALL);
225
calendar->set_attribute(CALENDAR_OWNER, obj->this());
226
calendar->lock_attribute(CALENDAR_OWNER);
228
// steam users can annotate and read the users attributes.
229
obj->sanction_object(_STEAMUSER, SANCTION_READ|SANCTION_ANNOTATE);
231
object forwards = get_module("forward");
232
if ( objectp(forwards) ) {
233
string mname = forwards->get_mask_char() + obj->get_user_name();
234
forwards->add_forward(obj->this(), mname);
235
forwards->add_forward(obj->this(), email);
238
if ( name != "guest" )
239
_STEAMUSER->add_member(obj->this());
242
array(object) inv = workroom->get_inventory_by_class(CLASS_EXIT);
243
if ( sizeof(inv) == 0 ) {
244
factory = _Server->get_factory(CLASS_EXIT);
245
object swa = _STEAMUSER->query_attribute(GROUP_WORKROOM);
246
object exit = factory->execute(
247
([ "name":swa->get_identifier(), "exit_to": swa, ]));
248
exit->set_creator(obj->this());
249
exit->move(workroom);
252
run_event(EVENT_EXECUTE, CALLER, obj);
254
// now remove all guest privileges on this object
255
if ( objectp(_GUEST) ) {
256
obj->sanction_object(_GUEST, 0);
257
workroom->sanction_object(_GUEST, 0);
259
iActivation = time() + random(100000);
260
obj->set_activation(iActivation);
266
* Queries and resets the activation code for an user. Thus
267
* it is required, that the creating object immidiately calls
268
* this function and sends the activation code to the user.
270
* @return activation code for the last created user
271
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
275
int res = iActivation;
280
string rename_user(object user, string new_name)
282
_SECURITY->check_access(user,CALLER,SANCTION_WRITE,ROLE_WRITE_ALL,false);
284
object users = get_module("users");
286
if ( users->lookup(user->get_user_name()) != user )
287
user->set_user_name(new_name);
289
if ( users->rename_user(user, new_name) == new_name )
290
user->set_user_name(new_name);
291
return user->get_user_name();
294
array recover_users()
296
array result = ({ });
298
MESSAGE("Starting User RECOVERY !");
299
foreach( get_module("users")->index(), string uname ) {
300
object user = get_module("users")->lookup(uname);
301
if ( objectp(user) && user->get_user_name() == 0 ) {
302
result += ({ user });
303
user->set_user_name(uname);
306
int oid = user->get_object_id();
308
user->set_attribute(USER_WORKROOM, find_object(oid+1));
309
user->set_attribute(USER_BOOKMARKROOM, find_object(oid+2));
310
user->set_attribute(USER_TRASHBIN, find_object(oid+3));
313
array groups = user->get_groups();
314
foreach ( get_module("groups")->get_groups(), object grp ) {
315
if ( grp->is_member(user) && search(groups, grp) == -1 ) {
316
grp->remove_member(user);
317
grp->add_member(user);
322
MESSAGE("Finished RECOVERY in %d", time() - t);
328
USER("guest")->unlock_attribute(OBJ_NAME);
329
USER("guest")->set_attribute(OBJ_NAME, "guest");
330
USER("guest")->set_user_password("guest");
331
USER("guest")->set_user_name("guest");
332
foreach(USER("guest")->get_groups(), object grp) {
333
if ( grp != GROUP("everyone") )
334
grp->remove_member(USER("guest"));
338
string get_identifier() { return "User.factory"; }
339
string get_class_name() { return "User"; }
340
int get_class_id() { return CLASS_USER; }