#! /usr/bin/php
ServerName gforge.company.com
ServerAlias *.gforge.company.com
VirtualDocumentRoot /home/groups/%1/htdocs
VirtualScriptAlias /home/groups/%1/cgi-bin
Options Indexes FollowSymlinks
AllowOverride All
order allow,deny
allow from all
LogFormat "%h %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" gforge
CustomLog "|/usr/local/sbin/cronolog /home/groups/%1/logs/%Y/%m/%d/gforge.log" gforge
# Ensure that we don't try to use SSL on SSL Servers
SSLDisable
*/
require_once dirname(__FILE__).'/../www/env.inc.php';
require_once $gfcommon.'include/pre.php';
require $gfcommon.'include/cron_utils.php';
setup_gettext_from_sys_lang();
define('USER_DEFAULT_GROUP', 'users');
// error variable
$err = '';
/*
* check whether directory prefices are set
* and create the prefix directories unless they exist
*/
if (!($gpfx = forge_get_config('groupdir_prefix'))) {
// this should be set in configuration
exit();
}
if (!is_dir($gpfx)) {
@mkdir($gpfx, 0755, true);
}
if (!($hpfx = forge_get_config('homedir_prefix'))) {
// this should be set in configuration
exit();
}
if (!is_dir($hpfx)) {
@mkdir($hpfx, 0755, true);
}
if (forge_get_config('use_ftp_uploads')) {
if (!($fpfx = forge_get_config('ftp_upload_dir'))) {
// this should be set in the configuration
exit();
}
if (!is_dir($fpfx)) {
@mkdir($fpfx, 0755, true);
}
} else {
/* signal that we do not use FTP */
$fpfx = false;
}
/* read in the group home template file */
$contents = '';
if (($fo = fopen(dirname(__FILE__) . '/../utils/default_page.php', 'r'))) {
while (!feof($fo)) {
$contents .= fread($fo, 8192);
}
fclose($fo);
} else {
$err .= 'Default Page not found';
}
/* create user homes */
$active_projects = group_get_active_projects();
$unames = array();
foreach ($active_projects as $project) {
foreach ($project->getUsers() as $u) {
$unames[] = $u->getUnixName();
}
}
$unames = array_unique($unames);
foreach ($unames as $uname) {
$uhome = $hpfx . "/" . $uname;
if (!is_dir($uhome)) {
@mkdir($uhome);
}
system("chown $uname:" . USER_DEFAULT_GROUP . " " . $uhome);
}
/* create project/group homes */
foreach ($active_projects as $project) {
$groupname = $project->getUnixName() ;
if ($fpfx && !is_dir($fpfx . '/' . $groupname)) {
@mkdir($fpfx . '/' . $groupname);
//XXX chown/chgrp/chmod?
}
$ghome = $gpfx . '/' . $groupname;
if (!is_dir($ghome)) {
@mkdir($ghome);
/* this is safe as this directory still belongs to root */
@mkdir($ghome . '/htdocs');
@mkdir($ghome . '/cgi-bin');
/* write substituted template to group home */
if (($fw = fopen($ghome . '/htdocs/index.html', 'w'))) {
fwrite($fw, str_replace('##comment##',
_('Default Web Page for groups that haven\'t setup their page yet'),
str_replace('##purpose##',
_('Please replace this file with your own website'),
str_replace('##welcome_to##',
sprintf(_('Welcome to %s'), $project->getPublicName()),
str_replace('##body##',
_("We're Sorry but this Project hasn't uploaded their personal webpage yet.").'
'.
sprintf(_('Please check back soon for updates or visit the project page.'),
util_make_url('/projects/' . $project->getUnixName())),
$contents)))));
fclose($fw);
}
if (forge_get_config('use_manual_uploads')) {
@mkdir($ghome . '/incoming');
}
//system('chmod -R ug=rwX,o=rX ' . $ghome);
system('chown -R ' . forge_get_config('apache_user') . ':' .
forge_get_config('apache_group') . ' ' . $ghome);
// find $ghome -type d -print0 | xargs -0 chmod g+s
//XXX disabled because, why is this owned by apache_group?
}
}
cron_entry(25,$err);