Verified Commit cea0b639 authored by Tharyrok's avatar Tharyrok
Browse files

Add Vpn Form

parent 601761e2
......@@ -8,10 +8,10 @@
"ext-ctype": "*",
"ext-filter": "*",
"ext-iconv": "*",
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-intl": "*",
"composer/package-versions-deprecated": "1.11.99.2",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.4",
......@@ -19,6 +19,7 @@
"doctrine/orm": "^2.9",
"gedmo/doctrine-extensions": "^3.1",
"phpdocumentor/reflection-docblock": "^5.2",
"phpseclib/phpseclib": "~3.0",
"sensio/framework-extra-bundle": "^6.1",
"stof/doctrine-extensions-bundle": "^1.6",
"symfony/asset": "5.3.*",
......
This diff is collapsed.
......@@ -11,7 +11,8 @@ framework:
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
form:
legacy_error_messages: false
#esi: true
#fragments: true
php_errors:
......
......@@ -13,7 +13,7 @@ webpack_encore:
# crossorigin: 'anonymous'
# Preload all rendered script and link tags automatically via the HTTP/2 Link header
# preload: true
preload: true
# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
# strict_mode: false
......
......@@ -5,6 +5,7 @@ namespace App\Controller\User;
use App\Entity\Openvpn;
use App\Form\OpenvpnType;
use App\Repository\OpenvpnRepository;
use phpseclib3\File\X509;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -29,10 +30,18 @@ class OpenvpnController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($openvpn);
$entityManager->flush();
$x509 = new X509();
$csr = $x509->loadCSR($form->getNormData()['certificates_csr']);
dd($x509->saveCSR($csr, X509::FORMAT_PEM));
/*$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($openvpn);
$entityManager->flush();*/
$this->addFlash('success', 'Vpn is created !');
return $this->redirectToRoute('user_openvpn_index');
}
......
......@@ -3,6 +3,7 @@
namespace App\Form;
use App\Entity\Openvpn;
use App\Validator\CertificateSigningRequest;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
......@@ -23,6 +24,8 @@ class OpenvpnType extends AbstractType
'spellcheck' => false,
'style' => 'font-family: var(--bs-font-monospace);'
],
'required' => true,
'constraints' => [new CertificateSigningRequest()],
'label' => 'Certificate Signing Request',
'help' => 'Copies the contents of the xxx.csr file generated with this command : openssl req -new -nodes -newkey ec:<(openssl ecparam -name secp384r1 -rand /dev/urandom) -keyout user.key -out user.csr -subj "/CN=Neutrinet/"',
])
......@@ -44,7 +47,7 @@ class OpenvpnType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Openvpn::class,
]);
}
}
<?php
namespace App\Services\Api;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\RetryableHttpClient;
class CertificatesApiKetupaService
{
/**
* @var RetryableHttpClient
*/
private RetryableHttpClient $client;
public function __construct()
{
$this->client = new RetryableHttpClient(HttpClient::create());
}
public function post(string $csr, string $email) {
$data = $this->client->request('POST', 'http://api.ketupa.vagrant.neutrinet.me/certificates/', [
'json' => [
]
]);
}
}
\ No newline at end of file
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class CertificateSigningRequest extends Constraint
{
/*
* Any public properties become valid options for the annotation.
* Then, use these in your validator class.
*/
public $message = 'The Certificate Signing Request is not valid.';
}
<?php
namespace App\Validator;
use phpseclib3\File\X509;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class CertificateSigningRequestValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
/* @var $constraint \App\Validator\CertificateSigningRequest */
if (null === $value || '' === $value) {
return;
}
$x509 = new X509();
$csr = $x509->loadCSR($value);
if(!$x509->validateSignature()) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $value)
->addViolation();
}
}
}
......@@ -106,6 +106,12 @@
"nikic/php-parser": {
"version": "v4.10.5"
},
"paragonie/constant_time_encoding": {
"version": "v2.4.0"
},
"paragonie/random_compat": {
"version": "v9.99.100"
},
"phar-io/manifest": {
"version": "2.0.1"
},
......@@ -121,6 +127,9 @@
"phpdocumentor/type-resolver": {
"version": "1.4.0"
},
"phpseclib/phpseclib": {
"version": "3.0.9"
},
"phpspec/prophecy": {
"version": "1.13.0"
},
......
......@@ -3,7 +3,16 @@
{% block title %}List clients OpenVPN{% endblock %}
{% block body %}
<div class="container-fluid px-4">
<div class="container-fluid">
<div class="row justify-content-md-center">
{% for message in app.flashes('success') %}
<div class="alert alert-success alert-dismissible fade show col-10 mt-1" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
</div>
<div class="row">
<div class="col">
<h1 class="mt-4">List clients OpenVPN</h1>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment