Skip to content

Commit

Permalink
feat: updated and added imageboard challenge (pathwar#214)
Browse files Browse the repository at this point in the history
feat: updated and added imageboard challenge
  • Loading branch information
moul authored Oct 21, 2019
2 parents 7e279b3 + 511a325 commit 5b6de4b
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 0 deletions.
14 changes: 14 additions & 0 deletions challenges/web/imageboard/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:
front:
build: front
ports:
- 80
depends_on:
- mysql

mysql:
build: mysql
expose:
- 3306
4 changes: 4 additions & 0 deletions challenges/web/imageboard/front/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM php:7.3-apache
RUN docker-php-ext-install mysqli
COPY www/ /var/www/html/
COPY on-init /pathwar-hooks/
3 changes: 3 additions & 0 deletions challenges/web/imageboard/front/on-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sed -i "s/__PASSPHRASE__/$(pwctl passphrase 0)" /var/www/html/admin.php
3 changes: 3 additions & 0 deletions challenges/web/imageboard/front/www/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
//The passphrase is __PASSPHRASE__
?>
6 changes: 6 additions & 0 deletions challenges/web/imageboard/front/www/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
$mysqli = new mysqli('mysql:3306', 'imageboard', 'imageboard', 'imageboard');

if (mysqli_connect_errno()) {
die(mysqli_connect_error());
}
7 changes: 7 additions & 0 deletions challenges/web/imageboard/front/www/get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
if (isset($_GET['file'])) {
header('Content-Type: image/jpeg');
header("Content-Transfer-Encoding: binary");
readfile('/var/www/html/images/'.$_GET['file']);
}
?>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions challenges/web/imageboard/front/www/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en" style="background: black">
<head>
<title>1337Chan</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
</head>
<center><p>Welcome to my new image board ! It is not finished yet, but you can already see what it will look like !</p></center>
<center><p>For can, only the admin can upload pictures, but you will soon be able to do the same !</p></center>

<?php
include('db.php');
//<a href="/admin.php">Admin<a/> //admin not finished yet
$query='SELECT * from posts LIMIT 10;';
$res = $mysqli->query($query) or die($mysqli->error);
while ($row=mysqli_fetch_assoc($res)) {
echo '<div class="post">';
echo '<span class="info">Post '.$row['id'].' | Author : '.$row['author'].'</span>';
$query='SELECT * FROM images where id='.$row['image_id'].';';
$res2=$mysqli->query($query) or die($mysqli->error);
echo '<img style="float: left;" src="get.php?file='.mysqli_fetch_assoc($res2)['path'].'">';
$query='SELECT * FROM comments where post_id='.$row['id'].';';
$res2=$mysqli->query($query) or die($mysqli->error);
while ($row2=mysqli_fetch_assoc($res2)) {
echo '<span class="comment" style="float: left; margin-top: 10px; margin-left: 10px;">';
echo '<blockquote>'.htmlentities($row2['content']).'</blockquote>';
echo '</span><br /><br /><br /><br /><br />';
}
echo '</div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
}
?>
</html>
6 changes: 6 additions & 0 deletions challenges/web/imageboard/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mysql:5.7
COPY bootstrap.sql /docker-entrypoint-initdb.d/
ENV MYSQL_DATABASE=imageboard \
MYSQL_USER=imageboard \
MYSQL_PASSWORD=imageboard \
MYSQL_RANDOM_ROOT_PASSWORD=yes
13 changes: 13 additions & 0 deletions challenges/web/imageboard/mysql/bootstrap.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DROP DATABASE IF EXISTS imageboard;
CREATE DATABASE imageboard;
GRANT ALL PRIVILEGES ON imageboard.* to 'imageboard'@'%';
USE imageboard;
CREATE TABLE posts (id INTEGER AUTO_INCREMENT PRIMARY KEY, image_id INTEGER, author TEXT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE comments (id INTEGER AUTO_INCREMENT PRIMARY KEY, content TEXT, post_id INTEGER);
CREATE TABLE images (id INTEGER AUTO_INCREMENT PRIMARY KEY, path TEXT);
INSERT INTO posts (image_id, author) VALUES (1, 'admin');
INSERT INTO posts (image_id, author) VALUES (1, 'admin');
INSERT INTO comments (content, post_id) VALUES ('Test comment, please ignore', 1);
INSERT INTO comments (content, post_id) VALUES ('lakdsfj;la;sdkjf<sc>', 1);
INSERT INTO comments (content, post_id) VALUES ('ffufufufufufuf', 2);
INSERT INTO images (path) VALUES ('test.jpg');

0 comments on commit 5b6de4b

Please sign in to comment.