Commits

joshjcarrier  committed 2cf4300

- hgweb.config and the repositories can now exist in separate directories
- error suppression when invalid absolute paths set
- auto-insertion bug which re-added all folders in the repo directory on create/delete, even if not formally registered
- blacklists creation of a repo derived from config 'base_url' instead of value "admin"
where $config['base_url'] = http://www.contoso.com/hgadmin will blacklist "hgadmin"
- missed translation items in hgdir controller
- add the default /lock directory to source controll

  • Participants
  • Parent commits 5ad3d86

Comments (0)

Files changed (8)

 http://redirect.joshjcarrier.com/?r=hgwebinstall
 
 More information available on the blog.
-Last updated: 5/19/2010
 ==============================
 Author: Josh Carrier <josh@joshjcarrier.com>
 Web: http://redirect.joshjcarrier.com/?r=hgphp
 
+Changelog:
+1.0.20100603
+- hgweb.config and the repositories can now exist in separate directories
+- error suppression when invalid absolute paths set
+- auto-insertion bug which re-added all folders in the repo directory on create/delete, even if not formally registered
+- blacklists creation of a repo derived from config 'base_url' instead of value "admin"
+	where $config['base_url'] = http://www.contoso.com/hgadmin will blacklist "hgadmin"
+- missed translation items in hgdir controller
+Upgrade warning: there are new items in hgphp.php configuration file, and some revised existing parameters.
+
+1.0.20100519
+- initial release
+
 
 -- Disclaimer --
 This application contains code written by other developers

File admin/application/config/hgphp.php

 $config['hgwebconf_allow_repo_delete'] = true;
 
 /*
+ * Absolute local path and filename to where the hgweb.config file is saved
+ * E.g. /home/jcarrier/htdocs/hg/hgweb.config
+ */
+$config['hgwebconf_abs_filepath'] = '/host/Users/jcarrier/workspace/hg-php.joshjcarrier.com/cgi-bin/hgweb.config';
+
+/*
  * Accessing the Mercurial repository.
  * This management tool assumes all Mercurial repositories reside in one location.
  * *Note: Update the repository listings (i.e. create a new repository) to put this value in to effect on hgweb.config.
  * Must be writable by web server.
+ * Trailing slash required!
+ * E.g. /home/jcarrier/hg_repositories/
  */
-$config['repositories_abs_dir'] = '/host/Users/jcarrier/workspace/hg-php.joshjcarrier.com/cgi-bin/'; // absolute path, trailing slash required
+$config['repositories_abs_dir'] = '/host/Users/jcarrier/workspace/hg-php.joshjcarrier.com/cgi-bin/';
 
 /*
  * Manager theme - mimics available Mercurial themes
  */
 $config['hgrc_default_arr'] = array(
 		'paths' => array(
-			'default' 			=> 	'http://localhost' // no trailing slash, project name automatically appended
+			'default' 			=> 	'http://localhost/%s' // project name denoted by %s
 		),
 			
 		'web' => array(
 			'allow_read' 		=> 	'',
 			'contact' 			=> 	'',
 			'description' 		=> 	'',
-			'name' 				=> 	'', // project name automatically appended
+			'name' 				=> 	'%s', // project name denoted by %s
 			'push_ssl' 			=> 	'false',
 			'style' 			=> 	'',
 		)
  * Lock directory. For optimistic lock management and php-ini compatability scratch space.
  * Must be writable by web server.
  */
-$config['lock_dir'] = './lock/'; // abs or rel path, trailing slash required
+$config['lock_dir'] = './lock/'; // abs or rel path from admin/index.php, trailing slash required
 $config['lock_ofl_index'] = 'ofl_index.dat';
 $config['compatability_delimiter'] = '----';
 $config['ofl_disabled'] = false; // highly recommended not to turn the optimistic lock manager off
 define('HGPHP_REPO_STATUS_DISABLED', 0);
 define('HGPHP_REPO_STATUS_MISSING', 2);
 
-define('HGPHP_VERSION', '1.0.20100519');
+define('HGPHP_VERSION', '1.0.20100603');
 define('HGPHP_AUTHOR_NAME', 'Josh Carrier');
 define('HGPHP_AUTHOR_LINK', 'http://www.joshjcarrier.com');
 

File admin/application/controllers/hgdir.php

 		$this->template->title(lang('hgphp_title_directory'), 'Mercurial Repository Manager');
 
 		$lsdir = $this->hgphp->lsdir($this->ofl_lock_hgwebconf);
+		
+		if(!is_array($lsdir))
+		{
+			$this->template->inject_partial('user_err', lang('hgphp_msg_hgwebconf_read_err_absdirs'));
+		}
+		
 		$this->session->set_flashdata('ofl_hgwebconf', $this->ofl_lock_hgwebconf);
 		$this->template->build('repo_directory', array('lsdir'=>$lsdir));
 	}
 		$r_name = $this->input->post('form_create_name');
 		$this->form_validation->set_rules('form_create_name', 'form_create_name', 'required|alpha_dash|min_length[1]|max_length[255]');
 			
