mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-12 19:13:57 +02:00
new login form; login form is now a template; logout function; closes #43
This commit is contained in:
786
build/libifm.php
786
build/libifm.php
File diff suppressed because one or more lines are too long
155
src/main.php
155
src/main.php
@@ -19,7 +19,7 @@ class IFM {
|
|||||||
|
|
||||||
private $defaultconfig = array(
|
private $defaultconfig = array(
|
||||||
// general config
|
// general config
|
||||||
"auth" => 0,
|
"auth" => 1,
|
||||||
"auth_source" => 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC',
|
"auth_source" => 'inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC',
|
||||||
"root_dir" => "",
|
"root_dir" => "",
|
||||||
"tmp_dir" => "",
|
"tmp_dir" => "",
|
||||||
@@ -52,36 +52,66 @@ class IFM {
|
|||||||
);
|
);
|
||||||
|
|
||||||
private $config = array();
|
private $config = array();
|
||||||
|
private $templates = array();
|
||||||
public $mode = "";
|
public $mode = "";
|
||||||
|
|
||||||
public function __construct( $config=array() ) {
|
public function __construct( $config=array() ) {
|
||||||
if( session_status() !== PHP_SESSION_ACTIVE )
|
if( session_status() !== PHP_SESSION_ACTIVE )
|
||||||
session_start();
|
session_start();
|
||||||
$this->config = array_merge( $this->defaultconfig, $config );
|
$this->config = array_merge( $this->defaultconfig, $config );
|
||||||
|
|
||||||
|
$templates = array();
|
||||||
|
$templates['app'] = <<<'f00bar'
|
||||||
|
@@@src/templates/app.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['login'] = <<<'f00bar'
|
||||||
|
@@@src/templates/login.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['filetable'] = <<<'f00bar'
|
||||||
|
@@@src/templates/filetable.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['ajaxrequest'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.ajaxrequest.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['copymove'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.copymove.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['createdir'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.createdir.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['deletefile'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.deletefile.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['extractfile'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.extractfile.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['file'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.file.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['multidelete'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.multidelete.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['remoteupload'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.remoteupload.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['renamefile'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.renamefile.html@@@
|
||||||
|
f00bar;
|
||||||
|
$templates['uploadfile'] = <<<'f00bar'
|
||||||
|
@@@src/templates/modal.uploadfile.html@@@
|
||||||
|
f00bar;
|
||||||
|
$this->templates = $templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function contains the client-side application
|
* This function contains the client-side application
|
||||||
*/
|
*/
|
||||||
public function getApplication() {
|
public function getApplication() {
|
||||||
print '<!DOCTYPE HTML>
|
$this->getHTMLHeader();
|
||||||
<html>
|
print '<div id="ifm"></div>';
|
||||||
<head>
|
|
||||||
<title>IFM - improved file manager</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">';
|
|
||||||
$this->getCSS();
|
|
||||||
print '
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="ifm"></div>';
|
|
||||||
$this->getJS();
|
$this->getJS();
|
||||||
print '
|
print '<script>var ifm = new IFM(); ifm.init( "ifm" );</script>';
|
||||||
<script>var ifm = new IFM(); ifm.init( "ifm" );</script>
|
$this->getHTMLFooter();
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInlineApplication() {
|
public function getInlineApplication() {
|
||||||
@@ -110,6 +140,22 @@ class IFM {
|
|||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getHTMLHeader() {
|
||||||
|
print '<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>IFM - improved file manager</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">';
|
||||||
|
$this->getCSS();
|
||||||
|
print '</head><body>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHTMLFooter() {
|
||||||
|
print '</body></html>';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
main functions
|
main functions
|
||||||
*/
|
*/
|
||||||
@@ -130,7 +176,7 @@ class IFM {
|
|||||||
elseif( $_REQUEST["api"] == "getConfig" ) {
|
elseif( $_REQUEST["api"] == "getConfig" ) {
|
||||||
$this->getConfig();
|
$this->getConfig();
|
||||||
} elseif( $_REQUEST["api"] == "getTemplates" ) {
|
} elseif( $_REQUEST["api"] == "getTemplates" ) {
|
||||||
echo json_encode( $this->getTemplates() );
|
echo json_encode( $this->templates );
|
||||||
} elseif( $_REQUEST["api"] == "logout" ) {
|
} elseif( $_REQUEST["api"] == "logout" ) {
|
||||||
unset( $_SESSION );
|
unset( $_SESSION );
|
||||||
session_destroy();
|
session_destroy();
|
||||||
@@ -732,30 +778,12 @@ class IFM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function loginForm($loginFailed=false) {
|
private function loginForm($loginFailed=false) {
|
||||||
print '<!DOCTYPE HTML>
|
$err = "";
|
||||||
<html>
|
if( $loginFailed )
|
||||||
<head>
|
$err = '<div class="alert alert-danger">Login failed.</div>';
|
||||||
<title>IFM - improved file manager</title>
|
$this->getHTMLHeader();
|
||||||
<meta charset="utf-8">
|
print str_replace( "{{error}}", $err, $this->templates['login'] );
|
||||||
<style type="text/css">
|
$this->getHTMLFooter();
|
||||||
* { box-sizing: border-box; font-family: Monospace, Arial, sans-serif; }
|
|
||||||
html { text-align: center; }
|
|
||||||
body { margin:auto; width: auto; display: inline-block; }
|
|
||||||
form { padding: 1em; border: 1px dotted #CCC; }
|
|
||||||
button { margin: 3px; margin-top: 10px; padding: 9px 12px; border: 1px solid #444; border-radius: 2px; font-size: 0.9em; font-weight: bold; text-transform: uppercase; cursor: pointer; background: #444; color: #fff; }
|
|
||||||
div.err { color: red; font-weight: bold; margin-bottom: 1em; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>IFM - Login</h1>
|
|
||||||
<form method="post">';
|
|
||||||
if($loginFailed){ print '<div class="err">Login attempt failed. Please try again.</div>'; }
|
|
||||||
print '<label>username:</label> <input type="text" name="user" size="12"><br>
|
|
||||||
<label>password:</label> <input type="password" name="pass" size="12"><br>
|
|
||||||
<button type="submit">login</button>
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function filePermsDecode( $perms ) {
|
private function filePermsDecode( $perms ) {
|
||||||
@@ -965,45 +993,4 @@ class IFM {
|
|||||||
fclose($stdout_stream);
|
fclose($stdout_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTemplates() {
|
|
||||||
$templates = array();
|
|
||||||
$templates['app'] = <<<'f00bar'
|
|
||||||
@@@src/templates/app.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['filetable'] = <<<'f00bar'
|
|
||||||
@@@src/templates/filetable.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['ajaxrequest'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.ajaxrequest.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['copymove'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.copymove.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['createdir'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.createdir.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['deletefile'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.deletefile.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['extractfile'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.extractfile.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['file'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.file.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['multidelete'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.multidelete.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['remoteupload'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.remoteupload.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['renamefile'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.renamefile.html@@@
|
|
||||||
f00bar;
|
|
||||||
$templates['uploadfile'] = <<<'f00bar'
|
|
||||||
@@@src/templates/modal.uploadfile.html@@@
|
|
||||||
f00bar;
|
|
||||||
|
|
||||||
return $templates;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,9 @@
|
|||||||
{{#config.ajaxrequest}}
|
{{#config.ajaxrequest}}
|
||||||
<li><a id="buttonAjaxRequest"><span class="icon icon-link-ext"></span> ajax request</a></li>
|
<li><a id="buttonAjaxRequest"><span class="icon icon-link-ext"></span> ajax request</a></li>
|
||||||
{{/config.ajaxrequest}}
|
{{/config.ajaxrequest}}
|
||||||
|
{{#config.auth}}
|
||||||
|
<li><a id="buttonLogout" href="?api=logout"><span class="icon icon-logout"></span> logout</a></li>
|
||||||
|
{{/config.auth}}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
54
src/templates/login.html
Normal file
54
src/templates/login.html
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
padding-top: 40px;
|
||||||
|
padding-bottom: 40px;
|
||||||
|
background-color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin {
|
||||||
|
max-width: 330px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.form-signin .form-signin-heading,
|
||||||
|
.form-signin .checkbox {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.form-signin .checkbox {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
.form-signin .form-control {
|
||||||
|
position: relative;
|
||||||
|
height: auto;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
.form-signin .form-control:focus {
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
.form-signin input[type="email"] {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
.form-signin input[type="password"] {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<form action="" method="post" class="form-signin">
|
||||||
|
<h2 class="form-signin-heading text-center">IFM Login</h2>
|
||||||
|
{{error}}
|
||||||
|
<label for="inputEmail" class="sr-only">Username</label>
|
||||||
|
<input type="text" id="user" name="user" class="form-control" placeholder="Username" required autofocus>
|
||||||
|
<label for="inputPassword" class="sr-only">Password</label>
|
||||||
|
<input type="password" id="pass" name="pass" class="form-control" placeholder="Password" required>
|
||||||
|
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
</div> <!-- /container -->
|
Reference in New Issue
Block a user