@@ -67,16 +67,11 @@ public function __construct($alternateConfig = null)
67
67
68
68
/**
69
69
* helper function to load the correct config file
70
- * @param string $alternateConfig path to alternative config ini file
71
70
* @return config array with config properties
72
71
*/
73
- protected function loadConfig ($ alternateConfig = null )
72
+ protected function loadConfig ()
74
73
{
75
- if ($ alternateConfig )
76
- {
77
- $ config = parse_ini_file ($ alternateConfig , false );
78
- }
79
- elseif (file_exists (MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG ))
74
+ if (file_exists (MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG ))
80
75
{
81
76
$ config = parse_ini_file (MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG , false );
82
77
}
@@ -92,25 +87,31 @@ protected function loadConfig($alternateConfig = null)
92
87
* will load the configuration property values for this module, and filter
93
88
* out only those properties that are in the 'batchmake.' config namespace,
94
89
* removing the 'batchmake.' from the key name.
95
- * @param string $alternateConfig a path to an alternate config ini file
90
+ * @param string $alternateConfig an array of alternate config props
96
91
* @return array of batchmake module specific config properties
97
92
*/
98
93
public function loadConfigProperties ($ alternateConfig = null )
99
94
{
100
- $ configPropertiesParamVals = array ();
101
- $ rawConfig = $ this ->loadConfig ($ alternateConfig );
102
-
103
- $ modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '. ' ;
104
- foreach ($ rawConfig as $ configProperty => $ configPropertyVal )
95
+ if (!isset ($ alternateConfig ))
105
96
{
106
- $ ind = strpos ($ configProperty , $ modulePropertyNamespace );
107
- if ($ ind !== false && $ ind == 0 )
97
+ $ configPropertiesParamVals = array ();
98
+ $ rawConfig = $ this ->loadConfig ();
99
+
100
+ $ modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '. ' ;
101
+ foreach ($ rawConfig as $ configProperty => $ configPropertyVal )
108
102
{
109
- $ reducedKey = substr ($ configProperty , strpos ($ configProperty , '. ' ) + 1 );
110
- $ configPropertiesParamVals [$ reducedKey ] = $ configPropertyVal ;
103
+ $ ind = strpos ($ configProperty , $ modulePropertyNamespace );
104
+ if ($ ind !== false && $ ind == 0 )
105
+ {
106
+ $ reducedKey = substr ($ configProperty , strpos ($ configProperty , '. ' ) + 1 );
107
+ $ configPropertiesParamVals [$ reducedKey ] = $ configPropertyVal ;
108
+ }
111
109
}
112
110
}
113
-
111
+ else
112
+ {
113
+ $ configPropertiesParamVals = $ alternateConfig ;
114
+ }
114
115
$ this ->componentConfig = $ configPropertiesParamVals ;
115
116
$ this ->configScriptDir = $ this ->componentConfig [MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY ];
116
117
$ this ->configAppDir = $ this ->componentConfig [MIDAS_BATCHMAKE_APP_DIR_PROPERTY ];
@@ -129,7 +130,7 @@ public function loadConfigProperties($alternateConfig = null)
129
130
* @TODO from KWUtils, may need to be moved, but first tested
130
131
* checks whether the file at the passed in path has the passed in options.
131
132
*/
132
- protected function checkFileFlag ($ file , $ options = 0x0 )
133
+ protected function checkFileFlag ($ file , $ processUserUid , $ options = 0x0 )
133
134
{
134
135
$ exist = file_exists ($ file );
135
136
Zend_Loader::loadClass ("InternationalizationComponent " , BASE_PATH .'/core/controllers/components ' );
@@ -157,7 +158,7 @@ protected function checkFileFlag($file, $options = 0x0)
157
158
}
158
159
if (!KWUtils::isWindows () && $ exist && ($ options & MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE ))
159
160
{
160
- $ chmodable = $ this ->IsChmodable ($ file );
161
+ $ chmodable = $ this ->IsChmodable ($ file, $ processUserUid );
161
162
$ status .= $ chmodable ? " / Chmodable " : " / NotChmodable " ;
162
163
$ ret = $ ret && $ chmodable ;
163
164
}
@@ -172,7 +173,7 @@ protected function checkFileFlag($file, $options = 0x0)
172
173
* Note: If return true, the mode of the file will be MIDAS_BATCHMAKE_DEFAULT_MKDIR_MODE
173
174
* On windows, return always True
174
175
*/
175
- protected function isChmodable ($ fileOrDirectory )
176
+ protected function isChmodable ($ fileOrDirectory, $ processUserUid )
176
177
{
177
178
if (KWUtils::isWindows ())
178
179
{
@@ -196,8 +197,20 @@ protected function isChmodable($fileOrDirectory)
196
197
197
198
if (is_writable ($ fileOrDirectory ))
198
199
{
199
- // Try to re-apply them
200
- $ return = chmod ($ fileOrDirectory , $ current_perms );
200
+ // first check on the uid of the fileOrDirectory
201
+ // if that is different than the processUserUid, then chmod
202
+ // will return false and add a warning, so let's prevent this beforehand
203
+ $ fileStat = stat ($ fileOrDirectory );
204
+ $ fileUid = $ fileStat ['uid ' ];
205
+ if ($ fileUid !== $ processUserUid )
206
+ {
207
+ return false ;
208
+ }
209
+ else
210
+ {
211
+ // Try to re-apply them
212
+ $ return = chmod ($ fileOrDirectory , $ current_perms );
213
+ }
201
214
}
202
215
else
203
216
{
@@ -227,13 +240,48 @@ public function testconfig($alternateConfigValues = null)
227
240
$ configToTest = $ this ->componentConfig ;
228
241
}
229
242
243
+ Zend_Loader::loadClass ("InternationalizationComponent " , BASE_PATH .'/core/controllers/components ' );
244
+
245
+ // Process web server user information
246
+
247
+ // TODO what should be done if there are warnings??
248
+ $ processUser = posix_getpwuid (posix_geteuid ());
249
+ $ processUserUid = $ processUser ['uid ' ];
250
+ $ processGroup = posix_getgrgid (posix_geteuid ());
251
+
252
+ $ phpProcessString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_STRING );
253
+ $ phpProcessUserString = $ phpProcessString . ' ' . InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_USER_STRING );
254
+ $ phpProcessNameString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING );
255
+ $ phpProcessGroupString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_GROUP_STRING );
256
+ $ phpProcessHomeString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_HOME_STRING );
257
+ $ phpProcessShellString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING );
258
+ $ unknownString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_UNKNOWN_STRING );
259
+
260
+ $ phpProcessUserNameString = $ phpProcessUserString . '[ ' . $ phpProcessNameString . '] ' ;
261
+ $ phpProcessUserGroupString = $ phpProcessUserString . '[ ' . $ phpProcessGroupString . '] ' ;
262
+ $ phpProcessUserHomeString = $ phpProcessUserString . '[ ' . $ phpProcessHomeString . '] ' ;
263
+ $ phpProcessUserShellString = $ phpProcessUserString . '[ ' . $ phpProcessShellString . '] ' ;
264
+
265
+ $ processProperties = array ($ phpProcessUserNameString => !empty ($ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ]) ? $ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ] : "" ,
266
+ $ phpProcessUserGroupString => !empty ($ processGroup [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ]) ? $ processGroup [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ] : "" ,
267
+ $ phpProcessUserHomeString => !empty ($ processUser [MIDAS_BATCHMAKE_DIR_KEY ]) ? $ processUser [MIDAS_BATCHMAKE_DIR_KEY ] : "" ,
268
+ $ phpProcessUserShellString => !empty ($ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING ]) ? $ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING ] : "" );
269
+
270
+ foreach ($ processProperties as $ property => $ value )
271
+ {
272
+ $ status = !empty ($ value );
273
+ $ configStatus [] = array (MIDAS_BATCHMAKE_PROPERTY_KEY => $ property ,
274
+ MIDAS_BATCHMAKE_STATUS_KEY => $ status ? $ value : $ unknownString ,
275
+ MIDAS_BATCHMAKE_TYPE_KEY => $ status ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_WARNING );
276
+ }
277
+
230
278
foreach (self ::$ configPropertiesRequirements as $ configProperty => $ configPropertyRequirement )
231
279
{
232
280
$ configPropertyVal = $ configToTest [$ configProperty ];
233
281
if ($ configPropertyVal )
234
282
{
235
283
// if the property exists, check its configuration
236
- list ($ result , $ status ) = $ this ->checkFileFlag ($ configPropertyVal , $ configPropertyRequirement );
284
+ list ($ result , $ status ) = $ this ->checkFileFlag ($ configPropertyVal , $ processUserUid , $ configPropertyRequirement );
237
285
$ configStatus [] = array (MIDAS_BATCHMAKE_PROPERTY_KEY => $ configProperty , MIDAS_BATCHMAKE_STATUS_KEY => $ status , MIDAS_BATCHMAKE_TYPE_KEY => $ result ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_ERROR );
238
286
// the property is in error, therefore so is the global config
239
287
if (!$ result )
@@ -255,8 +303,6 @@ public function testconfig($alternateConfigValues = null)
255
303
{
256
304
$ appPath = $ configToTest [$ pathProperty ] ."/ " . KWUtils::formatAppName ($ app );
257
305
list ($ result , $ status ) = $ this ->checkFileFlag ($ appPath , MIDAS_BATCHMAKE_CHECK_IF_EXECUTABLE );
258
- Zend_Loader::loadClass ("InternationalizationComponent " , BASE_PATH .'/core/controllers/components ' );
259
-
260
306
$ applicationString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_APPLICATION_STRING );
261
307
$ configStatus [] = array (MIDAS_BATCHMAKE_PROPERTY_KEY => $ applicationString . ' ' .$ appPath , MIDAS_BATCHMAKE_STATUS_KEY => $ status , MIDAS_BATCHMAKE_TYPE_KEY => $ result ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_ERROR );
262
308
// the property is in error, therefore so is the global config
@@ -266,37 +312,6 @@ public function testconfig($alternateConfigValues = null)
266
312
}
267
313
}
268
314
269
- // Process web server user information
270
-
271
- // TODO what should be done if there are warnings??
272
- $ processUser = posix_getpwuid (posix_geteuid ());
273
- $ processGroup = posix_getgrgid (posix_geteuid ());
274
-
275
- $ phpProcessString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_STRING );
276
- $ phpProcessUserString = $ phpProcessString . ' ' . InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_USER_STRING );
277
- $ phpProcessNameString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING );
278
- $ phpProcessGroupString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_GROUP_STRING );
279
- $ phpProcessHomeString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_HOME_STRING );
280
- $ phpProcessShellString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING );
281
- $ unknownString = InternationalizationComponent::translate (MIDAS_BATCHMAKE_UNKNOWN_STRING );
282
-
283
- $ phpProcessUserNameString = $ phpProcessUserString . '[ ' . $ phpProcessNameString . '] ' ;
284
- $ phpProcessUserGroupString = $ phpProcessUserString . '[ ' . $ phpProcessGroupString . '] ' ;
285
- $ phpProcessUserHomeString = $ phpProcessUserString . '[ ' . $ phpProcessHomeString . '] ' ;
286
- $ phpProcessUserShellString = $ phpProcessUserString . '[ ' . $ phpProcessShellString . '] ' ;
287
-
288
- $ processProperties = array ($ phpProcessUserNameString => !empty ($ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ]) ? $ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ] : "" ,
289
- $ phpProcessUserGroupString => !empty ($ processGroup [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ]) ? $ processGroup [MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING ] : "" ,
290
- $ phpProcessUserHomeString => !empty ($ processUser [MIDAS_BATCHMAKE_DIR_KEY ]) ? $ processUser [MIDAS_BATCHMAKE_DIR_KEY ] : "" ,
291
- $ phpProcessUserShellString => !empty ($ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING ]) ? $ processUser [MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING ] : "" );
292
-
293
- foreach ($ processProperties as $ property => $ value )
294
- {
295
- $ status = !empty ($ value );
296
- $ configStatus [] = array (MIDAS_BATCHMAKE_PROPERTY_KEY => $ property ,
297
- MIDAS_BATCHMAKE_STATUS_KEY => $ status ? $ value : $ unknownString ,
298
- MIDAS_BATCHMAKE_TYPE_KEY => $ status ? MIDAS_BATCHMAKE_STATUS_TYPE_INFO : MIDAS_BATCHMAKE_STATUS_TYPE_WARNING );
299
- }
300
315
301
316
return array ($ total_config_correct , $ configStatus );
302
317
0 commit comments