6 * The rest Copyright 2002-2005 (c) GForge Team
9 * @version $Id: usergroup.php,v 1.24.2.3 2005/12/05 12:47:48 danper Exp $
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 This file creates blank user home directories and
31 creates group home directories with a template in it.
35 require (dirname(__FILE__).'/../www/env.inc.php');
36 require_once $gfwww.'include/squal_pre.php';
37 require $gfcommon.'/include/cron_utils.php';
40 // Default values for the script
42 define('GROUP_ID_ADD',50000);
45 if (util_is_root_dir($groupdir_prefix))
47 $err .= ", groupdir_prefix points to root directory!";
51 cron_entry(16,"Error" . $err);
56 // Get the users from the gforge database
58 $res = db_query_params ('SELECT distinct users.user_name FROM users,user_group,groups WHERE users.user_id=user_group.user_id AND user_group.group_id=groups.group_id AND groups.status=$1 AND user_group.cvs_flags=$2 AND users.unix_status=$3',
63 $users = &util_result_column_to_array ($res, 'user_name');
66 // Get the groups from the gforge database
68 $res = db_query_params ('SELECT unix_group_name FROM groups WHERE status=$1 AND type_id=$2',
72 $groups = &util_result_column_to_array ($res, 'unix_group_name');
75 // Create home directories for users
77 foreach($users as $user)
79 if (is_dir($homedir_prefix."/".$user) == false)
81 @mkdir($homedir_prefix."/".$user);
83 system ("chown " . $user . ":" . $user . " " . $homedir_prefix . "/" . $user);
84 system ("chmod 0750 " . $homedir_prefix . "/" . $user);
88 // Create home directories for groups
90 $reload_apache = false;
91 foreach($groups as $group)
93 //create an FTP upload dir for this project
94 if ($sys_use_ftpuploads)
96 if (!is_dir($sys_ftp_upload_dir.'/'.$group))
98 @mkdir($sys_ftp_upload_dir.'/'.$group);
101 if (is_dir($groupdir_prefix."/".$group) == false)
103 $reload_apache = true;
104 @mkdir($groupdir_prefix."/".$group);
105 @mkdir($groupdir_prefix."/".$group."/htdocs");
106 @mkdir($groupdir_prefix."/".$group."/cgi-bin");
107 $g = &group_get_object_by_name($group);
109 // Read in the template file
112 if (is_file ($sys_custom_path . "/project_homepage_template.php") == true)
114 $fo = fopen ($sys_custom_path . "/project_homepage_template.php", "r");
119 $contents .= fread ($fo, 8192);
124 if (strlen ($contents) <= 0)
126 $contents = '<html><head><title>Default page for project not found</title></head><body><p><div align="center">Default page for project not found, please create a homepage for your project.</div></body></html>';
127 $err .= "Project homepage template " . $sys_custom_path . "/project_homepage_template.php not found";
130 // Change some defaults in the template file
132 $contents = str_replace ("<domain>", $sys_default_domain, $contents);
133 $contents = str_replace ("<project_description>", $g->getDescription (), $contents);
134 $contents = str_replace ("<project_name>", $g->getPublicName (), $contents);
135 $contents = str_replace ("<group_id>", $g->getID (), $contents);
136 $contents = str_replace ("<group_name>", $g->getUnixName (), $contents);
138 // Write the file back out to the project home dir
140 $fw = fopen ($groupdir_prefix . "/" . $group . "/htdocs/index.php", "w");
141 fwrite ($fw, $contents);
145 system ("chown -R root:" . $group. " " . $groupdir_prefix . "/" . $group);
146 system ("chmod -R ug+rw " . $groupdir_prefix . "/" . $group);
147 system ("find " . $groupdir_prefix . "/" . $group . " -type d -exec chmod g+s {} \;");
148 system ("chmod -R o-rwx " . $groupdir_prefix . "/" . $group);
150 if (($reload_apache == true)
151 && (is_file ($sys_apache_pid_file) == true))
153 $apache_pid = intval (file_get_contents ($sys_apache_pid_file));
154 if ((is_integer ($apache_pid) == true) && ($apache_pid > 0))
156 if (posix_kill ($apache_pid, 1) == false) // SIGHUP
158 $err .= "Failed to send SIGHUP to PID " . $apache_pid;