forked from madeny/lhttps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatorCommand.php
More file actions
84 lines (62 loc) · 2.39 KB
/
CreatorCommand.php
File metadata and controls
84 lines (62 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Madeny\lhttps;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Madeny\lhttps\Config;
use Madeny\lhttps\Factory;
use Madeny\lhttps\Path;
use Madeny\lhttps\DomainProvider;
class CreatorCommand extends Command
{
protected function configure()
{
$this
->setName('create')
->addArgument("domainName", InputArgument::OPTIONAL, 'Add a custom domain name defualt domain is localhost')
->setDescription('Creates a new certificate.')
->setHelp('This command allows you to create a root certificate...');
$this
->addOption(
'a',
null,
InputOption::VALUE_NONE,
'This will add your root certificate on your OS trusted list?'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Instantiating dependencies
$path = Path::all();
Config::createFolders($path);
$domain = new DomainProvider();
$domainName = $input->getArgument('domainName');
$domain->setDomainOne($domainName);
Config::file($path, $domain->getDomainOne(), $domain->getDomainTwo());
// generate a root certificate key.
Factory::keygen($path);
// Create a root certificate authority.
Factory::create($path);
// Create cert key for a domain.
Factory::domain($path, $domain->getDomainOne(), $domain->getDomainTwo());
// Request a certificate sign from root certificate authority.
Factory::request($path, $domainName);
$checker = exec("uname -a");
$option = $input->getOption('a');
if (!$option == true) {
exit();
}else{
$trust = Factory::trust($path, $checker, $option);
}
// Disply error messages.
if ( $trust->getError() == 1) {
$output->writeln('<error>Sorry this host not support!</error>');
}elseif ($trust->getError() == 1) {
$output->writeln('<info>Fail to add your certificate to trust list you can do it manually</info>');
}elseif ($trust->getError() == 0) {
$output->writeln('<info>Your certificate is added to your trust list</info>');
}
}
}