6 * The rest Copyright 2002-2005 (c) GForge Team
7 * Copyright 2012, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 This file creates blank user home directories and
28 creates a group home directory with a template in it.
33 <VirtualHost 192.168.1.5>
34 ServerName gforge.company.com
35 ServerAlias *.gforge.company.com
36 VirtualDocumentRoot /home/groups/%1/htdocs
37 VirtualScriptAlias /home/groups/%1/cgi-bin
39 <Directory /home/groups>
40 Options Indexes FollowSymlinks
46 LogFormat "%h %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" gforge
47 CustomLog "|/usr/local/sbin/cronolog /home/groups/%1/logs/%Y/%m/%d/gforge.log" gforge
48 # Ensure that we don't try to use SSL on SSL Servers
49 <IfModule apache_ssl.c>
54 require_once dirname(__FILE__).'/../www/env.inc.php';
55 require_once $gfcommon.'include/pre.php';
56 require $gfcommon.'include/cron_utils.php';
58 setup_gettext_from_sys_lang();
59 define('USER_DEFAULT_GROUP', 'users');
63 if (forge_get_config('groupdir_prefix') == '') { // this should be set in configuration
67 if (!is_dir(forge_get_config('groupdir_prefix'))) {
68 @mkdir(forge_get_config('groupdir_prefix'), 0755, true);
71 if (forge_get_config('homedir_prefix') == '') { // this should be set in configuration
75 if (!is_dir(forge_get_config('homedir_prefix'))) {
76 @mkdir(forge_get_config('homedir_prefix'), 0755, true);
79 $active_projects = group_get_active_projects();
81 foreach ($active_projects as $project) {
82 foreach ($project->getUsers() as $u) {
83 $unames[] = $u->getUnixName();
86 $unames = array_unique($unames);
87 foreach($unames as $uname) {
88 if (!is_dir(forge_get_config('homedir_prefix')."/".$uname)) {
89 @mkdir(forge_get_config('homedir_prefix')."/".$uname);
91 system("chown $uname:".USER_DEFAULT_GROUP." ".forge_get_config('homedir_prefix')."/".$uname);
94 //test if the FTP upload dir exists and create it if not
95 if (!is_dir(forge_get_config('ftp_upload_dir'))) {
96 @mkdir(forge_get_config('ftp_upload_dir'), 0755, true);
100 // Read in the template file
102 $fo=fopen(dirname(__FILE__).'/../utils/default_page.php','r');
103 $default_contents = '';
105 $err .= 'Default Page Not Found';
108 $default_contents .= fread($fo, 8192);
113 function create_dirs_and_files($params) {
114 $project = $params['project'];
115 $groupname = $project->getUnixName();
116 $default_contents = $parmas['default_contents'];
118 mkdir(forge_get_config('groupdir_prefix')."/".$groupname."/htdocs");
119 mkdir(forge_get_config('groupdir_prefix')."/".$groupname."/cgi-bin");
121 $contents = $default_contents;
123 // Change some defaults in the template file
125 $contents=str_replace('##comment##', _('Default Web Page for groups that haven\'t setup their page yet'), $contents);
126 $contents=str_replace('##purpose##', _('Please replace this file with your own website'), $contents);
127 $contents=str_replace('##welcome_to##', sprintf(_('Welcome to %s'), $project->getPublicName()), $contents);
128 $contents=str_replace('##body##',
130 _("We're Sorry but this Project hasn't yet uploaded their personal webpage yet. <br /> Please check back soon for updates or visit <a href=\"%s\">the project page</a>."),
131 util_make_url ('/projects/'.$project->getUnixName())),
134 // Write the file back out to the project home dir
136 $fw=fopen(forge_get_config('groupdir_prefix')."/".$groupname."/htdocs/index.html",'w');
137 fwrite($fw,$contents);
140 if (forge_get_config('use_manual_uploads')) {
141 $incoming = forge_get_config('groupdir_prefix')."/".$groupname."/incoming" ;
142 if (!is_dir($incoming))
149 foreach($active_projects as $project) {
150 $groupname = $project->getUnixName();
151 //create an FTP upload dir for this project
152 if (forge_get_config('use_ftp_uploads')) {
153 if (!is_dir(forge_get_config('ftp_upload_dir').'/'.$groupname)) {
154 @mkdir(forge_get_config('ftp_upload_dir').'/'.$groupname);
158 if (!is_dir(forge_get_config('groupdir_prefix')."/".$groupname)) {
159 @mkdir(forge_get_config('groupdir_prefix')."/".$groupname);
160 system("chown ".forge_get_config('apache_user').":".forge_get_config('apache_group')." ".forge_get_config('groupdir_prefix')."/".$groupname);
164 $params['project'] = $project;
165 $params['default_contents'] = $default_contents;
167 util_sudo_effective_user(forge_get_config('apache_user'),
168 "create_dirs_and_files",