|
|
@@ -10,6 +10,11 @@ Lib::loadClass('RouteBase');
|
|
|
*/
|
|
|
class Route_Debug extends RouteBase {
|
|
|
|
|
|
+ public $logPathPrefix = '/tmp/se-todo-';
|
|
|
+ public function __construct() {
|
|
|
+ $this->logPathPrefix = '/tmp/' . ('production' == V::get('P5_ENV', 'production', $_SERVER) ? "" : "dev-");
|
|
|
+ }
|
|
|
+
|
|
|
public function handleAuth() {
|
|
|
if (!User::logged()) {
|
|
|
throw new HttpException('Unauthorized', 401);
|
|
|
@@ -90,9 +95,9 @@ class Route_Debug extends RouteBase {
|
|
|
function ($logFile) {
|
|
|
// /tmp/se-debug-2017-01-25-plabudda-192.168.61.206-4qqrd0.log
|
|
|
try {
|
|
|
- if ('/tmp/se-debug-' != substr($logFile, 0, strlen('/tmp/se-debug-'))) throw new Exception("Wrong log file name '{$logFile}'");
|
|
|
+ if ("{$this->logPathPrefix}se-debug-" != substr($logFile, 0, strlen("{$this->logPathPrefix}se-debug-"))) throw new Exception("Wrong log file name '{$logFile}'");
|
|
|
if ('.log' != substr($logFile, -4)) throw new Exception("Wrong log file name extension '{$logFile}'");
|
|
|
- $logName = substr($logFile, strlen('/tmp/se-debug-'), -4);
|
|
|
+ $logName = substr($logFile, strlen("{$this->logPathPrefix}se-debug-"), -4);
|
|
|
list($logYear, $logMonth, $logDay, $logUser, $logIP, $logSessId, $logReqDate) = explode('-', $logName);
|
|
|
|
|
|
return [
|
|
|
@@ -119,10 +124,9 @@ class Route_Debug extends RouteBase {
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
- , glob("/tmp/se-debug-*.log", GLOB_NOSORT)
|
|
|
+ , glob("{$this->logPathPrefix}se-debug-*.log", GLOB_NOSORT)
|
|
|
)
|
|
|
]);
|
|
|
-
|
|
|
echo UI::hButtonPost("Test dbg with sleep", [
|
|
|
'class' => "btn-warning btn-xs",
|
|
|
'data' => [
|
|
|
@@ -189,9 +193,9 @@ class Route_Debug extends RouteBase {
|
|
|
function ($logFile) {
|
|
|
// /tmp/se-debug-2017-01-25-plabudda-192.168.61.206-4qqrd0.log
|
|
|
try {
|
|
|
- if ('/tmp/se-auth-' != substr($logFile, 0, strlen('/tmp/se-auth-'))) throw new Exception("Wrong log file name '{$logFile}'");
|
|
|
+ if ("{$this->logPathPrefix}se-auth-" != substr($logFile, 0, strlen("{$this->logPathPrefix}se-auth-"))) throw new Exception("Wrong log file name '{$logFile}'");
|
|
|
if ('.log' != substr($logFile, -4)) throw new Exception("Wrong log file name extension '{$logFile}'");
|
|
|
- $logName = substr($logFile, strlen('/tmp/se-auth-'), -4);
|
|
|
+ $logName = substr($logFile, strlen("{$this->logPathPrefix}se-auth-"), -4);
|
|
|
list($logYear, $logMonth, $logDay, $logIP, $logReqDate) = explode('-', $logName);
|
|
|
|
|
|
return [
|
|
|
@@ -218,7 +222,7 @@ class Route_Debug extends RouteBase {
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
- , glob("/tmp/se-auth-*.log", GLOB_NOSORT)
|
|
|
+ , glob("{$this->logPathPrefix}se-auth-*.log", GLOB_NOSORT)
|
|
|
)
|
|
|
]);
|
|
|
|
|
|
@@ -242,11 +246,11 @@ class Route_Debug extends RouteBase {
|
|
|
$logName = V::get('name', '', $_REQUEST);
|
|
|
if (!$logName) {
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "ls -1rt /tmp/se-debug-{$today}-*.log | tail -5";
|
|
|
+ $cmd = "ls -1rt {$this->logPathPrefix}se-debug-{$today}-*.log | tail -5";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
if (empty($out)) {
|
|
|
UI::alert('warning', "No logs today. Searching previous...");
|
|
|
- $cmd = "ls -1rt /tmp/se-debug-*.log | tail -5";
|
|
|
+ $cmd = "ls -1rt {$this->logPathPrefix}se-debug-*.log | tail -5";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
if (empty($out)) throw new Exception("Log files not found");
|
|
|
}
|
|
|
@@ -258,9 +262,9 @@ class Route_Debug extends RouteBase {
|
|
|
]);
|
|
|
$logName = end($out);// /tmp/se-debug-2017-01-30-plabudda-192.168.61.206-4qqrd0-1485775975.log
|
|
|
{
|
|
|
- if ('/tmp/se-debug-' != substr($logName, 0, strlen('/tmp/se-debug-'))) throw new Exception("Wrong log name prefix");
|
|
|
+ if ("{$this->logPathPrefix}se-debug-" != substr($logName, 0, strlen("{$this->logPathPrefix}se-debug-"))) throw new Exception("Wrong log name prefix");
|
|
|
if ('.log' != substr($logName, -1 * strlen('.log'))) throw new Exception("Wrong log name suffix");
|
|
|
- $logName = substr($logName, strlen('/tmp/se-debug-'), -1 * strlen('.log'));
|
|
|
+ $logName = substr($logName, strlen("{$this->logPathPrefix}se-debug-"), -1 * strlen('.log'));
|
|
|
}
|
|
|
}
|
|
|
$this->printLogFileView('debug', $logName);
|
|
|
@@ -282,11 +286,11 @@ class Route_Debug extends RouteBase {
|
|
|
$logName = V::get('name', '', $_REQUEST);
|
|
|
if (!$logName) {
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "ls -1rt /tmp/se-auth-{$today}-*.log | tail -5";
|
|
|
+ $cmd = "ls -1rt {$this->logPathPrefix}se-auth-{$today}-*.log | tail -5";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
if (empty($out)) {
|
|
|
UI::alert('warning', "No logs today. Searching previous...");
|
|
|
- $cmd = "ls -1rt /tmp/se-auth-*.log | tail -5";
|
|
|
+ $cmd = "ls -1rt {$this->logPathPrefix}se-auth-*.log | tail -5";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
if (empty($out)) throw new Exception("Log files not found");
|
|
|
}
|
|
|
@@ -298,9 +302,9 @@ class Route_Debug extends RouteBase {
|
|
|
]);
|
|
|
$logName = end($out);// /tmp/se-debug-2017-01-30-plabudda-192.168.61.206-4qqrd0-1485775975.log
|
|
|
{
|
|
|
- if ('/tmp/se-auth-' != substr($logName, 0, strlen('/tmp/se-auth-'))) throw new Exception("Wrong log name prefix");
|
|
|
+ if ("{$this->logPathPrefix}se-auth-" != substr($logName, 0, strlen("{$this->logPathPrefix}se-auth-"))) throw new Exception("Wrong log name prefix");
|
|
|
if ('.log' != substr($logName, -1 * strlen('.log'))) throw new Exception("Wrong log name suffix");
|
|
|
- $logName = substr($logName, strlen('/tmp/se-auth-'), -1 * strlen('.log'));
|
|
|
+ $logName = substr($logName, strlen("{$this->logPathPrefix}se-auth-"), -1 * strlen('.log'));
|
|
|
}
|
|
|
}
|
|
|
$this->printLogFileView('auth', $logName);
|
|
|
@@ -344,7 +348,7 @@ class Route_Debug extends RouteBase {
|
|
|
public function printLogFileView($type, $logName) {
|
|
|
if (empty($logName)) throw new Exception("Missing name");
|
|
|
$logName = $this->validateParamLogName($logName);
|
|
|
- $logPath = "/tmp/se-{$type}-{$logName}.log";
|
|
|
+ $logPath = "{$this->logPathPrefix}se-{$type}-{$logName}.log";
|
|
|
if (!file_exists($logPath)) throw new Exception("Log file not exists");
|
|
|
$content = file_get_contents($logPath);
|
|
|
UI::table([
|
|
|
@@ -457,7 +461,7 @@ class Route_Debug extends RouteBase {
|
|
|
session_write_close();
|
|
|
try {
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "rm -v /tmp/se-debug-*.log 2>&1";
|
|
|
+ $cmd = "rm -v {$this->logPathPrefix}se-debug-*.log 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -478,7 +482,7 @@ class Route_Debug extends RouteBase {
|
|
|
session_write_close();
|
|
|
try {
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "ls -1 /tmp/se-debug-*.log | grep -v '/tmp/se-debug-{$today}-' | xargs rm -v 2>&1";
|
|
|
+ $cmd = "ls -1 {$this->logPathPrefix}se-debug-*.log | grep -v '{$this->logPathPrefix}se-debug-{$today}-' | xargs rm -v 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -500,7 +504,7 @@ class Route_Debug extends RouteBase {
|
|
|
try {
|
|
|
$userLogin = User::getLogin();
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "rm -v /tmp/se-debug-*-{$userLogin}-*.log 2>&1";
|
|
|
+ $cmd = "rm -v {$this->logPathPrefix}se-debug-*-{$userLogin}-*.log 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -522,7 +526,7 @@ class Route_Debug extends RouteBase {
|
|
|
try {
|
|
|
$userLogin = User::getLogin();
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "ls -1 /tmp/se-debug-*-{$userLogin}-*.log | grep -v '/tmp/se-debug-{$today}-' | xargs rm -v 2>&1";
|
|
|
+ $cmd = "ls -1 {$this->logPathPrefix}se-debug-*-{$userLogin}-*.log | grep -v '{$this->logPathPrefix}se-debug-{$today}-' | xargs rm -v 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -543,7 +547,7 @@ class Route_Debug extends RouteBase {
|
|
|
session_write_close();
|
|
|
try {
|
|
|
$logName = $this->validateParamLogName(V::get('logName', '', $_REQUEST));
|
|
|
- $logPath = "/tmp/se-debug-{$logName}.log";
|
|
|
+ $logPath = "{$this->logPathPrefix}se-debug-{$logName}.log";
|
|
|
if (!file_exists($logPath)) throw new AlertWarningException("Log file not exists");
|
|
|
unlink($logPath);
|
|
|
throw new AlertSuccessException("File Removed");
|
|
|
@@ -560,7 +564,7 @@ class Route_Debug extends RouteBase {
|
|
|
try {
|
|
|
$userLogin = User::getLogin();
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "rm -v /tmp/se-auth-*.log 2>&1";
|
|
|
+ $cmd = "rm -v {$this->logPathPrefix}se-auth-*.log 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->authView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -582,7 +586,7 @@ class Route_Debug extends RouteBase {
|
|
|
try {
|
|
|
$userLogin = User::getLogin();
|
|
|
$today = date("Y-m-d");
|
|
|
- $cmd = "ls -1 /tmp/se-auth-*.log | grep -v '/tmp/se-auth-{$today}-' | xargs rm -v 2>&1";
|
|
|
+ $cmd = "ls -1 {$this->logPathPrefix}se-auth-*.log | grep -v '{$this->logPathPrefix}se-auth-{$today}-' | xargs rm -v 2>&1";
|
|
|
V::exec($cmd, $out, $ret);
|
|
|
$this->authView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
|
|
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
|
|
|
@@ -603,7 +607,7 @@ class Route_Debug extends RouteBase {
|
|
|
session_write_close();
|
|
|
try {
|
|
|
$logName = $this->validateParamLogName(V::get('logName', '', $_REQUEST));
|
|
|
- $logPath = "/tmp/se-auth-{$logName}.log";
|
|
|
+ $logPath = "{$this->logPathPrefix}se-auth-{$logName}.log";
|
|
|
if (!file_exists($logPath)) throw new AlertWarningException("Log file not exists");
|
|
|
unlink($logPath);
|
|
|
throw new AlertSuccessException("File Removed");
|