Elgg  Version 6.2
SecurityTxt.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Controllers;
4 
7 use Elgg\Values;
8 
14 class SecurityTxt {
15 
25  $contact = elgg_get_config('security_txt_contact');
26  $expires = elgg_get_config('security_txt_expires');
27  if (empty($contact) || empty($expires)) {
28  // @todo replace this with a PageNotFoundException in 7.0
29  throw new EntityNotFoundException();
30  }
31 
32  $lines = [
33  "Contact: {$contact}",
34  'Expires: ' . Values::normalizeTime($expires)->format(DATE_ATOM),
35  ];
36 
37  $fields = [
38  'encryption' => 'Encryption',
39  'acknowledgments' => 'Acknowledgments',
40  'language' => 'Preferred-Languages',
41  'canonical' => 'Canonical',
42  'policy' => 'Policy',
43  'hiring' => 'Hiring',
44  'csaf' => 'CSAF',
45  ];
46  foreach ($fields as $name => $output) {
47  $value = elgg_get_config("security_txt_{$name}");
48  if (empty($value)) {
49  continue;
50  }
51 
52  $lines[] = "{$output}: {$value}";
53  }
54 
55  $response = elgg_ok_response(implode(PHP_EOL, $lines));
56  $response->setHeaders([
57  'Content-Type' => 'text/plain; charset=utf-8',
58  ]);
59 
60  return $response;
61  }
62 }
HTTP response builder interface.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
__invoke(\Elgg\Request $request)
Handle the request.
Definition: SecurityTxt.php:24
Saves user notification settings.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$response
Definition: content.php:10
$request
Definition: livesearch.php:12
$value
Definition: generic.php:51
elgg_ok_response($content= '', string|array $message= '',?string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
$fields
Save the configuration of the security.txt contents.
Definition: security_txt.php:6
$expires
Controller for the /security.txt resource.
Definition: SecurityTxt.php:14
Request container.
Definition: Request.php:12
Aggregate action for saving settings.
static normalizeTime($time)
Returns DateTime object based on time representation.
Definition: Values.php:75
$output
Definition: download.php:9