feat: mode privé & ajouts icon awesome

This commit is contained in:
Nicolas Hordé 2021-01-08 18:39:28 +01:00
parent 2ae134226a
commit 74fe8b0f97
10 changed files with 119 additions and 85 deletions

View File

@ -11,4 +11,4 @@ define('ACCESS_IP', '');
define('HISTORY_FILE', 'history'); define('HISTORY_FILE', 'history');
define('MAX_HISTORY_FILES', 5); define('MAX_HISTORY_FILES', 5);
define('LANGUAGE', 'en'); define('LANGUAGE', 'en');
define('PRIVATE',false);

View File

@ -2,7 +2,7 @@
![moi](/moi.jpg?80-left)**Hordé Nicolas** ![moi](/moi.jpg?80-left)**Hordé Nicolas**
> *Passionate about computer and more particularly development. I started from a young age (17 years) in system programming. I handle about thirty programming languages among which there are many low level languages: wink:! I am also the author of MarkDoc, the Markdown-based documentation management system you are currently viewing * > *Passionate about computer and more particularly development. I started from a young age (17 years) in system programming. I handle about thirty programming languages among which there are many low level languages :wink:! I am also the author of MarkDoc, the Markdown-based documentation management system you are currently viewing *

View File

@ -10,11 +10,11 @@
4. Restricted access by ip address 4. Restricted access by ip address
5. Admin access logging 5. Admin access logging
6. Table of contents 6. Table of contents
7. Password protected area
## Planned ## Planned
1. Complete File Manager 1. Complete File Manager
2. Password protected area
3. Keeping the history of edited files and changes 3. Keeping the history of edited files and changes
4. Configuration viewer 4. Configuration viewer
5. Emoji menu in Markdown editor 5. Emoji menu in Markdown editor

View File

@ -14,7 +14,8 @@ Install Emoji data and copy Emoji data to the "emoji-data"
``` ```
wget https://github.com/iamcal/emoji-data/archive/v6.0.0.zip wget https://github.com/iamcal/emoji-data/archive/v6.0.0.zip
unzip v6.0.0.zip unzip v6.0.0.zip
mv emoji-data-v6.0.0 emoji-data mv emoji-data-6.0.0 emoji-data
rm -rf v6.0.0.zip
``` ```
## Multiples hosts ## Multiples hosts
@ -44,6 +45,7 @@ define('ACCESS_IP', '');
define('HISTORY_FILE', 'history.txt'); define('HISTORY_FILE', 'history.txt');
define('MAX_HISTORY_FILES', 5); define('MAX_HISTORY_FILES', 5);
define('LANG', 'en'); define('LANG', 'en');
define('ACCESS_PRIVATE', 'en');
``` ```
**NOTE**: **NOTE**:

View File

