Elgg  Version 6.1
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  throw new EntityNotFoundException();
29  }
30 
31  $lines = [
32  "Contact: {$contact}",
33  'Expires: ' . Values::normalizeTime($expires)->format(DATE_ATOM),
34  ];
35 
36  $fields = [
37  'encryption' => 'Encryption',
38  'acknowledgments' => 'Acknowledgments',
39  'language' => 'Preferred-Languages',
40  'canonical' => 'Canonical',
41  'policy' => 'Policy',
42  'hiring' => 'Hiring',
43  'csaf' => 'CSAF',
44  ];
45  foreach ($fields as $name => $output) {
46  $value = elgg_get_config("security_txt_{$name}");
47  if (empty($value)) {
48  continue;
49  }
50 
51  $lines[] = "{$output}: {$value}";
52  }
53 
54  $response = elgg_ok_response(implode(PHP_EOL, $lines));
55  $response->setHeaders([
56  'Content-Type' => 'text/plain; charset=utf-8',
57  ]);
58 
59  return $response;
60  }
61 }
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
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.
$response
Definition: content.php:10
$request
Definition: livesearch.php:12
$value
Definition: generic.php:51
$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