private function setPerms($action, $args) { if (posix_getuid() == 0) { $chown = new Chown(); switch ($action) { case 'install': case 'upgrade': case 'update': if (sizeof($args) == 1) { $chown->moduleName = $args[0]; } break; } $chown->execute($this->input, $this->out, true); } }
protected function execute(InputInterface $input, OutputInterface $output) { if (posix_geteuid() != 0) { $output->writeln("<error>You need to be root to run this command</error>"); exit(1); } $args = $input->getArgument('args'); if (!empty($args)) { $pre = $this->preAsteriskHooks($output, false); $post = $this->postAsteriskHooks($output, false); $aststat = $this->asteriskProcess(); $asteriskrunning = $aststat[0]; $bmo = \FreePBX::create(); $found = false; foreach ($pre as $pri => $data) { if (strtolower($data['module']) == $args[0]) { $found = true; if ($asteriskrunning) { $output->writeln("<error>" . _('This service must be started before Asterisk has started') . "</error>"); break; } $bmo->{$data}['module']->{$data}['method']($output); break; } } foreach ($post as $pri => $data) { if (strtolower($data['module']) == $args[0]) { $found = true; if (!$asteriskrunning) { $output->writeln("<error>" . _('This service must be started after Asterisk has started') . "</error>"); break; } $bmo->{$data}['module']->{$data}['method']($output); break; } } if (!$found) { $output->writeln("<error>" . _('Unable to find service to start') . "</error>"); } } else { $brand = \FreePBX::Config()->get("DASHBOARD_FREEPBX_BRAND"); $output->writeln(sprintf(_('Running %s startup...'), $brand)); $chown = new Chown(); $chown->execute($input, $output); $output->writeln(''); $output->writeln(_('Checking Asterisk Status...')); $aststat = $this->asteriskProcess(); if ($aststat[0]) { $output->writeln(sprintf(_('Asterisk Seems to be running on PID %s and has been running for %s'), $aststat[0], trim($aststat[1]))); $output->writeln('<info>' . _('Not running Pre-Asterisk Hooks.') . '</info>'); } else { $output->writeln(_('Run Pre-Asterisk Hooks')); $this->preAsteriskHooks($output); $output->writeln(''); $this->startAsterisk($output); $progress = new ProgressBar($output, 100); $progress->start(); $i = 0; while ($i++ < 3) { $progress->advance(33); sleep(1); } $aststat = $this->asteriskProcess(); if ($aststat[0]) { $progress->finish(); $output->writeln(''); $output->writeln(sprintf(_('Asterisk Started on %s'), $aststat[0])); $output->writeln(''); $output->writeln(_('Running Post-Asterisk Scripts')); $this->postAsteriskHooks($output); } else { $progress->finish(); $output->writeln('<error>' . _("Asterisk Failed to Start") . '</error>'); } } } }
protected function execute(InputInterface $input, OutputInterface $output) { if (posix_geteuid() != 0) { $output->writeln("<error>You need to be root to run this command</error>"); exit(1); } $options = $input->getOptions(); $this->skipChown = $options['skipchown'] ? true : $this->skipChown; $args = $input->getArgument('args'); $pre = $this->preAsteriskHooks($output, false); $post = $this->postAsteriskHooks($output, false); $aststat = $this->asteriskProcess(); $asteriskrunning = !empty($aststat); $bmo = \FreePBX::create(); // We were asked to only run the pre-start hooks? if ($options['pre']) { // Note: Do not i18n. $output->writeln("Only running pre-hooks"); $runpre = "force"; $startasterisk = false; $runpost = false; } elseif ($options['post']) { // Note: Do not i18n. $output->writeln("Only running post-hooks"); $runpre = false; $startasterisk = false; $runpost = "force"; } else { $runpre = true; $startasterisk = true; $runpost = true; } // Do we have any params? if ($args) { // We do. Create a temporary array with our hooks, using the ones // we've been asked to do. $newpre = array(); $newpost = array(); $startasterisk = false; foreach ($args as $v) { if ($runpre) { foreach ($pre as $pri => $data) { if (strtolower($data['module']) == strtolower($v)) { $newpre[$pri] = $data; } } } if ($runpost) { foreach ($post as $pri => $data) { if (strtolower($data['module']) == strtolower($v)) { $newpost[$pri] = $data; } } } } // And overwrite our hooks to run later $pre = $newpre; $post = $newpost; } if ($startasterisk && $asteriskrunning) { $output->writeln("<error>Asterisk already running</error>"); } // Now we're ready to go. $brand = \FreePBX::Config()->get("DASHBOARD_FREEPBX_BRAND"); $output->writeln(sprintf(_('Running %s startup...'), $brand)); if ($runpre) { if ($runpre !== "force") { if (!$this->skipChown) { $chown = new Chown(); $chown->execute($input, $output); } } if ($aststat) { $output->writeln(sprintf(_('Unable to run Pre-Asterisk hooks, because Asterisk is already running on PID %s and has been running for %s'), $aststat, $this->asteriskUptime())); $startasterisk = false; } else { foreach ($pre as $pri => $data) { $bmo->{$data}['module']->{$data}['method']($output); } } } if ($startasterisk) { if ($this->startAsterisk($output)) { $output->writeln(''); $output->writeln(_("Asterisk Started")); } else { $output->writeln(''); $output->writeln(_("Unable to start Asterisk!")); } } if ($runpost) { foreach ($post as $pri => $data) { $bmo->{$data}['module']->{$data}['method']($output); } } }
private function setPerms($action, $args) { if ($this->skipchown) { return; } if (posix_getuid() == 0) { $chown = new Chown(); if (sizeof($args) == 1) { $chown->moduleName = $args[0]; } $chown->execute($this->input, $this->out, true); } }