Created
March 27, 2020 19:17
-
-
Save m1k1o/21a8c8499d32ebaf1f5a01876f6d49dc to your computer and use it in GitHub Desktop.
Use Filerun's session as auth middle in traefik.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Stay logged in for 30min | |
$time_diff = 60 * 30; | |
// Create login page | |
$login_page = $_SERVER["HTTP_X_FORWARDED_PROTO"]."://".$_SERVER["HTTP_X_FORWARDED_HOST"].":".$_SERVER["HTTP_X_FORWARDED_PORT"]; | |
$sess = $_COOKIE["FileRunSID"]; | |
if(!preg_match("/^[a-zA-Z0-9]+$/", $sess)) { | |
header('HTTP/1.0 401 Unauthorized'); | |
header('Location: '.$login_page); | |
exit; | |
} | |
$file = "/tmp/sess_".$sess; | |
if(!file_exists($file) || !is_readable($file) || 0 === ($data = file_get_contents($file))) { | |
header('HTTP/1.0 401 Unauthorized'); | |
header('Location: '.$login_page); | |
exit; | |
} | |
$data = explode("|", $data); | |
$data = array_pop($data); | |
$data = unserialize($data); | |
if($time_diff != 0 && $data["last_request"] < time() - $time_diff) { | |
header('HTTP/1.0 401 Unauthorized'); | |
header('Location: '.$login_page); | |
exit; | |
} | |
header('X-Forwarded-User: '.$data["username"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to your filerun HTML directory.
Use in Traefik like this: