GenDuid into php app

This commit is contained in:
James Gilliland 2022-03-06 01:02:17 -06:00
parent 27f49445fb
commit b3d3728186
3 changed files with 73 additions and 58 deletions

View file

@ -1,45 +0,0 @@
#!/bin/sh
ascii2hex() { echo -n "$*" | awk 'BEGIN{for(n=0;n<256;n++)ord[sprintf("%c",n)]=n}{len=split($0,c,"");for(i=1;i<=len;i++)printf("%x",ord[c[i]])}'; }
printhexstring() { awk '{l=split($0,c,"");for(i=1;i<l-1;i=i+2)printf("%s:",substr($0,i,2));print(substr($0,l-1,2))}'; }
echo
echo "Step 1) RG information"
echo
while read -p " Manufacturer [1=Pace, 2=Motorola/Arris]: " mfg; do
([ "$mfg" = "1" ] || [ "$mfg" = "2" ]) && break
done
while read -p " Serial number: " serial; do [ -n "$serial" ] && break; done
echo
[ "$mfg" = "1" ] && mfg="00D09E" || mfg="001E46"
echo -n "Identifier: "
ascii2hex "$mfg-$serial" | printhexstring
cat << EOF
Step 2) Navigate to System->Advanced->Networking in webConfigurator.
IPv6 Options
DHCP6 DUID: DUID-EN
DUID-EN
Enterprise Number: 3561
Identifier: As shown above
Click Save.
Step 3) Navigate to Interfaces->WAN in webConfigurator.
General Configuration
IPv6 Configuration Type: DHCP6
MAC Address: Same as MAC address of RG
Other options are probably needed, so set those too.
Click Save. This will finally save dhcp6c's DUID file and start the client.
Step 4) Finished, hopefully.
Good luck!
EOF

View file

@ -4,23 +4,16 @@ declare(strict_types=1);
namespace Pfatt\Commands; namespace Pfatt\Commands;
use Pfatt\Service\Logger;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
final class GenDuid extends Command final class GenDuid extends Command
{ {
protected static $defaultName = 'gen-duid'; protected static $defaultName = 'gen-duid';
protected static $defaultDescription = 'Generate DUID for IPV6 configuration.'; protected static $defaultDescription = 'Generate DUID for IPV6 configuration.';
protected Logger $logger;
public function __construct(
Logger $logger,
) {
parent::__construct('gen-duid');
$this->logger = $logger;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -29,9 +22,72 @@ final class GenDuid extends Command
InputInterface $input, InputInterface $input,
OutputInterface $output OutputInterface $output
): int { ): int {
$this->logger->setOutput($output);
$this->logger->info('Starting 5268AC ping monitor ...'); $output->writeln('');
$output->writeln('Step 1) RG information');
$output->writeln('');
/** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ChoiceQuestion('Manufacturer?', [
1 => 'Pace',
2 => 'Motorola/Arris',
]);
/** @var string $manufacturer */
$manufacturer = $helper->ask($input, $output, $question);
if ($manufacturer === 'Pace') {
$manufacturer = '00D09E';
} else {
$manufacturer = '001E46';
}
$question = new Question('Serial number?');
/** @var string $serial */
$serial = $helper->ask($input, $output, $question);
$output->writeln('Identifier: ' . $this->ascii2hex($manufacturer . ':' . $serial));
$output->write($this->getInstructions());
return Command::SUCCESS; return Command::SUCCESS;
} }
private function ascii2hex(string $ascii): string
{
$bytes = [];
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii[$i])));
$bytes[] = str_repeat('0', 2 - strlen($byte)) . $byte;
}
return implode(':', $bytes);
}
private function getInstructions(): string
{
return <<<EOF
Step 2) Navigate to System->Advanced->Networking in webConfigurator.
IPv6 Options
DHCP6 DUID: DUID-EN
DUID-EN
Enterprise Number: 3561
Identifier: As shown above
Click Save.
Step 3) Navigate to Interfaces->WAN in webConfigurator.
General Configuration
IPv6 Configuration Type: DHCP6
MAC Address: Same as MAC address of RG
Other options are probably needed, so set those too.
Click Save. This will finally save dhcp6c's DUID file and start the client.
Step 4) Finished, hopefully.
Good luck!
EOF;
}
} }

View file

@ -56,12 +56,16 @@ final class PfattKernel
$containerBuilder->autowire(NgController::class, NgController::class) $containerBuilder->autowire(NgController::class, NgController::class)
->setPublic(true); ->setPublic(true);
// Register commands.
$containerBuilder->autowire(Startup::class, Startup::class)
->setPublic(true);
$containerBuilder->autowire(GenDuid::class, GenDuid::class)
->setPublic(true);
$containerBuilder->autowire(Monitor::class, Monitor::class) $containerBuilder->autowire(Monitor::class, Monitor::class)
->setPublic(true) ->setPublic(true)
->setArgument(Logger::class, new Reference('logger-5268')); ->setArgument(Logger::class, new Reference('logger-5268'));
$containerBuilder->autowire(Startup::class, Startup::class)
->setPublic(true);
// Register application.
$containerBuilder->register(ContainerCommandLoader::class, ContainerCommandLoader::class) $containerBuilder->register(ContainerCommandLoader::class, ContainerCommandLoader::class)
->setArguments([ ->setArguments([
new Reference('service_container'), new Reference('service_container'),