darknet-lantern/www/submit.php

84 lines
3.3 KiB
PHP

<?php
session_start();
if (isset($_POST['submit'])){
// Clear user input
$link = htmlspecialchars($_POST['link']);
$name = htmlspecialchars($_POST['name']);
$description = htmlspecialchars($_POST['description']);
$captcha = htmlspecialchars($_POST['captcha']);
// Captcha Auth check
if ($captcha != htmlspecialchars($_SESSION['secure'])){
echo "Captcha Failed";
}else{
if (empty($link) or empty($name) or empty($description)){
echo "All of the fields must not be empty";
}else{
// Clearing unusual characters in all the fields
$clear_link = str_replace(['@','*','(',') ',';','#'],'',$link);
$clear_name = str_replace(['@','.',',','(',')','#',';'],'',$name);
$clear_description = str_replace(['@',';'], '', $description);
// Open the file once before the loop
$file = fopen("../submissions/submission.csv", "a");
if ($file !== false) {
// Create an array with the inputs to write as a single row
$row = [$clear_link, $clear_name,$clear_description];
// Write the row to the CSV file
fputcsv($file, $row, ',', '"');
// Close the file after writing
fclose($file);
} else {
// Handle error opening the file
errorlog("Error opening the file.");
}
header("Location: index.php");
}
}
}
?>
<!DOCTYPE html>
<head>
<title>Darknet Lantern</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="twitter:card" content="summary" />
<meta name="description" content="Darknet Lantern is a minimalistic Peer to Peer Decentralised Search Engine for the Darknet, that got officially released on>
<meta property="og:site_name" content="Darknet Lantern" />
<meta property="og:title" content="Darknet Lantern" />
<meta property="og:type" content="website" />
<!-- // Now displays the url of the instance -->
<meta property="og:url" content="<?php echo htmlspecialchars($_SERVER['SERVER_NAME']); ?>" />
<!-- // Default images for previews -->
<meta property="og:image:url" content="<?php echo htmlspecialchars($_SERVER['SERVER_NAME']) . "/img/logo-large.png"; ?>" />
<meta property="og:locale" content="en_US" />
<!-- // This tells search engines which URL should be considered the original source when multiple URLs contain the same content. -->
<link rel="canonical" href="<?php echo htmlspecialchars($_SERVER['SERVER_NAME']); ?>" />
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" href="/img/logo-favicon.png">
</head>
<html>
<?php include("header.php");?>
<div class="width-class">
<form action="submit.php" method="POST">
<label style="color:white">Link</label>
<input required class="input-class" type="text" name="link" placeholder="http://link.com/onion">
<label style="color:white">Name</label>
<input required class="input-class" type="text" name="name">
<label style="color:white">Description</label>
<input required class="input-class" type="text" name="description">
<label style="color:white">Captcha</label>
<div>
<img src="generate.php">
<input type="text" name="captcha">
<input type="submit" value="submit" name="submit" />
</div>
</form>
</div>
</html>