Server Record Hooks
The eight hooks over server records, server groups and imports.
Overview
Server records hold the details of the machines services are built on. Saving, updating, deleting and importing all live here.
? One distinction matters: in the save filter the password is in the clear, while in the events it is encrypted. The filter sits ahead of the encryption.
Reference
Changing the server data before it is saved
Runs before a server record is written. This is the point before the access details are encrypted.
Hook::add('filter:product.server_save_data', 10, function (&$set_data, $type, $detail) {
// THE PASSWORD IS IN THE CLEAR HERE: do not write the record anywhere as it stands.
$set_data['ns1'] = Acme::defaultNs(1);
$set_data['ns2'] = Acme::defaultNs(2);
});Following a server being added
Runs after a new server record is created.
Hook::add('action:product.server_created', 10, function ($id, $set_data, $type) {
// The password is encrypted here: give monitoring only the address.
Acme::addMonitor($id, $set_data['ip'] ?? '');
});Following a server update
Runs after a server record is updated.
Hook::add('action:product.server_updated', 10, function ($id, $set_data, $type, $detail) {
// Move monitoring when the address changed.
if (($detail['ip'] ?? '') !== ($set_data['ip'] ?? ''))
Acme::moveMonitor($id, $set_data['ip'] ?? '');
});Stopping a server deletion
Runs before a server record is deleted. The record goes; the machine and the accounts on it stay.
Hook::add('gate:product.server_delete', 10, function ($id, $detail) {
// The record goes but the accounts on the machine remain.
if (Acme::serverHasServices($id)) return 'Live services still run on this server.';
return null;
});Following a server being deleted
Runs after the server record is deleted.
Hook::add('action:product.server_deleted', 10, function ($i, $detail) {
Acme::dropMonitor($i);
});Following an import from a server
Runs after the accounts on a server are brought in as services.
Hook::add('action:product.server_imported', 10, function ($server, $imported) {
// The entries are TEXT, not records.
Acme::notifyOps(count($imported) . ' services imported from ' . ($server['name'] ?? ''));
});Changing server group data
Runs before a server group is saved.
Hook::add('filter:product.server_group_save_data', 10, function (&$data, $detail) {
// The server list is COMMA TEXT, not an array.
$ids = array_filter(explode(',', (string) ($data['servers'] ?? '')));
$data['servers'] = implode(',', Acme::onlyHealthy($ids));
});Stopping a server group deletion
Runs before a server group is deleted.
Hook::add('gate:product.server_group_delete', 10, function ($id, $detail) {
if (Acme::groupBoundToProducts($id)) return 'Products are still bound to this group.';
return null;
});Pitfalls
The server save filter runs before the encryption: the password field holds plain text. Writing that array to a log, sending it to an outside service or copying it into a table of your own leaks the server password in the clear. In the events the same field is encrypted.
The deletion removes only the record. The accounts, domains and data on the server stay where they are; the system stops knowing about them. The delete gate is your last chance to notice.
Related Articles
- Product Hooks
- Service Hooks
- How Hooks Work
Merci pour votre retour !
Notre équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas ci-dessus.