Commits

Anonymous committed e3d97fd

Global permissions fix and case where hgrc missing

  • Participants
  • Parent commits 3a482a6

Comments (0)

Files changed (7)

admin/application/config/phphgadmin.php

  * Global permission levels, which override the authenticated user's permissions.
  * For when you want to completely lock down access.
  */
-$config['hgwebconf_allow_repo_create'] = true;
-$config['hgwebconf_allow_repo_update'] = true;
-$config['hgwebconf_allow_repo_view'] = true;
-$config['hgwebconf_allow_repo_delete'] = true;
+$config['global_allow_repo_create'] = true;
+$config['global_allow_repo_update'] = true;
+$config['global_allow_repo_view'] = true;
+$config['global_allow_repo_delete'] = true;
 
 /***********************
  * Not recommended to change once deployed beyond this point

admin/application/config/phphgadmin_core.php

 define('HGPHP_REPO_STATUS_MISSING', 2);
 
 define('HGPHP_NAME', 'phpHgAdmin Mercurial Repository Manager');
-define('HGPHP_VERSION', '1.0.20100612');
+define('HGPHP_VERSION', '1.1.20100612');
 define('HGPHP_AUTHOR_NAME', 'Josh Carrier');
 define('HGPHP_AUTHOR_LINK', 'http://www.joshjcarrier.com');
 

admin/application/controllers/hgrepo.php

 					case OFL_ERR_LOCKING:
 						$this->load->vars(array('user_err'=>lang('hgphp_msg_hgrc_save_err_locking') . '<a href="'.site_url('/hgrepo/manage/'.$repositoryName).'" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span>'.lang('hgphp_action_reload').'</a>'));
 						break;	
+					case OFL_ERR_NOTEXISTS_OR_PERM:
+						$this->load->vars(array('user_err'=>lang('hgphp_msg_hgrc_save_err_notfound')));
+						break;
 					default:
 						$this->load->vars(array('user_err'=>lang('hgphp_msg_unknown_err') . $save_status));
 						break;
 		$hgrc = $this->phphgadmin->stat_repository($repositoryName);
 		$this->phphgadmin->end_tx();
 		
-		if($hgrc === FALSE)
+		if(is_integer($hgrc) && $save_status === TRUE)
 		{
 			switch($hgrc)
 			{
-				case OFL_ERR_READING: 
+				case OFL_ERR_NOTEXISTS_OR_PERM: 
 					$this->load->vars(array('user_err'=>lang('hgphp_msg_hgrc_read_err')));
 					break;
 				default:
-					$this->load->vars(array('user_err'=>lang('hgphp_msg_hgrc_save_err_notfound') . $hgrc));
+					$this->load->vars(array('user_err'=>lang('hgphp_msg_unknown_err') . $hgrc));
 					break;
 			}
 		}

admin/application/helpers/hg_repo_helper.php

 	{
 		$ci =& get_instance();
 		$_hgrc_ini64 = $ci->phphgadmin->stat_repository(the_name());
-		$_sections = $_hgrc_ini64->get();
-		$_section_iter_keys = array_keys($_sections);
+		if(is_object($_hgrc_ini64))
+		{
+			$_sections = $_hgrc_ini64->get();
+			$_section_iter_keys = array_keys($_sections);
+		}
+		else
+		{
+			return FALSE;
+		}
 		$_section_iter_count = 0;
 		$_item_iter_count = 0;
 	}

admin/application/libraries/hg_ini.php

 	
 	function getHgRCPath($r_name, $hgweb = null)
 	{
-		$hgweb_ini = $this->loadHgWeb($r_name, $hgweb);
+		$hgweb_ini = $this->loadHgWeb($hgweb);
 		$repo_dir = $hgweb_ini->get($r_name, 'paths');
 		if(empty($repo_dir))
 		{
 		// load the PHP to file
 		
 		$hgwebconf = $this->getHgRCPath($r_name, $hgweb).'/.hg/hgrc';
-
+		
 		// concurrency-safe get contents
 		$hgwebconf_err_code = '';
 		$hgwebconf_all = $this->_ci->optimisticflock->ofl_parse_ini_file($hgwebconf, true, $this->_ofl_lock, $hgwebconf_err_code);
 	 * @param hgrc_data multi-array representation of the new HGRC file
 	 * @return status code
 	 */
