Merge separate files into php-integration #12

Merged
fred.boniface merged 3 commits from separate into php-integration 2022-09-20 20:43:03 +01:00
2 changed files with 22 additions and 53 deletions

View File

@ -8,56 +8,24 @@
<body> <body>
<?php <?php
// Define form variables and set to empty values (or to the UA)
$subject = $detail = ""; // Imports the functions needed to validate and submit data
require './php/submitIssue.php';
// Set initial values
$title = $detail = "";
$ua_str = $_SERVER["HTTP_USER_AGENT"]; $ua_str = $_SERVER["HTTP_USER_AGENT"];
// Define response variable & data variable as blank before POSTing // If the page has been POSTed to then run this:
$giteaResponse = "";
$issueData = "";
// If the page is loading after submission then run this:
if ($_SERVER["REQUEST_METHOD"] == "POST" ) { if ($_SERVER["REQUEST_METHOD"] == "POST" ) {
$subject = validate($_POST["subject"]); $title = cleanInput($_POST["subject"]);
$detail = validate($_POST["detail"]); $detail = cleanInput($_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 Server PHP Version: " . PHP_VERSION . "\n\n\n" . $detail; $body = "User Agent: " . $ua_str . "\n\n Server PHP Version: " . PHP_VERSION . "\n\n" . $detail;
// Prepare the request // Call POST function
$rawData = array( sendInput($title,$body);
'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;
} }
?> ?>
@ -74,7 +42,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 $subject;?>"> <input type="text" name="subject" value="<?php echo $title;?>">
<br> <br>
<br> <br>
Details: Details:
@ -94,12 +62,6 @@
<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 submitToGitea($title,$body) { function sendInput($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 submitToGitea($title,$body) {
// Prepare the request // Prepare the request
$rawData = array( $rawData = array(
'body' => $body, 'body' => $body,
'title' => $subject 'title' => $title
); );
$preparedData = json_encode($rawData); $preparedData = json_encode($rawData);
@ -32,3 +32,10 @@ function submitToGitea($title,$body) {
return $response; return $response;
} }
function cleanInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}