Issues (2963)

includes/html/modal/device_maintenance.inc.php (1 issue)

1
<?php
2
/**
3
 * device_maintenance.inc.php
4
 *
5
 * LibreNMS device maintenance modal
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 * @link       https://www.librenms.org
21
 *
22
 * @copyright  2020 Thomas Berberich
23
 * @author     Thomas Berberich <[email protected]>
24
 */
25
if (! Auth::user()->hasGlobalAdmin()) {
0 ignored issues
show
The method hasGlobalAdmin() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
if (! Auth::user()->/** @scrutinizer ignore-call */ hasGlobalAdmin()) {
Loading history...
26
    exit('ERROR: You need to be admin');
27
}
28
29
$hour_steps = range(0, 23, 1);
30
$minute_steps = [0, 30];
31
$exclude_durations = ['0:00'];
32
33
$maintenance_duration_list = [];
34
foreach ($hour_steps as $hour) {
35
    foreach ($minute_steps as $min) {
36
        if (empty($hour) && empty($min)) {
37
            continue;
38
        }
39
        $str_hour = $hour;
40
        $str_min = $min < 10 ? '0' . $min : $min;
41
42
        $duration = $str_hour . ':' . $str_min;
43
44
        if (in_array($duration, $exclude_durations)) {
45
            continue;
46
        }
47
        $maintenance_duration_list[] = $duration;
48
    }
49
}
50
?>
51
<div class="modal fade" id="device_maintenance_modal" tabindex="-1" role="dialog" aria-labelledby="device_edit" aria-hidden="true">
52
    <div class="modal-dialog">
53
        <div class="modal-content">
54
            <div class="modal-header">
55
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
56
                <h5 class="modal-title" id="search_alert_rule_list">Device Maintenance</h5>
57
            </div>
58
            <div class="modal-body">
59
                <form method="post" role="form" id="sched-form" class="form-horizontal schedule-maintenance-form">
60
                    <?php echo csrf_field() ?>
61
                    <div class="form-group">
62
                        <label for="notes" class="col-sm-4 control-label">Notes: </label>
63
                        <div class="col-sm-8">
64
                            <textarea class="form-control" id="notes" name="notes" placeholder="Maintenance notes"></textarea>
65
                        </div>
66
                    </div>
67
                    <div class="form-group">
68
                        <label for="duration" class="col-sm-4 control-label">Duration: </label>
69
                        <div class="col-sm-8">
70
                            <select name='duration' id='duration' class='form-control input-sm'>
71
                                <?php foreach ($maintenance_duration_list as $dur) { ?>
72
                                <option value='<?=$dur?>'><?=$dur?>h</option>
73
                                <?php }?>
74
                            </select>
75
                        </div>
76
                    </div>
77
                    <div class="form-group">
78
                        <label for="maintenance-submit" class="col-sm-4 control-label"></label>
79
                        <div class="col-sm-8">
80
                            <button type="submit" id="maintenance-submit" data-device_id="<?php echo $device['device_id']; ?>" <?php echo \LibreNMS\Alert\AlertUtil::isMaintenance($device['device_id']) ? 'disabled class="btn btn-warning"' : 'class="btn btn-success"'?> name="maintenance-submit">Start Maintenance</button>
81
                        </div>
82
                    </div>
83
                </form>
84
            </div>
85
        </div>
86
    </div>
87
</div>
88
<script>
89
    $("#maintenance-submit").on("click", function() {
90
        var device_id = $(this).data("device_id");
91
        var title = '<?=\LibreNMS\Util\Clean::html($device['hostname'], []); ?>';
92
        var notes = $('#notes').val();
93
        var recurring = 0;
94
        var start = '<?=date('Y-m-d H:i:00'); ?>';
95
        var duration = $('#duration').val();
96
        $.ajax({
97
            type: 'POST',
98
            url: 'ajax_form.php',
99
            data: { type: "schedule-maintenance",
100
                    sub_type: 'new-maintenance',
101
                    title: title,
102
                    notes: notes,
103
                    recurring: recurring,
104
                    start: start,
105
                    duration: duration,
106
                    maps: [device_id]
107
                  },
108
            dataType: "json",
109
            success: function(data){
110
                if(data['status'] == 'ok') {
111
                    toastr.success(data['message']);
112
                } else {
113
                    toastr.error(data['message']);
114
                }
115
            },
116
            error:function(){
117
                toastr.error('An error occured setting this device into maintenance mode');
118
            }
119
        });
120
    });
121
</script>
122