This commit is contained in:
afornerot 2020-06-24 17:14:18 +02:00
parent 994972606a
commit ee5d2439de
11 changed files with 367 additions and 233 deletions

View File

@ -6,8 +6,6 @@
<containers>
<container name='web'>
<package>ninestat-apps</package>
<file filelist='ninestat' name='/etc/apache2/sites-available/ninestat' source='ninestat-apache.conf' rm="True"/>
<file filelist="ninestat" name="/var/www/html/ninestat/app/config/parameters.yml" source="ninestat-parameters.yml" rm="True"/>
<file filelist="ninestat" name="/var/www/html/ninestat/app/config/template.yml" source="ninestat-template.yml" rm="True"/>

View File

@ -1,5 +1,7 @@
#!/bin/bash
export HTTP_PROXY="192.168.57.160:8080"
export HTTPS_PROXY="192.168.57.160:8080"
cd /var/www/html/ninestat

View File

@ -49,41 +49,6 @@ class PurgeFileCommand extends Command
$now=new \DateTime('now');
// /uploads/file
$this->writelnred('');
$this->writelnred('== Directory = File');
$directory=$this->container->get('kernel')->getRootDir()."/../uploads/file";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->directories()->exclude("thumb");
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
$type = explode("-",$name)[0];
$id = explode("-",$name)[1];
switch($type) {
case "widget":
$entity=$this->em->getRepository("CadolesPortalBundle:Pagewidget")->find($id);
if(!$entity) {
$this->writeln($name);
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
break;
}
}
}
// /web/uploads/avatar
$this->writelnred('');
$this->writelnred('== Directory = Avatar');
@ -164,184 +129,6 @@ class PurgeFileCommand extends Command
}
}
// /web/uploads/niveau01
$this->writelnred('');
$this->writelnred('== Directory = Niveau01');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/niveau01";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->files();
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
if($name!="logo.png") {
$entity=$this->em->getRepository("CadolesCoreBundle:Niveau01")->findBy(["logo"=>"uploads/niveau01/".$name]);
if(!$entity) {
$this->writeln($name);
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
}
}
}
// /web/uploads/slide
$this->writelnred('');
$this->writelnred('== Directory = Slide');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/slide";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->files();
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
$entity=$this->em->getRepository("CadolesPortalBundle:Slide")->findBy(["image"=>"uploads/slide/".$name]);
if(!$entity) {
$this->writeln($name);
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
}
}
// /web/uploads/icon
$this->writelnred('');
$this->writelnred('== Directory = Icon');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/icon";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->files();
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
if(!stripos($name,"icon_")) {
$entity=$this->em->getRepository("CadolesPortalBundle:Icon")->findBy(["label"=>"uploads/icon/".$name]);
if(!$entity) {
$this->writeln($name);
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
}
}
}
// /web/uploads/blogarticle
$this->writelnred('');
$this->writelnred('== Directory = Blog Article');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/blogarticle";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->files();
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
if(strpos($name,"thumb-")===false) {
$entity=$this->em->getRepository("CadolesPortalBundle:Blogarticle")->findBy(["image"=>"uploads/blogarticle/".$name]);
if(!$entity) {
$this->writeln($name);
// Suppression du fichier
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
// Suppression du thumb fichier
$url=$directory."/thumb-".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
}
}
}
// /web/uploads/ckeditor
$this->writelnred('');
$this->writelnred('== Directory = Ckeditor');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/ckeditor";
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->in($directory)->files();
foreach (iterator_to_array($finder) as $file) {
$name = $file->getRelativePathname();
$tofind = "/".$alias."/uploads/ckeditor/".$name;
$find=false;
// On recherche l'image dans les pages
$result = $this->em
->getRepository("CadolesPortalBundle:Page")->createQueryBuilder('page')
->where('page.html LIKE :tofind')
->setParameter('tofind', '%'.$tofind.'%')
->getQuery()->getResult();
if($result) $find=true;
// Si pas trouvé on la cherche dans les widgets
if(!$find) {
$result = $this->em
->getRepository("CadolesPortalBundle:Pagewidget")->createQueryBuilder('pagewidget')
->where('pagewidget.parameter LIKE :tofind')
->setParameter('tofind', '%'.$tofind.'%')
->getQuery()->getResult();
if($result) $find=true;
}
// Si pas trouvé on la cherche dans les blogs
if(!$find) {
$result = $this->em
->getRepository("CadolesPortalBundle:Blogarticle")->createQueryBuilder('blogarticle')
->where('blogarticle.description LIKE :tofind')
->setParameter('tofind', '%'.$tofind.'%')
->getQuery()->getResult();
if($result) $find=true;
}
// Si pas trouvé on supprime
if(!$find) {
$this->writeln($name);
$url=$directory."/".$name;
if($fs->exists($url)) {
$fs->remove($url);
}
}
}
}
// /web/uploads/ckeditor
$this->writelnred('');
$this->writelnred('== Directory = Flux');
$directory=$this->container->get('kernel')->getRootDir()."/../web/uploads/flux";
$fs = new Filesystem();
$fs->remove($directory);
$this->writeln('');
return 1;
}

