]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/websites/tools/tools/landing/report_csp_violation.php
Use personnal project for landing page
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / tools / landing / report_csp_violation.php
diff --git a/modules/private/websites/tools/tools/landing/report_csp_violation.php b/modules/private/websites/tools/tools/landing/report_csp_violation.php
new file mode 100644 (file)
index 0000000..13a3234
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+$email_address = 'ismael@bouya.org';
+$email_subject = 'Content-Security-Policy violation';
+
+$current_domain = $_SERVER['SERVER_NAME'];
+$email_subject = $email_subject . ' on ' . $current_domain;
+
+http_response_code(204);
+
+$json_data = file_get_contents('php://input');
+
+if ($json_data = json_decode($json_data)) {
+  $json_data = json_encode($json_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+
+  $message = "The following Content-Security-Policy violation occurred on " .
+    $current_domain . ":\n\n" .
+    $json_data;
+  mail($email_address, $email_subject, $message, 'Content-Type: text/plain;charset=utf-8');
+}