[Fusionforge-commits] r6996 - trunk/gforge/cronjobs

Christian Bayle cbayle at libremir.placard.fr.eu.org
Thu Feb 19 08:34:47 CET 2009


Author: cbayle
Date: 2009-02-19 08:34:47 +0100 (Thu, 19 Feb 2009)
New Revision: 6996

Added:
   trunk/gforge/cronjobs/auth_unix.php
   trunk/gforge/cronjobs/create_home_dirs.php
Log:
Add files from Novaforge branch


Added: trunk/gforge/cronjobs/auth_unix.php
===================================================================
--- trunk/gforge/cronjobs/auth_unix.php	                        (rev 0)
+++ trunk/gforge/cronjobs/auth_unix.php	2009-02-19 07:34:47 UTC (rev 6996)
@@ -0,0 +1,232 @@
+<?php
+/*
+ *
+ * Novaforge is a registered trade mark from Bull S.A.S
+ * Copyright (C) 2007 Bull S.A.S.
+ * 
+ * http://novaforge.org/
+ *
+ *
+ * This file has been developped within the Novaforge(TM) project from Bull S.A.S
+ * and contributed back to GForge community.
+ *
+ * GForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this file; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+?>
+<?php
+/**
+ * Script for creating user and group permissions
+ *
+ * Based on cronjobs/cvs-cron/usergroup.php from GForge 4.5.11
+ *
+ * GForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * This script creates user and group permissions by generating
+ * the /etc/passwd, /etc/shadow and /etc/group files
+ */
+
+require_once('squal_pre.php');
+require ('common/include/cron_utils.php');
+
+// Default shell
+$default_shell = "/bin/bash";
+
+// Value to add to group id
+$gid_add = 10000;
+
+$err = "";
+if (file_exists ("/etc/passwd.org") == false)
+{
+	$err .= ", /etc/passwd.org missing!";
+}
+if (file_exists ("/etc/shadow.org") == false)
+{
+	$err .= ", /etc/shadow.org missing!";
+}
+if (file_exists ("/etc/group.org") == false)
+{
+	$err .= ", /etc/group.org missing!";
+}
+if (util_is_root_dir ($homedir_prefix) == true)
+{
+	$err .= ", homedir_prefix points to root directory!";
+}
+
+if ($err == "")
+{
+	//
+	// Get the users from the database
+	//
+	$res = db_query ("SELECT user_name,unix_pw,unix_uid,unix_gid,realname,shell FROM users WHERE unix_status='A'::bpchar");
+	$user_names = &util_result_column_to_array ($res, "user_name");
+	$user_pws = &util_result_column_to_array ($res, "unix_pw");
+	$user_ids = &util_result_column_to_array ($res, "unix_uid");
+	$user_gids = &util_result_column_to_array ($res, "unix_gid");
+	$user_realnames = &util_result_column_to_array ($res, "realname");
+	$user_shells = &util_result_column_to_array ($res, "shell");
+	//
+	// Read the "default" users in /etc/passwd.org
+	//
+	$h = fopen ("/etc/passwd.org", "r");
+	$passwdcontents = fread ($h, filesize ("/etc/passwd.org"));
+	fclose ($h);
+	$passwdlines = explode ("\n", $passwdcontents);
+	//
+	// Write the "default" users in /etc/passwd
+	//
+	$h2 = fopen ("/etc/passwd", "w");
+	for ($k = 0; $k < count ($passwdlines); $k++)
+	{
+		$passwdline = explode (":", $passwdlines [$k]);
+		$def_users [$passwdline [0]] = 1;
+		fwrite ($h2, $passwdlines [$k] . "\n");
+	}
+	//
+	// Append the users from the database
+	//
+	for ($i = 0; $i < count ($user_names); $i++)
+	{
+		if ($def_users [$user_names [$i]])
+		{
+			// This username was already existing in the /etc/passwd.org file
+		}
+		else
+		{
+			if ((strlen ($user_shells [$i]) > 0) && (file_exists ($user_shells [$i]) == true))
+			{
+				$shell = $user_shells [$i];
+			}
+			else
+			{
+				$shell = $default_shell;
+			}
+			$line = $user_names [$i] . ":x:" . $user_ids [$i] . ":" . $user_ids [$i] . ":" . $user_realnames [$i] . ":" . $homedir_prefix . "/" . $user_names [$i] . ":" . $shell . "\n";
+			fwrite ($h2, $line);
+		}
+
+	}
+	fclose($h2);
+
+	//
+	// Read the "default" users in /etc/shadow.org
+	//
+	$h3 = fopen ("/etc/shadow.org", "r");
+	$shadowcontents = fread ($h3, filesize ("/etc/shadow.org"));
+	fclose ($h3);
+	$shadowlines = explode ("\n", $shadowcontents);
+	//
+	// Write the "default" users in /etc/shadow
+	//
+	$h4 = fopen("/etc/shadow","w");
+	for($k = 0; $k < count ($shadowlines); $k++)
+	{
+		$shadowline = explode (":", $shadowlines [$k]);
+		$def_shadow [$shadowline [0]] = 1;
+		fwrite ($h4, $shadowlines [$k] . "\n");
+	}
+	//
+	// Append the users from the database
+	//
+	for ($i = 0; $i < count ($user_names); $i++)
+	{
+		if ($def_shadow [$user_names [$i]])
+		{
+			// This username was already existing in the /etc/shadow.org file
+		}
+		else
+		{
+			$line = $user_names [$i] . ":" . $user_pws [$i] . ":12090:0:99999:7:::\n";
+			fwrite ($h4, $line);
+		}
+	}
+	fclose($h4);
+
+	//
+	// Get the groups from the database
+	//
+	$res = db_query ("SELECT unix_group_name,group_id FROM groups WHERE status='A'::bpchar AND use_scm=1");
+	$group_names = &util_result_column_to_array ($res, "unix_group_name");
+	$group_ids = &util_result_column_to_array ($res, "group_id");
+	//
+	// Read the "default" groups in /etc/group.org
+	//
+	$h5 = fopen ("/etc/group.org", "r");
+	$groupcontents = fread ($h5, filesize ("/etc/group.org"));
+	fclose ($h5);
+	$grouplines = explode ("\n", $groupcontents);
+	//
+	// Write the "default" groups in /etc/group
+	//
+	$h6 = fopen ("/etc/group", "w");
+	for ($k = 0; $k < count ($grouplines); $k++)
+	{
+		$groupline = explode (":", $grouplines [$k]);
+		$def_group [$groupline [0]] = 1;
+		fwrite ($h6, $grouplines [$k] . "\n");
+	}
+	//
+	// Add the groups from the database
+	//
+	for ($i = 0; $i < count ($group_names); $i++)
+	{
+		if ($def_group [$group_names [$i]])
+		{
+			// This groupname was already existing in the /etc/group.org file
+		}
+		else
+		{
+			$line = $group_names [$i] . ":x:" . ($group_ids [$i] + $gid_add) . ":";
+			$resusers = db_query ("SELECT user_name"
+			          . " FROM user_group,users,groups"
+			          . " WHERE users.user_id=user_group.user_id"
+			          . " AND groups.group_id=user_group.group_id"
+			          . " AND groups.status='A'::bpchar"
+			          . " AND groups.use_scm=1"
+			          . " AND groups.unix_group_name='" . $group_names [$i] . "'"
+			          . " AND users.status='A'::bpchar"
+			          . " AND users.unix_status='A'::bpchar");
+			$members = &util_result_column_to_array ($resusers, "user_name");
+			if (count ($members) > 0)
+			{
+				$line .= implode (",", $gmembers) . ",";
+			}
+			$line .= $sys_apache_user . "\n";
+			fwrite ($h6, $line);
+		}
+	}
+	fclose($h6);
+}
+
+if ($err != "")
+{
+	$err = "Error" . $err;
+}
+cron_entry (16, $err);
+
+?>