View File

@ -0,0 +1,73 @@
<?php
namespace Cadoles\CoreBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraints\DateTime;
use Cadoles\CoreBundle\Entity\Registration;
class PurgeServerCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
protected function configure()
{
$this
->setName('Core:PurgeServer')
->setDescription('Purge Server not updated')
->setHelp('This command Purge the obsolete Server')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
$this->output = $output;
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$alias = $this->container->getParameter('alias');
$this->writelnred('');
$this->writelnred('== Core:PurgeServer');
$this->writelnred('==========================================================================================================');
$now=new \DateTime('now');
$now->sub(new \DateInterval('P3M'));
$servers=$this->em->getRepository("CadolesCoreBundle:Server")->findAll();
foreach($servers as $server) {
if($server->getUpdatedate()<$now) {
$this->writeln($server->getId()." = ".$server->getUpdatedate()->format("Ymd"));
$this->em->remove($server);
$this->em->flush();
}
}
return 1;
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -4,7 +4,7 @@ SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
INSERT IGNORE INTO `user` (`id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`) VALUES
(-100, 'admin', 'Administrateur', 'STAT', '{SSHA}euZCgZjWhBu0xUZI9lPK2ncV9oaB+Jqo', 'tina-boot@ac-dijon.fr', 'admin.jpg', 'ROLE_ADMIN');
(-100, 'admin', 'Administrateur', 'STAT', '{SSHA}euZCgZjWhBu0xUZI9lPK2ncV9oaB+Jqo', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN');
@ -31,7 +31,7 @@ INSERT IGNORE INTO `config` (`order`, `visible`, `changeable`, `required`, `type
('060', 1, 1, 1, 'font', 'fontfacetitle', 'Anton-Regular', '', 'Police des titres de votre site'),
('061', 1, 1, 1, 'font', 'fontfacebody', 'Helvetica', '', 'Police des titres de votre site'),
('200', 1, 0, 1, 'boolean', 'PROXYactivate', '0', '', 'Définit un Proxy'),
('201', 1, 0, 1, 'string', 'PROXYserver', '', 'PROXYactivate','Adresse du Proxy'),
('202', 1, 0, 1, 'string', 'PROXYport', '', 'PROXYactivate','Port du Proxy');
('200', 1, 0, 1, 'boolean', 'PROXYactivate', '1', '', 'Définit un Proxy'),
('201', 1, 0, 1, 'string', 'PROXYserver', '192.168.57.160', 'PROXYactivate','Adresse du Proxy'),
('202', 1, 0, 1, 'string', 'PROXYport', '8080', 'PROXYactivate','Port du Proxy');

View File

@ -147,7 +147,126 @@ class CoreController extends Controller
'totalbyacademies' => $totalbyacademies->getQuery()->getResult(),
'totalbysecteurs' => $totalbysecteurs->getQuery()->getResult(),
'totalbynatures' => $totalbynatures->getQuery()->getResult(),
'by' => "total",
]);
}
public function acadAction($acad, Request $request)
{
$em = $this->getDoctrine()->getManager();
$user=$this->getUser();
// Total servers
$servers = $em->createQueryBuilder()
->select('s')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad);
// Total by module
$totalmodules = $em->createQueryBuilder()
->select('COUNT(s.module) total','s.module label')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad)
->groupBy('s.module')
->orderBy('total','DESC')
->addOrderBy('label','ASC');
// Total by version
$totalversions = $em->createQueryBuilder()
->select('COUNT(s.version) total','s.version label')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad)
->groupBy('s.version')
->orderBy('total','DESC')
->addOrderBy('label','ASC');
// Total by Secteur
$totalbysecteurs = $em->createQueryBuilder()
->select('COUNT(e.secteur_public_prive_libe) total','e.secteur_public_prive_libe label')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad)
->groupBy('e.secteur_public_prive_libe')
->orderBy('total','DESC')
->addOrderBy('label','ASC');
// Total by Nature
$totalbynatures = $em->createQueryBuilder()
->select('COUNT(e.nature_uai_libe) total','e.nature_uai_libe label')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad)
->groupBy('e.nature_uai_libe')
->orderBy('total','DESC')
->addOrderBy('label','ASC');
// Total applications
$applications = $em->createQueryBuilder()
->select('a')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->from('CadolesCoreBundle:ServerApplication','sa')
->from('CadolesCoreBundle:Application','a')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->andWhere('sa.server=s')
->andWhere(('sa.application=a'))
->setParameter('acad',$acad);
// Total by apps
$totalapplications = $em->createQueryBuilder()
->select('COUNT(a.package) total','a.name label')
->from('CadolesCoreBundle:ServerApplication','sa')
->from('CadolesCoreBundle:Application','a')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('sa.application=a')
->andWhere('sa.server=s')
->andwhere('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad)
->groupBy('a.package')
->orderBy('total','DESC')
->addOrderBy('label','ASC');
// Servers
$etabs = $em->createQueryBuilder()
->select('e')
->from('CadolesCoreBundle:Etab','e')
->from('CadolesCoreBundle:Server','s')
->where('s.etab=e')
->andWhere('e.libelle_academie=:acad')
->setParameter('acad',$acad);
return $this->render('CadolesCoreBundle:Core:home.html.twig',[
'useheader' => true,
'usemenu' => false,
'usesidebar' => false,
'etabs' => $etabs->getQuery()->getResult(),
'totalservers' => count($servers->getQuery()->getResult()),
'totalbymodules' => $totalmodules->getQuery()->getResult(),
'totalbyversions' => $totalversions->getQuery()->getResult(),
'totalapplications' => count($applications->getQuery()->getResult()),
'totalbyapplications' => $totalapplications->getQuery()->getResult(),
'totalbysecteurs' => $totalbysecteurs->getQuery()->getResult(),
'totalbynatures' => $totalbynatures->getQuery()->getResult(),
'by' => "acad",
'servers' => $servers->getQuery()->getResult(),
'acad' => $acad,
]);
}

View File

@ -0,0 +1,79 @@
<?php
namespace Cadoles\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
use Cadoles\CoreBundle\Form\IconChoiceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManager;
class ScrumType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if($options["mode"]!="view") {
$builder
->add('submit', SubmitType::class, [
'label' => 'Valider',
'attr' => ['class' => 'btn btn-success']
]);
$builder
->add('title', TextType::class, [
'label' => 'Titre',
'attr' => ['class' => 'form-control', 'style' => 'margin-bottom:15px']
]);
$builder
->add('groups', Select2EntityType::class, [
'label' => 'Visible pour les Groupes',
'class' => 'CadolesCoreBundle:Group',
'text_property' => 'label',
'multiple' => true,
'remote_route' => 'cadoles_core_user_group_ajax_list',
'primary_key' => 'id',
'text_property' => 'label',
'minimum_input_length' => 0,
'page_limit' => 100,
'allow_clear' => true,
'delay' => 250,
'cache' => false,
'cache_timeout' => 60000,
'language' => 'fr',
'placeholder' => 'Selectionner un groupe',
]);
}
else {
$builder
->add('description',CKEditorType::class,[
'config_name' => 'full_config',
'label' => 'Description',
'mapped' => false,
'required' => false,
'config' => ['height' => '300px','filebrowserUploadRoute' => 'cadoles_core_user_scrum_upload'],
]);
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Cadoles\CoreBundle\Entity\Scrum',
'mode' => "string"
));
}
}

View File

@ -7,6 +7,9 @@ cadoles_core_server:
path: /server/{id}
defaults: { _controller: CadolesCoreBundle:Core:server }
cadoles_core_acad:
path: /acad/{acad}
defaults: { _controller: CadolesCoreBundle:Core:acad }
#== Theme ================================================================================================================
@ -141,7 +144,7 @@ cadoles_core_user_group_ajax_list:
path: /user/group/ajaxlist
defaults: { _controller: CadolesCoreBundle:Group:ajaxlist}
#== Group =================================================================================================================
#== API ===================================================================================================================
cadoles_core_api:
path: /api
defaults: { _controller: CadolesCoreBundle:Api:api}

View File

@ -5,6 +5,10 @@
{% endblock %}
{% block pagewrapper %}
{%if by=="acad" %}
<h1 style="text-align:center">{{acad}}</h1>
{% endif %}
<div class="row" style="margin-top:20px">
@ -27,20 +31,20 @@
</div>
<div class="row">
{% if totalbyacademies is defined %}
<div class="col-md-6" >
<h2>Serveurs par Académies</h2>
<div id='byacademie-chart' style="height:250px"></div>
<div id="byacademie-legend"></div>
</div>
{% endif %}
<div class="col-md-6" >
<h2>Serveurs par Secteurs</h2>
<div id='bysecteur-chart' style="height:250px"></div>
<div id="bysecteur-legend"></div>
</div>
</div>
<div class="row">
<div class="col-md-6" >
<h2>Serveurs par Natures</h2>
<div id='bynature-chart' style="height:250px"></div>
@ -52,9 +56,7 @@
<div id='bymodule-chart' style="height:250px"></div>
<div id="bymodule-legend"></div>
</div>
</div>
<div class="row">
<div class="col-md-6" >
<h2>Serveurs par Version</h2>
<div id='byversion-chart' style="height:250px"></div>
@ -64,6 +66,42 @@
</div>
</div>
{% if by=="acad" and app.user %}
<table class="table table-striped table-bordered table-hover">
<thead>
<th>UAI</th>
<th>Nom</th>
<th>Adresse</th>
<th>Ville</th>
<th>Secteur</th>
<th>Nature</th>
<th>URL</th>
<th>Module</th>
<th>Version</th>
<th>Application</th>
<th>Paquet</th>
</thead>
{% for server in servers %}
{% for serverapplication in server.serverapplications %}
<tr>
<td>{{server.etab.numerouai}}</td>
<td>{{server.etab.denominationprincipale}}</td>
<td>{{server.etab.adresseuai}}</td>
<td>{{server.etab.libellecommune}}</td>
<td>{{server.etab.secteurpublicprivelibe}}</td>
<td>{{server.etab.natureuailibe}}</td>
<td>{{server.url}}</td>
<td>{{server.module}}</td>
<td>{{server.version}}</td>
<td>{{serverapplication.application.name}}</td>
<td>{{serverapplication.version}}</td>
</tr>
{% endfor %}
{% endfor %}
</table>
{% endif %}
{% endblock %}
{% block localjavascript %}
@ -114,6 +152,7 @@
{% endfor %}
//== byAcademie
{% if totalbyacademies is defined %}
var byacademie = Morris.Donut({
element: 'byacademie-chart',
data: [
@ -125,14 +164,18 @@
});
byacademie.options.data.forEach(function(label, i) {
var legendItem = $('<span style="margin:auto; display: block;text-align: left;"></span>').text( label['label'] + " ( " +label['value'] + " )" ).prepend('<span>&nbsp;</span>');
var url = "{{ path("cadoles_core_acad",{"acad":"xx"}) }}";
var url = url.replace("xx",label['label']);
var legendItem = $('<span style="margin:auto; display: block;text-align: left;"></span>').html( "<a href='"+url+"'>"+label['label'] + "</a> ( " +label['value'] + " )" ).prepend('<span>&nbsp;</span>');
legendItem.find('span')
.css('backgroundColor', byacademie.options.colors[i])
.css('width', '20px')
.css('display', 'inline-block')
.css('margin', '5px');
$('#byacademie-legend').append(legendItem)
$('#byacademie-legend').append(legendItem)
});
{% endif %}
//== byNature
var bynature = Morris.Donut({
@ -242,6 +285,14 @@
$('#byapplication-legend').append(legendItem)
});
//= Table
$('.table').DataTable({
columnDefs: [ { "targets": "no-sort", "orderable": false }, { "targets": "no-string", "type" : "num" } ],
responsive: true,
iDisplayLength: 25,
order: [[ 1, "asc" ]]
});
});
function showModal(id) {

View File

@ -16,8 +16,12 @@
<b>Version</b> = {{ server.version }}<br><br>
<b>Applications</b><br>
{% for application in server.serverapplications %}
{{ application.version }}<br>
{% for application in server.serverapplications|sort((a, b) => a.version <=> b.version) %}
{% if app.user %}
{{ application.version }}<br>
{% else %}
{{ application.application.name }}<br>
{% endif %}
{% endfor %}
</div>

View File

@ -102,6 +102,24 @@ class InitDataCommand extends ContainerAwareCommand
$this->entityManager->persist($entity);
}
// Job de purge des servers obsolète
// Toute les 24h à 3h00
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(210);
if(!$entity) {
$entity = new Cron;
$nextdate=$entity->getSubmitdate();
$nextdate->setTime(3,0);
$entity->setCommand("Core:PurgeServer");
$entity->setDescription("Suppression des serveurs obsolètes");
$entity->setId(210);
$entity->setStatut(2);
$entity->setRepeatcall(0);
$entity->setRepeatexec(0);
$entity->setRepeatinterval(86400);
$entity->setNextexecdate($nextdate);
$this->entityManager->persist($entity);
}
$this->entityManager->flush();
}
}