55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
class neoCMSCore {
|
|
|
|
public $auditEnabled=true;
|
|
public $users=[];
|
|
public $loggedIn=false;
|
|
private $loggedInUser='';
|
|
public $version='2.0';
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Write an entry into the audit log
|
|
* @param $value
|
|
* @return void
|
|
*/
|
|
public function writeAudit($value) {
|
|
if($this->auditEnabled)
|
|
file_put_contents(__DIR__ . "/".date('y-m-d-')."audit.txt", date('Y-m-d H:i:s')."\t".$this->loggedInUser."\t".trim($value)."\n", FILE_APPEND);
|
|
}
|
|
|
|
public function login($username, $password) {
|
|
$this->loggedIn=(!empty($this->users[$username]) && $this->users[$username]==$password);
|
|
if($this->loggedIn) $this->loggedInUser=$username;
|
|
$this->writeAudit("User login for ".$username." was ".($this->loggedIn?"successful":"denied due to incorrect credentials")." from ".$_SERVER['REMOTE_ADDR']);
|
|
return $this->loggedIn;
|
|
}
|
|
|
|
public function isLoggedIn() {
|
|
return $this->loggedIn;
|
|
}
|
|
|
|
public function getLoggedinUser() {
|
|
return $this->loggedInUser;
|
|
}
|
|
|
|
public function saveContent($uri,$content) {
|
|
$this->writeAudit("Content for ".$uri." was saved.");
|
|
$uri=str_replace("../","./",$uri);
|
|
|
|
//check to see if we're dealing with a default (index.htm{l}) page
|
|
if(str_ends_with($uri,"/") || $uri=='/') {
|
|
if(file_exists($_SERVER['DOCUMENT_ROOT'].$uri.'index.htm')) {
|
|
$uri=$uri.'/index.htm';
|
|
}
|
|
elseif(file_exists($_SERVER['DOCUMENT_ROOT'].$uri.'index.html')) {
|
|
$uri=$uri.'/index.html';
|
|
} else {
|
|
die('Unknown default file:'.$uri);
|
|
}
|
|
}
|
|
file_put_contents($_SERVER['DOCUMENT_ROOT'].$uri,$content);
|
|
}
|
|
} |