Commits

Anonymous committed 325d484

- most of 1.0 functionality restored (need to verify)
- TODO code commenting, remaining minor config integration, begin new features

Comments (0)

Files changed (8)

 Pre-requisites:
 * server supports Mercurial (visit web site for more information)
 * server supports PHP
-* all files and folders are writable by the server in:
-	* cgi-bin, where Mercurial holds it's configuration and repositories
-	* /admin/lock, where this application exercises optimistic locking and has a small amount of scratch space
+* all files and folders are writable by the server where:
+	* folders where Mercurial holds it's configuration and repositories
+	* ./lock directory, where this application exercises optimistic locking and has a small amount of scratch space
 
 Configuration files:
 Must revise and edit these configuration files before installation is complete. In /admin/application/config/:
-	* config.php - standard CodeIgniter setup
-	* hgphp.php - Mercurial-related defaults
+	* phphgadmin.php - Mercurial-related defaults
 						
 This system was designed for use with the quick Hg installation guide available at:
 http://redirect.joshjcarrier.com/?r=hgwebinstall
 Web: http://redirect.joshjcarrier.com/?r=hgphp
 
 Changelog:
-1.0.2010xxxx
-- 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
+1.1.xxx (unstable)
+- rebranded to phpHgAdmin
+- framework revised
+- support for multiple hgweb.config
+- much more customizable and flexible installation
 - 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
-- installation portability
-- rebranded to phpHgAdmin
-Upgrade warning: there are new items in hgphp.php configuration file, and some revised existing parameters.
+- multiple bug fixes
+Upgrade warning: fresh install recommended due to significant changes.
 
 1.0.20100519
 - initial release

admin/application/config/phphgadmin.php

 <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
 
+
+$config['base_url']	= "http://localhost:8080/admin/";
+
 /*
  * Global permission levels, which override the authenticated user's permissions.
  * For when you want to completely lock down access.

admin/application/controllers/hgdir.php

 		{
 			$this->phphgadmin->start_tx($this->ofl_lock_hgwebconf, $dummy='');
 			$action_status = $this->phphgadmin->create_repository($r_name);
-			
-			if($action_status == HGPHP_OK)
-			{
-				$action_status = $this->hg_ini->touchHgRC($r_name);
-			}
 			$this->phphgadmin->end_tx();
 			
 			switch($action_status){
 	
 	function delete()
 	{
-		$r_key = $this->input->post('form_delete_name');
+		$r_name = $this->input->post('form_delete_name');
 		$this->form_validation->set_rules('form_delete_name', 'form_delete_name', 'required');
 			
 		if ($this->form_validation->run() == FALSE)
 		}
 		else
 		{
-			$r_name = base64_decode($r_key);
+//			$r_name = base64_decode($r_key);
 			$this->phphgadmin->start_tx($this->ofl_lock_hgwebconf, $dummy='');
-			$action_status = $this->phphgadmin->delete_repository($r_key);
+			$action_status = $this->phphgadmin->delete_repository($r_name);
 			$this->phphgadmin->end_tx();
 			
 			switch($action_status){

admin/application/libraries/hg_filesystem.php

 	 * @param r_name name of repository to create directory for
 	 * @return status code
 	 */
