Beispiel #1
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $names = StringTools::Delimit($input->getArgument('name'), ',');
     $user = $input->getArgument('user');
     $group = $input->getArgument('group');
     $parent = $input->getOption('parent');
     // TODO support
     if (!empty($parent)) {
         var_dump($parent);
     }
     foreach ($names as $website) {
         // adding website
         //$website = $name['text'];
         LogCLI::Message('Adding website: ' . $website, 0);
         LogCLI::MessageResult('Group and user: '******'/' . $user, 2, LogCLI::INFO);
         $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $user . Paths::$separator;
         if (file_exists($path)) {
             if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                 FileOperation::CreateEmptyFile($path . $website . '.yml');
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $user . ' already exists!');
                 LogCLI::Result(LogCLI::FAIL);
             }
         } else {
             LogCLI::Fail('Group and/or user ' . $group . '/' . $user . ' does not exist!');
             LogCLI::Result(LogCLI::FAIL);
         }
     }
 }
Beispiel #2
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $application = $input->getArgument('application');
     // TODO: this should be USER or optionally GROUP/USER or ALL when generating everything
     $directories = $input->getArgument('directories');
     $files = array();
     foreach ($directories as $dir) {
         $filelist = FileOperation::getAllFilesByExtension(Paths::$db . Paths::$separator . Paths::$defaultGroup . Paths::$separator . $dir, 'yml');
         if ($filelist !== false) {
             $files = array_merge($files, $filelist);
         } else {
             user_error('No such site: ' . $dir, E_USER_WARNING);
             //return false;
         }
     }
     //ApplicationsDB::LoadAll();
     $configScopes = ApplicationsDB::LoadApplication($application);
     $settingsDB = new ConfigScopes\SettingsDB();
     // merging the defaults
     $settingsDB->mergeFromYAML(Paths::$db . Paths::$separator . Paths::$hypoconf . Paths::$separator . Paths::$defaultUser . Paths::$separator . 'config.yml', false, true, true);
     //true for compilation
     // merging the files
     $settingsDB->mergeFromYAMLs($files, 'nginx/server', true, true, false, true);
     //true for compilation
     //var_dump($settingsDB->DB);
     ApplicationsDB::LoadConfig($settingsDB->DB);
     $parsedFile = $configScopes->parseTemplateRecursively($application);
     //        echo PHP_EOL.$parsedFile;
     $output->writeln($parsedFile);
 }
Beispiel #3
0
 public static function getFullPath($site)
 {
     $files = FileOperation::getAllFilesByExtension(Paths::$db, 'yml');
     $pathinfo = array();
     foreach ($files as $id => $file) {
         $pathinfo[$id] = FileOperation::pathinfo_utf($file);
         if ($pathinfo[$id]['filename'] == $site) {
             return $files[$id];
         }
     }
     return false;
 }
Beispiel #4
0
 public function AddFromFile($file, $scopeUser = false)
 {
     LogCLI::Message('Adding template file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 4);
     try {
         $data = trim(file_get_contents($file));
         $scopeData = FileOperation::pathinfo_utf($file);
         $scopeName = $scopeUser === false ? $scopeData['filename'] : $scopeUser;
         $this->DB = ArrayTools::MergeArrays($this->DB, array($scopeName => $data));
         LogCLI::MessageResult('Templates DB updated with ' . LogCLI::BLUE . $scopeName . LogCLI::RESET . ' definition', 5, LogCLI::INFO);
         LogCLI::Result(LogCLI::OK, 4);
     } catch (Exception $e) {
         LogCLI::Result(LogCLI::FAIL);
         LogCLI::Fail($e->getMessage());
     }
 }
Beispiel #5
0
 /**
  * @static
  * @param string $application
  * @return object returns ConfigScopes instance
  */
 public static function LoadApplication($application)
 {
     // load templates:
     $templateFiles = FileOperation::getAllFilesByExtension(Paths::$apps . $application, 'tpl');
     self::$DB[$application]['templatesInstance'] = new TemplatesDB($templateFiles);
     self::$DB[$application]['templates'] = self::$DB[$application]['templatesInstance']->DB;
     // register possible settings:
     if (isset(self::$applications[$application])) {
         $classInfo = self::$applications[$application];
         $className = $classInfo[0];
     } else {
         // TODO: throw error
         return false;
     }
     self::$DB[$application]['parserInstance'] = new $className(self::$DB[$application]['templates']);
     self::$DB[$application]['parsers'] = self::$DB[$application]['parserInstance']->GetSubParsers();
     self::$DB[$application]['scopesInstance'] = new HypoConf\ConfigScopes(self::$DB[$application]['parsers'], self::$DB[$application]['templates']);
     self::$DB[$application]['scopesInstance']->rootscope = $application;
     return self::$DB[$application]['scopesInstance'];
 }
Beispiel #6
0
//$actionInfo = \Console_CommandLine::$actions;
//var_dump($actionInfo);
LogCLI::SetVerboseLevel(5);
$config['root'] = array('user' => 'testowy', 'group' => 'group');
$config['events'] = array('connections' => 1024, 'multi_accept' => false);
//$config['http'] = array('user' => 'testowy', 'group' => 'group');
//$config['server'][0][] = array('domain'=>'koma.net');
$config['server'][0] = array('domain' => 'komalol.net');
$config['server'][0]['listen'][0] = array('ip' => '10.0.0.1', 'port' => '80');
$config['server'][0]['listen'][1] = array('ip' => '10.0.0.1', 'port' => '81');
$config['server'][0]['listen'][2] = array('ip' => '10.0.0.1', 'port' => '81');
$config['server'][1] = array('domain' => 'moma.com');
$config['server'][1]['listen'][0] = array('ip' => '192.168.0.1', 'port' => '80');
$config['server'][1]['listen'][1] = array('ip' => '192.168.0.2', 'port' => '81');
$config['server'][2] = array('domain' => 'jajco.com');
FileOperation::ToYAMLFile($config, true);
/*$template = '
user [[%(user)s]][[ %(group)s]];
listen [[%(listen)s]][[ %(listen_options)s]];';
*/
/*
<<multiple files>>
[[replace string]]
*/
//recursive
$template = array();
$template['root'] = <<<EOT
[[user %(user)s[[ %(group)s]];]]
events
{
    <<events>>
Beispiel #7
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $names = StringTools::TypeList($input->getArgument('name'), '@', ',');
     $userorgroup = $input->getArgument('userorgroup');
     //        $group = $input->getArgument('group');
     //        $group =
     //        $directories = $input->getArgument('directories');
     //        $files = array();
     //ApplicationsDB::LoadAll();
     foreach ($names as $name) {
         if ($name['exclamation'] !== false) {
             // adding user
             LogCLI::MessageResult('Exclamation: ' . $name['exclamation'], 2, LogCLI::INFO);
             $username = $name['text'];
             LogCLI::Message('Adding user: '******'Creating directory: ' . $structure, 2, LogCLI::INFO);
             if (@mkdir($structure, 0755, true)) {
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('User ' . $username . ' already exists!');
                 //LogCLI::Fail($e->getMessage());
             }
         } else {
             // adding website
             $website = $name['text'];
             LogCLI::Message('Adding website: ' . $website, 0);
             $username = !empty($userorgroup) ? $userorgroup : Paths::$defaultUser;
             $group = Paths::$defaultGroup;
             LogCLI::MessageResult('User and group: ' . $username . '/' . $group, 2, LogCLI::INFO);
             $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $username . Paths::$separator;
             if (file_exists($path)) {
                 if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                     FileOperation::CreateEmptyFile($path . $website . '.yml');
                     LogCLI::Result(LogCLI::OK);
                 } else {
                     LogCLI::Result(LogCLI::FAIL);
                     LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $username . ' already exists!');
                 }
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('Group and/or user ' . $group . '/' . $username . ' does not exist!');
             }
         }
     }
 }
Beispiel #8
0
 public static function Add($arguments)
 {
     foreach (StringTools::TypeList($arguments['name'], '@') as $argument) {
         $name = $argument['text'];
         if ($argument['exclamation'] !== false) {
             LogCLI::MessageResult('Exclamation: ' . $argument['exclamation'], 2, LogCLI::INFO);
             $username = $name;
             LogCLI::Message('Adding user: '******'name2']) ? $arguments['name2'] : Paths::$defaultGroup;
             $structure = Paths::$db . Paths::$separator . $group . Paths::$separator . $username;
             LogCLI::MessageResult('Creating directory: ' . $structure, 2, LogCLI::INFO);
             if (@mkdir($structure, 0755, true)) {
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('User ' . $username . ' already exists!');
                 //LogCLI::Fail($e->getMessage());
             }
         } else {
             // adding website
             $website = $name;
             LogCLI::Message('Adding website: ' . $website, 0);
             $username = isset($arguments['name2']) ? $arguments['name2'] : Paths::$defaultUser;
             $group = Paths::$defaultGroup;
             LogCLI::MessageResult('Username and group: ' . $username . '/' . $group, 2, LogCLI::INFO);
             $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $username . Paths::$separator;
             if (file_exists($path)) {
                 if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                     FileOperation::CreateEmptyFile($path . $website . '.yml');
                     LogCLI::Result(LogCLI::OK);
                 } else {
                     LogCLI::Result(LogCLI::FAIL);
                     LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $username . ' already exists!');
                 }
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('Group and/or user ' . $group . '/' . $username . ' does not exist!');
             }
         }
     }
 }
