devices_apply.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. if (!defined("CONFIG")) die("Not defined");
  5. $page_url = null;
  6. if (getPOST("ApplyForAll", $page_url)) {
  7. // Получаем массив ID устройств
  8. $dev_id = getPOST("fid", $page_url, []);
  9. // Получаем и валидируем параметры через getPOST
  10. $a_dev_type = (int)getPOST("a_dev_type", $page_url, 0);
  11. $a_device_model_id = (int)getPOST("a_device_model_id", $page_url, 0);
  12. $a_building_id = (int)getPOST("a_building_id", $page_url, 0);
  13. $a_snmp_version = (int)getPOST("a_snmp_version", $page_url, 0);
  14. $a_ro_community = trim(getPOST("a_ro_community", $page_url, 'public'));
  15. $a_rw_community = trim(getPOST("a_rw_community", $page_url, 'private'));
  16. $msg = "Massive change devices!";
  17. LOG_WARNING($db_link, $msg);
  18. $all_ok = true;
  19. foreach ($dev_id as $val) {
  20. if (!$val = (int)$val) { // Пропускаем неправильные ID
  21. continue;
  22. }
  23. $device = [];
  24. if (getPOST("e_set_type", $page_url) !== null) {
  25. $device['device_type'] = $a_dev_type;
  26. }
  27. if (getPOST("e_set_model", $page_url) !== null) {
  28. $device['device_model_id'] = $a_device_model_id;
  29. $device['vendor_id'] = get_device_model_vendor($db_link, $a_device_model_id);
  30. }
  31. if (getPOST("e_set_snmp_version", $page_url) !== null) {
  32. $device['snmp_version'] = $a_snmp_version;
  33. }
  34. if (getPOST("e_set_ro_community", $page_url) !== null) {
  35. $device['community'] = $a_ro_community;
  36. }
  37. if (getPOST("e_set_rw_community", $page_url) !== null) {
  38. $device['rw_community'] = $a_rw_community;
  39. }
  40. if (getPOST("e_set_building", $page_url) !== null) {
  41. $device['building_id'] = $a_building_id;
  42. }
  43. if (!empty($device)) {
  44. // 🔒 Безопасный вызов: параметризованное условие
  45. $ret = update_record($db_link, "devices", "id = ?", $device, [$val]);
  46. if (!$ret) {
  47. $all_ok = false;
  48. }
  49. }
  50. }
  51. if ($all_ok) {
  52. print "Success!";
  53. } else {
  54. print "Fail!";
  55. }
  56. }
  57. ?>