Skip to content
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

fix path #1765

Merged
merged 3 commits into from Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 32 additions & 17 deletions portal/import_template.php
Expand Up @@ -25,16 +25,18 @@
require_once("../interface/globals.php");

if ($_POST['mode'] == 'get') {
if (validateFile($_POST['docid'])) {
echo file_get_contents($_POST['docid']);
$rebuilt = validateFile($_POST['docid']);
if ($rebuilt) {
echo file_get_contents($rebuilt);
exit();
} else {
die(xlt('Invalid File'));
}
} else if ($_POST['mode'] == 'save') {
if (validateFile($_POST['docid'])) {
$rebuilt = validateFile($_POST['docid']);
if ($rebuilt) {
if (stripos($_POST['content'], "<?php") === false) {
file_put_contents($_POST['docid'], $_POST['content']);
file_put_contents($rebuilt, $_POST['content']);
exit(true);
} else {
die(xlt('Invalid Content'));
Expand All @@ -43,8 +45,9 @@
die(xlt('Invalid File'));
}
} else if ($_POST['mode'] == 'delete') {
if (validateFile($_POST['docid'])) {
unlink($_POST['docid']);
$rebuilt = validateFile($_POST['docid']);
if ($rebuilt) {
unlink($rebuilt);
exit(true);
} else {
die(xlt('Invalid File'));
Expand All @@ -56,7 +59,7 @@
define("UPLOAD_DIR", $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/');
} else {
if ($_POST['up_dir'] > 0) {
define("UPLOAD_DIR", $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $_POST['up_dir'] . '/');
define("UPLOAD_DIR", $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . convert_safe_file_dir_name($_POST['up_dir']) . '/');
} else {
define("UPLOAD_DIR", $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/');
}
Expand Down Expand Up @@ -95,19 +98,31 @@
// set proper permissions on the new file
chmod(UPLOAD_DIR . $name, 0644);
header("location: " . $_SERVER['HTTP_REFERER']);
die();
}

function validateFile($filename = '')
{
$valid = false;
$filePath = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
if (stripos($filename, $filePath) === false || !realpath($filename)) {
return false;
$knownPath = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/'; // default path
$unknown = str_replace("\\", "/", realpath($filename)); // normalize requested path
$parts = pathinfo($unknown);
$unkParts = explode('/', $parts['dirname']);
$ptpid = $unkParts[count($unkParts) - 1]; // is this a patient or global template
$ptpid = ($ptpid == 'templates') ? '' : ($ptpid . '/'); // last part should be pid or template
$rebuiltPath = $knownPath . $ptpid . $parts['filename'] . '.tpl';
if (file_exists($rebuiltPath) === false || $parts['extension'] != 'tpl') {
redirect();
} elseif (realpath($rebuiltPath) != realpath($filename)) { // these need to match to be valid request
redirect();
} elseif (stripos(realpath($filename), realpath($knownPath)) === false) { // this needs to pass be a valid request
redirect();
}
if (preg_match("/(.*)\.(php|php3|php4|php5|php7)$/i", $filename) === 0) {
if (preg_match("/(.*)\.(tpl)$/i", $filename) === 1) {
$valid = true;
}
}
return $valid;

return $rebuiltPath;
}

function redirect()
{
header('HTTP/1.0 404 Not Found');
die();
}
150 changes: 77 additions & 73 deletions portal/import_template_ui.php
Expand Up @@ -24,7 +24,7 @@
require_once("../interface/globals.php");
$getdir = isset($_POST['sel_pt']) ? $_POST['sel_pt'] : 0;
if ($getdir > 0) {
$tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $getdir . '/';
$tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . convert_safe_file_dir_name($getdir) . '/';
if (!is_dir($tdir)) {
if (!mkdir($tdir, 0755, true)) {
die(xl('Failed to create folder'));
Expand Down Expand Up @@ -114,61 +114,65 @@ function getTemplateList($dir)
if(delok === true) {getDocument(docname, 'delete', '')}
return false;
};
function getDocument(docname, mode, content){
var liburl = 'import_template.php';
$.ajax({
type: "POST",
url: liburl,
data: {docid: docname, mode: mode,content: content},
beforeSend: function(xhr){
console.log("Please wait..."+content);
},
error: function(qXHR, textStatus, errorThrow){
console.log("There was an error");
},
success: function(templateHtml, textStatus, jqXHR){
if(mode == 'get'){
//console.log("File get..."+templateHtml);
$('#templatecontent').summernote('destroy');
$('#templatecontent').empty().append(templateHtml);
$('#popeditor').modal({backdrop: "static"});
$('#templatecontent').summernote({
// height: 200,
focus: true,
placeholder: '',
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['insert', ['link','picture', 'video', 'hr']],
['view', ['fullscreen', 'codeview']],
['insert', ['nugget']],
['edit',['undo','redo']]
],
nugget: {
list: [
'{ParseAsHTML}{TextInput}', '{smTextInput}', '{CheckMark}', '{ynRadioGroup}', '{DOS}','{ReferringDOC}', '{PatientID}',
'{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{PatientSignature}', '{Address}', '{City}', '{State}', '{Zip}',
'{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}'
],
label: 'Tags / Directives',
tooltip: 'Insert at current cursor location.'
},
options:{'label': 'Tags/Directives',
'tooltip': 'Insert Tag or Directive'}
});
}
else if(mode == 'save'){
$('#templatecontent').summernote('destroy');
location.reload();
}
else if(mode == 'delete'){
location.reload();

function getDocument(docname, mode, content) {
var liburl = 'import_template.php';
$.ajax({
type: "POST",
url: liburl,
data: {docid: docname, mode: mode, content: content},
beforeSend: function (xhr) {
console.log("Please wait..." + content);
},
error: function (qXHR, textStatus, errorThrow) {
console.log("There was an error");
alert('<?php echo xlt("File Error") ?>' + "\n" + docname)
},
success: function (templateHtml, textStatus, jqXHR) {
if (mode == 'get') {
//console.log("File get..."+templateHtml);
$('#templatecontent').summernote('destroy');
$('#templatecontent').empty().append(templateHtml);
$('#popeditor').modal({backdrop: "static"});
$('#templatecontent').summernote({
// height: 200,
focus: true,
placeholder: '',
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['insert', ['link', 'picture', 'video', 'hr']],
['view', ['fullscreen', 'codeview']],
['insert', ['nugget']],
['edit', ['undo', 'redo']]
],
nugget: {
list: [
'{ParseAsHTML}{TextInput}', '{smTextInput}', '{CheckMark}', '{ynRadioGroup}', '{DOS}', '{ReferringDOC}', '{PatientID}',
'{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{PatientSignature}', '{Address}', '{City}', '{State}', '{Zip}',
'{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}'
],
label: 'Tags / Directives',
tooltip: 'Insert at current cursor location.'
},
options: {
'label': 'Tags/Directives',
'tooltip': 'Insert Tag or Directive'
}
}
});
}
});
}
else if (mode == 'save') {
$('#templatecontent').summernote('destroy');
location.reload();
}
else if (mode == 'delete') {
location.reload();
}
}
});
}
</script>
<style>
.modal.modal-wide .modal-dialog {
Expand Down Expand Up @@ -246,25 +250,25 @@ function getDocument(docname, mode, content){
});
</script>
</div>
<div class="modal modal-wide fade" id="popeditor">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span class="sr-only"><?php echo xlt('Close'); ?></span>
</button>
<h4 class="modal-title"><?php echo xlt('Edit Template'); ?></h4>
</div>
<div class="modal-body">
<div class="edittpl" id="templatecontent"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-xs" data-dismiss="modal"><?php echo xlt('Dismiss'); ?></button>
<button type="button" class="btn btn-success btn-xs" data-dismiss="modal" onclick="tsave()"><?php echo xlt('Save'); ?></button>
</div>
<div class="modal modal-wide fade" id="popeditor">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span class="sr-only"><?php echo xlt('Close'); ?></span>
</button>
<h4 class="modal-title"><?php echo xlt('Edit Template'); ?></h4>
</div>
<div class="modal-body">
<div class="edittpl" id="templatecontent"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-xs" data-dismiss="modal"><?php echo xlt('Dismiss'); ?></button>
<button type="button" class="btn btn-success btn-xs" data-dismiss="modal" onclick="tsave()"><?php echo xlt('Save'); ?></button>
</div>
</div>
</div>
</body>
</div>
</body>
</html>