Compare commits

..

No commits in common. "952383d6aa9143baef5025adfbb4d33508964866" and "64c69ef01cd2b7b233aed16daf58f151c82e6cf8" have entirely different histories.

2 changed files with 53 additions and 22 deletions

View File

@ -8,24 +8,56 @@
<body> <body>
<?php <?php
// Define form variables and set to empty values (or to the UA)
// Imports the functions needed to validate and submit data $subject = $detail = "";
require './php/submitIssue.php';
// Set initial values
$title = $detail = "";
$ua_str = $_SERVER["HTTP_USER_AGENT"]; $ua_str = $_SERVER["HTTP_USER_AGENT"];
// If the page has been POSTed to then run this: // Define response variable & data variable as blank before POSTing
$giteaResponse = "";
$issueData = "";
// If the page is loading after submission then run this:
if ($_SERVER["REQUEST_METHOD"] == "POST" ) { if ($_SERVER["REQUEST_METHOD"] == "POST" ) {
$title = cleanInput($_POST["subject"]); $subject = validate($_POST["subject"]);
$detail = cleanInput($_POST["detail"]); $detail = validate($_POST["detail"]);
// Get API Key for git.fjla.uk
require '/srv/php-keys/athena/gitea.php';
// Set httpHeaders
$httpHeaders = array(
"accept: application/json",
$giteaKey,
"Content-Type: application/json"
);
// Prepare $detail to POST // Prepare $detail to POST
$body = "User Agent: " . $ua_str . "\n\n Server PHP Version: " . PHP_VERSION . "\n\n" . $detail; $body = "User Agent: " . $ua_str . "\n Server PHP Version: " . PHP_VERSION . "\n\n\n" . $detail;
// Call POST function // Prepare the request
sendInput($title,$body); $rawData = array(
'body' => $body,
'title' => $subject
);
$issueData = json_encode($rawData);
// Prepare CURL
$curlConnection = curl_init('https://git.fjla.uk/api/v1/repos/fred.boniface/athena.fb-infra.uk/issues');
curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $issueData);
curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlConnection, CURLOPT_HTTPHEADER, $httpHeaders);
// Get response and exit CURL
$giteaResponse = curl_exec($curlConnection);
curl_close($curlConnection);
}
function validate($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} }
?> ?>
@ -42,7 +74,7 @@
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
Subject: Subject:
<br> <br>
<input type="text" name="subject" value="<?php echo $title;?>"> <input type="text" name="subject" value="<?php echo $subject;?>">
<br> <br>
<br> <br>
Details: Details:
@ -62,6 +94,12 @@
<input type="submit"> <input type="submit">
</form> </form>
<p>You have submitted:</p>
<p>REQUEST DATA: <?php echo $issueData;?>
<br>
<br>
JSON REPLY: <?php echo $giteaResponse;?>
</p>
<!-- Footer --> <!-- Footer -->
<?php include "./page-blocks/footer.php" ?> <?php include "./page-blocks/footer.php" ?>

View File

@ -1,6 +1,6 @@
<?php <?php
function sendInput($title,$body) { function submitToGitea($title,$body) {
// Get API Key for git.fjla.uk // Get API Key for git.fjla.uk
require '/srv/php-keys/athena/gitea.php'; require '/srv/php-keys/athena/gitea.php';
@ -15,7 +15,7 @@ function sendInput($title,$body) {
// Prepare the request // Prepare the request
$rawData = array( $rawData = array(
'body' => $body, 'body' => $body,
'title' => $title 'title' => $subject
); );
$preparedData = json_encode($rawData); $preparedData = json_encode($rawData);
@ -32,10 +32,3 @@ function sendInput($title,$body) {
return $response; return $response;
} }
function cleanInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}