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

added option to browse as guest when auth on #583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config-sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// Is independent from IP white- and blacklisting
$use_auth = true;

// Allow guest user when using auth
$auth_allow_guest = true;

// Login user name and password
// Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
// Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
Expand All @@ -27,7 +30,7 @@
// Readonly users
// e.g. array('users', 'guest', ...)
$readonly_users = array(
'user'
'user', 'guest'
);

// Enable highlight.js (https://highlightjs.org/) on view's page
Expand Down
23 changes: 19 additions & 4 deletions tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// Is independent from IP white- and blacklisting
$use_auth = true;

// Allow guest user when using auth
$auth_allow_guest = true;

// Login user name and password
// Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
// Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
Expand All @@ -32,7 +35,7 @@
// Readonly users
// e.g. array('users', 'guest', ...)
$readonly_users = array(
'user'
'user', 'guest'
);

// Enable highlight.js (https://highlightjs.org/) on view's page
Expand Down Expand Up @@ -283,12 +286,12 @@ function session_error_handling_function($code, $msg, $file, $line) {
} else {
unset($_SESSION[FM_SESSION_ID]['logged']);
fm_set_msg(lng('Login failed. Invalid username or password'), 'error');
fm_redirect(FM_SELF_URL);
fm_redirect(FM_SELF_URL . '?login=1');
}
} else {
fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');;
}
} else {
} elseif(!$auth_allow_guest || ($_GET['login'] ?? false)) {
// Form
unset($_SESSION[FM_SESSION_ID]['logged']);
fm_show_header_login();
Expand Down Expand Up @@ -333,6 +336,13 @@ function session_error_handling_function($code, $msg, $file, $line) {
<?php echo lng('Login'); ?>
</button>
</div>
<?php if ($auth_allow_guest) { ?>
<div class="form-group">
<a href="<?php echo FM_SELF_URL?>" class="btn btn-secondary btn-block mt-4" role="button">
<?php echo "Guest" ?>
</a>
</div>
<?php } ?>
</form>
</div>
</div>
Expand All @@ -351,6 +361,10 @@ function session_error_handling_function($code, $msg, $file, $line) {
}
}

if($use_auth && $auth_allow_guest && !isset($_SESSION[FM_SESSION_ID]['logged'])){
$_SESSION[FM_SESSION_ID]['logged'] = 'guest';
}

// update root path
if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
$root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
Expand Down Expand Up @@ -3398,7 +3412,8 @@ function fm_show_nav_path($path)
<a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
<?php endif ?>
<a title="<?php echo lng('Help') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;help=2"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> <?php echo lng('Help') ?></a>
<a title="<?php echo lng('Logout') ?>" class="dropdown-item nav-link" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i> <?php echo lng('Logout') ?></a>
<?php $is_guest = $_SESSION[FM_SESSION_ID]['logged'] == 'guest' ?>
<a title="<?php echo $is_guest ? lng('Login') : lng('Logout') ?>" class="dropdown-item nav-link" href=<?php echo $is_guest ? "?login=1": "?logout=1" ?>><i class="fa fa-sign-out" aria-hidden="true"></i> <?php echo $is_guest ? lng('Login') : lng('Logout') ?></a>
</div>
</li>
<?php else: ?>
Expand Down