예제 #1
0
 print ' <td>' . $vlan['number'] . '</td>' . "\n";
 print ' <td>' . ShortenText($line['description'], $chars = 50) . '</td>' . "\n";
 print ' <td>' . $line['dns_name'] . '</td>' . "\n";
 # mac
 if (in_array('mac', $setFields)) {
     print '	<td>' . "\n";
     if (strlen($line['mac']) > 0) {
         print '<i class="fa fa-sitemap fa-gray" rel="tooltip" title="MAC: ' . $line['mac'] . '"></i>' . "\n";
     }
     print '	</td>' . "\n";
 }
 # switch
 if (in_array('switch', $setFields)) {
     if (strlen($line['switch']) > 0 && $line['switch'] != 0) {
         # get switch
         $switch = getDeviceDetailsById($line['switch']);
         $line['switch'] = $switch['hostname'];
     }
     print ' <td class="hidden-sm hidden-xs">' . $line['switch'] . '</td>' . "\n";
 }
 # port
 if (in_array('port', $setFields)) {
     print ' <td>' . $line['port'] . '</td>' . "\n";
 }
 # owner and note
 if (in_array('owner', $setFields) && in_array('note', $setFields)) {
     print ' <td class="hidden-sm hidden-xs">' . $line['owner'] . '</td>' . "\n";
     print ' <td class="note hidden-sm hidden-xs">' . "\n";
     if (!empty($line['note'])) {
         $line['note'] = str_replace("\n", "<br>", $line['note']);
         print '<i class="fa fa-gray fa fa-comment-o" rel="tooltip" title="' . $line['note'] . '"></i>' . "\n";
        $temp[] = $key2;
        unset($device[$key]);
    }
}
/* glue sections together */
if (sizeof($temp) > 0) {
    $device['sections'] = implode(";", $temp);
}
/* Hostname must be present! */
if ($device['hostname'] == "") {
    die('<div class="alert alert alert-danger">' . _('Hostname is mandatory') . '!</div>');
}
# we need old hostname
if ($device['action'] == "edit" || $device['action'] == "delete") {
    # get old switch name
    $oldHostname = getDeviceDetailsById($device['switchId']);
    $oldHostname = $oldHostname['hostname'];
    # if delete new hostname = ""
    if ($device['action'] == "delete") {
        $device['hostname'] = "";
    }
}
//custom
$myFields = getCustomFields('devices');
if (sizeof($myFields) > 0) {
    foreach ($myFields as $myField) {
        # replace possible ___ back to spaces!
        $myField['nameTest'] = str_replace(" ", "___", $myField['name']);
        if (isset($_POST[$myField['nameTest']])) {
            $device[$myField['name']] = $device[$myField['nameTest']];
        }
예제 #3
0
/**
 * Write new changelog
 */
function writeChangelog($ctype, $action, $result, $old, $new)
{
    /* set query, open db connection and fetch results */
    global $database;
    # get settings
    $settings = getAllSettings();
    if ($settings['enableChangelog'] == 1) {
        # get user details
        $cuser = getActiveUserDetails();
        # unset unneeded values and format
        if ($ctype == "ip_addr") {
            unset($new['action'], $new['subnet'], $new['type']);
        } elseif ($ctype == "subnet") {
            $new['id'] = $new['subnetId'];
            unset($new['action'], $new['subnetId'], $new['location'], $new['vrfIdOld'], $new['permissions']);
            # if section does not change
            if ($new['sectionId'] == $new['sectionIdNew']) {
                unset($new['sectionIdNew']);
                unset($new['sectionId']);
                unset($old['sectionId']);
            } else {
                $old['sectionIdNew'] = $old['sectionId'];
            }
            //transform subnet
            if (strlen($new['subnet']) > 0) {
                $new['subnet'] = Transform2decimal(substr($new['subnet'], 0, strpos($new['subnet'], "/")));
            }
        } elseif ($ctype == "section") {
            unset($new['action']);
        }
        # calculate diff
        if ($action == "edit") {
            //old - checkboxes
            foreach ($old as $k => $v) {
                if (!isset($new[$k]) && $v == 1) {
                    $new[$k] = 0;
                }
            }
            foreach ($new as $k => $v) {
                //change
                if ($old[$k] != $v && $old[$k] != str_replace("\\'", "'", $v)) {
                    //empty
                    if (strlen(@$old[$k]) == 0) {
                        $old[$k] = "NULL";
                    }
                    if (strlen(@$v) == 0) {
                        $v = "NULL";
                    }
                    //state
                    if ($k == 'state') {
                        $old[$k] = reformatIPStateText($old[$k]);
                        $v = reformatIPStateText($v);
                    } elseif ($k == 'sectionIdNew') {
                        //get old and new device
                        if ($old[$k] != "NULL") {
                            $dev = getSectionDetailsById($old[$k]);
                            $old[$k] = $dev['name'];
                        }
                        if ($v != "NULL") {
                            $dev = getSectionDetailsById($v);
                            $v = $dev['name'];
                        }
                    } elseif ($k == "masterSubnetId") {
                        if ($old[$k] == 0) {
                            $old[$k] = "Root";
                        } else {
                            $dev = getSubnetDetailsById($old[$k]);
                            $old[$k] = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]";
                        }
                        if ($v == 0) {
                            $v = "Root";
                        } else {
                            $dev = getSubnetDetailsById($v);
                            $v = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]";
                        }
                    } elseif ($k == 'switch') {
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getDeviceDetailsById($old[$k]);
                            $old[$k] = $dev['hostname'];
                        }
                        if ($v == 0) {
                            $v = "None";
                        }
                        if ($v != "NULL") {
                            $dev = getDeviceDetailsById($v);
                            $v = $dev['hostname'];
                        }
                    } elseif ($k == 'vlanId') {
                        //get old and new device
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getVLANById($old[$k]);
                            $old[$k] = $dev['name'] . " [{$dev['number']}]";
                        }
                        if ($v == 0) {
                            $v = "None";
                        } elseif ($v != "NULL") {
                            $dev = getVLANById($v);
                            $v = $dev['name'] . " [{$dev['number']}]";
                        }
                    } elseif ($k == 'vrfId') {
                        //get old and new device
                        if ($old[$k] == 0) {
                            $old[$k] = "None";
                        } elseif ($old[$k] != "NULL") {
                            $dev = getVRFDetailsById($old[$k]);
                            $old[$k] = $dev['name'] . " [{$dev['description']}]";
                        }
                        if ($v == 0) {
                            $v = "None";
                        } elseif ($v != "NULL") {
                            $dev = getVRFDetailsById($v);
                            $v = $dev['name'] . " [{$dev['description']}]";
                        }
                    } elseif ($k == 'masterSection') {
                        if ($old[$k] == 0) {
                            $old[$k] = "Root";
                        } else {
                            $dev = getSectionDetailsById($old[$k]);
                            $old[$k] = "{$dev['name']}";
                        }
                        if ($v == 0) {
                            $v = "Root";
                        } else {
                            $dev = getSectionDetailsById($v);
                            $v = "{$dev['name']}";
                        }
                    } elseif ($k == "permissions") {
                        # get old and compare
                        $new['permissions'] = str_replace("\\", "", $new['permissions']);
                        //Remove /
                        # Get all groups:
                        $groups = getAllGroups();
                        $groups = rekeyGroups($groups);
                        # reformat:
                        $newp = json_decode($new['permissions']);
                        $v = '';
                        foreach ($newp as $ke => $p) {
                            $v .= "<br>" . $groups[$ke]['g_name'] . " : " . parsePermissions($p);
                        }
                        $old[$k] = "";
                    }
                    $log["[{$k}]"] = "{$old[$k]} => {$v}";
                }
            }
        } elseif ($action == "add") {
            $log['[create]'] = "{$ctype} created";
        } elseif ($action == "delete") {
            $log['[delete]'] = "{$ctype} deleted";
            $new['id'] = $old['id'];
        } elseif ($action == "truncate") {
            $log['[truncate]'] = "Subnet truncated";
        } elseif ($action == "resize") {
            $log['[resize]'] = "Subnet Resized";
            $log['[New mask]'] = "/" . $new['mask'];
        } elseif ($action == "perm_change") {
            # get old and compare
            $new['permissions_change'] = str_replace("\\", "", $new['permissions_change']);
            //Remove /
            # Get all groups:
            $groups = getAllGroups();
            $groups = rekeyGroups($groups);
            # reformat
            if ($new['permissions_change'] != "null") {
                $newp = json_decode($new['permissions_change']);
                foreach ($newp as $k => $p) {
                    $log['[Permissions]'] .= "<br>" . $groups[$k]['g_name'] . " : " . parsePermissions($p);
                }
            }
        }
        //if change happened write it!
        if (isset($log)) {
            # format change
            foreach (@$log as $k => $l) {
                $changelog .= "{$k} {$l}\n";
            }
            $changelog = $database->real_escape_string(trim($changelog));
            # set insert query
            $query = "insert into `changelog` (`ctype`,`coid`,`cuser`,`caction`,`cresult`,`cdate`,`cdiff`) values ('{$ctype}', '{$new['id']}', '{$cuser['id']}', '{$action}', '{$result}', NOW(), '{$changelog}');";
            # execute
            try {
                $database->executeQuery($query);
            } catch (Exception $e) {
                $error = $e->getMessage();
                return true;
            }
            # mail it!
            # all good
            return true;
        }
    } else {
        return true;
    }
}
예제 #4
0
 $worksheet->write($lineCount, $x, transform2long($ip['ip_addr']), $format_left);
 $x++;
 # state
 if (in_array('state', $setFields)) {
     $worksheet->write($lineCount, $x, _($ip['state']));
     $x++;
 }
 $worksheet->write($lineCount, $x, $ip['description']);
 $x++;
 $worksheet->write($lineCount, $x, $ip['dns_name']);
 $x++;
 # switch
 if (in_array('switch', $setFields)) {
     if (strlen($ip['switch']) > 0 && $ip['switch'] != 0) {
         # get switch
         $switch = getDeviceDetailsById($ip['switch']);
         $ip['switch'] = $switch['hostname'];
     }
     $worksheet->write($lineCount, $x, $ip['switch']);
     $x++;
 }
 # port
 if (in_array('port', $setFields)) {
     $worksheet->write($lineCount, $x, $ip['port']);
     $x++;
 }
 # owner
 if (in_array('owner', $setFields)) {
     $worksheet->write($lineCount, $x, $ip['owner']);
     $x++;
 }
예제 #5
0
<?php

/**
 *	Edit switch details
 ************************/
/* required functions */
require_once '../../functions/functions.php';
/* verify that user is admin */
if (!checkAdmin()) {
    die('');
}
/* get custom fields */
$custom = getCustomFields('devices');
/* get switch detaild by Id! */
if ($_POST['action'] == "edit" || $_POST['action'] == "delete") {
    $device = getDeviceDetailsById($_POST['switchId']);
}
if ($_POST['action'] == "delete") {
    $readonly = "readonly";
} else {
    $readonly = "";
}
?>

<script type="text/javascript">
$(document).ready(function(){
     if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); }
});
</script>