#! /usr/bin/php
<?php
/**
- * GForge Cron Job
+ * Fusionforge Cron Job
*
* The rest Copyright 2002-2005 (c) GForge Team
* Copyright 2012, Franck Villaume - TrivialDev
- * http://fusionforge.org/
+ * Copyright © 2013 Thorsten Glaser, tarent solutions GmbH
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
*/
/*
-This file creates blank user home directories and
-creates a group home directory with a template in it.
+ * This file creates blank user home directories and
+ * creates a group home directory with a template in it.
#
# * hosts
SSLDisable
</IfModule>
</VirtualHost>
+
*/
+
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
+define('USER_DEFAULT_GROUP', 'users');
+// error variable
$err = '';
-if (forge_get_config('groupdir_prefix') == '') { // this should be set in configuration
- exit () ;
+/*
+ * check whether directory preficēs are set
+ * and create the præfix directories unless they exist
+ */
+
+if (!($gpfx = forge_get_config('groupdir_prefix'))) {
+ // this should be set in configuration
+ exit();
}
-if (!is_dir(forge_get_config('groupdir_prefix'))) {
- @mkdir(forge_get_config('groupdir_prefix'),0755,true);
+if (!is_dir($gpfx)) {
+ @mkdir($gpfx, 0755, true);
}
-if (forge_get_config('homedir_prefix') == '') { // this should be set in configuration
- exit () ;
+if (!($hpfx = forge_get_config('homedir_prefix'))) {
+ // this should be set in configuration
+ exit();
}
-if (!is_dir(forge_get_config('homedir_prefix'))) {
- @mkdir(forge_get_config('homedir_prefix'),0755,true);
+if (!is_dir($hpfx)) {
+ @mkdir($hpfx, 0755, true);
}
-$active_projects = group_get_active_projects() ;
-$unames = array () ;
-foreach ($active_projects as $project) {
- foreach ($project->getUsers() as $u) {
- $unames[] = $u->getUnixName() ;
+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;
}
-$unames = array_unique ($unames) ;
-foreach($unames as $uname) {
- if (is_dir(forge_get_config('homedir_prefix')."/".$uname)) {
- } else {
- @mkdir(forge_get_config('homedir_prefix')."/".$uname);
+/* 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);
}
- system("chown $uname:".USER_DEFAULT_GROUP." ".forge_get_config('homedir_prefix')."/".$uname);
+ fclose($fo);
+} else {
+ $err .= 'Default Page not found';
}
-//test if the FTP upload dir exists and create it if not
-if (!is_dir(forge_get_config('ftp_upload_dir'))) {
- @mkdir(forge_get_config('ftp_upload_dir'),0755,true);
+/* 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) {
+foreach ($active_projects as $project) {
$groupname = $project->getUnixName() ;
- //create an FTP upload dir for this project
- if (forge_get_config('use_ftp_uploads')) {
- if (!is_dir(forge_get_config('ftp_upload_dir').'/'.$groupname)) {
- @mkdir(forge_get_config('ftp_upload_dir').'/'.$groupname);
- }
- }
- if (is_dir(forge_get_config('groupdir_prefix')."/".$groupname)) {
-
- } else {
- @mkdir(forge_get_config('groupdir_prefix')."/".$groupname);
- @mkdir(forge_get_config('groupdir_prefix')."/".$groupname."/htdocs");
- @mkdir(forge_get_config('groupdir_prefix')."/".$groupname."/cgi-bin");
-
- //
- // Read in the template file
- //
- $fo=fopen(dirname(__FILE__).'/../utils/default_page.php','r');
- $contents = '';
- if (!$fo) {
- $err .= 'Default Page Not Found';
- } else {
- while (!feof($fo)) {
- $contents .= fread($fo, 8192);
- }
- fclose($fo);
- }
- //
- // Change some defaults in the template file
- //
- $contents=str_replace('##comment##', _('Default Web Page for groups that haven\'t setup their page yet'), $contents);
- $contents=str_replace('##purpose##', _('Please replace this file with your own website'), $contents);
- $contents=str_replace('##welcome_to##', sprintf(_('Welcome to %s'), $project->getPublicName()), $contents);
- $contents=str_replace('##body##',
- sprintf(
- _("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>."),
- util_make_url ('/projects/'.$project->getUnixName())),
- $contents);
- //
- // Write the file back out to the project home dir
- //
- $fw=fopen(forge_get_config('groupdir_prefix')."/".$groupname."/htdocs/index.html",'w');
- fwrite($fw,$contents);
- fclose($fw);
+ if ($fpfx && !is_dir($fpfx . '/' . $groupname)) {
+ @mkdir($fpfx . '/' . $groupname);
+ //XXX chown/chgrp/chmod?
}
- if (forge_get_config('use_manual_uploads')) {
- $incoming = forge_get_config('groupdir_prefix')."/".$groupname."/incoming" ;
- if (!is_dir($incoming))
- {
- @mkdir($incoming);
+ $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##',
+ sprintf(_("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>."),
+ util_make_url('/projects/' . $project->getUnixName())),
+ $contents)))));
+ fclose($fw);
}
- }
- system("chown -R ".forge_get_config('apache_user').":".forge_get_config('apache_group')." ".forge_get_config('groupdir_prefix')."/".$groupname);
+ 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);
-
-?>