Added: trunk/gforge/cronjobs/create_home_dirs.php
===================================================================
--- trunk/gforge/cronjobs/create_home_dirs.php	                        (rev 0)
+++ trunk/gforge/cronjobs/create_home_dirs.php	2009-02-19 07:34:47 UTC (rev 6996)
@@ -0,0 +1,157 @@
+#! /usr/bin/php4 -f
+<?php
+/**
+ * GForge Cron Job
+ *
+ * The rest Copyright 2002-2005 (c) GForge Team
+ * http://gforge.org/
+ *
+ * @version   $Id: usergroup.php,v 1.24.2.3 2005/12/05 12:47:48 danper Exp $
+ *
+ * This file is part of GForge.
+ *
+ * GForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+
+This file creates blank user home directories and 
+creates group home directories with a template in it.
+
+*/
+
+require_once('squal_pre.php');
+require ('common/include/cron_utils.php');
+
+//
+//	Default values for the script
+//
+define('GROUP_ID_ADD',50000);
+
+$err = "";
+if (util_is_root_dir($groupdir_prefix))
+{
+	$err .= ", groupdir_prefix points to root directory!";
+}
+if ($err != "")
+{
+	cron_entry(16,"Error" . $err);
+	exit;
+}
+
+//
+// Get the users from the gforge database
+//
+$res = db_query ("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='A' AND user_group.cvs_flags='1' AND users.unix_status='A'");
+$users = &util_result_column_to_array ($res, 'user_name');
+
+//
+// Get the groups from the gforge database
+//
+$res = db_query ("SELECT unix_group_name FROM groups WHERE status='A' AND type_id='1'");
+$groups = &util_result_column_to_array ($res, 'unix_group_name');
+
+//
+// Create home directories for users
+//
+foreach($users as $user)
+{
+	if (is_dir($homedir_prefix."/".$user) == false)
+	{
+		@mkdir($homedir_prefix."/".$user);
+	}
+	system ("chown " . $user . ":" . $user . " " . $homedir_prefix . "/" . $user);
+	system ("chmod 0750 " . $homedir_prefix . "/" . $user);
+}
+
+//
+// Create home directories for groups
+//
+$reload_apache = false;
+foreach($groups as $group)
+{
+	//create an FTP upload dir for this project
+	if ($sys_use_ftpuploads)
+	{ 
+		if (!is_dir($sys_ftp_upload_dir.'/'.$group))
+		{
+			@mkdir($sys_ftp_upload_dir.'/'.$group); 
+		}
+	}
+	if (is_dir($groupdir_prefix."/".$group) == false)
+	{
+		$reload_apache = true;
+		@mkdir($groupdir_prefix."/".$group);
+		@mkdir($groupdir_prefix."/".$group."/htdocs");
+		@mkdir($groupdir_prefix."/".$group."/cgi-bin");
+		$g = &group_get_object_by_name($group);
+		//
+		//	Read in the template file
+		//
+		$contents = "";
+		if (is_file ($sys_custom_path . "/project_homepage_template.php") == true)
+		{
+			$fo = fopen ($sys_custom_path . "/project_homepage_template.php", "r");
+			if ($fo)
+			{
+				while (!feof ($fo))
+				{
+    					$contents .= fread ($fo, 8192);
+				}
+				fclose($fo);
+			}
+		}
+		if (strlen ($contents) <= 0)
+		{
+			$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>';
+			$err .= "Project homepage template " . $sys_custom_path . "/project_homepage_template.php not found";
+		}
+		//
+		//	Change some defaults in the template file
+		//
+		$contents = str_replace ("<domain>", $sys_default_domain, $contents);
+		$contents = str_replace ("<project_description>", $g->getDescription (), $contents);
+		$contents = str_replace ("<project_name>", $g->getPublicName (), $contents);
+		$contents = str_replace ("<group_id>", $g->getID (), $contents);
+		$contents = str_replace ("<group_name>", $g->getUnixName (), $contents);
+		//
+		//	Write the file back out to the project home dir
+		//
+		$fw = fopen ($groupdir_prefix . "/" . $group . "/htdocs/index.php", "w");
+		fwrite ($fw, $contents);
+		fclose ($fw);
+		
+	}
+	system ("chown -R root:" . $group. " " . $groupdir_prefix . "/" . $group);
+	system ("chmod -R ug+rw " . $groupdir_prefix . "/" . $group);
+	system ("find " . $groupdir_prefix . "/" . $group . " -type d -exec chmod g+s {} \;");
+	system ("chmod -R o-rwx " . $groupdir_prefix . "/" . $group);
+}
+if (($reload_apache == true)
+&&  (is_file ($sys_apache_pid_file) == true))
+{
+	$apache_pid = intval (file_get_contents ($sys_apache_pid_file));
+	if ((is_integer ($apache_pid) == true) && ($apache_pid > 0))
+	{
+		if (posix_kill ($apache_pid, 1) == false) // SIGHUP
+		{
+			$err .= "Failed to send SIGHUP to PID " . $apache_pid;
+		}
+	}
+}
+
+cron_entry(16,$err);
+
+?>




More information about the Fusionforge-commits mailing list