Skip to content

Commit

Permalink
Merge pull request #64 from H2-invent/feature/licenseSystem
Browse files Browse the repository at this point in the history
Feature/license system
  • Loading branch information
holema authored Feb 13, 2021
2 parents 5db9d34 + f984fb7 commit 679960e
Show file tree
Hide file tree
Showing 27 changed files with 770 additions and 120 deletions.
14 changes: 14 additions & 0 deletions key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqoyqw2cO3aYFzV2T0aA7
WndQYSrROaNxqneEzlMA/L7yE9yloCo2HUcorerS3Ev/cubUWUAWBSlDjgpXJPyD
P0tv54hrwN3m/1s8V1IVZd99GVrcjP4ZoGlX+iCkza+DrAmIl7LqUkrWec4cLNTo
jnmegXmKnoKUOCcKH5CDohfUMe8uHZbO5avuf/6Wn/lDLt1PT4SIu6+d3h/Pt7Cv
M4SG2T5S421zWaVsZRLEHS++PcXS2JymryX6lqCiUIxYktG2UFOxEDa5moQY5URY
ZP2o95fwM42loayVBKCiPe0XIWn4nA8oMtVx4n4gQGjwg02cKgLnnAK/CaLQ1AUq
EUWvWjOKhGpvvD5EoHwflj4HEIRScTutOzLb1Hf9JC6+Z/JXE0rxMcGc0PHfmJhq
VbRwbvAmHkdgLzjzJklahWfkrg3ph5YGqtYvnilaXgtiZNyPpizkrl2JPJaMjAwn
oOpItcLt/c5yAo/8JQ+8tb6dZQ9/GshRDI2fkXhZ56wq6F3op6yoeYIrvu/TuYMV
/5gCyNWQI6PsROSMo1MrnHgg+wv30MqylK1ELV6mhqP4Hnmj+8zjULrD2Q5fu1zs
AnHzIxCTEprRPDvZKM5M79YsMhoLbPtSl48q5grAcEY8QOZfn+hugfOmBjDWrjna
asPYQPCc/W7ZmJuKVTjiRUUCAwEAAQ==
-----END PUBLIC KEY-----
38 changes: 36 additions & 2 deletions src/Controller/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use App\Entity\Rooms;
use App\Entity\Server;
use App\Entity\User;
use App\Form\Type\EnterpriseType;
use App\Form\Type\NewMemberType;
use App\Form\Type\NewPermissionType;
use App\Form\Type\RoomType;
use App\Form\Type\ServerType;
use App\Service\LicenseService;
use App\Service\MailerService;
use App\Service\ServerService;
use App\Service\UserService;
Expand Down Expand Up @@ -67,7 +69,37 @@ public function serverAdd(Request $request, ValidatorInterface $validator, Serve
return $this->render('servers/__addServerModal.html.twig', array('form' => $form->createView(), 'title' => $title, 'server' => $server));

}
/**
* @Route("/server/enterprise", name="servers_enterprise")
*/
public function serverEnterprise(Request $request, ValidatorInterface $validator, ServerService $serverService, TranslatorInterface $translator, LicenseService $licenseService)
{

$server = $this->getDoctrine()->getRepository(Server::class)->findOneBy(array('id' => $request->get('id')));
if ($server->getAdministrator() !== $this->getUser() || !$licenseService->verify($server)) {
return $this->redirectToRoute('dashboard', ['snack' => 'Keine Berechtigung']);
}
$title = $translator->trans('Jitsi-Admin Enterprise Einstellungen');


$form = $this->createForm(EnterpriseType::class, $server, ['action' => $this->generateUrl('servers_enterprise', ['id' => $server->getId()])]);
$form->handleRequest($request);

$errors = array();
if ($form->isSubmitted() && $form->isValid()) {
$server = $form->getData();
$errors = $validator->validate($server);
if (count($errors) == 0) {
$em = $this->getDoctrine()->getManager();
$em->persist($server);
$em->flush();
return $this->redirectToRoute('dashboard');
}
}

return $this->render('servers/__serverEnterpriseModal.html.twig', array('form' => $form->createView(), 'title' => $title, 'server' => $server));

}
/**
* @Route("/server/add-user", name="server_add_user")
*/
Expand Down Expand Up @@ -141,7 +173,7 @@ function servercheckEmail(Request $request, TranslatorInterface $translator, Mai
$res = ['snack'=>$translator->trans('Fehler, der Server ist nicht registriert'),'color'=>'danger'];
} else {
try {
$mailerService->sendEmail(
$r = $mailerService->sendEmail(
$this->getUser()->getEmail(),
$translator->trans('Testmail vom Jitsi-Admin').' | '.$server->getUrl(),
'<h1>' . $translator->trans('Sie haben einen SMTP-Server für Ihren Jitsi-Server erfolgreich eingerichtet') . '</h1>'
Expand All @@ -150,8 +182,10 @@ function servercheckEmail(Request $request, TranslatorInterface $translator, Mai
.$server->getSmtpSenderName().'<br>',
$server
);
if(!$r){
$res = ['snack'=>$translator->trans('Fehler, Ihre SMTP-Parameter sind fehlerhaft'),'color'=>'danger'];
}
} catch (\Exception $e) {

$res = ['snack'=>$translator->trans('Fehler, Ihre SMTP-Parameter sind fehlerhaft'),'color'=>'danger'];
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/Controller/api/APILicenseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Controller\api;

use App\Entity\License;
use App\Service\LicenseService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class APILicenseController extends AbstractController
{
/**
* @Route("/api/v1/generateLicense", name="api_generate_license",methods={"POST"})
*/
public function index(Request $request, LicenseService $licenseService): Response
{
return new JsonResponse($licenseService->generateNewLicense(
$request->get('license')
)
);
}
}
100 changes: 100 additions & 0 deletions src/Entity/License.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace App\Entity;

use App\Repository\LicenseRepository;
use App\Service\LicenseService;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\This;

/**
* @ORM\Entity(repositoryClass=LicenseRepository::class)
*/
class License
{

/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(type="text")
*/
private $licenseKey;

/**
* @ORM\Column(type="text")
*/
private $license;

/**
* @ORM\Column(type="datetime")
*/
private $validUntil;

/**
* @ORM\Column(type="text")
*/
private $url;



public function getId(): ?int
{
return $this->id;
}

public function getLicenseKey(): ?string
{
return $this->licenseKey;
}

public function setLicenseKey(string $licenseKey): self
{
$this->licenseKey = $licenseKey;

return $this;
}

public function getLicense(): ?string
{
return $this->license;
}

public function setLicense(string $license): self
{
$this->license = $license;

return $this;
}

public function getValidUntil(): ?\DateTimeInterface
{
return $this->validUntil;
}

public function setValidUntil(\DateTimeInterface $validUntil): self
{
$this->validUntil = $validUntil;

return $this;
}

public function getUrl(): ?string
{
return $this->url;
}

public function setUrl(string $url): self
{
$this->url = $url;

return $this;
}


}
19 changes: 19 additions & 0 deletions src/Entity/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
class Server
{

/**
* @ORM\Id
* @ORM\GeneratedValue
Expand Down Expand Up @@ -100,11 +101,17 @@ class Server
*/
private $privacyPolicy;

/**
* @ORM\Column(type="text", nullable=true)
*/
private $licenseKey;


public function __construct()
{
$this->user = new ArrayCollection();
$this->rooms = new ArrayCollection();

}

public function getId(): ?int
Expand Down Expand Up @@ -334,5 +341,17 @@ public function setPrivacyPolicy(?string $privacyPolicy): self
return $this;
}

public function getLicenseKey(): ?string
{
return $this->licenseKey;
}

public function setLicenseKey(?string $licenseKey): self
{
$this->licenseKey = $licenseKey;

return $this;
}

}

52 changes: 52 additions & 0 deletions src/Form/Type/EnterpriseType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Created by PhpStorm.
* User: Emanuel
* Date: 17.09.2019
* Time: 20:29
*/

namespace App\Form\Type;


use App\Entity\AuditTomAbteilung;
use App\Entity\Server;
use League\CommonMark\Inline\Element\Text;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EnterpriseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{

$builder
->add('smtpHost', TextType::class, ['required' => false, 'label' => 'label.serverSmtpHostName', 'translation_domain' => 'form'])
->add('smtpPort', TextType::class, ['required' => false, 'label' => 'label.serverSmtpHostPort', 'translation_domain' => 'form'])
->add('smtpEncryption', ChoiceType::class, ['required' => false, 'label' => 'label.serverSmtpEncryption', 'translation_domain' => 'form', 'choices'=>
array('choice.tls'=>'tls','choice.ssl'=>'ssl','choice.none'=>null)])
->add('smtpUsername', TextType::class, ['required' => false, 'label' => 'label.serverSmtpUsername', 'translation_domain' => 'form'])
->add('smtpPassword', TextType::class, ['required' => false, 'label' => 'label.serverSmtpPassword', 'translation_domain' => 'form'])
->add('smtpEmail', TextType::class, ['required' => false, 'label' => 'label.serverSmtpSenderEmail', 'translation_domain' => 'form'])
->add('smtpSenderName', TextType::class, ['required' => false, 'label' => 'label.serverSmtpSenderName', 'translation_domain' => 'form'])
->add('logoUrl', TextType::class, ['required' => false, 'label' => 'label.serverLintLogo', 'translation_domain' => 'form'])
->add('privacyPolicy', TextType::class, ['required' => false, 'label' => 'label.serverPrivacyPolicy', 'translation_domain' => 'form'])
->add('submit', SubmitType::class, ['attr' => array('class' => 'btn btn-outline-primary'), 'label' => 'label.speichern', 'translation_domain' => 'form']);

}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
]);

}
}
12 changes: 1 addition & 11 deletions src/Form/Type/ServerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('appId', TextType::class, ['required' => false, 'label' => 'label.appId', 'translation_domain' => 'form'])
->add('appSecret', TextType::class, ['required' => false, 'label' => 'label.appSecret', 'translation_domain' => 'form'])
->add('url', TextType::class, ['required' => true, 'label' => 'lable.serverUrl', 'translation_domain' => 'form', 'help' => 'help.serverUrl'])
->add('smtpHost', TextType::class, ['required' => false, 'label' => 'label.serverSmtpHostName', 'translation_domain' => 'form'])
->add('smtpPort', TextType::class, ['required' => false, 'label' => 'label.serverSmtpHostPort', 'translation_domain' => 'form'])
->add('smtpEncryption', ChoiceType::class, ['required' => false, 'label' => 'label.serverSmtpEncryption', 'translation_domain' => 'form', 'choices'=>
array('choice.tls'=>'tls','choice.ssl'=>'ssl','choice.none'=>null)])
->add('smtpUsername', TextType::class, ['required' => false, 'label' => 'label.serverSmtpUsername', 'translation_domain' => 'form'])
->add('smtpPassword', TextType::class, ['required' => false, 'label' => 'label.serverSmtpPassword', 'translation_domain' => 'form'])
->add('smtpEmail', TextType::class, ['required' => false, 'label' => 'label.serverSmtpSenderEmail', 'translation_domain' => 'form'])
->add('smtpSenderName', TextType::class, ['required' => false, 'label' => 'label.serverSmtpSenderName', 'translation_domain' => 'form'])
->add('logoUrl', TextType::class, ['required' => false, 'label' => 'label.serverLintLogo', 'translation_domain' => 'form'])
->add('privacyPolicy', TextType::class, ['required' => false, 'label' => 'label.serverPrivacyPolicy', 'translation_domain' => 'form'])
->add('licenseKey', TextType::class, ['required' => false, 'label' => 'label.serverLicenseKey', 'translation_domain' => 'form'])
->add('submit', SubmitType::class, ['attr' => array('class' => 'btn btn-outline-primary'), 'label' => 'label.speichern', 'translation_domain' => 'form']);

}

public function configureOptions(OptionsResolver $resolver)
Expand Down
33 changes: 33 additions & 0 deletions src/Migrations/Version20210212101036.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210212101036 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE license (id INT AUTO_INCREMENT NOT NULL, license_key LONGTEXT NOT NULL, license LONGTEXT NOT NULL, valid_until DATETIME NOT NULL, url LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');

}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE license');

}
}
31 changes: 31 additions & 0 deletions src/Migrations/Version20210212104128.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210212104128 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE server ADD license_key LONGTEXT DEFAULT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE server DROP license_key');
}
}
Loading

0 comments on commit 679960e

Please sign in to comment.