protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $cfg = $this->getSelimConfig($input); if ($cfg->siteExists($name)) { $cfg->removeSite($name); $cfg->write(); echo "removed: '{$name}'" . PHP_EOL; } else { Util::reportError("Site with name '{$name}' doesn't exists!"); } }
protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $cfg = $this->getSelimConfig($input); if ($cfg->siteExists($name)) { echo "Security-test for {$name}:" . PHP_EOL; $site = $cfg->getSite($name); $sc = new SecurityChecker(new SilverstripePage($site)); $vulns = $sc->findVulnerabilities(true); foreach ($vulns as $vul) { $severity = $vul["severity"] ? $vul["severity"] : "Warning"; Util::forceStringMinLength($severity, 9); echo "{$severity} " . $vul["title"] . PHP_EOL; } } else { Util::reportError("Site with name '{$name}' doesn't exists!"); } }
protected function execute(InputInterface $input, OutputInterface $output) { $cfg = $this->getSelimConfig($input); $skippaths = $input->getOption("skip-known-paths") ? true : false; $path = realpath($input->getArgument("path")); $projects = array(); $question_helper = $this->getHelper("question"); $output->write("Start searching _config.php files..."); $fact = new File_Iterator_Factory(); $iterator = $fact->getFileIterator($path, "php", "_config"); $output->writeln("OK"); $output->write("Filter for project paths..."); while ($file = $iterator->current()) { $content = Util::stripPhpComments(file_get_contents($file)); if (preg_match("/\\\$project\\s=/", $content)) { array_push($projects, dirname($file)); } $iterator->next(); } $output->writeln("OK"); if (count($projects)) { $sites_added = false; $output->writeln("found " . count($projects) . " possible sites"); foreach ($projects as $p) { if ($skippaths && $cfg->sitePathExists($p)) { continue; } $question = new Question("Please enter name for '{$p}' (leave empty to skip)"); do { $name = $question_helper->ask($input, $output, $question); } while ($cfg->siteExists($name)); if ($name) { $sites_added = true; $cfg->addSite($name, $p); } } if ($sites_added) { $output->write("Writing config.json ..."); $cfg->write(); $output->writeln("OK"); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $cfg = $this->getSelimConfig($input); $sites = $cfg->getSites(); $filter_name = $input->getOption("filter-name"); if (strlen($filter_name)) { $sites = Util::filterSitesByName($sites, $filter_name); } $sspages = array(); foreach ($sites as $sc) { if ($sc instanceof SiteConfig) { array_push($sspages, new SilverstripePage($sc)); } } $filter_version = $input->getOption("filter-version"); if (strlen($filter_version)) { $sspages = Util::filterPagesByVersion($sspages, $filter_version); } $filter_module = $input->getOption("filter-module"); if (strlen($filter_module)) { $sspages = Util::filterPagesByModules($sspages, $filter_module); } if ($input->getOption("filter-da")) { $sspages = Util::filterPagesByDefaultAdmin($sspages, true); } $filter_env = $input->getOption("filter-env"); if ($input->getOption("filter-env")) { $sspages = Util::filterPagesByEnvironmentType($sspages, $filter_env); } if ($input->getOption("table")) { $out = new ConsoleOutputTable($sspages); } else { $out = new ConsoleOutput($sspages); } $format = $input->getOption("format"); if (strlen($format)) { $out->write($format); } else { $out->write(); } }
public function testFilterPagesByEnvironmentType() { $pages = array(TestPage::getPage1()->getSSpage(), TestPage::getPage2()->getSSpage(), TestPage::getPage3()->getSSpage()); $filtered = Util::filterPagesByEnvironmentType($pages, "dev"); /* @var $filtered \Selim\SilverstripePage[] */ $this->assertCount(1, $filtered); $this->assertEquals($filtered[0]->getName(), "page1"); $filtered = Util::filterPagesByEnvironmentType($pages, "test"); $this->assertCount(0, $filtered); $filtered = Util::filterPagesByEnvironmentType($pages, "live"); $this->assertEquals($filtered[0]->getName(), "page2"); $this->assertEquals($filtered[1]->getName(), "page3"); $this->assertCount(2, $filtered); }
/** * searches for a regex string in PROJECT/_config.php. * * @param string $regex * * @return boolean */ private function matchInConfigPhp($regex) { if ($this->path_configphp) { $content = file_get_contents($this->path_configphp); $content = Util::stripPhpComments($content); $matches = array(); preg_match_all($regex, $content, $matches); return $matches; } return null; }
public function setPath($config_path = "", $is_cli = true) { $dir = dirname($config_path); if (file_exists($dir)) { if (!file_exists($config_path) && $is_cli) { echo "The file {$config_path} doesn't exist. Do you want to create it? yes/[no]"; $line = fgets(STDIN); if (preg_match("/^y|yes/", $line)) { file_put_contents($config_path, '{"sites":{}}'); } else { Util::reportError("Aborting..."); } } $this->path_config = $config_path; $this->load(); } else { Util::reportError("The directory \"{$dir}\" doesnt exist."); } }