@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 56 lines 1.6 kB view raw
1<?php 2 3final class HeraldWebhookKeyController 4 extends HeraldWebhookController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $hook = id(new HeraldWebhookQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($request->getURIData('id'))) 12 ->requireCapabilities( 13 array( 14 PhabricatorPolicyCapability::CAN_VIEW, 15 PhabricatorPolicyCapability::CAN_EDIT, 16 )) 17 ->executeOne(); 18 if (!$hook) { 19 return new Aphront404Response(); 20 } 21 22 $action = $request->getURIData('action'); 23 if ($action === 'cycle') { 24 if (!$request->isFormPost()) { 25 return $this->newDialog() 26 ->setTitle(pht('Regenerate HMAC Key')) 27 ->appendParagraph( 28 pht( 29 'Regenerate the HMAC key used to sign requests made by this '. 30 'webhook?')) 31 ->appendParagraph( 32 pht( 33 'Requests which are currently authenticated with the old key '. 34 'may fail.')) 35 ->addCancelButton($hook->getURI()) 36 ->addSubmitButton(pht('Regnerate Key')); 37 } else { 38 $hook->regenerateHMACKey()->save(); 39 } 40 } 41 42 $form = id(new AphrontFormView()) 43 ->setViewer($viewer) 44 ->appendControl( 45 id(new AphrontFormTextControl()) 46 ->setLabel(pht('HMAC Key')) 47 ->setValue($hook->getHMACKey())); 48 49 return $this->newDialog() 50 ->setTitle(pht('Webhook HMAC Key')) 51 ->appendForm($form) 52 ->addCancelButton($hook->getURI(), pht('Done')); 53 } 54 55 56}