protected function onExec(InputInterface $input, OutputInterface $output) { $username = $input->getOption('username'); $password = $input->getOption('password'); if (!Text::is($username)) { $output->writeln('Please specify a username using via <error>-U or --username</error>'); } else { if (!Text::is($password)) { $output->writeln('Please specify a password using via <error>-P or --password</error>'); } else { $output->write(sprintf('Resetting password for <comment>%s</comment>...', $username)); try { /** @var $db \Doctrine\DBAL\Connection */ /** @var $encoder \Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder */ $db = $this->container['db']; $encoder = $this->container['encoder']; $qb = $db->createQueryBuilder(); $qb->update('users')->set('password', '?')->where($qb->expr()->eq('username', '?'))->setParameter(0, $encoder->encodePassword($password, null))->setParameter(1, $username); if ($qb->execute() == 1) { $output->writeln('<info>Done</info>'); $output->writeln(sprintf('New password for <comment>%s</comment> is <info>%s</info>', $username, $password)); } else { $output->writeln('<error>Failed</error>'); } } catch (\Exception $e) { $output->writeln('<error>Failed</error>'); throw new \RuntimeException($e); } } } }
protected function onExec(InputInterface $input, OutputInterface $output) { $file = $this->container['root'] . '/.env'; $contents = @file_get_contents($file); if (!Text::is($contents)) { $output->writeln(sprintf('Using to write <comment>%s</comment>...', $file)); } else { $output->write(sprintf('Setting up key in <comment>%s</comment>...', $file)); $lines = explode(PHP_EOL, $contents); for ($i = 0; $i < count($lines); ++$i) { $line = $lines[$i]; if (Text::is($line) && strpos($line, 'SECURITY_KEY') === 0) { /** @var $random \RandomLib\Generator */ $random = $this->container['random']; $lines[$i] = sprintf('SECURITY_KEY=%s', $random->generateString(16)); break; } } if (file_put_contents($file, implode(PHP_EOL, $lines))) { $output->writeln('<info>Done</info>'); } else { $output->writeln('<error>Failed</error>'); $output->writeln(sprintf('Unable to write to write <comment>%s</comment>...', $file)); } } }
protected function onExec(InputInterface $input, OutputInterface $output) { $username = $input->getOption('username'); $password = $input->getOption('password'); if (!Text::is($username)) { $output->writeln('Please specify a username using via <error>-U or --username</error>'); } else { if (!Text::is($password)) { $output->writeln('Please specify a password using via <error>-P or --password</error>'); } else { $output->write(sprintf('Adding user <comment>%s</comment> to database...', $username)); try { /** @var $db \Doctrine\DBAL\Connection */ /** @var $encoder \Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder */ $db = $this->container['db']; $encoder = $this->container['encoder']; $qb = $db->createQueryBuilder(); $qb->insert('users')->values(array('created_at' => '?', 'password' => '?', 'username' => '?'))->setParameter(0, date('Y-m-d H:i:s'))->setParameter(1, $encoder->encodePassword($password, null))->setParameter(2, $username); if ($qb->execute() == 1) { $output->writeln('<info>Done</info>'); $output->writeln(sprintf('You can now login as <info>%s</info>:<info>%s</info>', $username, $password)); } else { $output->writeln('<error>Failed</error>'); } } catch (\Exception $e) { $output->writeln('<error>Failed</error>'); throw new \RuntimeException($e); } } } }
public function save() { /** @var $request \Symfony\Component\HttpFoundation\Request */ $request = $this->container['request']; $package = $request->getUser(); $token = $request->getPassword(); if (Text::is($package, $token)) { /** @var $qb \Doctrine\DBAL\Query\QueryBuilder */ $qb = $this->container['db']->createQueryBuilder(); $result = $qb->select('id')->from('applications')->where($qb->expr()->eq('package_name', '?'))->andWhere($qb->expr()->eq('token', '?'))->setParameter(0, $package)->setParameter(1, $token)->execute(); if ($result->rowCount() == 1) { $application = $result->fetchColumn(0); $post = $request->request->all(); $data = array(); foreach ($post as $key => $value) { $data[strtolower($key)] = $value; } $data = array_replace($data, array('application_id' => $application, 'checksum' => hash('md5', $data['package_name'] . $data['stack_trace']), 'created_at' => date('Y-m-d H:i:s'), 'user_app_start_date' => $data['user_app_start_date'], 'user_crash_date' => $data['user_crash_date'])); $stacktrace = explode(PHP_EOL, $data['stack_trace']); foreach ($stacktrace as $line) { if (strpos($line, 'Caused by: ') === 0) { $data['exception'] = substr($line, strpos($line, ':') + 2); break; } } if (!isset($data['exception'])) { $data['exception'] = substr($data['stack_trace'], 0, strpos($data['stack_trace'], ':')); } /** @var $db \Doctrine\DBAL\Connection */ $db = $this->container['db']; return new Response('', $db->insert('reports', $data) == 1 ? 200 : 500); } else { throw new AccessDeniedHttpException(); } } else { throw new BadRequestHttpException(); } }
public function query($query) { if (Text::is($query)) { /** @var $qb \Doctrine\DBAL\Query\QueryBuilder */ $qb = $this->container['db']->createQueryBuilder(); $qb->select('R.id', 'A.title as application', 'R.checksum', 'R.exception', 'R.created_at')->from('reports', 'R')->leftJoin('R', 'applications', 'A', 'A.id = R.application_id')->where($qb->expr()->like('R.stack_trace', ':query'))->orWhere($qb->expr()->like('A.title', ':query'))->orderBy('R.created_at', 'DESC'); /** @var $group \Doctrine\DBAL\Query\QueryBuilder */ $group = $this->container['db']->createQueryBuilder(); $group->select('*')->from('(' . $qb->getSQL() . ')', 'T')->groupBy('checksum')->setParameter('query', "%{$query}%"); $result = $group->execute(); $results = array(); if ($result->rowCount() >= 1) { /** @var $url \Symfony\Component\Routing\Generator\UrlGeneratorInterface */ $url = $this->container['url_generator']; while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { $results[] = array('application' => $row['application'], 'datetime' => $row['created_at'], 'exception' => $row['exception'], 'url' => $url->generate('reports_view', array('id' => $row['id']))); } } return new JsonResponse($results); } else { throw new BadRequestHttpException(); } }
protected function onExec(InputInterface $input, OutputInterface $output) { $file = $input->getOption('file'); if (Text::is($file)) { $file = realpath($file); $sql = @file_get_contents($file); if (Text::is($sql)) { $output->write(sprintf('Importing file <comment>%s</comment>...', $file)); try { /** @var $db \Doctrine\DBAL\Connection */ $db = $this->container['db']; $db->exec($sql); $output->writeln('<info>Done</info>'); } catch (\Exception $e) { $output->writeln('<error>Failed</error>'); throw new \RuntimeException($e); } } else { $output->writeln('Unable to read any SQL commands from file'); } } else { $output->writeln('Please specify a file to import SQL from'); } }