Merge pull request 'Merge separate files into php-integration' (#12) from separate into php-integration
Reviewed-on: #12
This commit is contained in:
commit
952383d6aa
64
issue.php
64
issue.php
@ -8,56 +8,24 @@
|
||||
<body>
|
||||
|
||||
<?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"];
|
||||
|
||||
// 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);
|
||||
}
|
||||
?>
|
||||
|
||||
@ -74,7 +42,7 @@
|
||||
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
|
||||
Subject:
|
||||
<br>
|
||||
<input type="text" name="subject" value="<?php echo $subject;?>">
|
||||
<input type="text" name="subject" value="<?php echo $title;?>">
|
||||
<br>
|
||||
<br>
|
||||
Details:
|
||||
@ -94,12 +62,6 @@
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
||||
<p>You have submitted:</p>
|
||||
<p>REQUEST DATA: <?php echo $issueData;?>
|
||||
<br>
|
||||
<br>
|
||||
JSON REPLY: <?php echo $giteaResponse;?>
|
||||
</p>
|
||||
|
||||
<!-- Footer -->
|
||||
<?php include "./page-blocks/footer.php" ?>
|
||||
|
@ -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';
|
||||
@ -15,7 +15,7 @@ function submitToGitea($title,$body) {
|
||||
// Prepare the request
|
||||
$rawData = array(
|
||||
'body' => $body,
|
||||
'title' => $subject
|
||||
'title' => $title
|
||||
);
|
||||
|
||||
$preparedData = json_encode($rawData);
|
||||
@ -32,3 +32,10 @@ function submitToGitea($title,$body) {
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function cleanInput($data) {
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
$data = htmlspecialchars($data);
|
||||
return $data;
|
||||
}
|
||||
|
Reference in New Issue
Block a user