Skip to content

adding installer -> finish version #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

5 changes: 5 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Empty file modified FRAMEWORK.md
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Copyright 2021 Aaron Gensetter
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 11 additions & 16 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Feautures

- Markdown Support
- User Management
- Installer
# Installation

Base OS: Ubuntu-server 20.04
Expand Down Expand Up @@ -56,25 +61,15 @@ EXIT;

``` bash
$ cd /var/www/html
$ git clone https://github.com/HATBE/PHP-MVC-Blog.git .
$ sudo mysql -u root -p blog < dump.sql
$ git clone https://github.com/HATBE/Blog.git .
$ sudo chmod 755 /var/www/html -R
$ sudo chown www-data:www-data /var/www/html
```

Changing Config

``` bash
$ nano src/config/config.php
```

``` php
define('DB_HOST', '<host>');
define('DB_USER', '<user>');
define('DB_PASSWORD', '<password>');
define('DB_NAME', '<dbname>');
```
Now, you can navigate to https://<ip/host> in your browser.

Now, you can navigate to http://<ip/host> in your browser.
Follow the instructions of the installer.

Standard credentials (from dump.sql):
Standard credentials:
Username: admin
Password: 1234
5 changes: 1 addition & 4 deletions TODO.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# TODO

Prio / description

- 100 markdown -> parsedown
- 40 Search system
- 20 Searchbar
- 5 installer
- 20 Searchbar
15 changes: 0 additions & 15 deletions config/config.php

This file was deleted.

40 changes: 40 additions & 0 deletions install/blog.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

CREATE TABLE `posts` (
`id` int(11) NOT NULL,
`user_fk` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`body` text NOT NULL,
`date` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `posts` (`id`, `user_fk`, `title`, `body`, `date`) VALUES
(1, 1, 'Hello World', 'This is the first blog post!', '2021-11-04 12:00:00');

CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, 'admin', '$2y$10$D5Xy0fbHmIz1i0Scu3mD0Oa/eKUaaW/c6Zz0eu1kqsmLM76Cfxdry');

ALTER TABLE `posts`
ADD PRIMARY KEY (`id`),
ADD KEY `posts_users` (`user_fk`);

ALTER TABLE `users`
ADD PRIMARY KEY (`id`);

