Brilliant, that did the trick:
public function onAfterWrite() {
if($this->ParentID) {
$top = $this->getAncestors()->First();
} else {
$top = $this;
}
$cmd = escapeshellarg('ban.url ' . $top->Link());
system('varnishadm -T :6082 ' . $cmd);
return true;
}
Thanks again!