Advertisement
Guest User

Untitled

a guest
Jun 25th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/local/bin/php
  2. <?php
  3. require_once("config.inc");
  4. require_once("interfaces.inc");
  5. require_once("util.inc");
  6. $subsystem = !empty($argv[1]) ? $argv[1] : '';
  7. $type = !empty($argv[2]) ? $argv[2] : '';
  8. if ($type != 'MASTER' && $type != 'BACKUP') {
  9. log_error("Carp '$type' event unknown from source '{$subsystem}'");
  10. exit(1);
  11. }
  12. if (!strstr($subsystem, '@')) {
  13. log_error("Carp '$type' event triggered from wrong source '{$subsystem}'");
  14. exit(1);
  15. }
  16. foreach($config['interfaces'] as $ifkey => $interface) {
  17. if ($ifkey=='opt4') {
  18. if ($type == 'MASTER') {
  19. log_msg("Carp Status is now Master!");
  20. log_msg("Enabling interface: $ifkey - {$interface['if']}");
  21. shell_exec("/sbin/ifconfig {$interface['if']} up");
  22. $config['interfaces'][$ifkey]['enable'] = '1';
  23. write_config("enable interface '$ifkey' due CARP event '$type'", false);
  24. interface_configure(false, $ifkey, false, false);
  25. sleep(1);
  26. log_msg("Restarting DHCPD");
  27. shell_exec('pluginctl -s dhcpd restart');
  28. sleep(1);
  29. log_msg("Issueing dhclient command to request a DHCP lease");
  30. shell_exec("dhclient {$interface['if']}");
  31. } else if ($type == 'BACKUP') {
  32. log_msg("Carp Status is now Backup!");
  33. log_msg("Disabling interface: $ifkey - {$interface['if']}");
  34. shell_exec("/sbin/ifconfig {$interface['if']} down");
  35. unset($config['interfaces'][$ifkey]['enable']);
  36. write_config("disable interface '$ifkey' due CARP event '$type'", false);
  37. interface_configure(false, $ifkey, false, false);
  38. log_msg("Stopping DHCPD");
  39. shell_exec('pluginctl -s dhcpd stop');
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement