php-integration #21

Closed
fred.boniface wants to merge 146 commits from php-integration into main
2 changed files with 19 additions and 44 deletions
Showing only changes of commit 2ac8c3fa83 - Show all commits

View File

@ -8,56 +8,24 @@
<body>
<?php
// Define form variables and set to empty values (or to the UA)
// Imports the functions needed to validate and submit data
require './php/submitIssue.php';
// Set initial values
$subject = $detail = "";
$ua_str = $_SERVER["HTTP_USER_AGENT"];
// Define response variable & data variable as blank before POSTing
$giteaResponse = "";
$issueData = "";
// If the page is loading after submission then run this:
// If the page has been POSTed to then run this:
if ($_SERVER["REQUEST_METHOD"] == "POST" ) {
$subject = validate($_POST["subject"]);
$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"
);
$title = cleanInput($_POST["subject"]);
$detail = cleanInput($_POST["detail"]);
// 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
$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;
// Call POST function
sendInput($title,$body);
}
?>

View File

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