ALTER TABLE `posts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

ALTER TABLE `posts`
ADD CONSTRAINT `posts_users` FOREIGN KEY (`user_fk`) REFERENCES `users` (`id`);
COMMIT;
132 changes: 132 additions & 0 deletions install/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
if(!is_writable(__DIR__ . '/../config/')) {
echo "Error! no permissions on /config!";
exit();
}
if(isset($_POST['submit'])) {
$dbhost = $_POST['dbhost'];
$dbuser = $_POST['dbuser'];
$dbpass = $_POST['dbpass'];
$dbname = $_POST['dbname'];
$url = substr($_POST['url'], -1) !== '/' ? $_POST['url'] . '/': $_POST['url'];
$keywords = $_POST['keywords'];
$description = $_POST['description'];
$title = $_POST['title'];
$slogan = $_POST['slogan'];

$config = "<?php
// database
define('DB_HOST', '".$dbhost."');
define('DB_USER', '".$dbuser."');
define('DB_PASS', '".$dbpass."');
define('DB_NAME', '".$dbname."');

// page settings
define('ROOT_PATH', '".$url."'); // domain (must end with a \"/\"!)
define('DEFAULT_KEYWORDS', '".$keywords."');
define('DESCRIPTION', '".$description."');
define('PAGE_TITLE', '".$title."');
define('PAGE_SLOGAN', '".$slogan."');

define('ITEMS_PER_PAGE', 4);";

$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if (mysqli_connect_errno()) {
echo "Connection to database failed";
exit();
}

$sql = "SHOW TABLES IN $dbname";
$result = $conn->query($sql);

if($result->num_rows !== 0) {
echo "Database is not empty, delete all tables!";
exit();
}

mysqli_select_db($conn, $dbname);

$templine = '';
$lines = file(__DIR__ . '/blog.sql');

foreach ($lines as $line) {
if (substr($line, 0, 2) == '--' || $line == '') {
continue;
}
$templine .= $line;
if (substr(trim($line), -1, 1) == ';') {
mysqli_query($conn, $templine);
$templine = '';
}

}

file_put_contents(__DIR__ . '/../config/config.php', $config);

file_put_contents(__DIR__ . '/../install/.installed', 'true');
header('Location: ' . $url);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

<title>Installation</title>
</head>
<body>

<div class="container">
<h1>Installation</h1>
<form method="post">
<span>Please Create the Database!</span>
<div class="mb-3">
<label class="form-label">DB Host*</label>
<input name="dbhost" type="text" value="localhost" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">DB User*</label>
<input name="dbuser" type="text" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">DB Password*</label>
<input name="dbpass" type="password" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">DB Name*</label>
<input name="dbname" type="text" class="form-control">
</div>
<hr>
<div class="mb-3">
<label class="form-label">Title*</label>
<input name="title" type="text" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">URL/Path*</label>
<input name="url" value="<?= $_SERVER['HTTPS'] ? 'https://' : 'http://' ?><?= $_SERVER['HTTP_HOST']?>/" type="text" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Keywords*</label>
<input name="keywords" type="text" class="form-control">
<div class="form-text">Separate with ","</div>
</div>
<div class="mb-3">
<label class="form-label">Description*</label>
<input name="description" type="text" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Slogan*</label>
<input name="slogan" type="text" class="form-control">
</div>

<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</form>
</div>

</body>
</html>
Empty file modified public/.htaccess
100644 → 100755
Empty file.
Empty file modified public/assets/css/style.css
100644 → 100755
Empty file.
Empty file modified public/index.php
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *

Disallow: /auth/
Disallow: /users/
Empty file modified src/classes/Controller.php
100644 → 100755
Empty file.
12 changes: 10 additions & 2 deletions src/classes/Core.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class Core {
private $method = 'index'; // this must exist! in /src/classes/controllers/{class}->{method}
private $params = [];

private $loggedInUser = null;

public function __construct() {
$this->init();
}

private function init() {
session_start();

$this->checkInstalled();

$this->include();
$this->getUrl();
$this->getController();
Expand Down Expand Up @@ -65,4 +66,11 @@ private function getUrl() {
$this->url = $url;
}
}

private function checkInstalled() {
if(!file_exists(__DIR__ . '/../../install/.installed')) {
require_once(__DIR__ . '/../../install/install.php');
exit();
}
}
}
Empty file modified src/classes/Database.php
100644 → 100755
Empty file.
Empty file modified src/classes/Linker.php
100644 → 100755
Empty file.
Empty file modified src/classes/Model.php
100644 → 100755
Empty file.
Empty file modified src/classes/Template.php
100644 → 100755
Empty file.
Empty file modified src/classes/controllers/AuthController.php
100644 → 100755
Empty file.
Empty file modified src/classes/controllers/PostsController.php
100644 → 100755
Empty file.
Empty file modified src/classes/controllers/UsersController.php
100644 → 100755
Empty file.
Empty file modified src/classes/lib/Parsedown.php
100644 → 100755
Empty file.
Empty file modified src/classes/models/AuthModel.php
100644 → 100755
Empty file.
Empty file modified src/classes/models/PostModel.php
100644 → 100755
Empty file.
Empty file modified src/classes/models/UserModel.php
100644 → 100755
Empty file.
Empty file modified src/templates/alert.php
100644 → 100755
Empty file.
Empty file modified src/templates/backBtn.php
100644 → 100755
Empty file.
Empty file modified src/templates/delete.php
100644 → 100755
Empty file.
Empty file modified src/templates/footer.php
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions src/templates/header.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

<title><?= PAGE_TITLE?> - <?= $title?></title>
<meta name="description" content="<?= DESCRIPTION?>">
<meta name="keywords" content="<?= DEFAULT_KEYWORDS?>">
<meta name="keywords" content="<?= DEFAULT_KEYWORDS . $tags?>">
<meta name="author" content="hatbe2113">
</head>
<body>
<header class="bg-dark mb-4 shadow text-light">
<div class="container">
<div class="text-center p-3">
<h1>
<h2>
<a href="<?= ROOT_PATH?>" class="link-light text-decoration-none">
<?= PAGE_TITLE?>
</a>
</h1>
</h2>
<h6 class="text-muted">
<?= PAGE_SLOGAN?>
</h6>
Expand Down
Empty file modified src/templates/pagination.php
100644 → 100755
Empty file.
Empty file modified src/templates/post.php
100644 → 100755
Empty file.
Empty file modified src/templates/postForm.php
100644 → 100755
Empty file.
Empty file modified src/templates/postsList.php
100644 → 100755
Empty file.
Empty file modified src/templates/userForm.php
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion src/views/auth/login.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => 'Login']);?>
<?= Template::load('header', ['title' => 'Login', 'tags' => '']);?>

<h1 class="d-none">Login</h1>

<?= Template::load('userForm', ['username' => $data['username'], 'msg' => $data['msg'], 'action' => 'Login']);?>

Expand Down
4 changes: 3 additions & 1 deletion src/views/auth/register.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => 'Register']);?>
<?= Template::load('header', ['title' => 'Register', 'tags' => '']);?>

<h1 class="d-none">Register</h1>

<?= Template::load('userForm', ['username' => $data['username'], 'msg' => $data['msg'], 'action' => 'Register']);?>

Expand Down
6 changes: 4 additions & 2 deletions src/views/posts/create.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?= Template::load('header', ['title' => 'Home']);?>
<?= Template::load('header', ['title' => 'Create Post', 'tags' => '']);?>

<h1 class="d-none">Create Post</h1>

<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
<?php Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>
<?= Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>

<?= Template::load('footer');?>
4 changes: 3 additions & 1 deletion src/views/posts/delete.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => 'Home']);?>
<?= Template::load('header', ['title' => 'Delete Post', 'tags' => '']);?>

<h1 class="d-none">Delete Post</h1>

<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
<?= Template::load('delete', ['actionName' => 'Post', 'id' => $data['id']]);?>
Expand Down
4 changes: 3 additions & 1 deletion src/views/posts/edit.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => 'Home']);?>
<?= Template::load('header', ['title' => 'Edit Post', 'tags' => '']);?>

<h1 class="d-none">Edit Post</h1>

<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
<?= Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>
Expand Down
8 changes: 5 additions & 3 deletions src/views/posts/index.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?= Template::load('header', ['title' => 'Home']);?>
<?= Template::load('header', ['title' => 'Home', 'tags' => '']);?>

<?= Template::load('postsList', ['posts' => $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?>
<?= Template::load('pagination', ['meta' => $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?>
<h1 class="d-none">Home</h1>

<?= Template::load('postsList', ['posts' => $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?>
<?= Template::load('pagination', ['meta' => $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?>

<?= Template::load('footer');?>
4 changes: 3 additions & 1 deletion src/views/posts/post.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => $data['post'] != null ? $data['post']->title : 'post not found']);?>
<?= Template::load('header', ['title' => $data['post'] != null ? $data['post']->title : 'post not found', 'tags' => '']);?>

<h1 class="d-none"><?=$data['post'] != null ? $data['post']->title : 'post not found'?></h1>

<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => $data['page']])?>
<?php if($data['post'] !== null):?>
Expand Down
4 changes: 3 additions & 1 deletion src/views/users/delete.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?= Template::load('header', ['title' => 'Home']);?>
<?= Template::load('header', ['title' => 'Delete User', 'tags' => '']);?>

<h1 class="d-none">Delete User</h1>

<?= Template::load('backBtn', ['controller' => 'users', 'method' => 'index', 'args' => ''])?>
<?= Template::load('delete', ['actionName' => 'User', 'id' => $data['id']]);?>
Expand Down
Loading