Initial commit

This commit is contained in:
2021-01-27 20:23:49 +01:00
commit 66d10fdcda
25 changed files with 1357 additions and 0 deletions

101
public/admin/audit.php Executable file
View File

@@ -0,0 +1,101 @@
<?php
include('auth.php');
include('redirect.php');
$old_path = '../uploads/unaudited/';
$new_path = '../uploads/audited/';
$directory = "../uploads/unaudited";
$files = array_diff(scandir($directory), array('..', '.'));
if ((isset($_GET['action'])) && ($_GET['action'] === 'accept_all'))
{
foreach ($files as $file) {
rename($old_path.$file, $new_path.$file);
}
header("Location: /admin/audit.php");
die();
}
// Code written with little too no sleep at 05:16
if ((isset($_GET['action'])) && (isset($_GET['file']))) {
if (file_exists($old_path.$_GET['file'])===false)
{
header("Location: /admin/audit.php");
die('File does not exist');
}
switch ($_GET['action']) {
case 'accept':
// is this safe?
rename($old_path.$_GET['file'], $new_path.$_GET['file']);
break;
case 'delete':
// Enterprise(tm) security
unlink($old_path.$_GET['file']);
break;
default:
die('Action not found');
break;
}
header("Location: /admin/audit.php");
die();
}
?>
<?php include('../../_header.php'); ?>
<h3>Nye bilde forslag</h3>
<p>Totalt: <?=count($files)?></p>
<a href="audit.php?action=accept_all"><button type="button">Godta alt</button></a>
<br>
<br>
<table>
<tr>
<th>Fil</th>
<th>Handling</th>
</tr>
<?php foreach($files as $file): ?>
<tr>
<td><a href="/uploads/unaudited/<?=$file;?>"><img class="img" src="/uploads/unaudited/<?=$file;?>" alt=""></a></td>
<td style="text-align: center;">
<a href="audit.php?action=accept&file=<?=$file;?>">Godta</a>
<br>
<br>
<br>
<a style="color: red;" href="audit.php?action=delete&file=<?=$file;?>">Avslå</a>
</td>
</tr>
<?php endforeach;?>
</table>
<br>
<a href="audit.php?action=accept_all"><button type="button">Godta alt</button></a>
<style>
table {
border-collapse: collapse;
width: 100%;
}
table, td, th {
border: 1px solid #888;
}
tr:nth-child(even) {background-color: #f2f2f2;}
.img {
margin: auto;
object-fit: contain;
width:100%;
max-height: 600px;
min-height: 150px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
<?php include('../../_footer.php'); ?>

79
public/admin/audited.php Executable file
View File

@@ -0,0 +1,79 @@
<?php
include('auth.php');
include('redirect.php');
// Code written with little too no sleep at 05:16
if ((isset($_GET['action'])) && (isset($_GET['file']))) {
$path = '../uploads/audited/';
if (file_exists($path.$_GET['file'])===false)
{
header("Location: /admin/audited.php");
die('File does not exist');
}
switch ($_GET['action']) {
case 'delete':
// Is this safe?
unlink($path.$_GET['file']);
break;
default:
die('Action not found');
break;
}
header("Location: /admin/audited.php");
die();
}
?>
<?php include('../../_header.php'); ?>
<h3>Bilder som er i bruk</h3>
<?php
$directory = "../uploads/audited";
$files = array_diff(scandir($directory), array('..', '.'));
?>
<p>Totalt: <?=count($files)?></p>
<table>
<tr>
<th>Fil</th>
<th>Handling</th>
</tr>
<?php foreach($files as $file): ?>
<tr>
<td><a href="/uploads/audited/<?=$file;?>"><img class="img" src="/uploads/audited/<?=$file;?>" alt=""></a></td>
<td style="text-align: center;">
<a style="color: red;" href="audited.php?action=delete&file=<?=$file;?>">Slett</a>
</td>
</tr>
<?php endforeach;?>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
table, td, th {
border: 1px solid #888;
}
tr:nth-child(even) {background-color: #f2f2f2;}
.img {
margin: auto;
object-fit: contain;
width:100%;
max-height: 600px;
min-height: 150px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
<?php include('../../_footer.php'); ?>

19
public/admin/auth.php Executable file
View File

@@ -0,0 +1,19 @@
<?php
error_reporting(E_ERROR | E_PARSE);
session_start();
$config = include("../../config.php");
if (isset($_SESSION['password']) && isset($_SESSION['username']))
{
if ($_SESSION['password'] !== $config['password'] ||
$_SESSION['username'] !== $config['username'])
{
$_SESSION['admin'] = false;
}
}
if (isset($_SESSION['username']) || isset($_SESSION ['password'])) {
$error = "Konto opplysningene dine har blitt endret. Vennligst logg inn igjen.";
}

20
public/admin/index.php Executable file
View File

@@ -0,0 +1,20 @@
<?php
include('auth.php');
include('redirect.php');
?>
<?php include('../../_header.php'); ?>
<a href="/kiosk.php">Åpne infoskjerm</a>
<h3>Administrator Panel</h3>
<div style="border: 1px solid #888; padding: 10px; border-radius: 2px;">
<ul>
<li><a href="audit.php">Se nye bilde forslag</a></li>
<li><a href="audited.php">Se bilder som er i bruk</a></li>
</ul>
</div>
<?php include('../../_footer.php'); ?>

58
public/admin/login.php Executable file
View File

@@ -0,0 +1,58 @@
<?php
include('auth.php');
#include('redirect.php');
/* custom redirect */
if ($_SESSION["admin"] === true) {
header("Location: /admin/index.php");
die();
}
/* Login logic */
if ((isset($_POST['username'])) && (isset($_POST['password']))) {
if(anti_spam()){
$error = "AntiSpam: Vennligst vent og prøv igjen.";
} else {
if (($_POST['username'] === $config['username']) && $_POST['password'] === $config['password']) {
$_SESSION["admin"] = true;
$_SESSION["username"] = $_POST['username'];
$_SESSION["password"] = $_POST['password'];
header("Location: /admin/index.php");
die();
} else {
$error = "Feil påloggingsinformasjon.";
}
}
}
function anti_spam() {
$last_time = file_get_contents("../../anti_spam/login.txt");
$seconds = time() - $last_time;
if($seconds < 10) {
return true;
} else {
file_put_contents("../../anti_spam/login.txt", time());
return false;
}
}
?>
<?php include('../../_header.php'); ?>
<h3>Administrator Login</h3>
<form style="border: 1px solid #888; padding: 10px; border-radius: 2px;" action="" method="post">
<?php
if(isset($error)==true) {
print("<small style='color: red;'>".$error."</small><br><br>");
}
?>
<!-- hvem bryr seg om CSRF -->
<label for="username">Brukernavn:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Passord:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Bekreft">
</form>
<?php include('../../_footer.php'); ?>

4
public/admin/logout.php Executable file
View File

@@ -0,0 +1,4 @@
<?php
session_start();
session_destroy();
header("Location: /admin/login.php");

6
public/admin/redirect.php Executable file
View File

@@ -0,0 +1,6 @@
<?php
if ($_SESSION["admin"] !== true) {
header("Location: /admin/login.php");
die();
}

15
public/fetch.php Executable file
View File

@@ -0,0 +1,15 @@
<?php
$directory = "./uploads/audited";
$old_files = array_diff(scandir($directory), array('..', '.'));
$files=[];
foreach($old_files as $file) {
$files[] = $file;
}
if(empty($files)) {
die();
}
$random_index = rand(0, count($files)-1);
echo("/uploads/audited/".$files[$random_index]);

84
public/index.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
error_reporting(E_ERROR | E_PARSE);
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
if(empty($file_name)){
$errors[] = 'Vennligst velg en fil.';
}
if(empty($file_tmp)){
$errors[] = 'Feil med server oppsett. Kontakt en server administrator og prøv igjen senere.'; # Increase upload and post size in php.ini
}
$extensions= array("jpeg","jpg","png", "gif");
if(in_array($file_ext,$extensions)=== false){
$errors[] = "Filtypen er ikke tillatt. Velg en JPEG, PNG eller GIF-fil.";
}
# Check if the image is valid and not some bogus (dont know if this works yet)
if(!is_image($file_tmp)) {
$errors[] = 'Filtypen er ikke tillatt. Velg en JPEG, PNG eller GIF-fil.';
}
if($file_size > 8000000){
$errors[] = 'Filstørrelsen må ikke være større enn 8 MB.';
}
if(empty($errors)==true){
if(anti_spam()) {
$errors[] = 'AntiSpam: Vennligst vent og prøv igjen.';
} else {
move_uploaded_file($file_tmp,"./uploads/unaudited/".time().".".$file_ext);
}
}
}
function is_image($path)
{
$a = getimagesize($path);
$image_type = $a[2];
if(in_array($image_type, array(IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG)))
{
return true;
}
return false;
}
function anti_spam() {
$last_time = file_get_contents("../anti_spam/index.txt");
$seconds = time() - $last_time;
if($seconds < 10) {
return true;
} else {
file_put_contents("../anti_spam/index.txt", time());
return false;
}
}
?>
<?php include('../_header.php'); ?>
<h3>Send inn bilde som skal revideres</h3>
<form style="border: 1px solid #888; padding: 10px; border-radius: 2px;" action="" method="POST" enctype="multipart/form-data">
<?php
if(isset($errors)==true) {
if(empty($errors)==true) {
print("<small style='color: green;'>Supert! Filen din er lastet opp og vil bli vurdert snarest.</small><br><br>");
} else {
print("<small style='color: red;'>".$errors[0]."</small><br><br>");
}
}
?>
Ditt bilde: <input type="file" name="image" /> <br> <br>
<input type="submit" value="Last opp"/>
</form>
<?php include('../_footer.php'); ?>

69
public/kiosk.php Executable file
View File

@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Refresh" content="1800">
<link rel="stylesheet" href="/static/css/kiosk.css">
</head>
<body>
<!-- Advarsel! Dette er spaghetti og ikke optimalt. Men det fungerer :) -->
<!-- Slide 1 -->
<div class="mySlides">
<iframe src="https://rms.sexy" frameborder="0" style="width: 100%; height: 100%;"></iframe>
</div>
<!-- Slide 2 -->
<div class="mySlides" style="background-color: #fff; color: #000; padding: 7px;">
<img style="height: 44px;" src="/static/img/brand.png" alt="">
<div style="padding-left: 80px">
<h2 style="display: inline; position: absolute; top: -20px; font-size: 30px;">Presento</h2>
<p style="display: inline; position: absolute; top: 21px;">Extreme Professional Edition</p>
</div>
<hr style="border: 0;height: 3px;background-image: linear-gradient(to right, #fff, #208fe3, #fff);">
<div style="text-align: center; font-size: 5rem;">
<h1>Vil du se ditt bilde her?</h1>
<h3>Send inn <a style="color: #208fe3;" href="https://presento.raskest.net/">presento.raskest.net</a></h3>
</div>
</div>
<!-- Slide 3 -->
<div class="mySlides">
<img class="img" id="inspirationalQuote" src="" alt="">
</div>
<!-- User uploaded images -->
<!-- Slide 4 -->
<div class="mySlides" style="background-color: #000;">
<img class="img" id="userImage1" src="" alt="">
</div>
<!-- Slide 5
<div class="mySlides" style="background-color: #000;">
<img class="img" id="userImage2" src="" alt="">
</div>-->
<!-- Slide 6
<div class="mySlides" style="background-color: #000;">
<img class="img" id="userImage3" src="" alt="">
</div>-->
<!-- YR weather data -->
<!-- Slide 5 -->
<div class="mySlides">
<video id="slide5Vid" src="https://www.yr.no/satellitt/data/europe.webm" loop=1 style="width: 100%; height: 100%;">
<source src="https://www.yr.no/satellitt/data/europe.webm" type="video/webm">
<source src="https://www.yr.no/satellitt/data/europe.mp4" type="video/mp4">
</video>
</div>
<script src="/static/js/kiosk.js"></script>
</body>
</html>

27
public/static/css/kiosk.css Executable file
View File

@@ -0,0 +1,27 @@
body {
background-color: #000;
color: #fafafa;
font-family: Arial, Helvetica, sans-serif;
}
.mySlides {
width: 100%;
height: 100%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.img {
margin: auto;
position: absolute;
object-fit: contain;
width:100%;
height:100%;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/* Disable scrolling */
html, body {margin: 0; height: 100%; overflow: hidden}

52
public/static/css/style.css Executable file
View File

@@ -0,0 +1,52 @@
html {
background-color: #fff;
background-image: url(../img/wallpaper.jpg);
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
display: block;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: #222;
background: #fff;
max-width: 600px;
margin: 0 auto;
padding: 12px;
padding-top: 7px;
box-shadow: 0 0 4px #222;
}
@media screen and (max-width: 622px) {
body {
padding: 7px;
box-shadow: 0 0 0;
}
html {
background-image: none;
}
}
a {
color: #208fe3;
text-decoration: none;
}
a:hover {
color: #689dff;
}
h1, h2, h3, h4, h5, h6 {
line-height: 1.2;
}
li {
line-height: 1.5;
}
hr {
border: 0;
height: 3px;
background-image: linear-gradient(to right, #fff, #208fe3, #fff);
}
.animate-top{
position:relative;animation:animatetop 0.4s}@keyframes animatetop{from{top:-300px;opacity:0} to{top:0;opacity:1}
}

BIN
public/static/img/brand.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
public/static/img/wallpaper.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

63
public/static/js/kiosk.js Executable file
View File

@@ -0,0 +1,63 @@
// A number for each slide
var slideFuncs = {
1: function () {
// Prepare slide 3
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("inspirationalQuote").src = this.responseText;
}
};
xhttp.open("GET", "https://inspirobot.me/api?generate=true", true);
xhttp.send();
// Then prepare slide 4
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("userImage1").src = this.responseText;
}
};
xhttp.open("GET", "/fetch.php", true);
xhttp.send();
},
5: function () {
// Play video
var video = document.getElementById("slide5Vid");
video.pause();
video.currentTime = 0;
video.load();
video.play();
},
};
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
setInterval(() => {
plusSlides(1)
}, 22000);
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
console.log("Slide " + slideIndex);
try {
slideFuncs[slideIndex]();
}
catch(err) {
console.log("Nothing to do for this slide: " + err)
}
}