Skip to content

Commit d63c74a

Browse files
authored
adminator3: add work-handlers for node add/update (#262)
1 parent a58c61f commit d63c74a

File tree

2 files changed

+109
-52
lines changed

2 files changed

+109
-52
lines changed

adminator3/app/Core/Topology/nodeAction.class.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public function add(ServerRequestInterface $request): string
125125
$vysledek_write . "') ");
126126

127127
//automaticke restarty
128-
$this->work->workActionTopologyNodeAdd();
128+
list($work_output) = $this->work->workActionTopologyNodeAdd($pole);
129+
$output .= $work_output;
129130

130131
} else {
131132
//zobrazime formular
@@ -687,7 +688,7 @@ public function update(ServerRequestInterface $request): string
687688

688689
} // konec foreach
689690

690-
$pole .= "".$pole3;
691+
$pole .= $pole3;
691692

692693
if ($uprava) {
693694
$vysledek_write = 1;
@@ -702,7 +703,8 @@ public function update(ServerRequestInterface $request): string
702703
);
703704

704705
//automaticke restarty
705-
$this->work->workActionTopologyNodeDiff();
706+
list($work_output) = $this->work->workActionTopologyNodeDiff($pole, $pole_puvodni_data, $id_new);
707+
$output .= $work_output;
706708

707709
} else {
708710
//zobrazime formular

adminator3/app/Core/work.php

Lines changed: 104 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -306,34 +306,34 @@ public function workActionObjektyFiberDiff(string $changes, array $origData, $it
306306
)
307307
)
308308
) {
309-
$work_output[] = $this->work_handler("1"); //reinhard-3 (ros) - restrictions (net-n/sikana)
310-
$work_output[] = $this->work_handler("2"); //reinhard-wifi (ros) - restrictions (net-n/sikana)
309+
$work_output[] = $this->work_handler("1");
310+
$work_output[] = $this->work_handler("2");
311311

312-
$work_output[] = $this->work_handler("3"); //reinhard-fiber - sikana/net-n
312+
$work_output[] = $this->work_handler("3");
313313

314-
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
315-
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
314+
$work_output[] = $this->work_handler("4");
315+
$work_output[] = $this->work_handler("21");
316316

317-
$work_output[] = $this->work_handler("6"); //(reinhard-fiber) - mikrotik.dhcp.leases.erase
317+
$work_output[] = $this->work_handler("6");
318318

319-
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
319+
$work_output[] = $this->work_handler("7");
320320

321321
} elseif (preg_match("/.*změna.*IP.*adresy.*z.*/", $changes)) {
322322

323-
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
323+
$work_output[] = $this->work_handler("4");
324324

325-
$work_output[] = $this->work_handler("6"); //(reinhard-fiber) - mikrotik.dhcp.leases.erase
325+
$work_output[] = $this->work_handler("6");
326326

327-
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
327+
$work_output[] = $this->work_handler("7");
328328
}
329329

330330
if (preg_match("/.*změna.*MAC.*adresy.*/", $changes)) {
331331

332-
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
333-
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
332+
$work_output[] = $this->work_handler("4");
333+
$work_output[] = $this->work_handler("21");
334334

335-
$work_output[] = $this->work_handler("6"); //(reinhard-fiber) - mikrotik.dhcp.leases.erase
336-
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
335+
$work_output[] = $this->work_handler("6");
336+
$work_output[] = $this->work_handler("7");
337337

338338
}
339339

