Mercurial > public > src > phphgadmin
changeset 54:e3d97fd94adf
Global permissions fix and case where hgrc missing
author | joshjcarrier |
---|---|
date | Sat, 12 Jun 2010 18:12:02 -0700 |
parents | 3a482a6010d8 |
children | 3cdaf4949278 |
files | admin/application/config/phphgadmin.php admin/application/config/phphgadmin_core.php admin/application/controllers/hgrepo.php admin/application/helpers/hg_repo_helper.php admin/application/libraries/hg_ini.php admin/application/libraries/iniparser.php admin/application/libraries/phphgadmin.php |
diffstat | 7 files changed, 86 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/admin/application/config/phphgadmin.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/config/phphgadmin.php Sat Jun 12 18:12:02 2010 -0700 @@ -72,10 +72,10 @@ * 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
--- a/admin/application/config/phphgadmin_core.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/config/phphgadmin_core.php Sat Jun 12 18:12:02 2010 -0700 @@ -23,7 +23,7 @@ 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');
--- a/admin/application/controllers/hgrepo.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/controllers/hgrepo.php Sat Jun 12 18:12:02 2010 -0700 @@ -79,6 +79,9 @@ 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; @@ -96,15 +99,15 @@ $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; } }
--- a/admin/application/helpers/hg_repo_helper.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/helpers/hg_repo_helper.php Sat Jun 12 18:12:02 2010 -0700 @@ -30,8 +30,15 @@ { $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; }
--- a/admin/application/libraries/hg_ini.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/libraries/hg_ini.php Sat Jun 12 18:12:02 2010 -0700 @@ -109,7 +109,7 @@ 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)) { @@ -124,7 +124,7 @@ // 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); @@ -178,12 +178,12 @@ * @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; @@ -211,7 +211,7 @@ 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']; @@ -222,18 +222,16 @@ $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]; } } \ No newline at end of file
--- a/admin/application/libraries/iniparser.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/libraries/iniparser.php Sat Jun 12 18:12:02 2010 -0700 @@ -98,20 +98,23 @@ } 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; + } } } } @@ -202,24 +205,27 @@ { // 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;
--- a/admin/application/libraries/phphgadmin.php Sat Jun 12 15:14:37 2010 -0700 +++ b/admin/application/libraries/phphgadmin.php Sat Jun 12 18:12:02 2010 -0700 @@ -6,11 +6,15 @@ 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) @@ -26,8 +30,18 @@ $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(); @@ -45,6 +59,7 @@ } else { + $this->_cache['lsdir'] = $hgwebrepos; // error code return $hgwebrepos; } @@ -72,6 +87,7 @@ } } + $this->_cache['lsdir'] = $hgrepos; return $hgrepos; } @@ -111,6 +127,7 @@ // $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 @@ -129,6 +146,8 @@ // repository already exists $create_status = HGPHP_ERR_FS_PREEXISTS; } + + return $create_status; } @@ -146,6 +165,8 @@ 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); } @@ -166,40 +187,18 @@ $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]); } @@ -207,6 +206,7 @@ { $del_status = HGPHP_ERR_FS_PREEXISTS; } + $this->flush_cache(); return $del_status; } @@ -219,8 +219,7 @@ */ 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'); } /** @@ -232,8 +231,7 @@ */ 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'); } /** @@ -244,8 +242,7 @@ */ function can_view($r_name) { - return true; -// return $this->_hgwebconf_allow_repo_view; + return $this->_ci->config->item('global_allow_repo_view'); } /** @@ -257,8 +254,7 @@ */ 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'); }