ServiceRegister.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class Application_Model_ServiceRegister
  3. {
  4. public static function GetRemoteIpAddr()
  5. {
  6. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  7. //check ip from share internet
  8. $ip=$_SERVER['HTTP_CLIENT_IP'];
  9. } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  10. //to check ip is pass from proxy
  11. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  12. } else {
  13. $ip=$_SERVER['REMOTE_ADDR'];
  14. }
  15. return $ip;
  16. }
  17. public static function Register($p_componentName, $p_ipAddress)
  18. {
  19. $component = CcServiceRegisterQuery::create()->findOneByDbName($p_componentName);
  20. if (is_null($component)) {
  21. $component = new CcServiceRegister();
  22. $component->setDbName($p_componentName);
  23. }
  24. // Need to convert ipv6 to ipv4 since Monit server does not appear
  25. // to allow access via an ipv6 address.
  26. // http://[::1]:2812 does not respond.
  27. // Bug: http://savannah.nongnu.org/bugs/?27608
  28. if ($p_ipAddress == "::1") {
  29. $p_ipAddress = "127.0.0.1";
  30. }
  31. $component->setDbIp($p_ipAddress);
  32. $component->save();
  33. }
  34. }