Skip to content

Commit

Permalink
fix configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zavy86 committed May 4, 2023
1 parent 37ef239 commit 6bb11d3
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 101 deletions.
12 changes: 6 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.git/
.idea/
documents/*
trash/*
.gitignore
.htaccess
development.dockerfile
production.dockerfile
config.inc.php
robots.txt
sitemap.xml
datasets/config.inc.php
datasets/documents/*
datasets/trash/*
!datasets/documents/.gitkeep
!datasets/trash/.gitkeep
!index.php
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
.htaccess
config.inc.php
robots.txt
sitemap.xml


datasets/config.inc.php
datasets/documents/*
datasets/trash/*

!datasets/documents/.gitkeep
!datasets/trash/.gitkeep




!index.php
!index.php
32 changes: 0 additions & 32 deletions datasets/config.sample.inc.php

This file was deleted.

32 changes: 32 additions & 0 deletions datasets/sample.config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Configuration
*
* @package WikiDocs
* @repository https://github.com/Zavy86/WikiDocs
*/

// Enable debug
define('DEBUGGABLE',false);
// Virtualhost path or subdirectory with trailing slashes
define('PATH',"/");
// Application title
define('TITLE',"Wiki|Docs");
// Application subtitle
define('SUBTITLE',"flat-file markdown wiki engine");
// Contents owner
define('OWNER',"Owner");
// Contents credits notice
define('NOTICE',"Credits");
// Privacy banner for GDPR-compliant
define('PRIVACY',null);
// MD5 encoded password for editing (default',password)
define('EDITCODE',"5f4dcc3b5aa765d61d8327deb882cf99");
// MD5 encoded password for reading (set null for public wiki)
define('VIEWCODE',null);
// Main theme color
define('COLOR',"#4CAF50");
// Dark mode
define('DARK',false);
// Google Analytics Tag
define('GTAG',null);
2 changes: 0 additions & 2 deletions docker/development.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ RUN apk add --no-cache $DEPENDENCIES

# configure httpd
RUN sed -ri \
# -e 's!^DocumentRoot "/var/www/localhost/htdocs"$!DocumentRoot "/var/www/localhost/htdocs/public"!g' \
# -e 's!^<Directory "/var/www/localhost/htdocs">$!<Directory "/var/www/localhost/htdocs/public">!g' \
-e 's!^#(LoadModule rewrite_module .*)$!\1!g' \
-e 's!^(\s*AllowOverride) None.*$!\1 All!g' \
"/etc/apache2/httpd.conf"
Expand Down
48 changes: 21 additions & 27 deletions docker/production.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#
# Wiki|Docs Production Build
#
# Build command:
# docker build --no-cache -t zavy86/wikidocs .
# Build:
# docker build --no-cache -f docker/production.dockerfile -t zavy86/wikidocs .
#
# Build multi-architecture
# Run:
# docker run --name wikidocs -d -p 80:80 -v wikidocs-datasets:/datasets zavy86/wikidocs
#
# Build multi-architecture and push
# docker buildx create --name builder --driver docker-container --use
# docker buildx inspect --bootstrap
# docker buildx build --platform linux/amd64,linux/arm64 --no-cache --push -t zavy86/wikidocs .
Expand All @@ -25,29 +28,19 @@ shadow \
# installation
RUN apk add --no-cache $DEPENDENCIES

# enable rewrite module and allow .htaccess overrides
RUN sed -i "s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/" /etc/apache2/httpd.conf && \
printf "\n<Directory \"/var/www/localhost/htdocs\">\n\tAllowOverride All\n</Directory>\n" >> /etc/apache2/httpd.conf && \
rm -f /var/www/localhost/htdocs/index.html
# configure apache
RUN sed -ri \
-e 's!^#(LoadModule rewrite_module .*)$!\1!g' \
-e 's!^(\s*AllowOverride) None.*$!\1 All!g' \
"/etc/apache2/httpd.conf"
RUN echo "ServerName localhost" >> /etc/apache2/httpd.conf

# download and extract wikidocs archive
RUN curl -Lso wikidocs.tar.gz https://github.com/Zavy86/WikiDocs/archive/master.tar.gz && \
tar --strip-components=1 -xf wikidocs.tar.gz -C /var/www/localhost/htdocs/ && \
rm wikidocs.tar.gz && \
cd /var/www/localhost/htdocs && \
sed -i "s/config\.inc\.php/config\/config.inc.php/" setup.php update.php functions.inc.php && \
mkdir config && \
ln -s /var/www/localhost/htdocs/config / && \
ln -s /var/www/localhost/htdocs/documents /
# copy application files
COPY . /var/www/localhost/htdocs/

# pre-populate the .htaccess file so if we supply a config.inc.php, everything still works
RUN echo -e \
'<IfModule mod_rewrite.c>\n'\
'RewriteEngine On\n'\
'RewriteBase /\n'\
'RewriteCond %{REQUEST_FILENAME} !-f\n'\
'RewriteRule ^(.*)$ index.php?doc=$1 [NC,L,QSA]\n'\
'</IfModule>' >/var/www/localhost/htdocs/.htaccess
# copy configuration and htacess files from samples
COPY ./datasets/sample.config.inc.php /var/www/localhost/htdocs/datasets/config.inc.php
COPY ./sample.htaccess /var/www/localhost/htdocs/.htaccess

# start script to override apache user's uid/gid
RUN echo -e \
Expand All @@ -59,8 +52,9 @@ RUN echo -e \
RUN chmod +x /start.sh