-	function saveHgRC($r_name, $hgrc_data, $hgweb = null)
+	function saveHgRC($r_name, $hgrc_data, $profile = null)
 	{
 		$dummy = '';
 		$ofl_lock = $this->_ofl_lock;
 		$this->_ofl_lock = &$dummy;
-		$hgrc_path = $this->getHgRCPath($r_name, $hgweb) . '/.hg/hgrc';
+		$hgrc_path = $this->getHgRCPath($r_name, $profile) . '/.hg/hgrc';
 		$this->_ofl_lock = &$ofl_lock;
 		
 		$hgrc_new_ini = ';Generated by Hg-PHP Mercurial Repository Manager v'.HGPHP_VERSION;
 	function __blank_hgrc($r_name, $profile = null)
 	{
 		$profile_arr = $this->getInstallConfig($profile);
-		// automatic appending
+		// automatic variable management
 		$hgserve_url = $profile_arr['hgserve_url'];
 		$blank_hgrc = $profile_arr['default_hgrc'];
 		
 				$blank_hgrc[$c_name][$i_name] = sprintf($i_value, $hgserve_url, $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 new ini64($blank_hgrc);
 	}
 	
-	function getInstallConfig($hgwebdir = null)
+	function getInstallConfig($profile = null)
 	{
-		if(empty($webdir))
+		if(empty($profile))
 		{
-			$webdir = $this->_default_webdir;
+			$profile = $this->_default_webdir;
 		}
 		
-		return $this->_webdir_arr[$webdir];
+		return $this->_webdir_arr[$profile];
 	}
 }

admin/application/libraries/iniparser.php

 		}
 		else
 		{
-			foreach($values as $collection_name => $collection_value)
+			if(is_array($values))
 			{
-				$hashcollection_name = base64_encode($collection_name);
-				if(is_array($collection_value))
+				foreach($values as $collection_name => $collection_value)
 				{
-					foreach($collection_value as $key_name=>$key_value)
+					$hashcollection_name = base64_encode($collection_name);
+					if(is_array($collection_value))
 					{
-						$hashkey_name = base64_encode($key_name);
-						$this->_values[$hashcollection_name][$hashkey_name] = $key_value;
+						foreach($collection_value as $key_name=>$key_value)
+						{
+							$hashkey_name = base64_encode($key_name);
+							$this->_values[$hashcollection_name][$hashkey_name] = $key_value;
+						}
 					}
-				}
-				else
-				{
-					$this->_values[$hashcollection_name] = $collection_value;
+					else
+					{
+						$this->_values[$hashcollection_name] = $collection_value;
+					}
 				}
 			}
 		}
 	{
 		// generate ini string
 		$ini = '';
-		foreach($this->_values as $hashcollection_name => $collection_val)
+		if(is_array($this->_values))
 		{
-			$collection_name = base64_decode($hashcollection_name);
-			
-			if(is_array($collection_val))
+			foreach($this->_values as $hashcollection_name => $collection_val)
 			{
-				// section header
-				$ini .= "\n[".$collection_name.']';
+				$collection_name = base64_decode($hashcollection_name);
 				
-				foreach($collection_val as $hashkey_name => $key_val)
+				if(is_array($collection_val))
 				{
-					$key_name = base64_decode($hashkey_name);
-					$ini .= "\n" . $key_name . ' = ' . $key_val;
+					// section header
+					$ini .= "\n[".$collection_name.']';
+					
+					foreach($collection_val as $hashkey_name => $key_val)
+					{
+						$key_name = base64_decode($hashkey_name);
+						$ini .= "\n" . $key_name . ' = ' . $key_val;
+					}
+				}	
+				else
+				{
+					$ini .= "\n" . $collection_name . ' = ' . $collection_val;
 				}
-			}	
-			else
-			{
-				$ini .= "\n" . $collection_name . ' = ' . $collection_val;
 			}
 		}
 		return $ini;

admin/application/libraries/phphgadmin.php

 	private $_ofl_lock_hgweb;
 	private $_ofl_lock_hgrc;
 	
+	private $_cache;
+	
 	function __construct()
 	{
 		$this->_ci = &get_instance();
 		$this->_ci->load->library('Hg_Filesystem');
 		$this->_ci->load->library('Hg_Ini');
+		
+		$this->flush_cache();
 	}
 	
 	function start_tx(&$ofl_lock_hgweb, &$ofl_lock_hgrc)
 		$this->_ofl_lock_hgrc = &$dummy;
 	}
 	
