2021-01-01 12:34:11 +01:00
|
|
|
<?php
|
2021-01-01 12:08:59 +01:00
|
|
|
/*
|
2021-01-01 12:34:11 +01:00
|
|
|
|
2021-01-01 12:08:59 +01:00
|
|
|
* MarkDoc
|
|
|
|
* PHP MarkDown document manager
|
|
|
|
* Hordé Nicolas
|
|
|
|
* https://github.com/dahut87/MarkDoc
|
|
|
|
* Release under GPLv3.0 license
|
|
|
|
* Base on Pheditor "PHP file editor" By Hamid Samak Release under MIT license
|
|
|
|
*/
|
|
|
|
|
|
|
|
### Global defines
|
|
|
|
define('ROOT_DIR', realpath(dirname(__FILE__)) .'/');
|
|
|
|
define('LIB_DIR', ROOT_DIR.'lib/');
|
|
|
|
define('HOST_DIR',ROOT_DIR.'hosts/'.$_SERVER['SERVER_NAME'].'/');
|
|
|
|
|
|
|
|
### Hosts defines
|
|
|
|
include HOST_DIR."./config.php";
|
|
|
|
define('CONTENT_DIR', HOST_DIR.SUBCONTENT_DIR.'/');
|
|
|
|
define('LOG_DIR', HOST_DIR.LOG_FILE);
|
|
|
|
define('HISTORY_DIR', HOST_DIR.HISTORY_FILE);
|
|
|
|
include LIB_DIR."/Parsedown.php";
|
|
|
|
include LIB_DIR."/ParsedownExtra.php";
|
2021-01-01 13:41:31 +01:00
|
|
|
include LIB_DIR."/ParsedownExtraPlus.php";
|
2021-01-01 12:08:59 +01:00
|
|
|
include LIB_DIR."/functions.php";
|
|
|
|
|
2021-01-02 19:58:35 +01:00
|
|
|
### Translations
|
|
|
|
loadlang(LANGUAGE);
|
2021-01-03 14:32:47 +01:00
|
|
|
global $LANG,$JSLANG;
|
2021-01-02 19:58:35 +01:00
|
|
|
|
2021-01-01 12:08:59 +01:00
|
|
|
### Security
|
|
|
|
testip();
|
|
|
|
logprotect();
|
|
|
|
|
|
|
|
### Sessions
|
2021-01-03 14:32:47 +01:00
|
|
|
session_name('markdoc');
|
2021-01-01 12:08:59 +01:00
|
|
|
session_start();
|
|
|
|
|
|
|
|
/*var_dump($_POST);
|
|
|
|
var_dump($_GET);*/
|
|
|
|
|
|
|
|
$file=explode('?', ($_GET['doc']=="")?"index.md":$_GET['doc'], 2)[0] ?? "";
|
|
|
|
$filedetail = pathinfo($file);
|
|
|
|
|
|
|
|
if (isset($_GET['logout'])) {
|
|
|
|
unset($_SESSION['md_admin']);
|
|
|
|
redirect();
|
|
|
|
}
|
|
|
|
else if (isset($_POST['action']))
|
|
|
|
{
|
|
|
|
switch ($_POST['action']) {
|
|
|
|
case 'ident':
|
|
|
|
if (isset($_SESSION['md_admin']) === false || $_SESSION['md_admin'] !== true)
|
|
|
|
{
|
|
|
|
if (isset($_POST['md_password']) && empty($_POST['md_password']) === false)
|
|
|
|
{
|
|
|
|
if (hash('sha512', $_POST['md_password']) === PASSWORD)
|
|
|
|
{
|
|
|
|
$_SESSION['md_admin'] = true;
|
|
|
|
redirect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 19:58:35 +01:00
|
|
|
$content = '<h1>'.$LANG['BADPASS'].'</h1>';
|
|
|
|
$log = file_exists(LOG_DIR) ? unserialize(file_get_contents(LOG_DIR)) : array();
|
2021-01-01 12:08:59 +01:00
|
|
|
if (isset($log[$_SERVER['REMOTE_ADDR']]) === false)
|
|
|
|
{
|
|
|
|
$log[$_SERVER['REMOTE_ADDR']] = array('num' => 0, 'time' => 0);
|
|
|
|
}
|
|
|
|
$log[$_SERVER['REMOTE_ADDR']]['num'] += 1;
|
|
|
|
$log[$_SERVER['REMOTE_ADDR']]['time'] = time();
|
2021-01-02 19:58:35 +01:00
|
|
|
file_put_contents(LOG_DIR, serialize($log));
|
2021-01-01 12:08:59 +01:00
|
|
|
}
|
2021-01-02 19:58:35 +01:00
|
|
|
}
|
2021-01-01 12:08:59 +01:00
|
|
|
else
|
|
|
|
$content='<h1>Aucun mot de passe renseigné !</h1>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$content='<h1>Vous êtes déjà logué !</h1>';
|
|
|
|
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;
|
|
|
|
case 'realopen':
|
|
|
|
$file=urldecode($_POST['file']);
|
|
|
|
print(getcontent($file,false));
|
|
|
|
exit;
|
|
|
|
case 'save':
|
|
|
|
$file=urldecode($_POST['file']);
|
|
|
|
print(setcontent($file,$_POST['data']));
|
|
|
|
exit;
|
|
|
|
case 'search':
|
|
|
|
$results=searchstr(CONTENT_DIR,$_POST['search']);
|
|
|
|
//print_r($results);
|
2021-01-03 14:17:40 +01:00
|
|
|
$content=sprintf($LANG['FOUND'],$results['totalFiles']);
|
2021-01-01 12:08:59 +01:00
|
|
|
foreach($results['files'] as $key => $value)
|
|
|
|
$content.='<p class="filefound"><a href="'.$key.'">'.$key.'</a></p><p class="textfound">'.$value.'</p>';
|
|
|
|
if ($_POST['type']=="js")
|
|
|
|
{
|
|
|
|
print($content);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (substr($file,0,1)==":")
|
|
|
|
{
|
|
|
|
$content=specialurl($file);
|
|
|
|
}
|
|
|
|
else if ($filedetail['extension']=="md")
|
|
|
|
{
|
|
|
|
$content=getcontent($file);
|
|
|
|
}
|
|
|
|
else if ($filedetail['extension']!="" && strpos(ALLOWED_EXT, $filedetail['extension']) !== false)
|
|
|
|
{
|
|
|
|
if (file_exists(CONTENT_DIR . $file))
|
|
|
|
{
|
|
|
|
if ($filedetail['extension']=="css") header("Content-type: text/css");
|
|
|
|
print file_get_contents(CONTENT_DIR . $file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
http_response_code(404);
|
|
|
|
$content=getcontent("/special/404.md");
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content=getcontent("/special/404.md");
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title><?php echo TITLE; ?>
|
|
|
|
</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/prism.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/jstree.min.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/emoji.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/style.css" />
|
|
|
|
<?php print(($_SESSION['md_admin'] == true)?'<link rel="stylesheet" href="/css/codemirror.min.css" />':''); ?>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="head" class="">
|
2021-01-03 14:17:40 +01:00
|
|
|
<span id="forkongithub"><a href="https://github.com/dahut87/MarkDoc"><?php print($LANG['FORK']); ?></a></span>
|
2021-01-02 12:46:21 +01:00
|
|
|
<nav class="navbar fixed-top navbar-expand-md <?php print(($_SESSION['md_admin'] == true)?"navbar-custom":"bg-dark navbar-dark"); ?>">
|
2021-01-01 12:08:59 +01:00
|
|
|
<a class="navbar-brand" href="/index.md"><i class="fas <?php echo ICON; ?>"></i> <?php echo TITLE; ?></a>
|
|
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
</button>
|
|
|
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
|
|
<ul class="navbar-nav mr-auto">
|
|
|
|
<li class="nav-item dropdown">
|
2021-01-03 14:17:40 +01:00
|
|
|
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button"><?php print($LANG['MENU']); ?></a>
|
2021-01-01 12:08:59 +01:00
|
|
|
<div class="dropdown-menu">
|
|
|
|
<?php
|
|
|
|
print(getnav());
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
print(($_SESSION['md_admin'] == true)?'<li class="nav-item dropdown">
|
2021-01-03 14:17:40 +01:00
|
|
|
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" role="button">'.$LANG['ADMIN'].'</a>
|
2021-01-01 12:08:59 +01:00
|
|
|
<div class="dropdown-menu">
|
2021-01-03 14:17:40 +01:00
|
|
|
<a class="dropdown-item" href=":CONFIG">'.$LANG['CONFIG'].'</a>
|
|
|
|
<a class="dropdown-item" href=":PASSWORD">'.$LANG['PASSWORD'].'</a>
|
2021-01-01 12:08:59 +01:00
|
|
|
<hr>
|
2021-01-03 14:17:40 +01:00
|
|
|
<a class="dropdown-item" href="https://'.$_SERVER['SERVER_NAME'].'?logout">'.$LANG['LOGOUT'].'</a>
|
|
|
|
</div></li>':'<li class="nav-item"><a class="nav-link " href=":ADMIN">'.$LANG['ADMIN'].'</a></li>');
|
2021-01-01 12:08:59 +01:00
|
|
|
?>
|
2021-01-03 14:17:40 +01:00
|
|
|
<li class="nav-item"><a class="nav-link " href="<?php print($LANG['ABOUTMD'].'">'.$LANG['ABOUT']); ?></a></li>
|
2021-01-01 12:08:59 +01:00
|
|
|
</ul>
|
|
|
|
<form class="form-inline" id="form" name="form" action="/index.php" method="POST">
|
|
|
|
<input type="hidden" id="action" name="action" value="search"/>
|
2021-01-03 14:17:40 +01:00
|
|
|
<?php print(($_SESSION['md_admin'] == true)?'<input class="btn btn-outline-light" my-2 my-sm-0" value="'.$LANG['VIEW'].'" name="voir" id="voir" type="submit"/> <input class="btn btn-outline-light" my-2 my-sm-0" value="'.$LANG['SAVE'].'" name="save" id="save" type="button"/> ':''); ?>
|
|
|
|
<input class="btn <?php print(($_SESSION['md_admin'] == true)?"btn-outline-light":"btn-outline-info"); ?> my-2 my-sm-0" value="<?php print($LANG['TOC']); ?>" name="toc" id="toc" type="button" style="display: none;"/>
|
2021-01-01 12:08:59 +01:00
|
|
|
<input class="form-control mr-sm-2" type="text" id="search" name="search"/>
|
2021-01-03 14:17:40 +01:00
|
|
|
<input class="btn <?php print(($_SESSION['md_admin'] == true)?"btn-outline-light":"btn-outline-info"); ?> my-2 my-sm-0" value="<?php print($LANG['SEARCH']); ?>" name="submit" id="submit" type="submit"/>
|
2021-01-01 12:08:59 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
<div class="container-fluid">
|
2021-01-02 19:58:35 +01:00
|
|
|
<div class="float-right d-none d-md-block d-lg-block"><div class="toc fixed-top"></div></div>
|
2021-01-01 12:08:59 +01:00
|
|
|
<div class="row">
|
|
|
|
<div id="files" class="col-xs-12 order-last order-sm-last order-sm-last order-md-first order-lg-first col-md-4 col-lg-2"></div>
|
|
|
|
<div id="separate" class="bg-dark text-white col-xs-12 col-sm-12 order-3 d-md-none d-lg-none container">Documentations</div>
|
|
|
|
<div class="col-12 col-md-8 col-lg-10 order-2">
|
|
|
|
<div id="content" class="col-12 col-md-8 col-lg-10 order-2">
|
|
|
|
<?php
|
|
|
|
print($content);
|
|
|
|
?><br><br>
|
|
|
|
</div>
|
2021-01-03 14:17:40 +01:00
|
|
|
<div id="image" class="imagepreview" style="display: none;"><img></div><div id="editor" style="display: none;"><textarea data-file="" class="form-control"></textarea></div>
|
2021-01-01 12:08:59 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="footer" class="footer <?php print(($_SESSION['md_admin'] == true)?"navbar-custom":"bg-dark"); ?> text-white">
|
|
|
|
<?php
|
|
|
|
print(getcontent("special/footer.md"));
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
<div class="alert"></div>
|
2021-01-02 12:46:21 +01:00
|
|
|
<script type="text/javascript" src="/js/jquery.min.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/popper.min.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/jstree.min.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/prism.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/emoji.min.js"></script>
|
2021-01-02 19:58:35 +01:00
|
|
|
<script type="text/javascript" src="/js/toc.bundle.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/magnifik.js"></script>
|
2021-01-03 14:32:47 +01:00
|
|
|
<script type="text/javascript">
|
|
|
|
var LANG = <?php echo $JSLANG; ?>
|
|
|
|
</script>
|
2021-01-02 12:46:21 +01:00
|
|
|
<?php print(($_SESSION['md_admin'] == true)?'<link rel="stylesheet" href="/css/simplemde.min.css">
|
|
|
|
<script src="/js/simplemde.min.js"></script>
|
|
|
|
<script type="text/javascript" src="/js/functionsadmin.js"></script>':'<script type="text/javascript" src="/js/functions.js"></script>'); ?>
|
2021-01-01 12:08:59 +01:00
|
|
|
</body>
|
|
|
|
</html>
|