-	function create_repository_dir($r_name, $webdir = null)
+	function create_repository_dir($r_name, $hgweb = null)
 	{
-		$install_config = $this->_ci->hg_ini->getInstallConfig($webdir);
+		$install_config = $this->_ci->hg_ini->getInstallConfig($hgweb);
 		$repo_dir = $install_config['default_repo_dir'];
 		// create repo directory structure recursively
 		$create_status = @mkdir($repo_dir . $r_name . '/.hg/store/data/', 0755, TRUE);
 		if($create_status == TRUE)
 		{
 			// create hgrc
-			
-//			$this->_ci->hgconf2ini->register_OFL($this->_ofl_lock_hgrc);
-//			$create_status = $this->_ci->hgconf2ini->touchHgRC($r_name);
 			$create_status = HGPHP_OK;
 		}
 		else
 	 * @param r_name name of repository to delete directory of
 	 * @return status code
 	 */
-	function delete_repository_dir($repository_name, $webdir = null)
+	function delete_repository_dir($r_name, $hgweb = null)
 	{
-		// FIXME read from hgweb
-		$cd = 'C:\Users\joshjcarrier\workspace\hg-php.joshjcarrier.com\admin\lock\cgi-bin/' . $repository_name;
+		$cd = $this->_ci->hg_ini->getHgRCPath($r_name, $hgweb);
+		
 		$this->recursiveDelete($cd . '/.hg/');
 		$del_status = $this->recursiveDelete($cd);
 		if($del_status == TRUE)
 	 * 
 	 * @return the array containing 0 or more valid directories
 	 */
-	function real_dirscan()
+	function real_dirscan($hgweb = null)
 	{
 		$this->_ci->load->helper('directory');
 		
-		$realdir = directory_map('C:\Users\joshjcarrier\workspace\hg-php.joshjcarrier.com\admin\lock\cgi-bin/', TRUE);
+		$install_config = $this->_ci->hg_ini->getInstallConfig($hgweb);
+		$repo_dir = $install_config['default_repo_dir'];
+		
+		$realdir = directory_map($repo_dir, TRUE);
 		
 		$verifiedrealdir = array();
 		if(is_array($realdir))
 			foreach($realdir as $file)
 			{
 				// checks if we detected a folder
-				if(is_dir('C:\Users\joshjcarrier\workspace\hg-php.joshjcarrier.com\admin\lock\cgi-bin/' . $file))
+				if(is_dir($repo_dir . $file))
 				{
 					$verifiedrealdir[$file] = $file;
 				}

admin/application/libraries/hg_ini.php

 {
 	private $_ci;
 	
+	private $_ofl_lock;
 	private $_default_webdir;
 	private $_webdir_arr;
 	
 		$hgwebconf_all = $this->_ci->optimisticflock->ofl_parse_ini_file($ini_path, true, $this->_ofl_lock, $hgwebconf_err_code);
 		if($hgwebconf_err_code == HGPHP_OK)
 		{
-				return $hgwebconf_all;
+			return $hgwebconf_all;
 		}
 		return $hgwebconf_err_code;
 	}
 	
-	function saveHgWeb($r_name, $hgrc_data, $hgweb = null)
+	function saveHgWeb($hgrc_data, $hgweb = null)
 	{
 		// load the PHP to file
 		$install_config = $this->getInstallConfig($hgweb);
 		}
 	}
 	
-	function getHgRCPath($r_name, $hgweb)
+	function getHgRCPath($r_name, $hgweb = null)
 	{
 		$hgweb_ini = $this->loadHgWeb($r_name, $hgweb);
 		$repo_dir = $hgweb_ini->get($r_name, 'paths');
 	 * @param r_name name of the repo folder which will have an HGRC file added to
 	 * @return status code
 	 */
-	function touchHgRC($r_name)
+	function touchHgRC($r_name, $hgweb = null)
 	{
 		$hgrc_path = $this->getHgRCPath($r_name, $hgweb) . '/.hg/hgrc';
 		
 		// create file
+
 		$touch_status = $this->_ci->optimisticflock->ofl_touch($hgrc_path, $this->_ofl_lock);
 		if($touch_status == HGPHP_OK)
 		{
 			$blank_hgrc = $this->__blank_hgrc($r_name);
-			
 			// update touch status for setHGRC return code
 			$touch_status = $this->saveHgRC($r_name, $blank_hgrc);
 		}
 	 * @param hgrc_data multi-array representation of the new HGRC file
 	 * @return status code
 	 */
-	function saveHgRC($r_name, $hgrc_data)
+	function saveHgRC($r_name, $hgrc_data, $hgweb = null)
 	{
+		$dummy = '';
+		$ofl_lock = $this->_ofl_lock;
+		$this->_ofl_lock = &$dummy;
 		$hgrc_path = $this->getHgRCPath($r_name, $hgweb) . '/.hg/hgrc';
+		$this->_ofl_lock = &$ofl_lock;
 		
 		$hgrc_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager v'.HGPHP_VERSION;
 		

admin/application/libraries/iniparser.php

 		}
 	}
 	
-	function unsetKey($hashkey, $collection=null)
+	function unsetKey($hashkey, $collection=null, $pre_hashed = FALSE)
 	{
+		if(!$pre_hashed)
+		{
+			$hashkey = base64_encode($hashkey);
+		}
+		
 		if($collection != null)
 		{
 			$hashcollection = base64_encode($collection);

admin/application/libraries/phphgadmin.php

 			}
 		}
 		
-		foreach($hgwebrepos as $id => $repo)
-		{
-			$hgrepos[$repo]['id'] = $id;
-		}
+//		foreach($hgwebrepos as $id => $repo)
+//		{
+//			$hgrepos[$repo]['id'] = $id;
+//		}
 		
 		return $hgrepos;
 	}
 //		$existingdir = $tempexistingdir;
 		
 		// not registered in hgweb.config
-		if(!in_array($r_name, array_values($lsdir)))
+		
+		$hashr_name = base64_encode($r_name);
+//		print_r($lsdir);
+//		echo $hashr_name;
+		if(!isset($lsdir[$hashr_name]))
 		{
+			
 			// edit the directory
 //			$existingdir[$r_name] = $r_name;
 			$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgweb);
 			{
 				// then create the repository
 //				$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgrc);
+				$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgrc);
 				$create_status = $this->_ci->hg_filesystem->create_repository_dir($r_name);
+				
+				if($create_status == HGPHP_OK)
+				{
+					
+					$create_status = $this->_ci->hg_ini->touchHgRC($r_name);
+				}
 			}
 		}
 		else
 	 * @param r_key id of the repo to delete permanently
 	 * @return status code
 	 */
-	function delete_repository($r_key)
+	function delete_repository($r_key, $hgweb = null)
 	{
+		$hashr_key = base64_encode($r_key);
 		if(!$this->can_delete($r_key))
 		{
 			return HGPHP_ERR_PERM_USR;
 		
 		// simplifies repo list into array where name is both key and value
 		// this is how hgweb.config wants it
-		$existingdir = array_values($lsdir);
-		$tempexistingdir = array();
-		foreach($existingdir as $repo_name)
-		{
-			$tempexistingdir[$repo_name] = $repo_name;
-		}
-		$existingdir = $tempexistingdir;
-		
-		if(isset($lsdir[$r_key]))
+//		$existingdir = array_values($lsdir);
+//		$tempexistingdir = array();
+//		foreach($existingdir as $repo_name)
+//		{
+//			$tempexistingdir[$repo_name] = $repo_name;
+//		}
+//		$existingdir = $tempexistingdir;
+		if(isset($lsdir[$hashr_key]))
 		{
 			// edit the directory
-			
 			// remove hgweb.config
 			$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgweb);
 //			$del_status = $this->_ci->hgconf2ini->setHgWebDirCollections($existingdir);
 				
-			$del_status = $this->_ci->hg_ini->unregisterRepo($r_key);
+			$del_status = $this->_ci->hg_filesystem->delete_repository_dir($r_key);
+			
 			
 			// remove from hgweb.config
 			if($del_status == HGPHP_OK)
 //					
 //					if($del_status == HGPHP_OK)
 //					{
-						$del_status = $this->_ci->hg_filesystem->delete_repository_dir($lsdir[$r_key]);
+						$del_status = $this->_ci->hg_ini->unregisterRepo($r_key);
 //					}
 //				}
 			}
-			unset($existingdir[$r_key]);
+//			unset($existingdir[$r_key]);
 		}
 		else
 		{

admin/application/views/repo_directory.php

 						<br />
 						<select style="width:100%" name="form_delete_name" id="form_delete_name">
 							<option selected="selected" value=""></option>
-							<?php if(isset($lsdir)): foreach($lsdir as $repo): if(isset($repo['id'])): ?>
-							<option value="<?php echo $repo['id']; ?>"><?php echo $repo['name']; ?></option>
-							<?php endif; endforeach; endif; ?>
+							<?php if(isset($lsdir)): foreach($lsdir as $r_id => $repo): ?>
+							<option value="<?php echo $r_id; ?>"><?php echo $repo['name']; ?></option>
+							<?php endforeach; endif; ?>
 						</select>
 						<br />
 					</td>