@@ -343,10 +343,10 @@ public function workActionObjektyFiberDiff(string $changes, array $origData, $it
343343

344344
//zmena cisla portu
345345
if (preg_match("/.*Číslo sw. portu.*/", $changes)) {
346-
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
347-
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
346+
$work_output[] = $this->work_handler("4");
347+
$work_output[] = $this->work_handler("21");
348348

349-
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
349+
$work_output[] = $this->work_handler("7");
350350
}
351351

352352
// $output .= var_export($work_output, true);
@@ -365,13 +365,13 @@ public function workActionObjektyFiber(string $changes, int $itemId): array
365365
$output = "";
366366
$work_output = [];
367367

368-
$work_output[] = $this->work_handler("3"); //rh-fiber - iptables
369-
$work_output[] = $this->work_handler("4"); //rh-fiber - radius
370-
$work_output[] = $this->work_handler("5"); //rh-fiber - shaper
371-
$work_output[] = $this->work_handler("6"); //reinhard-fiber - mikrotik.dhcp.leases.erase
372-
$work_output[] = $this->work_handler("7"); //trinity - sw.h3c.vlan.set.pl update
368+
$work_output[] = $this->work_handler("3");
369+
$work_output[] = $this->work_handler("4");
370+
$work_output[] = $this->work_handler("5");
371+
$work_output[] = $this->work_handler("6");
372+
$work_output[] = $this->work_handler("7");
373373

374-
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
374+
$work_output[] = $this->work_handler("21");
375375

376376
// $output .= var_export($work_output, true);
377377

@@ -553,6 +553,11 @@ public function workActionObjektyWifi(string $changes, int $itemId, array $args)
553553

554554
public function workActionTopologyRouterAdd(): void
555555
{
556+
$this->logger->info(__CLASS__ . "\\" . __FUNCTION__ . " called");
557+
558+
$output = "";
559+
$work_output = [];
560+
556561
// TODO: enable actions for topology/router-add
557562

558563
// Aglobal::work_handler("13"); //reinhard-wifi (ros) - shaper (client's tariffs)
@@ -576,6 +581,11 @@ public function workActionTopologyRouterAdd(): void
576581

577582
public function workActionTopologyRouterDiff(): void
578583
{
584+
$this->logger->info(__CLASS__ . "\\" . __FUNCTION__ . " called");
585+
586+
$output = "";
587+
$work_output = [];
588+
579589
// TODO: enable actions for topology/router-update
580590
// if( ereg(".*změna.*Alarmu.*z.*", $pole3) )
581591
// {
@@ -616,45 +626,90 @@ public function workActionTopologyRouterDiff(): void
616626
// }
617627
}
618628

619-
public function workActionTopologyNodeDiff(): void
629+
public function workActionTopologyNodeDiff(string $changes, array $origData, $itemId): array
620630
{
621-
// TODO: fix automatic restarts
622-
// if(ereg(".*Routeru, kde se provádí filtrace.*", $pole3)) {
623-
// Aglobal::work_handler("14"); //(trinity) filtrace-IP-on-Mtik's-restart
624-
// }
631+
$this->logger->info(__CLASS__ . "\\" . __FUNCTION__ . " called");
625632

626-
// if(ereg(".*<b>Routeru</b>.*", $pole3)) {
627-
// Aglobal::work_handler("1"); //reinhard-3 (ros) - restrictions (net-n/sikana)
628-
// Aglobal::work_handler("20"); //reinhard-3 (ros) - shaper (client's tariffs)
633+
$output = "";
634+
$work_output = [];
629635

630-
// Aglobal::work_handler("24"); //reinhard-5 (ros) - restrictions (net-n/sikana)
631-
// Aglobal::work_handler("23"); //reinhard-5 (ros) - shaper (client's tariffs)
636+
if (preg_match("/.*Routeru, kde se provádí filtrace.*/", $changes)) {
637+
$work_output[] = $this->work_handler("14"); //(trinity) filtrace-IP-on-Mtik's-restart
638+
}
632639

633-
// Aglobal::work_handler("13"); //reinhard-wifi (ros) - shaper (client's tariffs)
634-
// Aglobal::work_handler("2"); //reinhard-wifi (ros) - restrictions (net-n/sikana)
640+
if (preg_match("/.*<b>Routeru<\/b>.*/", $changes)) {
641+
$work_output[] = $this->work_handler("1"); //reinhard-3 (ros) - restrictions (net-n/sikana)
642+
$work_output[] = $this->work_handler("20"); //reinhard-3 (ros) - shaper (client's tariffs)
635643

636-
// Aglobal::work_handler("14"); //(trinity) filtrace-IP-on-Mtik's-restart
644+
$work_output[] = $this->work_handler("24"); //reinhard-5 (ros) - restrictions (net-n/sikana)
645+
$work_output[] = $this->work_handler("23"); //reinhard-5 (ros) - shaper (client's tariffs)
637646

638-
// }
647+
$work_output[] = $this->work_handler("13"); //reinhard-wifi (ros) - shaper (client's tariffs)
648+
$work_output[] = $this->work_handler("2"); //reinhard-wifi (ros) - restrictions (net-n/sikana)
639649

640-
// if(ereg(".*vlan_id.*", $pole3)) {
641-
// Aglobal::work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
650+
$work_output[] = $this->work_handler("14"); //(trinity) filtrace-IP-on-Mtik's-restart
651+
}
642652

643-
// Aglobal::work_handler("4"); //reinhard-fiber - radius
644-
// Aglobal::work_handler("21"); //artemis - radius (tunel. verejky, optika)
645-
// }
653+
if (preg_match("/.*vlan_id.*/", $changes)) {
654+
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
646655

647-
// if(ereg(".*změna.*koncového.*zařízení.*", $pole3)) {
648-
// Aglobal::work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
656+
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
657+
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
658+
}
649659

650-
// Aglobal::work_handler("4"); //reinhard-fiber - radius
651-
// Aglobal::work_handler("21"); //artemis - radius (tunel. verejky, optika)
652-
// }
660+
if (preg_match("/.*změna.*koncového.*zařízení.*/", $changes)) {
661+
$work_output[] = $this->work_handler("7"); //(trinity) - sw.h3c.vlan.set.pl update
662+
663+
$work_output[] = $this->work_handler("4"); //reinhard-fiber - radius
664+
$work_output[] = $this->work_handler("21"); //artemis - radius (tunel. verejky, optika)
665+
}
666+
667+
// $output .= var_export($work_output, true);
668+
669+
foreach ($work_output as $id => $item) {
670+
$output .= $item[0];
671+
}
672+
673+
return array($output);
653674
}
654675

655-
public function workActionTopologyNodeAdd(): void
676+
public function workActionTopologyNodeAdd(string $changes): array
656677
{
657-
// TODO: add work items
678+
$this->logger->info(__CLASS__ . "\\" . __FUNCTION__ . " called");
679+
680+
$output = "";
681+
$work_output = [];
682+
683+
// wifi
684+
if (preg_match("/.*\[typ_nodu\]=> 1.*/", $changes)) {
685+
$work_output[] = $this->work_handler("1");
686+
$work_output[] = $this->work_handler("20");
687+
688+
$work_output[] = $this->work_handler("24");
689+
$work_output[] = $this->work_handler("23");
690+
691+
$work_output[] = $this->work_handler("13");
692+
$work_output[] = $this->work_handler("2");
693+
694+
$work_output[] = $this->work_handler("14");
695+
696+
$work_output[] = $this->work_handler("21");
697+
}
698+
699+
//optika
700+
if (preg_match("/.*\[typ_nodu\]=> 2.*/", $changes)) {
701+
$work_output[] = $this->work_handler("7");
702+
703+
$work_output[] = $this->work_handler("4");
704+
$work_output[] = $this->work_handler("21");
705+
}
706+
// $output .= var_export($work_output, true);
707+
708+
foreach ($work_output as $id => $item) {
709+
$output .= $item[0];
710+
}
711+
712+
return array($output);
658713
}
659714

660715
}

0 commit comments

Comments
 (0)