Beispiel #9
0
 /**
  * @param string $file          path to a YAML file
  * @param string|bool $path     start the merge at designated settings path
  * @param bool $applyDefaults
  * @param bool $mergeDefaults
  * @param bool $createNewIfNonexistant
  * @param bool $addFilename
  * @return void
  */
 public function mergeFromYAML($file, $path = false, $applyDefaults = false, $mergeDefaults = true, $createNewIfNonexistant = false, $addFilename = false)
 {
     LogCLI::Message('Loading file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
     if (file_exists($file)) {
         LogCLI::Result(LogCLI::OK);
         LogCLI::Message('Parsing YAML file: ' . LogCLI::BLUE . $file . LogCLI::RESET, 1);
         try {
             //$config = YAML::load($file);
             $config = Yaml::parse($file);
             //                 if the file is empty create an empty array:
             //                    $config = array();
             if (!empty($config)) {
                 if ($path === false) {
                     $this->DB = ArrayTools::MergeArrays($this->DB, $config);
                     if ($mergeDefaults === true) {
                         $this->mergeDefinitionsDB($config, $this->defaultsDefinitions, $applyDefaults, 'defaults');
                     }
                 } else {
                     if ($addFilename === true) {
                         $fileInfo = FileOperation::pathinfo_utf($file);
                         $config['filename'] = $fileInfo['filename'];
                         //$config['filename'] = $file;
                     }
                     if (!isset($config['template']) && (!isset($config['disabled']) || $config['disabled'] == false)) {
                         $iteration = $this->mergeOneIterativeByPath($path, $config);
                         //var_dump($this->defaultsDefinitions);
                         /**
                          * applying parents as defaults
                          */
                         if (isset($config['parent'])) {
                             foreach ((array) $config['parent'] as $parentName) {
                                 if (is_array($parentFiles = FileOperation::findFile($parentName, Paths::$db))) {
                                     if (count($parentFiles) > 1) {
                                         LogCLI::MessageResult('You have to be more specific in the way you specify the parent, found more than one file under this name: ' . $parentName, 0, LogCLI::INFO);
                                     } else {
                                         $parentFile =& current($parentFiles);
                                         LogCLI::Message('Parent definition found: ' . LogCLI::BLUE . $parentFile . LogCLI::RESET . ', parsing and merging.', 2);
                                         if (!isset($this->parentDefinitions[$parentFile])) {
                                             $parentConfig = array('parent' => Yaml::parse($parentFile));
                                             $this->parentDefinitions[$parentFile] = array();
                                             $this->mergeDefinitionsDB($parentConfig, $this->parentDefinitions[$parentFile], false, 'parent');
                                         }
                                         $this->applyDefaults($this->DB, $this->parentDefinitions[$parentFile], $path . '/' . $iteration, 'parent', true, false);
                                         LogCLI::Result(LogCLI::OK);
                                     }
                                     //var_dump($this->parentDefinitions);
                                 }
                             }
                         }
                         if ($applyDefaults === true) {
                             $this->applyDefaults($this->DB, $this->defaultsDefinitions, $path . '/' . $iteration, 'defaults', false, false);
                         }
                     }
                 }
                 LogCLI::MessageResult('Settings DB populated with new data!', 5, LogCLI::INFO);
             } else {
                 LogCLI::MessageResult('File empty, ignoring', 5, LogCLI::INFO);
             }
             LogCLI::Result(LogCLI::OK);
         } catch (\Exception $e) {
             LogCLI::Result(LogCLI::FAIL);
             LogCLI::Fail($e->getMessage());
         }
     } else {
         LogCLI::Result(LogCLI::FAIL);
         LogCLI::Fail("No such file: {$file}");
         if ($createNewIfNonexistant === true) {
             LogCLI::Message('Creating a new empty file.', 0);
             try {
                 //fclose(fopen($file, 'x'));
                 FileOperation::CreateEmptyFile($file);
                 $this->mergeFromYAML($file, $path, $applyDefaults, $mergeDefaults, false);
                 LogCLI::Result(LogCLI::OK);
             } catch (\Exception $e) {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail($e->getMessage());
             }
         }
     }
 }
Beispiel #10
0
 public function ReturnYAML($path = false)
 {
     if ($path === false) {
         FileOperation::ToYAMLFile($this->settingsDB, true);
     } else {
         FileOperation::ToYAMLFile($this->settingsDB, false, $path);
     }
 }