annotate admin/application/libraries/hgphp.php @ 28:4543c151a667

Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
author joshjcarrier
date Sun, 16 May 2010 13:50:22 -0700
parents 26ff1899349f
children 2cf4300b3541
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
2
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
3 /**
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
4 * CodeIgniter Mercurial Repository Management class
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
5 *
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
6 * Scans file system and Mercurial projects directory, allowing
11
2ec108f96fad Cleaned up config. UI tidy up. Commenting. Still missing caching and concurrency checks.
joshjcarrier
parents: 10
diff changeset
7 * web-based manipulation of the hgweb.config and hgrc configuration files.
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
8 *
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
9 * Depends on the HgConf2Ini library.
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
10 *
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
11 * @package CodeIgniter
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
12 * @subpackage Libraries
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
13 * @category Libraries
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
14 * @author Josh Carrier
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
15 * @link blog.joshjcarrier.com
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
16 *
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
17 */
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
18 class HgPHP
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
19 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
20 private $_ci;
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
21
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
22 function __construct($config = array())
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
23 {
28
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
24 $this->_ci =& get_instance();
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
25 if(!empty($config))
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
26 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
27 $this->initialize($config);
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
28 }
28
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
29 else
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
30 {
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
31 $this->_ci->config->load('hgphp', TRUE);
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
32 $this->initialize($this->_ci->config->item('hgphp'));
4543c151a667 Added additional configuration options. Fixed last possible concurrency error, removing a single hgweb.config.lock with per-save temporary files.
joshjcarrier
parents: 24
diff changeset
33 }
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
34
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
35 $this->_ci->lang->load('hgphp');
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
36 $this->_ci->load->library('hgconf2ini');
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
37 log_message('debug', 'HgPHP class Initialized');
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
38 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
39
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
40 function initialize($config = array())
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
41 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
42 foreach($config as $key=>$val)
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
43 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
44 $this->{'_'.$key} = $val;
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
45 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
46 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
47
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
48 /**
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
49 * Public accessors - hgweb.config
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
50 */
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
51
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
52 /**
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
53 * Returns a list of available repositories.
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
54 * Will show up if: detected in repo directory
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
55 * Will have status "enabled" if: detected in hgweb.config
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
56 *
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
57 * @param ofl_lock_hgwebconf (updated by reference) the current optimistic file lock value
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
58 * @return an array of 0 or more detected repositories
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
59 */
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
60 function lsdir(&$ofl_lock_hgwebconf)
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
61 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
62 $realdir = $this->__realdirscan();
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
63 $hgwebdir_compat = $this->_ci->hgconf2ini->getHgWebDirCollections($ofl_lock_hgwebconf);
2
492f28533a05 Cleaned up hgweb.config loading data array a bit. Starting to implement locking system, repository editor.
joshjcarrier
parents: 1
diff changeset
64
492f28533a05 Cleaned up hgweb.config loading data array a bit. Starting to implement locking system, repository editor.
joshjcarrier
parents: 1
diff changeset
65 $allrepo = array_merge($realdir, $hgwebdir_compat);
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
66
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
67 $hgrepos = array();
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
68 foreach($allrepo as $repo)
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
69 {
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
70 $hgrepos[$repo]['name'] = $repo;
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
71
2
492f28533a05 Cleaned up hgweb.config loading data array a bit. Starting to implement locking system, repository editor.
joshjcarrier
parents: 1
diff changeset
72 if(isset($realdir[$repo]) && isset($hgwebdir_compat[$repo]))
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
73 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
74 $hgrepos[$repo]['status'] = HGPHP_REPO_STATUS_ENABLED;
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
75 }
2
492f28533a05 Cleaned up hgweb.config loading data array a bit. Starting to implement locking system, repository editor.
joshjcarrier
parents: 1
diff changeset
76 else if(isset($realdir[$repo]) && !isset($hgwebdir_compat[$repo]))
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
77 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
78 $hgrepos[$repo]['status'] = HGPHP_REPO_STATUS_DISABLED;
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
79 }
2
492f28533a05 Cleaned up hgweb.config loading data array a bit. Starting to implement locking system, repository editor.
joshjcarrier
parents: 1
diff changeset
80 else if(!isset($realdir[$repo]) && isset($hgwebdir_compat[$repo]))
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
81 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
82 $hgrepos[$repo]['status'] = HGPHP_REPO_STATUS_MISSING;
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
83 }
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
84 }
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
85
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
86 return $hgrepos;
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
87 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
88
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
89 /**
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
90 * Create a Hg repository by:
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
91 * - adding an entry in hgrc if not present
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
92 * - creating a bare repository if not present
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
93 * @param r_name name of the new repository to create, used as folder name
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
94 * @param hg_lock_hgwebconf (updated by reference) the last known optimistic file lock value of hgwebconf
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
95 * @param hg_lock_hgrc (updated by reference) value of hgrc's lock value
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
96 * @return status code
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
97 */
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
98 function create_repository($r_name, &$ofl_lock_hgwebconf, &$hg_lock_hgrc)
3
53341b414217 Ability to create repository entry (via uri), which updates live hgweb.config + sets up an empty directory to push to.
joshjcarrier
parents: 2
diff changeset
99 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
100 if(!$this->can_create($r_name))
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
101 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
102 return HGPHP_ERR_PERM_USR;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
103 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
104
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
105 $create_status = HGPHP_OK;
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
106 $ofl_dummylock_hgwebconf = '';
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
107 $lsdir = $this->lsdir($ofl_dummylock_hgwebconf); // don't want to update the lock yet
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
108
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
109 // simplifies repo list into array where name is both key and value
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
110 // this is how hgweb.config wants it
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
111 $existingdir = array_keys($lsdir);
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
112 $tempexistingdir = array();
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
113 foreach($existingdir as $repo_name)
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
114 {
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
115 $tempexistingdir[$repo_name] = $repo_name;
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
116 }
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
117 $existingdir = $tempexistingdir;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
118
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
119 // not registered in hgweb.config
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
120 if(!isset($lsdir[$r_name]))
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
121 {
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
122 // edit the directory
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
123 $existingdir[$r_name] = $r_name;
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
124 $create_status = $this->_ci->hgconf2ini->setHgWebDirCollections($existingdir, $ofl_lock_hgwebconf);
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
125 if($create_status == HGPHP_OK)
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
126 {
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
127 // then create the repository
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
128 $create_status = $this->create_repository_dir($r_name, $hg_lock_hgrc);
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
129 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
130 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
131 else
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
132 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
133 // repository already exists
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
134 $create_status = HGPHP_ERR_FS_PREEXISTS;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
135 }
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
136 return $create_status;
3
53341b414217 Ability to create repository entry (via uri), which updates live hgweb.config + sets up an empty directory to push to.
joshjcarrier
parents: 2
diff changeset
137 }
53341b414217 Ability to create repository entry (via uri), which updates live hgweb.config + sets up an empty directory to push to.
joshjcarrier
parents: 2
diff changeset
138
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
139 /**
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
140 * update_repository
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
141 * Update repository's hgrc
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
142 * @param r_name name of the repository to update hgrc for
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
143 * @param hgrc_data array representing new hgrc file
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
144 * @param ofl_lock_hgrc (updated by reference) the current optimistic file lock value
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
145 * @return status code
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
146 */
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
147 function update_repository($r_name, $hgrc_data, &$ofl_lock_hgrc)
10
0e7e4cead7c9 HGRC write and handle true/false key values
joshjcarrier
parents: 9
diff changeset
148 {
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
149 if(!$this->can_update($r_name))
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
150 {
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
151 return HGPHP_ERR_PERM_USR;
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
152 }
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
153
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
154 return $this->_ci->hgconf2ini->setHGRC($r_name, $hgrc_data, $ofl_lock_hgrc);
10
0e7e4cead7c9 HGRC write and handle true/false key values
joshjcarrier
parents: 9
diff changeset
155 }
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
156
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
157 /**
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
158 * delete_repository
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
159 * Deletes a repository from the file system and unregisters it from hgweb.config
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
160 * @param r_name name of the repo to delete permanently
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
161 * @param $ofl_lock_hgwebconf (updated by reference) the current optimistic file lock value
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
162 * @return status code
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
163 */
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
164 function delete_repository($r_name, &$ofl_lock_hgwebconf)
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
165 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
166 if(!$this->can_delete($r_name))
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
167 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
168 return HGPHP_ERR_PERM_USR;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
169 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
170
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
171 $del_status = HGPHP_OK;
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
172 $ofl_dummylock_hgwebconf = '';
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
173 $lsdir = $this->lsdir($ofl_dummylock_hgwebconf); // don't want to update lock yet
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
174
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
175 // simplifies repo list into array where name is both key and value
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
176 // this is how hgweb.config wants it
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
177 $existingdir = array_keys($lsdir);
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
178 $tempexistingdir = array();
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
179 foreach($existingdir as $repo_name)
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
180 {
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
181 $tempexistingdir[$repo_name] = $repo_name;
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
182 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
183 $existingdir = $tempexistingdir;
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
184
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
185 if(isset($lsdir[$r_name]))
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
186 {
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
187 // edit the directory
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
188 unset($existingdir[$r_name]);
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
189 // remove hgweb.config
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
190 $del_status = $this->_ci->hgconf2ini->setHgWebDirCollections($existingdir, $ofl_lock_hgwebconf);
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
191
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
192 // remove from hgweb.config
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
193 if($del_status == HGPHP_OK)
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
194 {
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
195 // existing filesystem is not missing, thus needs to be deleted
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
196 if($lsdir[$r_name]['status'] != HGPHP_REPO_STATUS_MISSING)
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
197 {
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
198 // unregister hgrc from transaction manager to keep index small
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
199 $del_status = $this->_ci->hgconf2ini->unlinkHGRC($r_name);
19
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
200
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
201 if($del_status == HGPHP_OK)
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
202 {
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
203 $del_status = $this->delete_repository_dir($r_name);
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
204 }
51f6d4415b09 completed Issue #8 security - block creation of 'admin' repository name and issue #2 concurrency - hgweb support
joshjcarrier
parents: 18
diff changeset
205 }
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
206 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
207 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
208 else
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
209 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
210 $del_status = HGPHP_ERR_FS_PREEXISTS;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
211 }
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
212 return $del_status;
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
213 }
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
214
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
215 /**
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
216 * stat_repository
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
217 * Returns the HGRC represented as an array for the specified repository
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
218 * @param r_name name of the project whose hgrc to retrieve
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
219 * @param ofl_lock_hgrc (updated by reference) the current optimistic file lock value will be updated
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
220 * @return array representing hgrc or status code
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
221 */
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
222 function stat_repository($r_name, &$ofl_lock_hgrc)
9
97bc7635ce3f HGRC read properties, and prepped for write
joshjcarrier
parents: 8
diff changeset
223 {
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
224 if(!$this->can_view($r_name))
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
225 {
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
226 return HGPHP_ERR_PERM_USR;
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
227 }
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
228
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
229 return $this->_ci->hgconf2ini->getHGRC($r_name, $ofl_lock_hgrc);
9
97bc7635ce3f HGRC read properties, and prepped for write
joshjcarrier
parents: 8
diff changeset
230 }
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
231
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
232
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
233 /**
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
234 * can_create
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
235 * Checks if user has permissions to create this repository.
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
236 * Requires view permission.
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
237 * @param r_name name of repository wanting to be created
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
238 * @return true if allowed
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
239 */
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
240 function can_create($r_name)
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
241 {
24
26ff1899349f Bug fix: improper can_view function call causing script crash.
joshjcarrier
parents: 23
diff changeset
242 return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_create;
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
243 }
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
244
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
245 /**
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
246 * can_update
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
247 * Checks if user has permissions to update this repository
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
248 * Requires view permission.
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
249 * @param r_name name of repository wanting to be updated
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
250 * @return true if allowed
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
251 */
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
252 function can_update($r_name)
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
253 {
24
26ff1899349f Bug fix: improper can_view function call causing script crash.
joshjcarrier
parents: 23
diff changeset
254 return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_update;
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
255 }
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
256
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
257 /**
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
258 * can_create
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
259 * Checks if user has permissions to view this repository
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
260 * @param r_name name of repository wanting to be created
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
261 * @return true if allowed
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
262 */
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
263 function can_view($r_name)
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
264 {
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
265 return $this->_hgwebconf_allow_repo_view;
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
266 }
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
267
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
268 /**
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
269 * can_delete
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
270 * Checks if user has permissions to delete this repository
23
6f38dd98ff78 View and update permission checks (all permissions default to true atm)
joshjcarrier
parents: 19
diff changeset
271 * Requires view permission.
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
272 * @param r_name name of repository wanting to be deleted
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
273 * @return true if allowed
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
274 */
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
275 function can_delete($r_name)
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
276 {
24
26ff1899349f Bug fix: improper can_view function call causing script crash.
joshjcarrier
parents: 23
diff changeset
277 return $this->can_view($r_name) && $this->_hgwebconf_allow_repo_delete;
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
278 }
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
279
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
280 /**
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
281 * create_repository_dir
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
282 * Creates a whole repository directory, with hgrc
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
283 * @param r_name name of repository to create directory for
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
284 * @param ofl_lock_hgrc (updated by reference) the current optimistic file lock value will be updated
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
285 * @return status code
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
286 */
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
287 function create_repository_dir($r_name, &$ofl_lock_hgrc)
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
288 {
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
289 if(!$this->can_create($r_name))
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
290 {
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
291 return HGPHP_ERR_PERM_USR;
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
292 }
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
293
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
294 // create repo directory structure recursively
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
295 $create_status = mkdir($this->_repositories_abs_dir . $r_name . '/.hg/store/data/', 0755, TRUE);
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
296
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
297 if($create_status == TRUE)
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
298 {
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
299 // create hgrc
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
300 $create_status = $this->_ci->hgconf2ini->touchHGRC($r_name, $ofl_lock);
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
301 }
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
302 else
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
303 {
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
304 // system couldn't make directory
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
305 $create_status = HGPHP_ERR_PERM_SYS_REPODIR;
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
306 }
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
307 return $create_status;
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
308 }
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
309
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
310 /**
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
311 * delete_repository_dir
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
312 * Deletes a whole repository directory including hgrc and data files
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
313 * @param r_name name of repository to delete directory of
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
314 * @return status code
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
315 */
8
6215bb22f3d3 Refactored config handler functions to new library.
joshjcarrier
parents: 7
diff changeset
316 function delete_repository_dir($repository_name)
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
317 {
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
318 if(!$this->can_delete($repository_name))
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
319 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
320 return HGPHP_ERR_PERM_USR;
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
321 }
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
322
11
2ec108f96fad Cleaned up config. UI tidy up. Commenting. Still missing caching and concurrency checks.
joshjcarrier
parents: 10
diff changeset
323 $cd = $this->_repositories_abs_dir . $repository_name;
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
324 $this->recursiveDelete($cd . '/.hg/');
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
325 $del_status = $this->recursiveDelete($cd);
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
326 if($del_status == TRUE)
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
327 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
328 $del_status = HGPHP_OK;
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
329 }
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
330 else
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
331 {
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
332 $del_status = HGPHP_ERR_PERM_SYS_REPODIR;
17
4aa2707ae587 Optimistic locking integration mostly completed (missing some temp file stuff on hgweb.config). Need return code constants + ensure all error codes can be returned. OFL not enabled until session integration
joshjcarrier
parents: 11
diff changeset
333 }
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
334 return $del_status;
4
1648e02be7e0 Global lockout permission config
joshjcarrier
parents: 3
diff changeset
335 }
3
53341b414217 Ability to create repository entry (via uri), which updates live hgweb.config + sets up an empty directory to push to.
joshjcarrier
parents: 2
diff changeset
336
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
337 /**
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
338 * Performs a real directory scan where the projects are suppose to reside.
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
339 *
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
340 * @return the array containing 0 or more valid directories
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
341 */
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
342 function __realdirscan()
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
343 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
344 $this->_ci->load->helper('directory');
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
345
11
2ec108f96fad Cleaned up config. UI tidy up. Commenting. Still missing caching and concurrency checks.
joshjcarrier
parents: 10
diff changeset
346 $realdir = directory_map($this->_repositories_abs_dir, TRUE);
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
347
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
348 $verifiedrealdir = array();
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
349 foreach($realdir as $file)
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
350 {
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
351 // checks if we detected a folder
11
2ec108f96fad Cleaned up config. UI tidy up. Commenting. Still missing caching and concurrency checks.
joshjcarrier
parents: 10
diff changeset
352 if(is_dir($this->_repositories_abs_dir . $file))
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
353 {
1
2d2757428cc6 Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
joshjcarrier
parents: 0
diff changeset
354 $verifiedrealdir[$file] = $file;
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
355 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
356 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
357
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
358 return $verifiedrealdir;
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
359 }
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
360
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
361 /**
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
362 * Delete a file or recursively delete a directory
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
363 *
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
364 * @param string $str Path to file or directory
18
9aceab434288 Using constants instead of magic numbers. Cleaned up code and commenting.
joshjcarrier
parents: 17
diff changeset
365 * @return true on successful deletion
7
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
366 */
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
367 function recursiveDelete($str){
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
368 if(is_file($str)){
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
369 return @unlink($str);
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
370 }
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
371 elseif(is_dir($str)){
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
372 $scan = glob(rtrim($str,'/').'/*');
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
373 foreach($scan as $index=>$path){
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
374 $this->recursiveDelete($path);
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
375 }
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
376 return @rmdir($str);
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
377 }
9790c4a95b14 delete repo&data + basic UI support for delete
joshjcarrier
parents: 5
diff changeset
378 }
0
9124b60de5a6 CodeIgniter 1.7.2 base. .htaccess modification for subdirectory serve. Hg_conf library begin - can scan directories on disk.
joshjcarrier
parents:
diff changeset
379 }