[evolvis-commits] r11423: adding cvs acl check so some projects can have read-only membe?==?UTF-8?Q?rs↵
mirabilos at evolvis.org
mirabilos at evolvis.org
Thu Feb 24 18:09:50 CET 2011
Author: mirabilos
Date: 2011-02-24 18:09:50 +0100 (Thu, 24 Feb 2011)
New Revision: 11423
Modified:
trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/bin/aclcheck.php
trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/cronjobs/cvs.php
trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/etc/plugins/scmcvs/config.php
trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/www/acl.php
Log:
adding cvs acl check so some projects can have read-only members
Modified: trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/bin/aclcheck.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/bin/aclcheck.php 2011-02-24 17:09:49 UTC (rev 11422)
+++ trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/bin/aclcheck.php 2011-02-24 17:09:50 UTC (rev 11423)
@@ -29,11 +29,12 @@
exit(1);
}
-require_once('local.inc');
+require_once('plugins/scmcvs/config.php');
require ($sys_plugins_path.'/scmcvs/common/Snoopy.class');
// Input cleansing
$env_cvsroot = (string) $_ENV['CVSROOT'];
+
# Rules
# 1. Must begin with /cvs/ or /cvsroot/
# 2. Then must contain 3 - 15 alphanumeric chars or -
@@ -56,10 +57,16 @@
$SubmitVars['group'] = $projectName;
$SubmitVars['user'] = $userName;
-$snoopy->submit($SubmitUrl,$SubmitVars);
-if (!empty($snoopy->results)) {
- print $snoopy->results."\n";
- exit(1);
+if ($userName == 'root') {
+ exit(0);
+} else {
+
+ $snoopy->submit($SubmitUrl,$SubmitVars);
+ if (!empty($snoopy->results)) {
+ print $snoopy->results."\n";
+ exit(1);
+ }
+
}
?>
Modified: trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/cronjobs/cvs.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/cronjobs/cvs.php 2011-02-24 17:09:49 UTC (rev 11422)
+++ trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/cronjobs/cvs.php 2011-02-24 17:09:50 UTC (rev 11423)
@@ -34,18 +34,16 @@
setup_plugin_manager () ;
-$use_cvs_acl = false;
-$maincvsroot = "/cvsroot";
-
/**
-* Retrieve a file into a temporary directory from a CVS server
-*
-* @param String $repos Repository Name
-* @param String $file File Name
-*
-* return String the FileName in the working repository
-*/
-function get_CVS_file($repos,$file) {
+ * Retrieve a file into a temporary directory from a CVS server
+ *
+ * @param String $repos Repository Name
+ * @param String $file File Name
+ *
+ * return String the FileName in the working repository
+ */
+function checkout_cvs_file($repos,$file) {
+//echo "$repos,$file\n";
$actual_dir = getcwd();
$tempdirname = tempnam("/tmp","cvstracker");
if (!$tempdirname)
@@ -66,57 +64,13 @@
}
/**
-* is_logininfo_line_found
-*
-* @param String $repos Repository
-*
-* Returns true if loginfo line has already been added
-*/
-function is_logininfo_line_found($repos,&$tempfile){
- $LineFound=FALSE;
- $tempfile=get_CVS_File($repos,"CVSROOT/loginfo");
- $FIn = fopen($tempfile,"r");
- if ($FIn) {
- while (!feof($FIn)) {
- $Line = fgets ($FIn);
- if(!preg_match("/^#/", $Line) && preg_match("/cvstracker/",$Line)) {
- $LineFound = TRUE;
- }
- }
- }
- fclose($FIn);
- return $LineFound;
-}
-
-/**
- * Function to add cvstracker lines to a loginfo file
- * The lines are taken from the global var loginfo_lines,
- * loaded by the CVSTracker Plugin.
- * @param string $path The filename of loginfo
- *
- */
-function add_CVSTracker_to_file($path) {
- global $sys_plugins_path, $sys_users_host, $cvs_binary_version;
- $lines=array();
- $lines=$GLOBALS["loginfo_lines"];
- $FOut = fopen($path, "a");
- if($FOut) {
- fwrite($FOut, $lines[0]);
- fwrite($FOut, $lines[1]);
- fwrite($FOut, $lines[2]);
- fclose($FOut);
- }
-}
-
-
-/**
-* put_CVS_File commit a file to the repository
-*
-* @param String $repos Repository
-* @param String $file to commit
-* @param String $message to commit
-*/
-function put_CVS_File($repos,$file,$message="Automatic updated by cvstracker") {
+ * commit_cvs_file commit a file to the repository
+ *
+ * @param String $repos Repository
+ * @param String $file to commit
+ * @param String $message to commit
+ */
+function commit_cvs_file($repos,$file,$message="Automatic updated by cvstracker") {
$actual_dir = getcwd();
chdir(dirname($file));
system("cvs -d ".$repos." ci -m \"".$message."\" ".basename($file));
@@ -125,13 +79,13 @@
}
/**
- * release_CVS_File - Remove the file that was checked out from cvs
- * @see get_CVS_file
+ * release_cvs_file - Remove the file that was checked out from cvs
+ * @see checkout_cvs_file
*/
-function release_CVS_File($file) {
+function release_cvs_file($file) {
// $file is something like /tmp/(tmp_dir)/path/to/file
// we must delete /tmp/tmp_dir
- if (!preg_match("/^(\\/tmp\\/[^\\/]*)\\/.*/", $file, $result)) { // Make sure the dir is under /tmp
+ if (!preg_match("/^(\\/tmp\\/[^\\/]*)\\/.* /", $file, $result)) { // Make sure the dir is under /tmp
echo "Trying to release a directory not in /tmp. Skipping...";
return;
}
@@ -146,24 +100,6 @@
system("rm -rf ".$dir);
}
-//the directory exists
-if(is_dir($maincvsroot)) {
- add_Project_Repositories();
-} else {
- if(is_file($maincvsroot)) {
- $err .= "$maincvsroot exists but is a file\n";
- exit;
- } else {
- if (mkdir($maincvsroot)) {
- //need to update group permissions using chmod
- add_Project_Repositories();
- } else {
- $err .= "unable to make $maincvsroot directory\n";
- exit;
- }
- }
-}
-
function write_File($filePath, $content) {
$file = fopen($filePath, 'a');
flock($file, LOCK_EX);
@@ -177,63 +113,104 @@
}
/**
-*add_sync_mail
-*Copyright GForge 2004
-*add_sync_mail write to /CVSROOT/loginfo unix_name-commits at lists.gforge.company.com
-*
-*@autor Luis A. Hurtado A. luis at gforgegroup.com
-*@param $unix_group_name Name Group
-*@return void
-*@date 2004-10-25
-*/
+ *add_sync_mail write to /CVSROOT/loginfo unix_name-commits at lists.gforge.company.com
+ *
+ *@param $unix_group_name Name Group
+ *@return void
+ *@date 2004-10-25
+ */
function add_sync_mail($unix_group_name) {
global $sys_lists_host;
- global $maincvsroot;
- $loginfo_file=get_CVS_file($maincvsroot."/".$unix_group_name,'CVSROOT/loginfo');
+ global $cvsdir_prefix;
+ $loginfo_file=$cvsdir_prefix.'/'.$unix_group_name.'/CVSROOT/loginfo';
+
if (!$loginfo_file) {
- echo "Couldn't get loginfo";
+ echo "Couldn't get loginfo for $unix_group_name";
return;
}
- $pathsyncmail = "ALL ".
- dirname(__FILE__)."/syncmail -u %p %{sVv} ".
- $unix_group_name."-commits@".$sys_lists_host."\n";
$content = file_get_contents ($loginfo_file);
if ( strstr($content, "syncmail") == FALSE) {
- echo $unix_group_name.":Syncmail not found in loginfo.Adding\n";
+// echo $unix_group_name.":Syncmail not found in loginfo.Adding\n";
+ $pathsyncmail = "ALL ".
+ dirname(__FILE__)."/syncmail -u %p %{sVv} ".
+ $unix_group_name."-commits@".$sys_lists_host."\n";
$content .= "\n#BEGIN Added by cvs.php script\n".
$pathsyncmail. "\n#END Added by cvs.php script\n";
+ $loginfo_file = checkout_cvs_file($cvsdir_prefix.'/'.$unix_group_name,'CVSROOT/loginfo');
if(is_file($loginfo_file)){
echo $unix_group_name.":About to write the lines\n";
- write_File($loginfo_file, $content);
+ write_File($loginfo_file, $content, 1);
}
- put_CVS_File($maincvsroot."/".$unix_group_name,$loginfo_file);
+ commit_cvs_file($cvsdir_prefix."/".$unix_group_name,$loginfo_file);
+ release_cvs_file($loginfo_file);
} else {
- echo "Syncmail Found!\n";
+// echo "Syncmail Found!\n";
}
- release_CVS_File($loginfo_file);
}
-function addAclCheck($unix_group_name) {
+/**
+ * Function to add cvstracker lines to a loginfo file
+ * @param string the unix_group_name
+ *
+ */
+function add_cvstracker($unix_group_name) {
+ global $cvsdir_prefix, $sys_plugins_path, $cvs_binary_version;
+ $loginfo_file=$cvsdir_prefix.'/'.$unix_group_name.'/CVSROOT/loginfo';
- global $maincvsroot;
- $commitinfo = $maincvsroot."/".$unix_group_name.'/CVSROOT/commitinfo';
-
- $Group =& group_get_object_by_name($unix_group_name);
- if (!$Group || !is_object($Group)) {
- return false;
+ if (!$loginfo_file) {
+ echo "Couldn't get loginfo for $unix_group_name";
+ return;
}
- if (isAclCheckSet($commitinfo) === false) {
- $aclcheck = "ALL php -q -d include_path=".ini_get('include_path').
- " ".$GLOBALS['sys_plugins_path']."/scmcvs/bin/aclcheck.php\n";
- if(!file_exists($commitinfo) || (file_exists($commitinfo) && is_file($commitinfo))){
- writeFile($commitinfo, $aclcheck, 1);
+ $content = file_get_contents ($loginfo_file);
+ if ( strstr($content, "cvstracker") == FALSE) {
+ $content = "\n# BEGIN added by gforge-plugin-cvstracker";
+ if ( $cvs_binary_version == "1.11" ) {
+ $content .= "\nALL ( php -q -d include_path=".ini_get('include_path').
+ " ".$sys_plugins_path."/cvstracker/bin/post.php".
+ " %r %{sVv} )\n";
+ }else { //it's version 1.12
+ $content .= "\nALL ( php -q -d include_path=".ini_get('include_path').
+ " ".$sys_plugins_path."/cvstracker/bin/post.php".
+ " %r %p %{sVv} )";
+ }
+ $content .= "\n# END added by gforge-plugin-cvstracker";
+
+ $loginfo_file = checkout_cvs_file($cvsdir_prefix.'/'.$unix_group_name,'CVSROOT/loginfo');
+ if(is_file($loginfo_file)){
+ echo $unix_group_name.":About to write the lines\n";
+ write_File($loginfo_file, $content, 1);
}
+ commit_cvs_file($cvsdir_prefix."/".$unix_group_name,$loginfo_file);
+ release_cvs_file($loginfo_file);
+ } else {
+// echo "cvstracker Found!\n";
}
}
+function add_acl_check($unix_group_name) {
+ global $cvsdir_prefix;
+
+ $commitinfofile = $cvsdir_prefix."/".$unix_group_name.'/CVSROOT/commitinfo';
+
+ $content = file_get_contents ($commitinfofile);
+ if ( strstr($content, "aclcheck") == FALSE) {
+
+ $commitinfofile = checkout_cvs_file($cvsdir_prefix.'/'.$unix_group_name,'CVSROOT/commitinfo');
+ $aclcheck = "\n#BEGIN adding cvs acl check".
+ "\nALL php -q -d include_path=".ini_get('include_path').
+ " ".$GLOBALS['sys_plugins_path']."/scmcvs/bin/aclcheck.php %r %p ".
+ "\n#END adding cvs acl check\n";
+ writeFile($commitinfofile, $aclcheck, 1);
+ commit_cvs_file($cvsdir_prefix."/".$unix_group_name,$commitinfofile);
+ release_cvs_file($loginfo_file);
+ } else {
+// echo "cvstracker Found!\n";
+ }
+}
+
function writeFile($filePath, $content, $append=0) {
if ($append == 1) {
$file = fopen($filePath, 'a');
@@ -248,36 +225,9 @@
fclose($file);
}
-// return's true if it's ok to write the file
-function isAclCheckSet($file_name) {
- if (!file_exists($file_name)) {
- // files does't exist, it's ok to write it
- echo "no existe\n";
- return false;
- } else { // check if file is empty or commented out
- $file = @fopen($file_name, 'r');
- if (!$file) { // couldn't open file
- return 1;
- }
- while (!feof($file)) {
- $content = trim(fgets($file, 4096));
- if (strlen($content) > 1) {
- if(!preg_match("/^#/", $content) &&
- preg_match("/aclcheck\.php/",$content)) {
- fclose($file);
- return true;
- }
- }
- }
- fclose($file);
- return false;
- }
-}
+function update_cvs_repositories() {
+ global $cvsdir_prefix;
-function add_Project_Repositories() {
- global $maincvsroot;
- global $use_cvs_acl;
-
$res = db_query("select groups.group_id,groups.unix_group_name,groups.enable_anonscm,groups.enable_pserver".
" FROM groups, plugins, group_plugin".
" WHERE groups.status != 'P' ".
@@ -297,7 +247,7 @@
break; // continue to the next project
}
- $repositoryPath = $maincvsroot."/".$project->getUnixName();
+ $repositoryPath = $cvsdir_prefix."/".$project->getUnixName();
if (is_dir($repositoryPath)) {
$writersContent = '';
$readersContent = '';
@@ -315,17 +265,13 @@
write_File($repositoryPath.'/CVSROOT/writers', $writersContent);
write_File($repositoryPath.'/CVSROOT/readers', $readersContent);
write_File($repositoryPath.'/CVSROOT/passwd', $passwdContent);
- add_sync_mail($project->getUnixName());
- addAclCheck($project->getUnixName());
- if ($project->usesPlugin("cvstracker")){
- $newfile="";
- if(!is_logininfo_line_found($repositoryPath,$newfile)){
- plugin_hook("get_cvs_loginfo_lines",$hookParams);
- add_CVSTracker_to_file($newfile);
- put_CVS_File($repositoryPath,$newfile);
- }
- release_CVS_File($newfile);
+ if ($project->usesPlugin('cvssyncmail')) {
+ add_sync_mail($project->getUnixName());
}
+ if ($project->usesPlugin('cvstracker')) {
+ add_cvstracker($project->getUnixName());
+ }
+ add_acl_check($project->getUnixName());
} elseif (is_file($repositoryPath)) {
$err .= $repositoryPath.' already exists as a file';
} else {
@@ -336,55 +282,45 @@
' '.($project->getID()+50000).
' '.$enableAnonSCM.
' '.$enablePserver);
- add_sync_mail($project->getUnixName());
- addAclCheck($project->getUnixName());
- if ($project->usesPlugin("cvstracker")){
- $newfile="";
- if(!is_logininfo_line_found($repositoryPath,$newfile)){
- plugin_hook("get_cvs_loginfo_lines",$hookParams);
- add_CVSTracker_to_file($newfile);
- put_CVS_File($repositoryPath,$newfile);
- }
- release_CVS_File($newfile);
- }
- if ($use_cvs_acl == true) {
- system ("cp ".dirname($_SERVER['_']).
- "/aclconfig.default ".$repositoryPath.'/CVSROOT/aclconfig');
- $res_admins = db_query("SELECT users.user_name FROM users,user_group ".
- "WHERE users.user_id=user_group.user_id AND ".
- "user_group.group_id='".$project->getID()."'");
- $useradmin_group = db_result($res_admins,0,'user_name');
- system("cvs -d ".$repositoryPath." racl ".$useradmin_group.":p -r ALL -d ALL");
+ if ($project->usesPlugin('cvssyncmail')) {
+ add_sync_mail($project->getUnixName());
}
+ if ($project->usesPlugin('cvstracker')) {
+ add_cvstracker($project->getUnixName());
+ }
+ add_acl_check($project->getUnixName());
}
}
}
-// return's true if it's ok to write the file
-function check_Log_info($file_name) {
- if (!file_exists($file_name)) {
- // files does't exist, it's ok to write it
- return true;
- } else { // check if file is empty or commented out
- $file = @fopen($file_name, 'r');
- if (!$file) { // couldn't open file
- return false;
- }
- while (!feof($file)) {
- $content = trim(fgets($file, 4096));
- if (strlen($content) > 1) {
- if ($content{0} != '#') { // it's not a comment
- fclose($file);
- return false;
- }
- }
- }
- fclose($file);
- return true;
+
+/*
+
+
+ Loop through and create/update each repository for every project
+ that uses SCMCVS plugin
+
+
+*/
+if(is_dir($cvsdir_prefix)) {
+ update_cvs_repositories();
+} else {
+ if(is_file($cvsdir_prefix)) {
+ $err .= "$cvsdir_prefix exists but is a file\n";
+ exit;
+ } else {
+ if (mkdir($cvsdir_prefix)) {
+ //need to update group permissions using chmod
+ update_cvs_repositories();
+ } else {
+ $err .= "unable to make $cvsdir_prefix directory\n";
+ exit;
+ }
}
}
+
cron_entry(13,$err);
?>
Modified: trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/etc/plugins/scmcvs/config.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/etc/plugins/scmcvs/config.php 2011-02-24 17:09:49 UTC (rev 11422)
+++ trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/etc/plugins/scmcvs/config.php 2011-02-24 17:09:50 UTC (rev 11423)
@@ -3,6 +3,10 @@
//$default_cvs_server = $GLOBALS['sys_cvs_host'] ;
$default_cvs_server = "cvs." . $GLOBALS['sys_default_domain'] ;
$enabled_by_default = 1 ;
+$cvs_binary_version='1.12';
+$GLOBALS['cvs_binary_version']=$cvs_binary_version;
+$sys_plugins_path='/opt/gforge/plugins';
+$sys_default_domain='gforge.org';
// Local Variables:
// mode: php
Modified: trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/www/acl.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/www/acl.php 2011-02-24 17:09:49 UTC (rev 11422)
+++ trunk/gforge_base/evolvisforge-5.1/gforge-plugin-scmcvs/www/acl.php 2011-02-24 17:09:50 UTC (rev 11423)
@@ -45,18 +45,19 @@
exit_error('','Invalid username');
}
+ $userName = $matches2[count($matches2)-1];
+ $User =& user_get_object_by_name($userName);
+ if (!$User || !is_object($User)) {
+ exit_error('','User not found');
+ }
+ session_set_new($User->getID());
+
$projectName = $matches[count($matches)-1];
$Group =& group_get_object_by_name($projectName);
if (!$Group || !is_object($Group) || $Group->isError()) {
exit_no_group();
}
- $userName = $matches2[count($matches2)-1];
- $User =& user_get_object_by_name($userName);
- if (!$User || !is_object($User)) {
- exit_error('','User not found');
- }
-
$perm =& permission_get_object($Group, $User);
if (!$perm || !is_object($perm) || !$perm->isCVSWriter()) {
exit_permission_denied();
More information about the evolvis-commits
mailing list