Skip to content

Basic fixes, code cleanup, backports #20

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

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2a236b0
Create SECURITY.md
Nephiaust Sep 3, 2023
a0c989a
Create psalm.yml
Nephiaust Sep 3, 2023
531359a
Update psalm.yml
Nephiaust Sep 3, 2023
9fc8263
Update psalm.yml
Nephiaust Sep 3, 2023
4bea39d
Disabled composer requirements
Nephiaust Sep 3, 2023
11d79c3
Reset of palm...
Nephiaust Sep 3, 2023
5cff19d
Update psalm.yml
Nephiaust Sep 3, 2023
5abfc62
Create composer.json
Nephiaust Sep 3, 2023
2f7fccd
Update composer.json
Nephiaust Sep 3, 2023
3fa8ddb
Updated to Upload-sarif@v2
Nephiaust Sep 3, 2023
9224ce9
Added permissions to code scan
Nephiaust Sep 3, 2023
6ba29ed
Back ported code from donejeh
Nephiaust Sep 3, 2023
96558a7
Fixed formatting via Intelephense
Nephiaust Sep 3, 2023
4cf146f
Back ported ytyeoh's fix for full width
Nephiaust Sep 3, 2023
96f9197
Added Apple Mac & VScode ignore list
Nephiaust Sep 3, 2023
e8f251d
Updated Trumbowyg to 2.27.3
Nephiaust Sep 3, 2023
0446201
Updated style to use img 100%
Nephiaust Sep 3, 2023
d3d4337
Fixed missing quotation mark.
Nephiaust Sep 3, 2023
fdac356
Added license file
Nephiaust Sep 3, 2023
eeb89b9
Moved DB config to config.php
Nephiaust Sep 3, 2023
e2ef2a5
Updated to ignore pull request (dont know if bad)
Nephiaust Sep 3, 2023
c06a1f5
Formatting.
Nephiaust Sep 3, 2023
faaf9a8
Fix security issue #5
Nephiaust Sep 3, 2023
2fa666b
Fix security issue #3
Nephiaust Sep 3, 2023
8214f2b
Updated checkout to v3
Nephiaust Sep 3, 2023
1c0f0af
Fix security issues #6 & #7
Nephiaust Sep 3, 2023
a7732e2
File cleanup.
Nephiaust Sep 3, 2023
5ad085f
Fixed missing semicolons
Nephiaust Sep 3, 2023
c4b0ab0
fix references for functions.
Nephiaust Sep 3, 2023
bbfad65
Updated config to explain site_root better
Nephiaust Sep 6, 2023
296e96b
Added a debug mode, so errors can be seen.
Nephiaust Sep 6, 2023
4bda513
Fixed up debug mode options.
Nephiaust Sep 6, 2023
ca554b3
Changed login to detect for
Nephiaust Sep 6, 2023
842dead
Changed 'admin' table to 'users' table
Nephiaust Sep 6, 2023
04dd538
Fixed bug with SQL statement
Nephiaust Sep 6, 2023
ea1c8fc
Created install.php, file is tmp storage for setup
Nephiaust Sep 6, 2023
b16d57b
Moved SQL for creating slug column to install.php
Nephiaust Sep 6, 2023
23cd5b4
Added category table to the database.
Nephiaust Sep 6, 2023
850add3
Moved the redirect to index page, if logging out
Nephiaust Sep 6, 2023
a10927d
Removed generate_slugs.php isnt required any more.
Nephiaust Sep 6, 2023
fcdb736
removed config.yml as its not required for script.
Nephiaust Sep 6, 2023
6fbeb53
Updated logic for debug_mode to use true/false
Nephiaust Sep 6, 2023
da815a4
fixed sub list
Nephiaust Sep 6, 2023
8face65
Fix horizontal rules
Nephiaust Sep 6, 2023
e967e1e
Minor grammar and note updates.
Nephiaust Sep 6, 2023
777566d
Fixed note formatting
Nephiaust Sep 6, 2023
b75f989
formatting
Nephiaust Sep 6, 2023
cd856a2
Fixed issue with post deletion.
Nephiaust Sep 6, 2023
d3aa618
Create FUNDING.yml
Nephiaust Sep 8, 2023
8817e78
Update FUNDING.yml
Nephiaust Sep 8, 2023
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
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: ['Nephiaust']
35 changes: 35 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Psalm Static analysis

on: [push, pull_request]

