-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathautodiscovery.php
More file actions
902 lines (829 loc) · 26.9 KB
/
autodiscovery.php
File metadata and controls
902 lines (829 loc) · 26.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
<?php
/*
Lilac - A Nagios Configuration Tool
Copyright (C) 2013 Rene Hadler
Copyright (C) 2007 Taylor Dondich
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
Lilac Auto Discovery Page
*/
include_once('includes/config.inc');
include_once('autodiscovery/classes.inc.php');
include_once('AutodiscoveryJob.php');
include_once('AutodiscoveryLogEntry.php');
require_once("Net/Traceroute.php");
if(isset($_GET['id'])) {
$autodiscoveryJob = AutodiscoveryJobPeer::retrieveByPK($_GET['id']);
if(!$autodiscoveryJob) {
unset($autodiscoveryJob);
}
if(isset($_GET['action']) && $_GET['action'] == "restart") {
$autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_STARTING);
$autodiscoveryJob->save();
exec("php autodiscovery/autodiscover.php " . $autodiscoveryJob->getId() . " > /dev/null", $tempOutput, $retVal);
if($retVal != 42) {
$error = "Failed to run external autodiscovery script. Return value: " . $retVal . "<br /> Error:";
foreach($tempOutput as $output) {
$error .= $output . "<br />";
}
}
else {
// No need to show
//$success = "Restarted AutoDiscovery Job";
}
}
if(isset($_GET['delete'])) {
// We want to delete the job!
$autodiscoveryJob->delete();
unset($_GET['id']);
unset($autodiscoveryJob);
$success = "Removed Job and associated devices.";
}
}
if(isset($_GET['deviceId'])) {
// We want to review a specific device
$device = AutodiscoveryDevicePeer::retrieveByPK($_GET['deviceId']);
if(!$device) {
header("Location: autodiscovery.php");
exit();
}
if(isset($_GET['request']) && $_GET['request'] == 'recalc') {
// We want to recalculate template matches
$config = unserialize($autodiscoveryJob->getConfig());
$defaultTemplateId = $config->getVar("default_template");
if(!empty($defaultTemplateId)) {
$defaultTemplate = NagiosHostTemplatePeer::retrieveByPK($defaultTemplateId);
}
if(empty($defaultTemplate)) {
$defaultTemplate = null;
}
AutodiscoveryMatchMaker::match($device, $defaultTemplate);
$success = "Recalculated Matching Templates.";
}
}
if(isset($_GET['request']) && $_GET['request'] == 'status') {
// We're our AJAX client wanting status information
$result = array();
$autodiscoveryJob = AutodiscoveryJobPeer::retrieveByPK($_GET['id']);
if(!$autodiscoveryJob) {
$result['error'] = "Invalid job specified.";
print(json_encode($result));
exit();
}
// Okay, let's populate the status
$result['start_time'] = $autodiscoveryJob->getStartTime();
$result['status_code'] = $autodiscoveryJob->getStatusCode();
$result['status_text'] = $autodiscoveryJob->getStatus();
$result['status_change_time'] = $autodiscoveryJob->getStatusChangeTime();
// Build elapsed time
if(!in_array($autodiscoveryJob->getStatusCode(), array(AutoDiscoveryJob::STATUS_FAILED, AutoDiscoveryJob::STATUS_FINISHED))) {
$target = time();
}
else {
$target = strtotime($result['status_change_time']);
}
$start = strtotime($result['start_time']);
$total = $target - $start;
$hours = (int)($total / 3600);
$total = $total % 3600;
$minutes = (int)($total / 60);
$seconds = $total % 60;
$result['elapsed_time'] = $hours . " Hours " . $minutes . " Minutes " . $seconds . " Seconds";
print(json_encode($result));
exit();
}
if(isset($_GET['request']) && $_GET['request'] == 'fetch') {
// We're our AJAX client wanting to get new log data
$result = array();
$c = new Criteria();
$c->add(AutodiscoveryLogEntryPeer::JOB, $_GET['id']);
$c->setLimit($_POST['rp']);
$c->setOffset(isset($_POST['page']) ? ($_POST['page'] - 1) * $_POST['rp'] : 0);
$c->addDescendingOrderByColumn(AutodiscoveryLogEntryPeer::ID);
$entries = $autodiscoveryJob->getAutodiscoveryLogEntrys($c);
foreach($entries as $entry) {
$results['rows'][] = array('id' => $entry->getId(), 'cell' => array( $entry->getTime(),
$entry->getReadableType($entry->getType()),
$entry->getText()));
}
$c = new Criteria();
$c->add(AutodiscoveryLogEntryPeer::JOB, $autodiscoveryJob->getId());
$results['page'] = $_POST['page'];
$results['total'] = AutodiscoveryLogEntryPeer::doCount($c);
?>
<?php
print(json_encode($results));
exit();
}
if(isset($_POST['request'])) {
if($_POST['request'] == "autodiscover") {
if(!strlen(trim($_POST['job_name']))) {
$error = "Job name must be provided.";
}
else {
if(count($_POST['target']) == 0) {
$error = "You must provide at least one target.";
}
else {
ksort($_POST['target']);
$config = new AutodiscoveryConfig("NmapAutoDiscoveryEngine");
$config->setVar("targets", $_POST['target']);
$config->setVar("nmap_binary", $_POST['nmap_binary']);
$config->setVar("traceroute_enabled", (empty($_POST['traceroute_enabled'])) ? true : true);
$config->setVar("default_template", $_POST['default_template']);
$autodiscoveryJob = new AutodiscoveryJob();
$autodiscoveryJob->setName($_POST['job_name']);
$autodiscoveryJob->setDescription($_POST['job_description']);
$autodiscoveryJob->setCmd(AutodiscoveryJob::CMD_START);
$autodiscoveryJob->setConfig(serialize($config));
$autodiscoveryJob->setStatus("Starting...");
$autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_STARTING);
$autodiscoveryJob->save();
// Attempt to execute the external auto-discovery script, fork it, and love it.
exec("php autodiscovery/autodiscover.php " . $autodiscoveryJob->getId() . " > /dev/null", $tempOutput, $retVal);
if($retVal != 42) {
$status_msg = "Failed to run external Autodiscovery script. Return value: " . $retVal . "<br /> Error:";
foreach($tempOutput as $output) {
$status_msg .= $output . "<br />";
}
}
}
}
}
else if($_POST['request'] == "updateGeneral") {
if(trim($_POST['name']) != '' && trim($_POST['description']) != '') {
// Check to see first if a host or auto discovery device has that potential name
$c = new Criteria();
$c->add(NagiosHostPeer::NAME, trim($_POST['name']));
$c->setIgnoreCase(true);
$host = NagiosHostPeer::doSelectOne($c);
if(!$host) {
// Try a autodiscovery device?
$c = new Criteria();
$c->add(AutodiscoveryDevicePeer::NAME, trim($_POST['name']));
$c->setIgnoreCase(true);
$host = AutodiscoveryDevicePeer::doSelectOne($c);
}
if($host) {
$error = "A host already exists with that name. Must choose a unique name.";
}
else {
// Assign name and description
$device->setName(trim($_POST['name']));
$device->setDescription(trim($_POST['description']));
$device->save();
$success = "Updated discovered device's information.";
}
}
else {
$error = "Name and Description cannot be blank.";
}
}
else if($_POST['request'] == "assignTemplate") {
$hostTemplate = NagiosHostTemplatePeer::retrieveByPK($_POST['template']);
if(!$hostTemplate) {
$error = "That template no longer exists.";
}
else {
$device->setNagiosHostTemplate($hostTemplate);
$device->save();
$success = "Template assigned.";
}
}
else {
// We want to process our device list!
// First we check to see if there's any hosts now with the same name
foreach($_POST['selectedDevices'] as $deviceId) {
$device = AutodiscoveryDevicePeer::retrieveByPK($deviceId);
if(!$device) {
$error = "One of the devices provided no longer exists.";
continue;
}
$c = new Criteria();
$c->add(NagiosHostPeer::NAME, $device->getName());
$c->setIgnoreCase(true);
$host = NagiosHostPeer::doSelectOne($c);
if(!$host) {
$c = new Criteria();
$c->add(AutodiscoveryDevicePeer::NAME, $device->getName());
$c->setIgnoreCase(true);
$host = AutodiscoveryDevicePeer::doSelectOne($c);
if($host->getId() == $device->getId()) {
unset($host);
}
}
if(!empty($host)) {
$error = "A host already exists with the name of " . $device->getName() . ". Change the device's name before importing.";
}
}
if(empty($error)) {
$totalSuccess = 0;
// Okay, no errors, let's create our hosts!
foreach($_POST['selectedDevices'] as $deviceId) {
$device = AutodiscoveryDevicePeer::retrieveByPK($deviceId);
$tempHost = new NagiosHost();
$tempHost->setAddress($device->getAddress());
$tempHost->setName($device->getName());
$tempHost->setAlias($device->getDescription());
$tempHost->save();
// Now assign a template, if wanted
$template = $device->getNagiosHostTemplate();
if(!empty($template)) {
$inheritance = new NagiosHostTemplateInheritance();
$inheritance->setNagiosHost($tempHost);
$inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
$inheritance->save();
}
// Now parent
$parent = $device->getNagiosHost();
if(!empty($parent)) {
$parentRelationship = new NagiosHostParent();
$parentRelationship->setNagiosHostRelatedByChildHost($tempHost);
$parentRelationship->setNagiosHostRelatedByParentHost($parent);
$parentRelationship->save();
}
$totalSuccess++;
$device->delete();
}
$success = $totalSuccess . " Device(s) Imported.";
}
}
}
print_header("AutoDiscovery");
if(isset($autodiscoveryJob)) {
?>
<script type="text/javascript">
$(document).ready(function() {
$("#joblog").flexigrid({
url: 'autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>&request=fetch',
dataType: 'json', // type of data loaded
errormsg: 'There was a problem retrieving the error log. Refresh and try again',
colModel: [
{display: 'Time', name: 'name', width: 100, sortable: true, align: 'left'},
{display: 'Type', name: 'type', width: 100, sortable: true, align: 'left'},
{display: 'Text', name: 'text', width: 1200, sortable: true, align: 'left'}
],
resizable: false, //resizable table
sortname: "time",
sortorder: 'asc',
usepager: true,
procmsg: 'Grabbing Log Entries, please wait ...',
title: false,
showToggleBtn: false, //show or hide column toggle popup
useRp: true,
rp: 50,
height: 600
});
<?php
if(!in_array($autodiscoveryJob->getStatusCode(), array(AutodiscoveryJob::STATUS_FINISHED, AutodiscoveryJob::STATUS_FAILED))) {
// Add check timer
?>
var timer = 0;
$(document).everyTime(2000, "status", function() {
// Call ajax
$.getJSON("autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>&request=status&tok=" + Math.random() , function(data) {
$("#jobstatus").html(data.status_text);
$("#elapsedtime").html(data.elapsed_time);
$("#joblog").flexReload();
if(data.status_code == <?php echo AutodiscoveryJob::STATUS_FINISHED;?> || data.status_code == <?php echo AutodiscoveryJob::STATUS_FAILED;?>) {
if(data.status_code == <?php echo AutodiscoveryJob::STATUS_FINISHED;?>) {
$("#completemsg").show("slow").fadeIn("slow");
}
$(document).stopTime("status");
}
});
}, 0, true);
<?php
}
?>
});
</script>
<?php
}
else {
// We're setting up an autodiscovery job
?>
<script type="text/javascript">
var targetcount = 1;
$(function() {
// Find the enter keypress
if ($.browser.mozilla) {
$("#activetarget").keypress(function(event) {
if(event.keyCode == 13) {
$("#addtargetlink").click();
event.preventDefault();
event.stopPropagation();
return false;
}
});
} else {
$("#activetarget").keydown(function(event) {
if(event.keyCode == 13) {
$("#addtargetlink").click();
event.preventDefault();
event.stopPropagation();
return false;
}
});
}
$("#addtargetlink").click(function(event) {
targetcount = targetcount + 1;
event.preventDefault();
// Add new row to the table before this row, showing the
var content = $("<tr><td>" + $("#activetarget").attr("value") + "<input type='hidden' name='target[" + targetcount + "]' value='" + $("#activetarget").attr("value") + "'/></td><td><a href=''>Delete This Target</a></td></tr>");
// Add link to remove
$("a", content).click(function(event) {
event.preventDefault();
$(this).parents("tr").remove();
if($(this).parents("tr").length == 1) {
$("#jobSubmitButton").attr("disabled", true).attr("value", "You Must Provide At Least One Target");
}
});
$("#targetinputrow").before(content);
$("#activetarget").attr("value", "");
// Automatically set the button and enable the form
$("#jobSubmitButton").attr("disabled", false).attr("value", "Begin Auto-Discovery Job");
});
});
</script>
<?php
}
?>
<style type="text/css">
fieldset {
border:1px solid #CCCCCC;
margin:1em 0pt;
padding:1em;
}
legend {
font-weight:bold;
}
label {
display:block;
}
.checks label {
width:15em;
display: inline;
float: none;
}
.checks p {
padding: 2px;
}
}
</style>
<?php
if(!isset($autodiscoveryJob)) {
$c = new Criteria();
$c->add(AutodiscoveryJobPeer::END_TIME, null);
$autodiscoveryJobs = autodiscoveryJobPeer::doSelect($c);
if($autodiscoveryJobs) {
print_window_header("Jobs In Progress", "100%");
?>
There appears to be running autodiscovery jobs. There should only be one running. If there are multiple showing as running, you should cancel them or purge them. Click on a job to
view it's progress and it's log.
<table class="jobs">
<tr>
<td><strong>Name</strong></td>
<td><strong>Description</strong></td>
<td><strong>Start Time</strong></td>
<td><strong>Status</strong></td>
<td colspan="2"><strong>Actions</strong></td>
</tr>
<?php
foreach($autodiscoveryJobs as $job) {
?>
<tr>
<td><?php echo $job->getName();?></td>
<td><?php echo $job->getDescription();?></td>
<td><?php echo $job->getStartTime();?></td>
<td><?php echo $job->getStatus();?></td>
<td><a href="autodiscovery.php?id=<?php echo $job->getId();?>">View Job</a></td>
<td><a href="autodiscovery.php?id=<?php echo $job->getId();?>&action=restart">Restart</a></td>
</tr>
<?php
}
?>
</table>
<?php
print_window_footer();
}
$nmapPath = Lilac::getExecutablePath("nmap");
$sudoPath = Lilac::getExecutablePath("sudo");
$procUser = Lilac::getProcessUserInfo("name");
print_window_header("Create New Auto Discovery Job", "100%", "center");
if(!$nmapPath)
{
$nmapPath = "";
?>
<div class="error">
The nmap program was not found on your system. Please make sure nmap is installed properly and available in the system path. You can also enter the path to nmap manually if you have installed it in a different place outside the system path.
</div>
<?php
}
if(!$sudoPath)
{
$sudoPath = "";
?>
<div class="error">
The sudo program was not found on your system. Please make sure sudo is installed / configured properly and available in the system path. Also make sure the webserver-user (<?php echo $procUser; ?>) is able to execute nmap via sudo with administrative rights.
</div>
<?php
}
if(!empty($nmapPath) && !empty($sudoPath))
{
?>
<div class="notice">
Please make sure to add following line to your sudoers file to make autodiscovery work correctly:<br>
<pre><?php echo $procUser; ?> ALL=(ALL) NOPASSWD: <?php echo $nmapPath; ?> *</pre>
</div>
<?php
}
?>
To begin an auto-discovery of your configuration, an Auto Discovery Job must be defined. Configure your auto discovery job below. Once created, your auto discovery
job will begin in the background. You will be able to check on the status of your job and view it's log as it continues running. You are advised to NOT edit anything
in Lilac while your job is running.
<br />
<form name="autodiscovery_job" method="post" action="autodiscovery.php">
<input type="hidden" name="request" value="autodiscover" />
<p>
<fieldset>
<legend>Job Definition</legend>
<label for="job_name">Job Name</label>
<input id="job_name" name="job_name" type="text" size="100" maxlength="255" />
<label for="job_description">Job Description</label>
<textarea id="job_description" name="job_description" name="job_description" rows="5" cols="80" /></textarea>
</fieldset>
</p>
<p>
<fieldset>
<legend>Discovery Options</legend>
<p>
<label for="nmap_binary">NMAP Binary Location</label>
<input id="nmap_binary" name="nmap_binary" type="text" size="100" maxlength="255" value="<?php echo $nmapPath; ?>" />
</p>
<p>
<input id="traceroute_enabled" name="traceroute_enabled" type="checkbox" checked="checked" /> Enable Traceroute to Determine Parent Host<br />
</p>
<p>
<label for="default_template">Default Template If No Templates Match</label>
<?php
$templates = NagiosHostTemplatePeer::doSelect(new Criteria());
$options[] = array(
'option' => 'None',
'value' => ''
);
foreach($templates as $template) {
$options[] = array(
'option' => $template->getName(),
'value' => $template->getId()
);
}
print_select("default_template", $options, "value" , "option", '');
?>
</p>
</fieldset>
</p>
<p>
<fieldset>
<legend>Target Specification</legend>
<p>
<table id="targets">
<tr id="targetinputrow">
<td>
<input id="activetarget" type="text"size="40"></td><td><a id="addtargetlink" href=""> Add Target</a>
</td>
</tr>
</table>
Provide an IP address or range of ip addresses in NMAP-accepted style. See <a target="_blank" href="http://insecure.org/nmap/man/man-target-specification.html">Target Specification</a> for examples.
</p>
</fieldset>
</p>
<input id="jobSubmitButton" type="submit" disabled="disabled" value="You Must Provide At Least One Target" />
<?php
print_window_footer();
}
else if(!isset($_GET['review'])) {
?>
<?php
$stats = $autodiscoveryJob->getStats();
if($stats) {
$stats = unserialize($stats);
}
print_window_header("Job Details", "100%");
?>
<strong>Job Name:</strong> <?php echo $autodiscoveryJob->getName();?><br />
<?php echo $autodiscoveryJob->getDescription();?>
<br />
<br />
<strong>Start Time:</strong> <?php echo $autodiscoveryJob->getStartTime();?><br />
<br />
<?php
if(!in_array($autodiscoveryJob->getStatusCode(), array(AutodiscoveryJob::STATUS_FAILED, AutodiscoveryJob::STATUS_FINISHED) )) {
?>
<strong>Elapsed Time:</strong> <span id="elapsedtime">Unknown</span>
<?php
}
else {
if($autodiscoveryJob->getStatusCode() == AutodiscoveryJob::STATUS_FAILED) {
?>
<strong>Time of Failure:</strong> <?php echo $autodiscoveryJob->getStatusChangeTime();?>
<?php
}
else {
?>
<strong>Time When Completed:</strong> <?php echo $autodiscoveryJob->getStatusChangeTime();?>
<?php
}
}
?>
<br />
<strong>Current Status:</strong> <span id="jobstatus"><?php echo $autodiscoveryJob->getStatus();?></span><br />
<?php
$config = unserialize($autodiscoveryJob->getConfig());
?>
<a id="completemsg" href="autodiscovery.php?id=<?php echo $autodiscoveryJob->getid();?>&review=1" <?php if($autodiscoveryJob->getStatusCode() != AutodiscoveryJob::STATUS_FINISHED ) { ?>style="display: none;"<?php } ?>>
<div class="roundedcorner_success_box">
<div class="roundedcorner_success_top"><div></div></div>
<div class="roundedcorner_success_content">
Auto-Discovery Complete. Click to Continue To Reviewing Found Devices
</div>
<div class="roundedcorner_success_bottom"><div></div></div>
</div></a>
<a href="autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>&action=restart">Restart Job</a> | <a href="autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>&delete=1" onclick="javascript:confirmDelete();">Remove Job</a> | <a href="autodiscovery.php">Return To AutoDiscovery Menu</a>
<?php
print_window_footer();
print_window_header("Job Log");
?>
<div id="joblog">
</div>
<?php
print_window_footer();
}
else if(!isset($_GET['deviceId'])) {
// We're going to review
print_window_header("Auto-Discovery Results");
?>
<script type="text/javascript">
$(function() {
$(".checkAllLink").click(function(event){
event.preventDefault();
$(".autodiscoveryCheckbox").attr("checked", true);
});
$(".uncheckAllLink").click(function(event){
event.preventDefault();
$(".autodiscoveryCheckbox").attr("checked", false);
});
$(".autodiscoveryCheckbox").attr("checked", false);
});
</script>
<a href="autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>">Return To Auto-Discovery Job</a>
<div>
<?php
$c = new Criteria();
$c->add(AutodiscoveryDevicePeer::JOB_ID, $autodiscoveryJob->getId());
$devices = AutodiscoveryDevicePeer::doSelect($c);
if(empty($devices)) {
?>
<br />
<h3>No Devices Available For Import</h3>
<?php
}
else {
?>
<br />
<h3><?php echo count($devices);?> Device(s) Available For Import</h3>
<br />
<form action="autodiscovery.php?id=<?php echo $_GET['id'];?>&review=1" method="post">
<input type="hidden" name="request" value="process" />
<table class="tablelist">
<thead>
<tr>
<td>
</td>
<td>
Address
</td>
<td>Name</td>
<td>Description</td>
<td>OS Family</td>
<td>Parent</td>
<td>Hostname</td>
<td>
Template Assigned
</td>
<td>
Actions
</td>
</tr>
</thead>
<?php
foreach($devices as $device) {
?>
<tr class="alt">
<td><input class="autodiscoveryCheckbox" type="checkbox" name="selectedDevices[]" value="<?php echo $device->getId();?>" /></td>
<td>
<?php echo $device->getAddress();?>
</td>
<td>
<?php echo $device->getName();?>
</td>
<td>
<?php echo $device->getDescription();?>
</td>
<td>
<?php echo $device->getOsfamily();?>
</td>
<td>
<?php
$parent = $device->getNagiosHost();
if(empty($parent)) {
?>Top-Level<?php
}
else {
print($parent->getName());
}
?>
</td>
<td>
<?php echo $device->getHostname();?>
</td>
<td>
<?php
if(!$device->getHostTemplate()) {
?>None Assigned<?php
}
else {
$hostTemplate = NagiosHostTemplatePeer::retrieveByPK($device->getHostTemplate());
if(!empty($hostTemplate)) {
print($hostTemplate->getName());
}
else {
print("Template Not Found");
}
}
?>
</td>
<td>
<a href="autodiscovery.php?id=<?php echo $autodiscoveryJob->getId();?>&review=1&deviceId=<?php echo $device->getId();?>">Modify Details</a>
</td>
</tr>
<?php
}
?>
</table>
<a class="checkAllLink" href="#">Check All</a> / <a class="uncheckAllLink" href="#">Un-Check All</a> With Selected: <select>
<option value="accept">Import</option>
<option value="remove">Remove</option>
</select> <input type="submit" value="Process" /> </form>
<?php
}
?>
</div>
<?php
print_window_footer();
}
else {
print_window_header("Device Details");
?>
[ <a href="autodiscovery.php?id=<?php echo $device->getAutodiscoveryJob()->getId();?>&review=1">Return To Device List</a> ]
<br />
<br />
<h3>General Information</h3>
<table class="tablelist">
<thead>
<tr>
<td>Address</td>
<td>Name</td>
<td>Description</td>
<td>Parent</td>
<td>Hostname</td>
<td>OS Family</td>
<td>OS Generation</td>
<td>OS Vendor</td>
<td>Template Assigned</td>
</tr>
</thead>
<tr>
<td><?php echo $device->getAddress(); ?></td>
<td><?php echo $device->getName(); ?></td>
<td><?php echo $device->getDescription(); ?></td>
<td>
<?php
$parent = $device->getNagiosHost();
if(empty($parent)) {
?>Top-Level<?php
}
else {
print($parent->getName());
}
?>
</td>
<td><?php echo $device->getHostname(); ?></td>
<td><?php echo $device->getOsfamily(); ?></td>
<td><?php echo $device->getOsgen(); ?></td>
<td><?php echo $device->getOsvendor(); ?></td>
<td> <?php
if(!$device->getHostTemplate()) {
?>None Assigned<?php
}
else {
$hostTemplate = NagiosHostTemplatePeer::retrieveByPK($device->getHostTemplate());
if(!empty($hostTemplate)) {
print($hostTemplate->getName());
}
else {
print("Template Not Found");
}
}
?></td>
</tr>
</table>
<br />
<h3>Update General Information</h3>
<form action="autodiscovery.php?id=<?php echo $_GET['id'];?>&review=1&deviceId=<?php echo $device->getId();?>" method="post">
<input type="hidden" name="request" value="updateGeneral" />
<strong>Name: </strong><input type="text" value="<?php echo $device->getName();?>" name="name" size="40" maxlength="255" /> <strong>Description: </strong><input value="<?php echo $device->getDescription();?>" type="text" name="description" size="40" maxlength="255" />
<input type="submit" value="Update General" />
</form>
<br />
<h3>Change Template Assignment</h3>
<form action="autodiscovery.php?id=<?php echo $_GET['id'];?>&review=1&deviceId=<?php echo $device->getId();?>" method="post">
<input type="hidden" name="request" value="assignTemplate" />
<?php
$matchedTemplates = $device->getTemplateMatches();
$options = array();
$options[] = array(
'option' => 'None',
'value' => ''
);
$searchArray = array();
foreach($matchedTemplates as $match) {
$options[] = array(
'option' => $match->getNagiosHostTemplate()->getName() . " - " . $match->getPercent() . "%",
'value' => $match->getNagiosHostTemplate()->getId()
);
$searchArray[] = $match->getNagiosHostTemplate()->getId();
}
// Add the rest of the templates
$templates = NagiosHostTemplatePeer::doSelect(new Criteria());
foreach($templates as $template) {
if(!in_array($template->getId(), $searchArray)) {
$options[] = array(
'option' => $template->getName() . " - n/a",
'value' => $template->getId()
);
}
}
print_select("template", $options, "value", "option", $device->getHostTemplate());
?> <input type="submit" value="Assign Template" /> [ <a href="autodiscovery.php?id=<?php echo $_GET['id'];?>&review=1&deviceId=<?php echo $device->getId();?>&request=recalc">Recalculate Template Matches</a> ]
</form>
<br />
<br />
<?php
$c = new Criteria();
$c->add(AutodiscoveryDeviceServicePeer::DEVICE_ID, $device->getId());
$services = AutodiscoveryDeviceServicePeer::doSelect($c);
if(empty($services)) {
?>
<p>
<h3>No Services Were Found On This Device</h3>
</p>
<?php
}
else {
?>
<h3>Found <?php echo count($services);?> Service(s)</h3>
<table class="tablelist">
<?php
$tmp = 0;
foreach($services as $service) {
?>
<tr>
<td <?php if($tmp++ % 2) echo "class=\"alt\"";?>>
<h3><?php echo $service->getName();?> on port <?php echo $service->getProtocol();?>/<?php echo $service->getPort(); ?></h3>
<strong>Product: </strong><?php echo $service->getProduct(); ?><br />
<strong>Version: </strong><?php echo $service->getVersion(); ?><br />
<strong>Extra Information: </strong><?php echo $service->getExtraInfo(); ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
print_window_footer();
}
print_footer();
?>