zen.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * The zen file of host module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Yuting Wang<wangyuting@easycorp.ltd>
  8. * @package host
  9. * @link https://www.zentao.net
  10. */
  11. class hostZen extends host
  12. {
  13. /**
  14. * 检查新增和编辑表单提交的合法性。
  15. * Check formData of create and edit.
  16. *
  17. * @param object $formData
  18. * @access protected
  19. * @return bool
  20. */
  21. protected function checkFormData($formData)
  22. {
  23. if($formData->name && mb_strlen($formData->name) > 100)
  24. {
  25. dao::$errors['name'] = $this->lang->host->notice->nameLength;
  26. }
  27. if($formData->desc && mb_strlen($formData->desc) > 255)
  28. {
  29. dao::$errors['desc'] = $this->lang->host->notice->descLength;
  30. }
  31. $intFields = explode(',', $this->config->host->create->intFields);
  32. foreach($intFields as $field)
  33. {
  34. if(!$formData->{$field}) continue;
  35. if(!preg_match("/^-?\d+$/", $formData->{$field}))
  36. {
  37. dao::$errors[$field] = $this->lang->host->notice->{$field};
  38. }
  39. }
  40. $ipFields = explode(',', $this->config->host->create->ipFields);
  41. foreach($ipFields as $field)
  42. {
  43. if(!$formData->{$field}) continue;
  44. $ipList = explode(',', $formData->{$field});
  45. foreach($ipList as $ip)
  46. {
  47. $address = str_replace(array('https://', 'http://'), '', $ip);
  48. if(!filter_var($address, FILTER_VALIDATE_IP) && !filter_var(gethostbyname($address), FILTER_VALIDATE_IP))
  49. {
  50. dao::$errors[$field] = sprintf($this->lang->host->notice->ip, $this->lang->host->{$field});
  51. }
  52. }
  53. }
  54. return !dao::isError();
  55. }
  56. }