From 74fe8b0f9734633290d4b0006173bfb1997a3121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Fri, 8 Jan 2021 18:39:28 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20mode=20priv=C3=A9=20&=20ajouts=20icon?= =?UTF-8?q?=20awesome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hosts/localhost/config.php | 2 +- hosts/localhost/content/about.md | 2 +- hosts/localhost/content/features.md | 2 +- hosts/localhost/content/usage.md | 4 +- index.php | 91 +++++++++++++++++------------ js/functions.js | 2 +- js/functionsadmin.js | 38 ++++++------ lang/en.json | 1 + lang/fr.json | 1 + lib/functions.php | 61 +++++++++++-------- 10 files changed, 119 insertions(+), 85 deletions(-) diff --git a/hosts/localhost/config.php b/hosts/localhost/config.php index a9159fd..a092b58 100644 --- a/hosts/localhost/config.php +++ b/hosts/localhost/config.php @@ -11,4 +11,4 @@ define('ACCESS_IP', ''); define('HISTORY_FILE', 'history'); define('MAX_HISTORY_FILES', 5); define('LANGUAGE', 'en'); - \ No newline at end of file +define('PRIVATE',false); \ No newline at end of file diff --git a/hosts/localhost/content/about.md b/hosts/localhost/content/about.md index f3d7238..f44cc6f 100644 --- a/hosts/localhost/content/about.md +++ b/hosts/localhost/content/about.md @@ -2,7 +2,7 @@ ![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 * diff --git a/hosts/localhost/content/features.md b/hosts/localhost/content/features.md index 5b18729..bbdf75d 100644 --- a/hosts/localhost/content/features.md +++ b/hosts/localhost/content/features.md @@ -10,11 +10,11 @@ 4. Restricted access by ip address 5. Admin access logging 6. Table of contents +7. Password protected area ## Planned 1. Complete File Manager -2. Password protected area 3. Keeping the history of edited files and changes 4. Configuration viewer 5. Emoji menu in Markdown editor diff --git a/hosts/localhost/content/usage.md b/hosts/localhost/content/usage.md index 419444e..0ba9fb3 100644 --- a/hosts/localhost/content/usage.md +++ b/hosts/localhost/content/usage.md @@ -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 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 @@ -44,6 +45,7 @@ define('ACCESS_IP', ''); define('HISTORY_FILE', 'history.txt'); define('MAX_HISTORY_FILES', 5); define('LANG', 'en'); +define('ACCESS_PRIVATE', 'en'); ``` **NOTE**: diff --git a/index.php b/index.php index 4808951..07aa690 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,7 @@ */ ### Global defines +define('PRIVATE', true); define('ROOT_DIR', realpath(dirname(__FILE__)) .'/'); define('LIB_DIR', ROOT_DIR.'lib/'); define('HOST_DIR',ROOT_DIR.'hosts/'.$_SERVER['SERVER_NAME'].'/'); @@ -48,11 +49,11 @@ if (isset($_GET['logout'])) { } else if (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'ident': - if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true) + 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) { @@ -71,50 +72,64 @@ else if (isset($_POST['action'])) $log[$_SERVER['REMOTE_ADDR']]['time'] = time(); file_put_contents(LOG_DIR, serialize($log)); } - } + } else - $content='

Aucun mot de passe renseigné !

'; - } - else - $content='

Vous êtes déjà logué !

'; - break; - case 'children': - 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)==":") - print(specialurl($file)); - else - print(getcontent($file)); - exit; + $content='

'.$LANG['NOPASS'].'

'; + + } + else if (ACCESS_PRIVATE) + switch ($_POST['action']) + { + case 'allchildren': + case 'children': + print('{ "id" : "id1", "icon" : "fas fa-atlas", "parent" : "#", "text" : "'.$_SERVER["SERVER_NAME"].'" }'); + exit; + default: + $content=specialurl(":ADMIN",true); + } + } + switch ($_POST['action']) + { + case 'children': + 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': - $file=urldecode($_POST['file']); - print(getcontent($file,false)); + $file=urldecode($_POST['file']); + print(getcontent($file,false,true)); exit; case 'save': - $file=urldecode($_POST['file']); - print(setcontent($file,$_POST['data'])); + $file=urldecode($_POST['file']); + print(setcontent($file,$_POST['data'])); exit; case 'search': - $results=searchstr(CONTENT_DIR,$_POST['search']); - //print_r($results); - $content=sprintf($LANG['FOUND'],$results['totalFiles']); - foreach($results['files'] as $key => $value) - $content.='

'.$key.'

'.$value.'

'; - if ($_POST['type']=="js") - { - print($content); - exit; - } + $results=searchstr(CONTENT_DIR,$_POST['search']); + $content=sprintf($LANG['FOUND'],$results['totalFiles']); + foreach($results['files'] as $key => $value) + $content.='

'.$key.'

'.$value.'

'; + if ($_POST['type']=="js") + { + print($content); + exit; + } } } +else if (ACCESS_PRIVATE && !isset($_SESSION['md_admin'])) +{ + $content=specialurl(":ADMIN",false); +} else if (substr($file,0,1)==":") { - $content=specialurl($file); + $content=specialurl($file,false); } else if ($filedetail['extension']=="md") { diff --git a/js/functions.js b/js/functions.js index 56ae9cf..b7254c0 100644 --- a/js/functions.js +++ b/js/functions.js @@ -17,7 +17,7 @@ $(function(){ plugins: [ "types" ], core: { - strings:{ loading: LANG['LOADING'] }, + strings:{ loading: LANG['LOADING'] }, check_callback: true, data : { type: "POST", diff --git a/js/functionsadmin.js b/js/functionsadmin.js index 5fd840c..676b2d1 100644 --- a/js/functionsadmin.js +++ b/js/functionsadmin.js @@ -56,7 +56,7 @@ $(function(){ plugins: ["contextmenu", "dnd" ], core: { - strings:{ loading: LANG['LOADING'] }, + strings:{ loading: LANG['LOADING'] }, check_callback: true, data : { type: "POST", @@ -172,7 +172,7 @@ $(function(){ $("#files").on("select_node.jstree", function (e, nodes) { file="/"+$("#files").jstree("get_path",nodes.node,"/").replace(/^.+?[/]/, ''); if ($("#files").jstree("is_leaf",nodes.node)) - editlink(file); + openlink(file,false); else alertBox(LANG['NOTCODED'],'danger'); }); @@ -226,6 +226,11 @@ function alertBox(message, className) { function openlink(dest,majtree) { + if (dest.match(/.(jpg|jpeg|png|gif|webp|svg|ico)$/i)) + { + imagemode(dest); + return; + } $.ajax({ type: "POST", url: "/index.php", @@ -316,23 +321,18 @@ function viewmode(data) function editlink(dest) { - if (dest.match(/.(jpg|jpeg|png|gif|webp|svg|ico)$/i)) - imagemode(dest); - else - { - $.ajax({ - type: "POST", - url: "/index.php", - data: { action: "realopen", file: encodeURIComponent(dest) }, - success: function(data){ - editmode(data); - editfile=dest; - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - alertBox(LANG['AJAXERROR'], 'danger'); - } - }); - } + $.ajax({ + type: "POST", + url: "/index.php", + data: { action: "realopen", file: encodeURIComponent(dest) }, + success: function(data){ + editmode(data); + editfile=dest; + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + alertBox(LANG['AJAXERROR'], 'danger'); + } + }); } function majlink(context) diff --git a/lang/en.json b/lang/en.json index 32ddffc..5196dfb 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2,6 +2,7 @@ "MENU": "Menu", "HOME" : "Home", "GLOSSARY" : "Glossary", + "SITEMAP" : "Sitemap", "MARKDOC" : "About MarkDoc", "ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**PHP Markdown-based documentation management system, Free & 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", diff --git a/lang/fr.json b/lang/fr.json index 969b7df..c9de554 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -2,6 +2,7 @@ "MENU": "Menu", "HOME" : "Accueil", "GLOSSARY" : "Glossaire", + "SITEMAP" : "Plan du site", "MARKDOC" : "A propos de MarkDoc", "ABOUTMARKDOC" : "# MarkDoc\r\n\r\n**Syst\u00E8me de gestion de documents Mardown \u00E9crits en PHP, Gratuit & 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", diff --git a/lib/functions.php b/lib/functions.php index ad2b3f4..4fba651 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -25,7 +25,7 @@ function logprotect() $log = []; } if (isset($log[$_SERVER['REMOTE_ADDR']]) && $log[$_SERVER['REMOTE_ADDR']]['num'] > 3 && time() - $log[$_SERVER['REMOTE_ADDR']]['time'] < 86400) { - die($LANG['BLOCKIP']); + die("

".$LANG['BLOCKIP']."

"); } foreach ($log as $key => $value) { if (time() - $value['time'] > 86400) { @@ -50,28 +50,26 @@ function redirect($address = null) exit; } -function specialurl($url) +function specialurl($url,$quit) { global $LANG; switch ($url) { case ':APROPOS': - $content = $LANG['ABOUTMARKDOC']; $extra = new ParsedownExtraplus(); - print($extra->text($content)); - exit; + $content=$extra->text($LANG['ABOUTMARKDOC']); + break; case ':ADMIN': if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true) $content = '

' . (isset($error) ? '

' . $error . '

' : null) . '

'; else - $content = '

'.$LANG['ALREADYLOG'].'

'; - print($content); - exit; + $content = '

'.$LANG['ALREADYLOG'].'

'; + break; case ':SITEMAP': $content='

'.$LANG['SITEMAP'].'

'; foreach(plan(CONTENT_DIR) as $file) $content.='

'.$file.'

' ; - return $content; + break; case ':GLOSSAIRE': $content='

'.$LANG['GLOSSARY'].'

'; foreach(glossary(CONTENT_DIR) as $letter => $files) @@ -80,8 +78,15 @@ function specialurl($url) foreach($files as $file) $content.='

'.$file.'

' ; } - return $content; - } + break; + } + if ($quit) + { + print($content); + exit; + } + else + return $content; } function plan($path){ @@ -218,7 +223,7 @@ function setcontent($url,$data) return $content; } -function getcontent($url,$md=true) +function getcontent($url,$md=true,$header=false) { global $LANG; $file = CONTENT_DIR.$url; @@ -232,6 +237,7 @@ function getcontent($url,$md=true) else $content='**'.$LANG['404X2'].'**'; } + if ($header) header('Content-type: '.mime_content_type($file),true); if ($md==true) { $extra = new ParsedownExtraplus(); @@ -251,24 +257,33 @@ function filesJSON($path,$all,$first=true) $data = array(); if ( $node->isDir() && !$node->isDot() ) { - $data['text'] = $node->getFilename(); - $data['children'] = filesJSON($path.$node->getFilename()."/",$all,false); + $data['text'] = $node->getFilename(); + $data['children'] = filesJSON($path.$node->getFilename()."/",$all,false); + $data['icon'] = "far fa-folder"; } else { - if ($all) - $data['text'] = $node->getFilename(); - else - { - $file = pathinfo($node->getFilename()); - $data['text'] = $file['filename']; - } - $data['icon'] = "jstree-file"; + if ($all) + { + $data['text'] = $node->getFilename(); + if ($node->getExtension() == VIEWABLE_FORMAT) + $data['icon'] = "fas fa-book"; + else if (strpos(IMAGE_EXT,$node->getExtension())>=0) + $data['icon'] = "far fa-images"; + else + $data['icon'] = "far fa-file"; + } + else + { + $file = pathinfo($node->getFilename()); + $data['text'] = $file['filename']; + $data['icon'] = "fas fa-book-open"; + } } $alldata[]=$data; } 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 return $alldata; }