jobs:
psalm:
name: Psalm
permissions:
actions: read
checks: read
contents: read
deployments: none
id-token: none
issues: write
discussions: read
packages: read
pages: none
pull-requests: write
repository-projects: read
security-events: write
statuses: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Psalm
uses: docker://ghcr.io/psalm/psalm-github-actions:5.7.7
with:
security_analysis: true
report_file: results.sarif
- name: Upload Security Analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
.idea
/uploads/*

# General Apple files
.DS_Store
.AppleDouble
.LSOverride

# Apple Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Visual Studio code coverage results
*.coverage
*.coveragexml

# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
}
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//TODO
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
# Simple-PHP-Blog
Simple blog system for personal development using procedural PHP and MYSQL.
Simple blog system for personal development using procedural PHP and MySQLi. It allows you to create, edit, delete posts to get you started on your journey. If you are building your own from scratch this will give the head start that you need.

For educational purposes only.

# Setup
**__Security is not guaranteed with this system, best efforts have been made to make it secure__**

Update the `connect.php` file with your database credentials.
Import the `database.sql` file.
Setup
===

If installed on a sub-folder, edit the `config.php` and replace the empty constant with the folder's name.

The pagination results per page can be set on the `config.php` file.
1. Create a MySQL database on your MySQL server, take note of the details (username, password, database name, server name)
2. Import the `database.sql` file into the new database you created
3. Edit the `config.php` file
1. Edit the MySQL details to match your SQL server login details (e.g. server name, username, password, database)
2. Edit the `SITE_ROOT` if you are putting it in a folder/sub-directory (e.g. www.example.com/myblog/, you would enter 'myblog' there)
3. _OPTIONAL_ Change the number of blog posts to show per page with the `PAGINATION` option
4. _OPTIONAL_ Set the `DEBUG_MODE` option to `true` if you want/need to see any and all errors
4. Upload all the files to your web server
5. Go to your new site (e.g. www.example.com/myblog/)

### URL Rewrite
The latest update introduces 'slugs', also known as 'SEO URLs'.
After you update to the latest version, click on the "Generate slugs (SEO URLs)" button on the admin dashboard and slugs will be generated for all existing posts.
The system now uses **slugs**, also known as **SEO URLs**

The blog posts URL structure is like this: `http://localhost/p/4/apple-reveals-apple-watch-series-7`
The blog posts URL structure is like this: `http://www.example.com/myblog/p/4/apple-reveals-apple-watch-series-7`, where the `p/4/apple-reveals-apple-watch-series-7` is the slug

If you use Apache, enable the Apache rewrite module for the .htaccess rewrite rule to work.
#### Apache servers
There is an .htaccess file that has the required rewrite module and rule in the files.

#### Nginx servers
If you use NGINX, you can insert something similar to the code below in your NGINX configuration block.
```
location / {
rewrite ^p/(.*) view.php?id=$1;
}
```

# Default Admin Login
Using the Simple-PHP-Blog
===

The system is quite easy to use, as there isnt much work required to do a simple blog.

## Default Admin Login
Username: admin
Password: 12345

There is no way to update the admin password through the dashboard yet.
To change your password, hash your password with PHP's `password_hash()` function. Then update the database value with the new password hash.
**__There is no way to update the admin password through the dashboard yet.__**
**__To change your password, hash your password with PHP's `password_hash()` function. Then update the database value with the new password hash.__**

# Screenshots
## Screenshots

![screenshot_01](https://user-images.githubusercontent.com/16838612/66112823-78d32e00-e5c3-11e9-9b38-93ba488071e0.jpg)
![screenshot_02](https://user-images.githubusercontent.com/16838612/66112874-8d172b00-e5c3-11e9-97e4-590da5675100.jpg)
18 changes: 18 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Security Policy

## Supported Versions

Use this section to tell people about which versions of your project are
currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 4.x.x | :white_check_mark: |

## Reporting a Vulnerability

Use this section to tell people how to report a vulnerability.

Tell them where to go, how often they can expect to get an update on a
reported vulnerability, what to expect if the vulnerability is accepted or
declined, etc.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

35 changes: 20 additions & 15 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?php
require_once 'connect.php';
require_once 'header.php';
require_once 'security.php';
require_once 'functions/security.php';

# Turn on debug mode, and show all errors.
if (DEBUG_MODE == true) {
error_reporting(E_ALL);
ini_set("display_errors", 1);
}

?>
<h2 class="w3-container w3-teal w3-center">Admin Dashboard</h2>
<div class="w3-container">
<p>Welcome <?php echo $_SESSION['username']; ?>,</p>
<p><a href="new.php" class="w3-button w3-teal">Create new post</a></p>
<p><a href="generate_slugs.php" class="w3-button w3-teal">Generate slugs (SEO URLs)</a></p>
<h2 class="w3-container w3-teal w3-center">Admin Dashboard</h2>
<div class="w3-container">
<p>Welcome <?php echo $_SESSION['displayname']; ?>,</p>
<p><a href="new.php" class="w3-button w3-teal">Create new post</a></p>

</div>
<h5 class="w3-center">Posts</h5>
</div>
<h5 class="w3-center">Posts</h5>
<?php
$sql = "SELECT COUNT(*) FROM posts";
$result = mysqli_query($dbcon, $sql);
Expand All @@ -22,7 +27,7 @@
$page = 1;

if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$page = (INT)$_GET['page'];
$page = (int)$_GET['page'];
}
if ($page > $totalpages) {
$page = $totalpages;
Expand Down Expand Up @@ -54,19 +59,19 @@
$author = $row['posted_by'];
$time = $row['date'];

$permalink = "p/".$id ."/".$slug;
?>
$permalink = "p/" . $id . "/" . $slug;
?>

<tr>
<td><?php echo $id; ?></td>
<td><a href="<?php echo $permalink; ?>"><?php echo substr($title, 0, 50); ?></a></td>
<td><?php echo $time; ?></td>
<td><a href="edit.php?id=<?php echo $id; ?>">Edit</a> | <a href="del.php?id=<?php echo $id; ?>"
onclick="return confirm('Are you sure you want to delete this post?')">Delete</a>
<td><?php echo "<h3><a href='$permalink'>view post</a></h3><p>"; ?></td>
<td><a href="edit.php?id=<?php echo $id; ?>">Edit</a> | <a href="del.php?id=<?php echo $id; ?>" onclick="return confirm('Are you sure you want to delete this post?')">Delete</a>
</td>
</tr>

<?php
<?php
}
echo "</table>";

Expand Down
11 changes: 8 additions & 3 deletions cat.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php
require_once 'connect.php';
require_once 'header.php';

$id = (INT)$_GET['id'];
# Turn on debug mode, and show all errors.
if (DEBUG_MODE == true) {
error_reporting(E_ALL);
ini_set("display_errors", 1);
}

$id = (int)$_GET['id'];
if ($id < 1) {
header("location: index.php");
}
Expand Down Expand Up @@ -51,4 +56,4 @@
echo '</div>';
}

include("footer.php");
include("footer.php");
12 changes: 7 additions & 5 deletions categories.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<div class="w3-container w3-center w3-teal"><h3>Categories</div>
<div class="w3-container w3-center w3-teal">
<h3>Categories
</div>
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($dbcon, $sql);

if ($result){
if ($result) {
echo "<div class='w3-container w3-border'>";
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
$catname = $row['catname'];
$description = $row['description'];
?>
?>

<div class="w3-panel w3-border"><a href="cat.php?id=<?php echo $id; ?>"><?php echo $catname; ?></a><br>
<?php echo $description; ?>
</div>
<?php
<?php
}
echo "</div>";
}else{
} else {
echo "<div class='w3-panel w3-pale-red'>No Category found.</div>";
}
42 changes: 42 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "composer/composer",
"type": "library",
"description": "Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.",
"keywords": [
],
"authors": [
{
"name": "Philipinho (Philip)",
"homepage": "https://github.com/Philipinho",
"role": "Developer"
},
{
"name": "7s9n (Hussein Sarea)",
"homepage": "https://github.com/7s9n",
"role": "Contributor"
},
{
"name": "ankheur (Pierrick Rancoeur)",
"homepage": "https://github.com/ankheur",
"role": "Contributor"
},
{
"name": "terzinnorbert",
"homepage": "https://github.com/terzinnorbert",
"role": "Contributor"
},
{
"name": "myckgoncalves (Myck Gonçalves)",
"homepage": "https://github.com/myckgoncalves",
"role": "Contributor"
},
{
"name": "rastating",
"homepage": "https://github.com/rastating",
"role": "Contributor"
}
],
"require": {
"php": "^7.2.5 || ^8.0"
}
}
14 changes: 12 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<?php
define('SITE_ROOT', ''); // If installed on a sub-folder, replace the empty constant with the folder's name
define('PAGINATION', 10); // Pagination results per page
/* Database credentials.*/
define('DB_TYPE', 'mysql'); // NOT USED
define('DB_SERVER', 'LOCALHOST'); // Server name/IP for the mysql server
define('DB_USERNAME', 'USERNAME'); // What username to log in with
define('DB_PASSWORD', 'PASSWORD'); // What password to use when logging in
define('DB_NAME', 'MySimpleBlog'); // What is the database we are using
define('DB_CHARSET', 'utf8'); // What character set are we using

/* Define some settings for the blog */
define('SITE_ROOT', ''); // If installed on a sub-folder. E.g. if installed to 'www.example.com/blog', enter 'blog' for SITE_ROOT
define('PAGINATION', 10); // Pagination results per page
define('DEBUG_MODE', false); // Turns on all debug errors
17 changes: 0 additions & 17 deletions connect.php

This file was deleted.

Loading