[PLUGIN] SVN Plugin

when runing in suPHP mode mod_dav_svn ignores "SuexecUserGroup usr1 usr1" it still running as user apache. does anyone know a work around and make it run as the user instead?

Thank you for testing and making new instructions for CentOS at http://code.google.com/p/dasvn/wiki/Installation

So, is it not anybody here that can help out with this last problem when running suPHP? Also, please PM me if you will fix the problem for payment.
 
A few things I ran into while installing this plugin on CentOS 5.5, it works though:

  1. Slow google mirrors
  2. ./fixcurentusers.sh: line 32: syntax error near unexpected token `done'
  3. mv failed

I've provided with an own mirror on realwebsolutions, so you could try that one.

I'd love to see the following changes:

From:
Code:
mv subversion-1.6.5/ .

To:

Code:
cd subversion-1.6.5
cp -R * ../

From:
Code:
mv sqlite-3.6.13/sqlite3.c .

To:

Code:
cd sqlite-amalgamation
cp sqlite3.c ../

After 'wgetting' the files:

Code:
cd /usr/local/directadmin/scripts/custom
chown diradmin:diradmin *

chmod 700 domain_create_post.sh
chmod 700 domain_destroy_pre.sh
chmod 700 user_create_post.sh

Currentuser.sh script failed:

Code:
[root@web01 scripts]#./fixcurentusers.sh
User: admin IgZ05r37
---
./fixcurentusers.sh: line 32: syntax error near unexpected token `done'
./fixcurentusers.sh: line 32: `done;'

On top of that, I get the following error:

Warning: file_get_contents(/home/admin/domains/default/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 22 Warning: file_get_contents(/home/admin/domains/sharedip/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 22 Warning: file_get_contents(/home/admin/domains/suspended/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 2
 
Last edited:
New errors, could anyone give me a clue about where it went wrong or where I can get the missing files?

Code:
Warning: file_get_contents(/home/admin/domains/default/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 22 Call Stack: 0.0003 101440 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0005 113368 2. include('/usr/local/directadmin/plugins/svn/user/_templates/default.php') /usr/local/directadmin/plugins/svn/user/index.html:38 0.0007 140816 3. include('/usr/local/directadmin/plugins/svn/user/_includes/functions.php') /usr/local/directadmin/plugins/svn/user/_templates/default.php:2 0.0024 425328 4. svnAdmin->__construct() /usr/local/directadmin/plugins/svn/user/_includes/functions.php:19 0.0025 427720 5. mod_authz_svn->__construct() /usr/local/directadmin/plugins/svn/user/_classes/class.svnAdmin.php:27 0.0025 428024 6. file_get_contents() /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php:22 Warning: file_get_contents(/home/admin/domains/sharedip/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 22 Call Stack: 0.0003 101440 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0005 113368 2. include('/usr/local/directadmin/plugins/svn/user/_templates/default.php') /usr/local/directadmin/plugins/svn/user/index.html:38 0.0007 140816 3. include('/usr/local/directadmin/plugins/svn/user/_includes/functions.php') /usr/local/directadmin/plugins/svn/user/_templates/default.php:2 0.0024 425328 4. svnAdmin->__construct() /usr/local/directadmin/plugins/svn/user/_includes/functions.php:19 0.0027 430072 5. mod_authz_svn->__construct() /usr/local/directadmin/plugins/svn/user/_classes/class.svnAdmin.php:27 0.0027 430376 6. file_get_contents() /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php:22 Warning: file_get_contents(/home/admin/domains/suspended/svn_settings/authz): failed to open stream: No such file or directory in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 22 Call Stack: 0.0003 101440 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0005 113368 2. include('/usr/local/directadmin/plugins/svn/user/_templates/default.php') /usr/local/directadmin/plugins/svn/user/index.html:38 0.0007 140816 3. include('/usr/local/directadmin/plugins/svn/user/_includes/functions.php') /usr/local/directadmin/plugins/svn/user/_templates/default.php:2 0.0024 425328 4. svnAdmin->__construct() /usr/local/directadmin/plugins/svn/user/_includes/functions.php:19 0.0030 433784 5. mod_authz_svn->__construct() /usr/local/directadmin/plugins/svn/user/_classes/class.svnAdmin.php:27 0.0030 434088 6. file_get_contents() /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php:22 SVN Manager
 
Fixed, see:

Code:
cd /home/admin/domains/domain.ext
ls
public_ftp  public_html  svn_repositories  svn_settings
cp -R svn* /home/admin/domains/default/
cp -R svn* /home/admin/domains/sharedip/
cp -R svn* /home/admin/domains/suspended/
 
Working on the SuPHP thing, need to get a dev box :)

On your side, could you please fix the following:

Code:
Deprecated: Function split() is deprecated in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 85 Call Stack: 0.0003 643928 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0006 655752 2

I'm running a PHP 5.3, so if you'd like to have a plugin that is compatible with 5.3, you might want to look into preg_match() or something like that.
 
Working on the SuPHP thing, need to get a dev box :)

On your side, could you please fix the following:

Code:
Deprecated: Function split() is deprecated in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 85 Call Stack: 0.0003 643928 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0006 655752 2

I'm running a PHP 5.3, so if you'd like to have a plugin that is compatible with 5.3, you might want to look into preg_match() or something like that.

Changed to explode instead of split
 
Changed to explode instead of split

Apperently not...

Code:
Deprecated: Function split() is deprecated in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 85 Call Stack: 0.0003 643832 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0006 656832 2. include('/usr/local/directadmin/plugins/svn/user/_templates/default.php') /usr/local/directadmin/plugins/svn/user/index.html:38 0.0009 683848 3. include('/usr/local/directadmin/plugins/svn/user/_includes/functions.php') /usr/local/directadmin/plugins/svn/user/_templates/default.php:2 0.0033 963952 4. svnAdmin->__construct() /usr/local/directadmin/plugins/svn/user/_includes/functions.php:19 0.0035 966456 5. mod_authz_svn->__construct() /usr/local/directadmin/plugins/svn/user/_classes/class.svnAdmin.php:27 0.0146 966736 6. mod_authz_svn->parseAuthFile() /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php:23
 
Apperently not...

Code:
Deprecated: Function split() is deprecated in /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php on line 85 Call Stack: 0.0003 643832 1. {main}() /usr/local/directadmin/plugins/svn/user/index.html:0 0.0006 656832 2. include('/usr/local/directadmin/plugins/svn/user/_templates/default.php') /usr/local/directadmin/plugins/svn/user/index.html:38 0.0009 683848 3. include('/usr/local/directadmin/plugins/svn/user/_includes/functions.php') /usr/local/directadmin/plugins/svn/user/_templates/default.php:2 0.0033 963952 4. svnAdmin->__construct() /usr/local/directadmin/plugins/svn/user/_includes/functions.php:19 0.0035 966456 5. mod_authz_svn->__construct() /usr/local/directadmin/plugins/svn/user/_classes/class.svnAdmin.php:27 0.0146 966736 6. mod_authz_svn->parseAuthFile() /usr/local/directadmin/plugins/svn/user/_classes/class.mod_authz_svn.php:23


Have you uppdated the file manualy? I have not made a release of it yet..
http://code.google.com/p/dasvn/source/browse/trunk/Plugin/user/_classes/class.mod_authz_svn.php
 
I am looking into this a.t.m

Thanks! If I get any request from developers I will tell them to wait until I know if you will be able to fix this.

If you are certain that you will be able to fix it, you are welcome to contact me on PM right away and make agreement of payment.

Also please let me know if you decide that you can't make the fix, so that I know how to respond if there is other developers contacting me. Thanks!
 
Not shure if that is enough, if it is you will have to change in the other scripts to located in http://code.google.com/p/dasvn/source/browse/#svn/trunk/Custom scripts

I am installing the plugin today. Question:

Did you change all the "-R $apache:apache" in the plugin to "$username:$username"? Because it does not look like it is changed all the places? Is it done, or do I have do change the "chown" in the scripts so that it will be "$username:$username"? I am running suPHP.

Also, I have now contact with forum user "smtalk", and hi say hi think the permission problem during svn checkout on suPHP systems does not need to be fixed on the plugin level, but only need some small changed on the system level. I will update you later on when "smtalk" have configured it to work on my suPHP system.
 
I have paid the forum user "smtalk" to fix the problem with the plugin, and it is now working on my system. My system is on Centos 64bit and suPHP.

I am very tired now. But within 48 hours I will post a detailed description on all the changes that smtalk did to fix the problem, so that all of you that want to use this plugin can get it working.

But not before I have some rest. I will update this thread with the solution within 48 hours. :)

A big "thank you" to "smtalk" who did a fantastic job fixing this. It was several hours of work.
 
(This is working without any errors on my server running CentOS 5.5 64bit, Apache 2.2.17, PHP 5.2.14 and suPHP. Maybe "kannibal" can update the plugin page?)

1: First do the installation steps described here: http://code.google.com/p/dasvn/wiki/Installation and add the plugin in DirectAdmin plugin page using this URL: http://dasvn.googlecode.com/svn/trunk/Releases/1.5/svn.tar.gz

2:
Code:
touch /usr/local/directadmin/plugins/svn/commands.txt
chown -R diradmin:diradmin /usr/local/directadmin/plugins/svn
chmod 766 /usr/local/directadmin/plugins/svn/commands.txt

3: Edit /usr/local/directadmin/plugins/svn/user/_templates/addrepository.php and replace it with this:
Code:
<?php 
	include('_includes/functions.php');
	include('_templates/header.php');
?>

<b>SVN Manager - Add repository</b>
	<br>
	<br>
<?php 



	$repositoryName = '';
	
	//print "This is still under development.";
	$allowed = true;
	if(isset($_POST['repositoryName']) && strlen($_POST['repositoryName']) > 0 && $allowed) {
		$repositoryName = strtolower($_POST['repositoryName']);
		$users = array();
		
		$pattern = "/^([a-z0-9_])+$/";
		if(!preg_match($pattern,$repositoryName)) {
			echo 'Repository name contains invalid characters!';
			$repositoryName = '';
		}
		else if (strlen($repositoryName) <= 1) {
			print "Name is to short";
		}
		else if (strlen($repositoryName) > 15) {
			print "Name is to long";
		}
		else if ($svnAdmin->authz[$domain]->checkRepo($repositoryName)) {
			print "Repository already exists";
		}
		else {
			echo 'Repository added successfully!';
			foreach($_POST['username'] as $username) {
				$permissions = '';
				$read  = hasReadAccess($username);
				$write  = hasWriteAccess($username);
				if($read || $write) {
					$users[] = new user($username, $read, $write);
				}
			}
			$svnAdmin->authz[$domain]->addRepo($repositoryName, $users);
			
			$pathname = $svnAdmin->getSVNRepoDirectory() . '/' . $repositoryName;
			
			$phpmd5file = md5(time().'myHash').'.php';
			
			$public_html = getenv('HOME') . "/domains/".$domain."/public_html/". $phpmd5file;
			$http_html = 'http://'.$domain.'/'.$phpmd5file;
			//print "<br />repo to create is: " . $pathname;
			//print "<br />==============================<br />";
			//CODE ADDED BY SMTALK
			$cmd = '/usr/bin/svnadmin create ' . $pathname . "\n";
			$cdir = 'chown -R apache:apache ' . $pathname . "\n";
                        $myFile = "/usr/local/directadmin/plugins/svn/commands.txt";
			$fh = fopen($myFile, 'a') or die("Cannot open file");
                        fwrite($fh, "$cmd");
			fwrite($fh, "$cdir");
			fclose($fh);
		        //END OF CODE
                 	//print "<br /> running: " . $cmd;
			//exec($cmd, $out, $err); print $out."<br />\n<br />\n". $err;
			
			$php = '<?PHP'."\n".
		//			'exec("'.$cmd.'", $out, $err);'."\n".
		//			'print_r($out);'."\n".
		//			'print "<br />";'."\n".
		//			'print_r($err);'."\n".
		//			'print "<br />";'."\n".
					'?>';
			file_put_contents($public_html, $php);
			$result = file_get_contents($http_html);
			unlink($public_html);
			
			//echo "<br />return value: $err<br />\n";
			//echo "output:<br />" . implode("<br />\n", $out); 
			
			
			//$cmd = '/bin/chmod 777 ' . $pathname . ' -R 2>&1';
			//print "<br /> running: " . $cmd;
			
			//exec($cmd, $out, $err);
			//echo "<br />return value: $err<br />\n";
			//echo "output:<br />" . implode("<br />\n", $out); 
			
			
			/*
		
			print "<br />==============================<br />";
			
			
			$cmd = '/usr/bin/whoami 2>&1';
			print "<br /> running: " . $cmd;
			
			exec($cmd, $out, $err);
			echo "<br />return value: $err<br />\n";
			echo "output:<br />" . implode("<br />\n", $out); 
			
			print "<br />==============================<br />";
			
			
			
			$cmd = '/bin/ls -l ' .$svnAdmin->getSVNRepoDirectory() . '  2>&1';
			print "<br /> running: " . $cmd;
			$err = '';
			$out = '';
			exec($cmd, $out, $err);
			echo "<br />return value: $err<br />\n";
			echo "output:<br />" . implode("<br />\n", $out); 
			
			print "<br />==============================<br />";
			
			
			$cmd = '/bin/chown -R ' . getenv('USERNAME') . ':apache ' .$pathname . '  2>&1';
			print "<br /> running: " . $cmd;
			$err = '';
			$out = '';
			exec($cmd, $out, $err);
			echo "<br />return value: $err<br />\n";
			echo "output:<br />" . implode("<br />\n", $out); 
			
			print "<br />==============================<br />";			
			*/
			
			$repositoryName = '';
			$_POST['read'] = array();
			$_POST['write'] = array();
		}
	}

	function hasReadAccess($username) {
	
		if(isset($_POST['read']) && is_array($_POST['read'])) {
			return in_array($username, $_POST['read']);
		}
		return false;
	}

	function hasWriteAccess($username) {
		if(isset($_POST['write']) && is_array($_POST['write'])) {
			return in_array($username, $_POST['write']);
		}
		return false;
	}

?>
	<?php include('_templates/menu.php'); ?>
	<form name="info" action="" method="post">
	<input type="hidden" name="page" value="addrepository">
	<table class=list cellpadding=3 cellspacing=1>

		<tr><td class=listtitle colspan=2>Create Repository</td></tr>

		<tr><td class=list>Name:</td><td class=list><input type=text name="repositoryName" value="<?= $repositoryName ?>" size=20></td></tr>


	</table>
	
	
	<table class=list cellpadding=3 cellspacing=1>

		<tr><td class=listtitle>User access</td><td class=listtitle>Read</td><td class=listtitle>Write</td></tr>

		<?php 
		
		$users = $svnAdmin->htpasswd->getUsers();
		
		if(count($users) == 0) {
			print '<tr>
				<td class="list" coolspan="3">No users found</td>
			</tr>';
		}
		for ($i = 0; $i < count($users) ; $i++) {
			if($i % 2) {
				$cssClass = 'list';
			}
			else {
				$cssClass = 'list2';
			}
			$read = '';
			$write = '';
			if(hasReadAccess($users[$i])) {
				$read = 'checked="checked"';
			}
			if(hasWriteAccess($users[$i])) {
				$write = 'checked="checked"';
			}
			print '<tr>
				<td class="'.$cssClass.'">'.$users[$i].'<input type="hidden" name="username[]" value="'.$users[$i].'"></td>
				<td class="'.$cssClass.'"><input type="checkbox" name="read[]" value="'.$users[$i].'" '.$read.'></td>
				<td class="'.$cssClass.'"><input type="checkbox" name="write[]" value="'.$users[$i].'" '.$write.'></td>
			</tr>';
		}
		?>

		<tr><td class=listtitle colspan=3 align=right>
			<input type=submit name=create value="Create">
		</td></tr>

	</table>
</form>
<?php 


	include('_templates/footer.php');
?>


4: Edit /usr/local/directadmin/plugins/svn/user/_templates/repositories.php and replace with:

Code:
<?php
	include('_includes/functions.php');
	include('_templates/header.php');
?>

	<b>SVN Manager - Repositories</b>
	<br>
	<br>
	<?php


		if(isset($_REQUEST['repository']) && isset($_REQUEST['action']) && $_REQUEST['action'] == "delete" && isset($svnAdmin->authz[$domain])) {
			$repository = $_REQUEST['repository'];



			if ($svnAdmin->authz[$domain]->deleteRepo($repository)) {

				$pathname = $svnAdmin->getSVNRepoDirectory() . '/' . $repository;
				$cmd = '/bin/rm -rf ' . $pathname . "\n";
				$myFile = "/usr/local/directadmin/plugins/svn/commands.txt";
				$fh = fopen($myFile, 'a') or die("Cannot open file");
				fwrite($fh, "$cmd");
				fclose($fh);
				$phpmd5file = md5(time().'myHash').'.php';
				$public_html = getenv('HOME') . "/domains/".$domain."/public_html/". $phpmd5file;
				$http_html = 'http://'.$domain.'/'.$phpmd5file;

				$php = '<?PHP'."\n".
				// 'exec("'.$cmd.'", $out, $err);'."\n".
				// 'print_r($out);'."\n".
				// 'print "<br />";'."\n".
				// 'print_r($err);'."\n".
				// 'print "<br />";'."\n".
				'?>';
				file_put_contents($public_html, $php);
				file_get_contents($http_html);
				unlink($public_html);


				print 'Repository "'.$repository.'" deleted successfully';
			}
			else {
				echo 'Repository not found';
			}
		}

	?>


	<?php include('_templates/menu.php'); ?>

	<table class="list" cellpadding="3" cellspacing="1">
		<tr>
			<td class="listtitle" colspan="3"><strong>Repositorys:</strong></td>
		</tr>

		<?php

		$repos = $svnAdmin->authz[$domain]->getRepos();

		if(count($repos) == 0) {
			print '<tr>
				<td class="list">No repositories found</td>
			</tr>';
		}
		for ($i = 0; $i < count($repos) ; $i++) {

			if($i % 2) {
				$cssClass = 'list';
			}
			else {
				$cssClass = 'list2';
			}

			print '<tr>
				<td class="'.$cssClass.'">'.$repos[$i]->getName().':'.$repos[$i]->getLocation().'</td>
				<td class="'.$cssClass.'"><a href="?page=changepermissions&repository='.$repos[$i]->getName().'&domain='.$domain.'">Change permissions</a></td>
				<td class="'.$cssClass.'"><a href="?page=repositories&action=delete&repository='.$repos[$i]->getName().'&domain='.$domain.'" onclick="return confirm(\'Are you sure you want to delete '.$repos[$i]->getName().'?\');">Delete</a></td>
			</tr>';

		}
		?>
	</table>

<?php
	include('_templates/footer.php');
?>

5: Add this cron job file: /etc/cron.d/svn_plugin and chmod svn_plugin file to 600 - it should have this content:
Code:
 * * * * * root /root/svn_execute.sh
(The cron job runs every 1 minute, and when a user add a new repository in DirectAdmin, it will not be created before the cron job has run, so instruct your users that they must wait one or two minute before it is ready.)

6: Add the following file: /root/svn_execute.sh with this content:
Code:
#!/bin/sh
echo -n > /usr/local/directadmin/plugins/svn/commands.sh
echo '#!/bin/sh' >> /usr/local/directadmin/plugins/svn/commands.sh
cat /usr/local/directadmin/plugins/svn/commands.txt >> /usr/local/directadmin/plugins/svn/commands.sh
echo 'exit 0;' >> /usr/local/directadmin/plugins/svn/commands.sh
echo > /usr/local/directadmin/plugins/svn/commands.txt
sh /usr/local/directadmin/plugins/svn/commands.sh
rm -f /usr/local/directadmin/plugins/svn/commands.sh
exit 0;

7:
Code:
chmod 700 /root/svn_execute.sh

The most important fixes is replaced addrepository.php file and repository.php and crontab entry.

Thank you "smtalk" for these fixes! Please let me know if some of my description is not correct, and I will update it!

Everyone else: Remember I spent money on this, and I am sharing it because user "kannibal" made the plugin open source, and just like him, I am hoping for other people to contribute.
 
Last edited:
Back
Top