WORKDIR /var/www/localhost/htdocs
EXPOSE 80
VOLUME /documents
VOLUME /config

VOLUME /datasets

ENTRYPOINT ["/start.sh"]

EXPOSE 80
6 changes: 6 additions & 0 deletions sample.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?doc=$1 [NC,L,QSA]
</IfModule>
24 changes: 12 additions & 12 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
$VIEWCODE=($_POST['viewcode']===VIEWCODE?VIEWCODE:(strlen($_POST['viewcode'])?md5($_POST['viewcode']):null));
// build configuration file
$config="<?php\n";
$config.="const DEBUGGABLE=".(DEBUGGABLE?"true":"false").";\n";
$config.="const PATH=\"".PATH."\";\n";
$config.="const TITLE=\"".$_POST['title']."\";\n";
$config.="const SUBTITLE=\"".$_POST['subtitle']."\";\n";
$config.="const OWNER=\"".$_POST['owner']."\";\n";
$config.="const NOTICE=".($_POST['notice']?"\"".$_POST['notice']."\"":"null").";\n";
$config.="const PRIVACY=".($_POST['privacy']?"\"".$_POST['privacy']."\"":"null").";\n";
$config.="const EDITCODE=\"".$EDITCODE."\";\n";
$config.="const VIEWCODE=".($VIEWCODE?"\"".$VIEWCODE."\"":"null").";\n";
$config.="const COLOR=\"".$_POST['color']."\";\n";
$config.="const DARK=".(isset($_POST['dark'])?"true":"false").";\n";
$config.="const GTAG=".($_POST['gtag']?"\"".$_POST['gtag']."\"":"null").";\n";
$config.="define('DEBUGGABLE',".(DEBUGGABLE?"true":"false").");\n";
$config.="define('PATH',\"".PATH."\");\n";
$config.="define('TITLE',\"".$_POST['title']."\");\n";
$config.="define('SUBTITLE',\"".$_POST['subtitle']."\");\n";
$config.="define('OWNER',\"".$_POST['owner']."\");\n";
$config.="define('NOTICE',".($_POST['notice']?"\"".$_POST['notice']."\"":"null").");\n";
$config.="define('PRIVACY',".($_POST['privacy']?"\"".$_POST['privacy']."\"":"null").");\n";
$config.="define('EDITCODE',\"".$EDITCODE."\");\n";
$config.="define('VIEWCODE',".($VIEWCODE?"\"".$VIEWCODE."\"":"null").");\n";
$config.="define('COLOR',\"".$_POST['color']."\");\n";
$config.="define('DARK',".(isset($_POST['dark'])?"true":"false").");\n";
$config.="define('GTAG',".($_POST['gtag']?"\"".$_POST['gtag']."\"":"null").");\n";
// write configuration file
file_put_contents(BASE."datasets/config.inc.php",$config);
// alert and redirect
Expand Down
26 changes: 13 additions & 13 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$g_act=($_GET['act'] ?? '');
if(!$g_act){$g_act="setup";}
// include configuration sample
include("datasets/config.sample.inc.php");
include("datasets/sample.config.inc.php");
// defines constants
define('PATH_URI',explode("setup.php",$_SERVER['REQUEST_URI'])[0]);
// die if configuration already exist
Expand All @@ -45,18 +45,18 @@
if($g_act=="conclude"){
// build configuration file
$config="<?php\n";
$config.="const DEBUGGABLE=false;\n";
$config.="const PATH=\"".$_SESSION['wikidocs']['setup']['path']."\";\n";
$config.="const TITLE=\"".$_SESSION['wikidocs']['setup']['title']."\";\n";
$config.="const SUBTITLE=\"".$_SESSION['wikidocs']['setup']['subtitle']."\";\n";
$config.="const OWNER=\"".$_SESSION['wikidocs']['setup']['owner']."\";\n";
$config.="const NOTICE=\"".$_SESSION['wikidocs']['setup']['notice']."\";\n";
$config.="const PRIVACY=null;\n";
$config.="const EDITCODE=\"".md5($_SESSION['wikidocs']['setup']['editcode'])."\";\n";
$config.="const VIEWCODE=null;\n";
$config.="const COLOR=\"#4CAF50\";\n";
$config.="const DARK=false;\n";
$config.="const GTAG=null;\n";
$config.="define('DEBUGGABLE',false);\n";
$config.="define('PATH',\"".$_SESSION['wikidocs']['setup']['path']."\");\n";
$config.="define('TITLE',\"".$_SESSION['wikidocs']['setup']['title']."\");\n";
$config.="define('SUBTITLE',\"".$_SESSION['wikidocs']['setup']['subtitle']."\");\n";
$config.="define('OWNER',\"".$_SESSION['wikidocs']['setup']['owner']."\");\n";
$config.="define('NOTICE',\"".$_SESSION['wikidocs']['setup']['notice']."\");\n";
$config.="define('PRIVACY',null);\n";
$config.="define('EDITCODE',\"".md5($_SESSION['wikidocs']['setup']['editcode'])."\");\n";
$config.="define('VIEWCODE',null);\n";
$config.="define('COLOR',\"#4CAF50\");\n";
$config.="define('DARK',false);\n";
$config.="define('GTAG',null);\n";
// write configuration file
file_put_contents($root_dir."datasets/config.inc.php",$config);
// build htacess file
Expand Down

0 comments on commit 6bb11d3

Please sign in to comment.