Open Steltek opened 1 year ago
Hello,
Any idea how to solve it, because my scenario is exactly the same?
Bonjour,
Avez vous trouvé une solution à ce soucis ?
Hola, en mi caso simplemente reemplacé el contenido del archivo con los datos de la versión anterior y me funcionó. No se mucho del tema pero de momento todo corre bien en mi phpipam.
edit-result.php
/**
/ functions / require_once( dirname(FILE) . '/../../../functions/functions.php' );
$Database = new Database_PDO; $User = new User ($Database); $Admin = new Admin ($Database, false); $Tools = new Tools ($Database); $Racks = new phpipam_rack ($Database); $Result = new Result ();
$User->check_user_session();
if($_POST['action']=="edit") { $User->check_module_permissions ("devices", 2, true, false); } else { $User->check_module_permissions ("devices", 3, true, false); }
$User->check_maintaneance_mode ();
$User->Crypto->csrf_cookie ("validate", "device", $_POST['csrfcookie']) === false ? $Result->show("danger", ("Invalid CSRF cookie"), true) : "";
$device = $Admin->strip_input_tags($_POST);
if($_POST['action']!="add" && !is_numeric($POST['switchid'])) { $Result->show("danger", ("Invalid ID"), true); }
foreach($device as $key=>$line) { if (strlen(strstr($key,"section-"))>0) { $key2 = str_replace("section-", "", $key); $temp[] = $key2;
unset($device[$key]);
}
}
$device['sections'] = !empty($temp) ? implode(";", $temp) : null;
if($device['hostname'] == "") { $Result->show("danger", _('Hostname is mandatory').'!', true); }
if (strlen(@$device['rack']>0) && $User->get_module_permissions ("racks")>0) { if ($User->settings->enableRACK!="1") { unset($device['rack']); } else {
if (!is_numeric($device['rack'])) { $Result->show("danger", _('Invalid rack identifier').'!', true); }
if (!is_numeric($device['rack_start'])) { $Result->show("danger", _('Invalid rack start position').'!', true); }
if (!is_numeric($device['rack_size'])) { $Result->show("danger", _('Invalid rack size').'!', true); }
# validate rack
$rack = $Racks->fetch_rack_details ($device['rack']);
if ($rack===false) { $Result->show("danger", _('Rack does not exist').'!', true); }
}
}
$custom = $Tools->fetch_custom_fields('devices'); if(sizeof($custom) > 0) { foreach($custom as $myField) {
//replace possible ___ back to spaces
$myField['nameTest'] = str_replace(" ", "___", $myField['name']);
if(isset($_POST[$myField['nameTest']])) { $_POST[$myField['name']] = $_POST[$myField['nameTest']];}
//booleans can be only 0 and 1!
if($myField['type']=="tinyint(1)") {
if($device[$myField['name']]>1) {
$device[$myField['name']] = 0;
}
}
//not null!
if($myField['Null']=="NO" && strlen($device[$myField['name']])==0) { $Result->show("danger", $myField['name'].'" can not be empty!', true); }
# save to update array
$update[$myField['name']] = $device[$myField['nameTest']];
}
}
$values = array( "id" =>$device['switchid'], "hostname" =>$device['hostname'], "ip_addr" =>$device['ip_addr'], "type" =>$device['type'], "description" =>$device['description'], "sections" =>$device['sections'], "location" =>@$device['location_item'] );
if(isset($update)) { $values = array_merge($values, $update); }
if (strlen(@$device['rack'])>0 && $User->get_module_permissions ("racks")>0) { $values['rack'] = $device['rack']; $values['rack_start'] = $device['rack_start']; $values['rack_size'] = $device['rack_size']; }
if ($User->get_module_permissions ("locations")<1) { unset ($values['location']); }
if(!$Admin->object_modify("devices", $POST['action'], "id", $values)) {} else { $Result->show("success", ("Device $device[action] successfull").'!', false); }
if($_POST['action']=="delete"){
$Admin->remove_object_references ("subnets", "device", $values["id"]);
$Admin->remove_object_references ("nat", "device", $values["id"]);
$Admin->remove_object_references ("ipaddresses", "switch", $values["id"]);
$Admin->remove_object_references ("pstnPrefixes", "deviceId", $values["id"]);
$Admin->remove_object_references ("pstnNumbers", "deviceId", $values["id"]);
$Admin->remove_object_references ("circuits", "device1", $values["id"]);
$Admin->remove_object_references ("circuits", "device2", $values["id"]);
}#
Also having the same issue same version 1.6.0
Describe the bug Cannot add devices without placing them in rack (Error: "Rack does not exist!")
phpIPAM version 1.6.0 (github master)
Versions of phpIPAM known to contain the issue (delete as appropriate).
master
development branch.Your Environment (please supply the following information):
Steps To Reproduce Please include steps to reproduce the issue:
Screenshots and error logs![image](https://user-images.githubusercontent.com/1315116/236143466-224a5ae9-6132-437d-a53b-2d573c59c6fe.png)
PHP does not seem to be returning any error.
Additional Info Call to admin/devices/edit-result.php happens with "rack=0" in the payload. edit-result.php seems to be designed to expect it to be blank. Hacking the DOM (with dev tools) and changing the value="0" to just value, and then submitting the form makes it work.
I suspect either the frontend needs to be updated to leave the value blank when "None" is selected, or the backend needs to be updated to consider 0 as the equivalent of blank.