// get back the form object state and update it according to user input $confForm->wake($_SESSION[$cfgSvcName]); // validate user input $confForm->validForm(); $data['errors'] = $confForm->get_errQueue(); // something failed? if (count($data['errors']) > 0) { exit(json_encode($data)); } $svcMount = $confForm->getFldValue('fsmount'); $cfgPtr['fsmounts'][$svcMount]['uuid'] = $confForm->getFldValue('uuid'); $cfgPtr['fsmounts'][$svcMount]['label'] = $confForm->getFldValue('label'); $cfgPtr['fsmounts'][$svcMount]['filesystem'] = $confForm->getFldValue('filesystem'); $cfgPtr['fsmounts'][$svcMount]['comment'] = $confForm->getFldValue('desc'); $cfgPtr['fsmounts'][$svcMount]['active'] = $confForm->getFldValue('active'); $svcAvail = getAvailServices(); $svcSetNow = null; foreach (array_keys($svcAvail) as $svc) { $svcActive = $confForm->getCbState($svc, 'yes', 'int'); if ($svcActive === 1) { $cfgPtr['services'][$svc]['fsmount'] = $svcMount; $cfgPtr['services'][$svc]['active'] = 1; $svcSetNow[] = $svc; } else { if (isset($cfgPtr['services'][$svc]['fsmount'])) { if ($cfgPtr['services'][$svc]['fsmount'] == $svcMount) { $cfgPtr['services'][$svc]['active'] = 0; } } } }
function setupStorageDevices(&$conf, $filter = null, $boot = false) { // check that there are mountpoints defined if (!is_array($conf['system']['storage']) || !is_array($conf['system']['storage']['fsmounts'])) { return 0; } // $setup = mountStorageDevices($conf); // check that service configuration exists if (!is_array($conf['system']['storage']['services'])) { return 0; } // // get callable service functions $svcFuncs = getAvailServices(); // get a copy of the storage config array $storageCfg = $conf['system']['storage']['services']; // reduce it according to $filter if set if ($filter !== null && is_array($filter)) { $storageCfg = array_intersect_key($storageCfg, array_flip($filter)); } // now loop thru $storageCfg array to initialize services foreach (array_keys($storageCfg) as $service) { // first check some required symbols if (!is_array($storageCfg[$service])) { continue; } // if (!isset($storageCfg[$service]['active'])) { continue; } // skip if disabled... if ($storageCfg[$service]['active'] != 1) { continue; } // ...the same if no mount point was set if (!isset($storageCfg[$service]['fsmount'])) { continue; } // check that the mount point this service depends on is enabled, else skip it $fsMount = $storageCfg[$service]['fsmount']; if ($conf['system']['storage']['fsmounts'][$fsMount]['active'] != 1) { continue; } // check that service has a callable function defined if (!isset($svcFuncs[$service]['handler'])) { $conf['system']['storage']['services'][$service]['active'] = -3; $setup['cfgchanged'] = 1; msgToSyslog("initialization for service ({$service}) failed because no handler available."); continue; } /* check that the required directory exists, else make it. This also to avoid a system call except the very first time. */ $svcPath = "{$conf['system']['storage']['mountroot']}/{$fsMount}/{$svcFuncs[$service]['dirtree']}"; if (!is_dir($svcPath)) { if (!mkdir($svcPath, 0766, true)) { $conf['system']['storage']['services'][$service]['active'] = -1; $setup['cfgchanged'] = 1; msgToSyslog("making directory for service ({$service}) failed."); } } $svcResult = call_user_func($svcFuncs[$service]['handler'], $svcPath); if ($svcResult === false) { // disable that service $conf['system']['storage']['services'][$service]['active'] = -2; $setup['cfgchanged'] = 1; msgToSyslog("handler for service ({$service}) failed during execution."); } } // check if configuration was changed due to some errors if ($setup['cfgchanged'] != 0) { // update configuration with current storage status write_config(); // send this event to syslog msgToSyslog('something went wrong during storage initialization, please check status using the UI.', LOG_ERR); } }