@ -10,6 +10,7 @@
*/ */
### Global defines ### Global defines
define('PRIVATE', true);
define('ROOT_DIR', realpath(dirname(__FILE__)) .'/'); define('ROOT_DIR', realpath(dirname(__FILE__)) .'/');
define('LIB_DIR', ROOT_DIR.'lib/'); define('LIB_DIR', ROOT_DIR.'lib/');
define('HOST_DIR',ROOT_DIR.'hosts/'.$_SERVER['SERVER_NAME'].'/'); define('HOST_DIR',ROOT_DIR.'hosts/'.$_SERVER['SERVER_NAME'].'/');
@ -48,11 +49,11 @@ if (isset($_GET['logout'])) {
} }
else if (isset($_POST['action'])) else if (isset($_POST['action']))
{ {
switch ($_POST['action']) { if ((isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true))
case 'ident': {
if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true) if ($_POST['action']=='ident')
{ {
if (isset($_POST['md_password']) && empty($_POST['md_password']) === false) if (isset($_POST['md_password']) && empty($_POST['md_password']) === false)
{ {
if (hash('sha512', $_POST['md_password']) === PASSWORD) if (hash('sha512', $_POST['md_password']) === PASSWORD)
{ {
@ -71,50 +72,64 @@ else if (isset($_POST['action']))
$log[$_SERVER['REMOTE_ADDR']]['time'] = time(); $log[$_SERVER['REMOTE_ADDR']]['time'] = time();
file_put_contents(LOG_DIR, serialize($log)); file_put_contents(LOG_DIR, serialize($log));
} }
} }
else else
$content='<h1>Aucun mot de passe renseigné !</h1>'; $content='<h1>'.$LANG['NOPASS'].'</h1>';
}
else }
$content='<h1>Vous êtes déjà logué !</h1>'; else if (ACCESS_PRIVATE)
break; switch ($_POST['action'])
case 'children': {
print(json_encode(filesJSON(CONTENT_DIR,false))); case 'allchildren':
exit; case 'children':
case 'allchildren': print('{ "id" : "id1", "icon" : "fas fa-atlas", "parent" : "#", "text" : "'.$_SERVER["SERVER_NAME"].'" }');
print(json_encode(filesJSON(CONTENT_DIR,true))); exit;
exit; default:
case 'open': $content=specialurl(":ADMIN",true);
$file=urldecode($_POST['file']); }
if (substr($file,0,1)==":") }
print(specialurl($file)); switch ($_POST['action'])
else {
print(getcontent($file)); case 'children':
exit; print(json_encode(filesJSON(CONTENT_DIR,false)));
exit;
case 'allchildren':
print(json_encode(filesJSON(CONTENT_DIR,true)));
exit;
case 'open':
$file=urldecode($_POST['file']);
if (substr($file,0,1)==":")
specialurl($file,true);
else
print(getcontent($file,true,true));
exit;
case 'realopen': case 'realopen':
$file=urldecode($_POST['file']); $file=urldecode($_POST['file']);
print(getcontent($file,false)); print(getcontent($file,false,true));
exit; exit;
case 'save': case 'save':
$file=urldecode($_POST['file']); $file=urldecode($_POST['file']);
print(setcontent($file,$_POST['data'])); print(setcontent($file,$_POST['data']));
exit; exit;
case 'search': case 'search':
$results=searchstr(CONTENT_DIR,$_POST['search']); $results=searchstr(CONTENT_DIR,$_POST['search']);
//print_r($results); $content=sprintf($LANG['FOUND'],$results['totalFiles']);
$content=sprintf($LANG['FOUND'],$results['totalFiles']); foreach($results['files'] as $key => $value)
foreach($results['files'] as $key => $value) $content.='<p class="filefound"><a href="'.$key.'">'.$key.'</a></p><p class="textfound">'.$value.'</p>';
$content.='<p class="filefound"><a href="'.$key.'">'.$key.'</a></p><p class="textfound">'.$value.'</p>'; if ($_POST['type']=="js")
if ($_POST['type']=="js") {
{ print($content);
print($content); exit;
exit; }
}
} }
} }
else if (ACCESS_PRIVATE && !isset($_SESSION['md_admin']))
{
$content=specialurl(":ADMIN",false);
}
else if (substr($file,0,1)==":") else if (substr($file,0,1)==":")
{ {
$content=specialurl($file); $content=specialurl($file,false);
} }
else if ($filedetail['extension']=="md") else if ($filedetail['extension']=="md")
{ {

View File

@ -17,7 +17,7 @@ $(function(){
plugins: [ "types" ], plugins: [ "types" ],
core: core:
{ {
strings:{ loading: LANG['LOADING'] }, strings:{ loading: LANG['LOADING'] },
check_callback: true, check_callback: true,
data : { data : {
type: "POST", type: "POST",

View File

@ -56,7 +56,7 @@ $(function(){
plugins: ["contextmenu", "dnd" ], plugins: ["contextmenu", "dnd" ],
core: core:
{ {
strings:{ loading: LANG['LOADING'] }, strings:{ loading: LANG['LOADING'] },
check_callback: true, check_callback: true,
data : { data : {
type: "POST", type: "POST",
@ -172,7 +172,7 @@ $(function(){
$("#files").on("select_node.jstree", function (e, nodes) { $("#files").on("select_node.jstree", function (e, nodes) {
file="/"+$("#files").jstree("get_path",nodes.node,"/").replace(/^.+?[/]/, ''); file="/"+$("#files").jstree("get_path",nodes.node,"/").replace(/^.+?[/]/, '');
if ($("#files").jstree("is_leaf",nodes.node)) if ($("#files").jstree("is_leaf",nodes.node))
editlink(file); openlink(file,false);
else else
alertBox(LANG['NOTCODED'],'danger'); alertBox(LANG['NOTCODED'],'danger');
}); });
@ -226,6 +226,11 @@ function alertBox(message, className) {
function openlink(dest,majtree) function openlink(dest,majtree)
{ {
if (dest.match(/.(jpg|jpeg|png|gif|webp|svg|ico)$/i))
{
imagemode(dest);
return;
}
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/index.php", url: "/index.php",
@ -316,23 +321,18 @@ function viewmode(data)
function editlink(dest) function editlink(dest)
{ {
if (dest.match(/.(jpg|jpeg|png|gif|webp|svg|ico)$/i)) $.ajax({
imagemode(dest); type: "POST",
else url: "/index.php",
{ data: { action: "realopen", file: encodeURIComponent(dest) },
$.ajax({ success: function(data){
type: "POST", editmode(data);
url: "/index.php", editfile=dest;
data: { action: "realopen", file: encodeURIComponent(dest) }, },
success: function(data){ error: function(XMLHttpRequest, textStatus, errorThrown) {
editmode(data); alertBox(LANG['AJAXERROR'], 'danger');
editfile=dest; }
}, });
error: function(XMLHttpRequest, textStatus, errorThrown) {
alertBox(LANG['AJAXERROR'], 'danger');
}
});
}
} }
function majlink(context) function majlink(context)

View File

@ -2,6 +2,7 @@
"MENU": "Menu", "MENU": "Menu",
"HOME" : "Home", "HOME" : "Home",
"GLOSSARY" : "Glossary", "GLOSSARY" : "Glossary",
"SITEMAP" : "Sitemap",
"MARKDOC" : "About MarkDoc", "MARKDOC" : "About MarkDoc",
"ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**PHP Markdown-based documentation management system, Free &amp; OpenSource :heart_eyes: for easily create your documentation website**\r\n \r\nThis website is heavily formated with markdown format !\r\n```\r\n __ __ _ _____ \r\n | \\\/ | | | | __ \\ \r\n | \\ \/ | __ _ _ __| | _| | | | ___ ___ \r\n | |\\\/| |\/ _` | '__| |\/ \/ | | |\/ _ \\ \/ __|\r\n | | | | (_| | | | <| |__| | (_) | (__ \r\n |_| |_|\\__,_|_| |_|\\_\\_____\/ \\___\/ \\___|\r\n``` \r\n\r\n![gplV3](https:\/\/www.gnu.org\/graphics\/gplv3-127x51.png) Sous licence GPLv3 [Licence](\/special\/gpl-3.0.md) - *Sources downloadables on [GitHub](https:\/\/github.com\/dahut87\/MarkDoc)*\r\n \r\nBased on Pheditor \"PHP file editor\" released under MIT license\r\n \r\n *Specials thanks to Hamid Samak*\r\n \r\n Made in 2020 by Nicolas H.\r\n \r\n---\r\n \r\nFor more informations, visit the demo website running MarkDoc engine at : [https:\/\/markdoc.palon.fr](https:\/\/markdoc.palon.fr)", "ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**PHP Markdown-based documentation management system, Free &amp; OpenSource :heart_eyes: for easily create your documentation website**\r\n \r\nThis website is heavily formated with markdown format !\r\n```\r\n __ __ _ _____ \r\n | \\\/ | | | | __ \\ \r\n | \\ \/ | __ _ _ __| | _| | | | ___ ___ \r\n | |\\\/| |\/ _` | '__| |\/ \/ | | |\/ _ \\ \/ __|\r\n | | | | (_| | | | <| |__| | (_) | (__ \r\n |_| |_|\\__,_|_| |_|\\_\\_____\/ \\___\/ \\___|\r\n``` \r\n\r\n![gplV3](https:\/\/www.gnu.org\/graphics\/gplv3-127x51.png) Sous licence GPLv3 [Licence](\/special\/gpl-3.0.md) - *Sources downloadables on [GitHub](https:\/\/github.com\/dahut87\/MarkDoc)*\r\n \r\nBased on Pheditor \"PHP file editor\" released under MIT license\r\n \r\n *Specials thanks to Hamid Samak*\r\n \r\n Made in 2020 by Nicolas H.\r\n \r\n---\r\n \r\nFor more informations, visit the demo website running MarkDoc engine at : [https:\/\/markdoc.palon.fr](https:\/\/markdoc.palon.fr)",
"ADMIN" : "Admin", "ADMIN" : "Admin",

View File

@ -2,6 +2,7 @@
"MENU": "Menu", "MENU": "Menu",
"HOME" : "Accueil", "HOME" : "Accueil",
"GLOSSARY" : "Glossaire", "GLOSSARY" : "Glossaire",
"SITEMAP" : "Plan du site",
"MARKDOC" : "A propos de MarkDoc", "MARKDOC" : "A propos de MarkDoc",
"ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**Syst\u00E8me de gestion de documents Mardown \u00E9crits en PHP, Gratuit &amp; OpenSource :heart_eyes: afin de facilement cr\u00E9er vos sites internet de documentation**\r\n \r\nCe site est lourdement format\u00E9 au format Markdown !\r\n```\r\n __ __ _ _____ \r\n | \\\/ | | | | __ \\ \r\n | \\ \/ | __ _ _ __| | _| | | | ___ ___ \r\n | |\\\/| |\/ _` | '__| |\/ \/ | | |\/ _ \\ \/ __|\r\n | | | | (_| | | | <| |__| | (_) | (__ \r\n |_| |_|\\__,_|_| |_|\\_\\_____\/ \\___\/ \\___|\r\n``` \r\n \r\n![gplV3](https:\/\/www.gnu.org\/graphics\/gplv3-127x51.png) Sous licence GPLv3 [Licence](\/special\/gpl-3.0.md) - *Sources t\u00E9l\u00E9chargeables sur [GitHub](https:\/\/github.com\/dahut87\/MarkDoc)*\r\n \r\nBas\u00E9 sur Pheditor \"PHP file editor\" sous licence MIT\r\n \r\n*Merci \u00E0 Hamid Samak*\r\n \r\nR\u00E9alis\u00E9 en 2020 par Nicolas H.\r\n \r\n---\r\n \r\nPour plus d'informations, visitez le site internet de d\u00E9monstration \u00E0 l'url suivante : [https:\/\/markdoc.palon.fr](https:\/\/markdoc.palon.fr)", "ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**Syst\u00E8me de gestion de documents Mardown \u00E9crits en PHP, Gratuit &amp; OpenSource :heart_eyes: afin de facilement cr\u00E9er vos sites internet de documentation**\r\n \r\nCe site est lourdement format\u00E9 au format Markdown !\r\n```\r\n __ __ _ _____ \r\n | \\\/ | | | | __ \\ \r\n | \\ \/ | __ _ _ __| | _| | | | ___ ___ \r\n | |\\\/| |\/ _` | '__| |\/ \/ | | |\/ _ \\ \/ __|\r\n | | | | (_| | | | <| |__| | (_) | (__ \r\n |_| |_|\\__,_|_| |_|\\_\\_____\/ \\___\/ \\___|\r\n``` \r\n \r\n![gplV3](https:\/\/www.gnu.org\/graphics\/gplv3-127x51.png) Sous licence GPLv3 [Licence](\/special\/gpl-3.0.md) - *Sources t\u00E9l\u00E9chargeables sur [GitHub](https:\/\/github.com\/dahut87\/MarkDoc)*\r\n \r\nBas\u00E9 sur Pheditor \"PHP file editor\" sous licence MIT\r\n \r\n*Merci \u00E0 Hamid Samak*\r\n \r\nR\u00E9alis\u00E9 en 2020 par Nicolas H.\r\n \r\n---\r\n \r\nPour plus d'informations, visitez le site internet de d\u00E9monstration \u00E0 l'url suivante : [https:\/\/markdoc.palon.fr](https:\/\/markdoc.palon.fr)",
"ADMIN" : "Admin", "ADMIN" : "Admin",

View File

@ -25,7 +25,7 @@ function logprotect()
$log = []; $log = [];
} }
if (isset($log[$_SERVER['REMOTE_ADDR']]) && $log[$_SERVER['REMOTE_ADDR']]['num'] > 3 && time() - $log[$_SERVER['REMOTE_ADDR']]['time'] < 86400) { if (isset($log[$_SERVER['REMOTE_ADDR']]) && $log[$_SERVER['REMOTE_ADDR']]['num'] > 3 && time() - $log[$_SERVER['REMOTE_ADDR']]['time'] < 86400) {
die($LANG['BLOCKIP']); die("<h1>".$LANG['BLOCKIP']."</h1>");
} }
foreach ($log as $key => $value) { foreach ($log as $key => $value) {
if (time() - $value['time'] > 86400) { if (time() - $value['time'] > 86400) {
@ -50,28 +50,26 @@ function redirect($address = null)
exit; exit;
} }
function specialurl($url) function specialurl($url,$quit)
{ {
global $LANG; global $LANG;
switch ($url) switch ($url)
{ {
case ':APROPOS': case ':APROPOS':
$content = $LANG['ABOUTMARKDOC'];
$extra = new ParsedownExtraplus(); $extra = new ParsedownExtraplus();
print($extra->text($content)); $content=$extra->text($LANG['ABOUTMARKDOC']);
exit; break;
case ':ADMIN': case ':ADMIN':
if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true) if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true)
$content = '<form method="post"><div style="text-align:center"><h1></h1>' . (isset($error) ? '<p style="color:#dd0000">' . $error . '</p>' : null) . '<input id="mdsimple_password" name="md_password" type="password" value="" placeholder="Password&hellip;" tabindex="1"><br><br><input type="hidden" id="action" name="action" value="ident"><input type="submit" value="'.$LANG['LOGIN'].'" tabindex="2"></div></form><script type="text/javascript">$("#md_password").focus();</script>'; $content = '<form method="post"><div style="text-align:center"><h1></h1>' . (isset($error) ? '<p style="color:#dd0000">' . $error . '</p>' : null) . '<input id="mdsimple_password" name="md_password" type="password" value="" placeholder="Password&hellip;" tabindex="1"><br><br><input type="hidden" id="action" name="action" value="ident"><input type="submit" value="'.$LANG['LOGIN'].'" tabindex="2"></div></form><script type="text/javascript">$("#md_password").focus();</script>';
else else
$content = '<h1>'.$LANG['ALREADYLOG'].'</h1>'; $content = '<h1>'.$LANG['ALREADYLOG'].'</h1>';
print($content); break;
exit;
case ':SITEMAP': case ':SITEMAP':
$content='<h1>'.$LANG['SITEMAP'].'</h1>'; $content='<h1>'.$LANG['SITEMAP'].'</h1>';
foreach(plan(CONTENT_DIR) as $file) foreach(plan(CONTENT_DIR) as $file)
$content.='<p class="fileletter"><a href="'.$file.'">'.$file.'</a></p>' ; $content.='<p class="fileletter"><a href="'.$file.'">'.$file.'</a></p>' ;
return $content; break;
case ':GLOSSAIRE': case ':GLOSSAIRE':
$content='<h1>'.$LANG['GLOSSARY'].'</h1>'; $content='<h1>'.$LANG['GLOSSARY'].'</h1>';
foreach(glossary(CONTENT_DIR) as $letter => $files) foreach(glossary(CONTENT_DIR) as $letter => $files)
@ -80,8 +78,15 @@ function specialurl($url)
foreach($files as $file) foreach($files as $file)
$content.='<p class="fileletter"><a href="'.$file.'">'.$file.'</a></p>' ; $content.='<p class="fileletter"><a href="'.$file.'">'.$file.'</a></p>' ;
} }
return $content; break;
} }
if ($quit)
{
print($content);
exit;
}
else
return $content;
} }
function plan($path){ function plan($path){
@ -218,7 +223,7 @@ function setcontent($url,$data)
return $content; return $content;
} }
function getcontent($url,$md=true) function getcontent($url,$md=true,$header=false)
{ {
global $LANG; global $LANG;
$file = CONTENT_DIR.$url; $file = CONTENT_DIR.$url;
@ -232,6 +237,7 @@ function getcontent($url,$md=true)
else else
$content='**'.$LANG['404X2'].'**'; $content='**'.$LANG['404X2'].'**';
} }
if ($header) header('Content-type: '.mime_content_type($file),true);
if ($md==true) if ($md==true)
{ {
$extra = new ParsedownExtraplus(); $extra = new ParsedownExtraplus();
@ -251,24 +257,33 @@ function filesJSON($path,$all,$first=true)
$data = array(); $data = array();
if ( $node->isDir() && !$node->isDot() ) if ( $node->isDir() && !$node->isDot() )
{ {
$data['text'] = $node->getFilename(); $data['text'] = $node->getFilename();
$data['children'] = filesJSON($path.$node->getFilename()."/",$all,false); $data['children'] = filesJSON($path.$node->getFilename()."/",$all,false);
$data['icon'] = "far fa-folder";
} }
else else
{ {
if ($all) if ($all)
$data['text'] = $node->getFilename(); {
else $data['text'] = $node->getFilename();
{ if ($node->getExtension() == VIEWABLE_FORMAT)
$file = pathinfo($node->getFilename()); $data['icon'] = "fas fa-book";
$data['text'] = $file['filename']; else if (strpos(IMAGE_EXT,$node->getExtension())>=0)
} $data['icon'] = "far fa-images";
$data['icon'] = "jstree-file"; else
$data['icon'] = "far fa-file";
}
else
{
$file = pathinfo($node->getFilename());
$data['text'] = $file['filename'];
$data['icon'] = "fas fa-book-open";
}
} }
$alldata[]=$data; $alldata[]=$data;
} }
if ($first) if ($first)
return array('text'=>$_SERVER['SERVER_NAME'],'children'=>$alldata,'state' => array('opened'=>true)); return array('icon'=>"fas fa-atlas",'text'=>$_SERVER['SERVER_NAME'],'children'=>$alldata,'state' => array('opened'=>true));
else else
return $alldata; return $alldata;
} }