+		$blacklist = '';
+		$path = @parse_url($this->config->item('base_url'), PHP_URL_PATH);
+		if($path !== FALSE)
+		{
+			$components = @explode('/', $path);
+			if(isset($components[1]))
+			{
+				$blacklist = $components[1];
+			}
+		}
+		
 		if ($this->form_validation->run() == FALSE)
 		{
-			$this->template->inject_partial('user_err', 'Creating a repository requires a valid name:<li>contains only alpha-numerics, dashes or underscores<li>between 1 and 255 characters long');
+			$this->template->inject_partial('user_err', lang('hgphp_msg_hgwebconf_create_err_validname'));
 		}
-		else if($r_name == 'admin')
+		else if($r_name == $blacklist)
 		{
-			$this->template->inject_partial('user_err', 'Creating a repository cannot have the reserved name "admin".');
+			$this->template->inject_partial('user_err', lang(''));
 		}
 		else
 		{
 					$this->template->inject_partial('user_err', $r_name .': ' . lang('hgphp_msg_hgwebconf_create_err_permsys'));
 					break;
 				case -100:
-					$this->template->inject_partial('user_msg', 'Repository "'. $r_name .'" RESTORE.');
+					$this->template->inject_partial('user_msg', 'Repository "'. $r_name .'" RESTORE UNSUPPORTED.');
 					break;
 				case HGPHP_ERR_FS_PREEXISTS:
 					$this->template->inject_partial('user_err', 'Repository "'. $r_name .': ' . lang('hgphp_msg_hgwebconf_create_err_preexists'));
 			
 		if ($this->form_validation->run() == FALSE)
 		{
-			$this->template->inject_partial('user_err', 'Deleting a repository requires specifying an existing entry.');
+			$this->template->inject_partial('user_err', lang('hgphp_msg_hgwebconf_delete_err_unspecified_name'));
 		}
 		else
 		{
 					$this->template->inject_partial('user_err', $r_name .': ' . lang('hgphp_msg_hgwebconf_delete_err_permsys'));
 					break;
 				case HGPHP_ERR_FS_PREEXISTS:
-					$this->template->inject_partial('user_err', 'Repository "'. $r_name .': ' . lang('hgphp_msg_hgwebconf_delete_err_preexists'));
+					$this->template->inject_partial('user_err', $r_name .': ' . lang('hgphp_msg_hgwebconf_delete_err_preexists'));
 					break;	
 				case OFL_ERR_LOCKING:
 					$this->template->inject_partial('user_err', $r_name .': ' . lang('hgphp_msg_hgwebconf_delete_err_locking') . ' <a href="'.site_url('/hgdir').'" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span>'.lang('hgphp_action_reload').'</a>');

File admin/application/language/english/hgphp_lang.php

 $lang['hgphp_repostatus_missing'] = 'Missing';
 $lang['hgphp_repostatus_disabled'] = 'Disabled';
 
+$lang['hgphp_msg_hgwebconf_read_err_absdirs'] = 'Problem scanning repository directory. Check configuration paths to hgweb.config and the repositories and that the server has write permissions to both.';
+
 $lang['hgphp_msg_hgwebconf_create_success'] = 'Repository created successfully.';
+$lang['hgphp_msg_hgwebconf_create_err_validname'] = 'Creating a repository requires a valid name:<li>contains only alpha-numerics, dashes or underscores<li>between 1 and 255 characters long.';
+$lang['hgphp_msg_hgwebconf_create_err_blacklistname'] = 'Creating a repository name cannot match the path reserved for Hg-PHP.';
 $lang['hgphp_msg_hgwebconf_create_err_permuser'] = 'Repository could not be created; insufficient user privileges.';
 $lang['hgphp_msg_hgwebconf_create_err_permsys'] = 'Repository could not be created; insufficient server privileges.';
 $lang['hgphp_msg_hgwebconf_create_err_preexists'] = 'Repository could not be created; it already exists.';
 
 $lang['hgphp_msg_hgwebconf_delete_success'] = 'Repository deleted successfully.';
 $lang['hgphp_msg_hgwebconf_delete_err_permuser'] = 'Repository could not be deleted; insufficient user privileges.';
+$lang['hgphp_msg_hgwebconf_delete_err_unspecified_name'] = 'Deleting a repository requires specifying an existing entry.';
 $lang['hgphp_msg_hgwebconf_delete_err_permsys'] = 'Repository could not be deleted; insufficient server privileges.';
 $lang['hgphp_msg_hgwebconf_delete_err_preexists'] = 'Repository could not be deleted; it already exists.';
 $lang['hgphp_msg_hgwebconf_delete_err_locking'] = 'Could not complete deletion.<br />Configuration had been modified since last loaded.';

File admin/application/libraries/hgconf2ini.php

 	{
 		$hgwebconf_all = $this->getHgWebDirConfig($ofl_lock_hgwebconf);
 		
-		if(is_array($hgwebconf_all))
+		if(!is_integer($hgwebconf_all))
 		{
 			return $hgwebconf_all['collections'];
 		}
 	{
 		// automatic appending
 		$blank_hgrc = $this->_hgrc_default_arr;
-		$blank_hgrc['paths']['default'] .= '/' . $r_name;
-		$blank_hgrc['web']['name'] .= $r_name;
+		$blank_hgrc['paths']['default'] = sprintf($blank_hgrc['paths']['default'], $r_name);
+		$blank_hgrc['web']['name'] = sprintf($blank_hgrc['web']['name'], $r_name);
 		
 		return $blank_hgrc;
 	}
 	 */
 	function __hgwebconf_compat_load(&$ofl_hgwebconf)
 	{
-		$fs_hgwebdir = 'hgweb.config';
-		
 		// load the PHP to file
-		$hgwebconf = $this->_repositories_abs_dir . $fs_hgwebdir;
+		$hgwebconf = $this->_hgwebconf_abs_filepath;
 
 		// concurrency-safe get contents
 		$hgwebconf_err_code = '';
 			$hgwebconf_tmp_name = $this->_lock_dir . uniqid('hgweb.config.lock.', TRUE);
 			$hgwebconf_tmp_fp = @fopen($hgwebconf_tmp_name, 'x');		
 			$put_status = @fwrite($hgwebconf_tmp_fp, $hgwebconf_str);
-			
+			@fclose($hgwebconf_tmp_fp);
 			if($put_status != FALSE)
 			{
 				// load the new compat ini
-				@fclose($hgwebconf_tmp_fp);
+				
 				// maintain PHP<5.3 compatability, instead of using parse_ini_string
 				$hgwebconf_all = @parse_ini_file($hgwebconf_tmp_name, TRUE);
 				@unlink($hgwebconf_tmp_name);
 				
 				return $hgwebconf_all;
 			}
+			return HGPHP_ERR_PERM_SYS_TMPFILE;
 		}
-		return HGPHP_ERR_PERM_SYS_TMPFILE;
+		return $hgwebconf_err_code;
 	}
 	
 	
 	 */
 	function __hgwebconf_compat_persist($hgwebconf_all, &$ofl_lock)
 	{
-		$fs_hgwebdir = 'hgweb.config';
-		
 		$hgwebconf_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager v'.HGPHP_VERSION;
 		// generate ini string
 		if(isset($hgwebconf_all) && is_array($hgwebconf_all))
 		$hgwebconf_new_ini = str_replace($this->_compatability_delimiter, '/', $hgwebconf_new_ini);
 		
 		// concurrent-safe write
-		$put_status = $this->_ci->optimisticflock->ofl_file_put_contents($this->_repositories_abs_dir . $fs_hgwebdir, $hgwebconf_new_ini, $ofl_lock);
+		$put_status = $this->_ci->optimisticflock->ofl_file_put_contents($this->_hgwebconf_abs_filepath, $hgwebconf_new_ini, $ofl_lock);
 		
 		return $put_status;
 	}

File admin/application/libraries/hgphp.php

 		$realdir = $this->__realdirscan();
 		$hgwebdir_compat = $this->_ci->hgconf2ini->getHgWebDirCollections($ofl_lock_hgwebconf);
 				
-		$allrepo = array_merge($realdir, $hgwebdir_compat);
+		$allrepo = $realdir;
+		if(!is_integer($hgwebdir_compat))
+		{
+			$allrepo = array_merge($realdir, $hgwebdir_compat);
+		}
+		else
+		{
+			// error code
+			return $hgwebdir_compat;
+		}
 		
 		$hgrepos = array();
 		foreach($allrepo as $repo)
 		
 		$create_status = HGPHP_OK;
 		$ofl_dummylock_hgwebconf = '';
-		$lsdir = $this->lsdir($ofl_dummylock_hgwebconf); // don't want to update the lock yet
+		$lsdir = $this->_ci->hgconf2ini->getHgWebDirCollections($ofl_dummylock_hgwebconf); // don't want to update the lock yet
 
 		// simplifies repo list into array where name is both key and value
 		// this is how hgweb.config wants it
-		$existingdir = array_keys($lsdir);
+		$existingdir = array();
+		
+		if(!is_integer($lsdir))
+		{
+			$existingdir = array_keys($lsdir);
+		}
+		else
+		{
+			// error code
+			return $lsdir;
+		}
+		
 		$tempexistingdir = array();
 		foreach($existingdir as $repo_name)
 		{
 		
 		$del_status = HGPHP_OK;
 		$ofl_dummylock_hgwebconf = '';
-		$lsdir = $this->lsdir($ofl_dummylock_hgwebconf); // don't want to update lock yet
+		$lsdir = $this->_ci->hgconf2ini->getHgWebDirCollections($ofl_dummylock_hgwebconf); // don't want to update lock yet
 		
 		// simplifies repo list into array where name is both key and value
 		// this is how hgweb.config wants it
 		$realdir = directory_map($this->_repositories_abs_dir, TRUE);
 		
 		$verifiedrealdir = array();
-		foreach($realdir as $file)
+		if(is_array($realdir))
 		{
-			// checks if we detected a folder
-			if(is_dir($this->_repositories_abs_dir . $file))
+			foreach($realdir as $file)
 			{
-				$verifiedrealdir[$file] = $file;
+				// checks if we detected a folder
+				if(is_dir($this->_repositories_abs_dir . $file))
+				{
+					$verifiedrealdir[$file] = $file;
+				}
 			}
 		}
 		

File admin/application/views/repo_directory.php

         <th><?php echo lang('hgphp_title_status'); ?></th> 
         <th></th> 
     </tr> 
-<?php $parity=0; if(isset($lsdir)): foreach($lsdir as $repo): ?>
+<?php $parity=0; if(is_array($lsdir)): foreach($lsdir as $repo): ?>
 	<tr class="parity<?php echo $parity; $parity=($parity+1)%2;?>">
 	  <td>
 		<input type="checkbox" disabled="disabled"/>

File admin/lock/why.tmp

+this is the default lock writing directory. this file preserves folder structure when source-controlled.