Skip to content

Commit

Permalink
Init feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sescandell committed Oct 20, 2014
1 parent 4af0f33 commit 6c64a2b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 21 deletions.
38 changes: 17 additions & 21 deletions Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
$deployment->create();
$deployment->createRole($roleName);

$output->writeln(sprintf('<info>Created basic Azure structure and one WebRole "%s"</info>', $roleName));
$output->writeln(sprintf('<info>Renewing certificate for WebRole "%s"</info>', $roleName));
$output->writeln('Next steps:');
$output->writeln('- Take a look into the app\azure Folder, it contains Azure related files.');
$output->writeln('- See the app\config\parameters_azure.yml and app\config\config_azure.yml');
$output->writeln('- Run the packaging command "windowsazure:package"');

if (extension_loaded('openssl')) {
$length = 16;
$keyPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$keyPassword = substr($keyPassword, 0, $length);
$desktopPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$desktopPassword = substr($desktopPassword, 0, $length);

$deployment->generateRemoteDesktopKey($roleName, $desktopPassword, $keyPassword);

$output->writeln('');
$output->writeln('Automatically created certificates to open a remote desktop to this role.');
$output->writeln('Private Key Password: <info>' . $keyPassword . '</info>');
$output->writeln('RemoteDesktop Password: <info>' . $desktopPassword . '</info>');
$output->writeln('<comment>Write these passwords down, you need them during deployment.</comment>');
$output->writeln('You can disable RemoteDesktop in ServiceConfiguration.cscfg');
}
$output->writeln('- Update the new certificate to your portal.');

$length = 16;
$keyPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$keyPassword = substr($keyPassword, 0, $length);
$desktopPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$desktopPassword = substr($desktopPassword, 0, $length);

$deployment->generateRemoteDesktopKey($roleName, $desktopPassword, $keyPassword, true);

$output->writeln('');
$output->writeln('Certificate informations:');
$output->writeln('Private Key Password: <info>' . $keyPassword . '</info>');
$output->writeln('RemoteDesktop Password: <info>' . $desktopPassword . '</info>');
$output->writeln('<comment>Write these passwords down, you need them during deployment.</comment>');
$output->writeln('You can disable RemoteDesktop in ServiceConfiguration.cscfg');
}
}
64 changes: 64 additions & 0 deletions Command/RenewCertificateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* WindowsAzure DistributionBundle
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace WindowsAzure\DistributionBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

/**
* Renew remote desktop certificates
* @package WindowsAzure\DistributionBundle\Command
* @author Stéphane Escandell <stephane.escandell@gmail.com>
*/
class RenewCertificateCommand extends ContainerAwareCommand
{

protected function configure()
{
$this
->setName('azure:cloud-services:renew-certificate')
->setDescription('Renew certificate to remote desktop access.');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$deployment = $this->getContainer()->get('windows_azure_distribution.deployment');
if (!$deployment->exists()) {
throw new \RuntimeException("Azure Cloud Services is not initialized for this Symfony project. Please run the azure:cloud-services:init first.");
}

$roleName = 'Sf2.Web';

if (extension_loaded('openssl')) {
$length = 16;
$keyPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$keyPassword = substr($keyPassword, 0, $length);
$desktopPassword = base64_encode(openssl_random_pseudo_bytes(8, $strong));
$desktopPassword = substr($desktopPassword, 0, $length);

$deployment->generateRemoteDesktopKey($roleName, $desktopPassword, $keyPassword);

$output->writeln('');
$output->writeln('Automatically created certificates to open a remote desktop to this role.');
$output->writeln('Private Key Password: <info>' . $keyPassword . '</info>');
$output->writeln('RemoteDesktop Password: <info>' . $desktopPassword . '</info>');
$output->writeln('<comment>Write these passwords down, you need them during deployment.</comment>');
$output->writeln('You can disable RemoteDesktop in ServiceConfiguration.cscfg');
}
}
}

0 comments on commit 6c64a2b

Please sign in to comment.