+	function flush_cache()
+	{
+		$this->_cache = array();
+	}
+	
 	function lsdir($webdir = null)
 	{
+//		if(isset($this->_cache['lsdir']))
+//		{
+//			return $this->_cache['lsdir'];
+//		}
+		
 		// retrieves current directory structure
 		$realdir = $this->_ci->hg_filesystem->real_dirscan();
 		
 		}
 		else
 		{
+			$this->_cache['lsdir'] = $hgwebrepos;
 			// error code
 			return $hgwebrepos;
 		}
 			}
 		}
 		
+		$this->_cache['lsdir'] = $hgrepos;
 		return $hgrepos;
 	}
 	
 //			$existingdir[$r_name] = $r_name;
 			$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgweb);
 			$create_status = $this->_ci->hg_ini->registerRepo($r_name, $profile);
+			$this->flush_cache();
 			if($create_status == HGPHP_OK)
 			{
 				// then create the repository
 			// repository already exists
 			$create_status = HGPHP_ERR_FS_PREEXISTS;
 		}
+		
+		
 		return $create_status;
 	}
 	
 			return HGPHP_ERR_PERM_USR;
 		}
 		$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgrc);
+		
+		$this->flush_cache();
 		return $this->_ci->hg_ini->saveHgRC($r_name, $hgrc_data, $profile);
 	}
 	
 		$del_status = HGPHP_OK;
 		$lsdir = $this->_ci->hg_ini->getRepoList($hgweb);
 		
-		// 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[$hashr_key]))
 		{
 			// edit the directory
-			// remove hgweb.config
+			// remove from filesystem
 			$this->_ci->hg_ini->register_OFL($this->_ofl_lock_hgweb);
-//			$del_status = $this->_ci->hgconf2ini->setHgWebDirCollections($existingdir);
 				
 			$del_status = $this->_ci->hg_filesystem->delete_repository_dir($r_key);
 			
-			
 			// remove from hgweb.config
 			if($del_status == HGPHP_OK)
 			{
-				// existing filesystem is not missing, thus needs to be deleted
-//				if($lsdir[$r_name]['status'] != HGPHP_REPO_STATUS_MISSING)
-//				{
-//					// unregister hgrc from transaction manager to keep index small
-////					$this->_ci->hgconf2ini->register_OFL($this->_ofl_lock_hgrc);
-////					$del_status = $this->_ci->hgconf2ini->unlinkHGRC($r_name);
-//					
-//					if($del_status == HGPHP_OK)
-//					{
-						$del_status = $this->_ci->hg_ini->unregisterRepo($r_key, $hgweb);
-//					}
-//				}
+				$del_status = $this->_ci->hg_ini->unregisterRepo($r_key, $hgweb);
 			}
 //			unset($existingdir[$r_key]);
 		}
 		{
 			$del_status = HGPHP_ERR_FS_PREEXISTS;
 		}
+		$this->flush_cache();
 		return $del_status;
 	}
 	
 	 */
 	function can_create($r_name)
 	{
-		return true;
-//		return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_create;
+		return $this->can_view($r_name) && $this->_ci->config->item('global_allow_repo_create');
 	}
 	
 	/**
 	 */
 	function can_update($r_name)
 	{
-		return true;
-//		return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_update;
+		return $this->can_view($r_name) && $this->_ci->config->item('global_allow_repo_update');
 	}
 	
 	/**
 	 */
 	function can_view($r_name)
 	{
-		return true;
-//		return $this->_hgwebconf_allow_repo_view;
+		return $this->_ci->config->item('global_allow_repo_view');
 	}
 	
 	/**
 	 */
 	function can_delete($r_name)
 	{
-		return true;
-//		return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_delete;
+		return $this->can_view($r_name) && $this->_ci->config->item('global_allow_repo_delete');
 	}