From 44870defdcddbfceede437950fd9e3342f84ebf0 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Tue, 28 Oct 2014 23:47:28 +0100 Subject: Added experimental CDN support. --- action.php | 14 +++---- bootstrap.php | 9 ++++- cdn/originpull.php | 82 +++++++++++++++++++++++++++++++++++++++++ config-sample.php | 3 +- functions.php | 64 ++++++++++++++++---------------- index.php | 2 +- static/footer.php | 2 +- static/header.php | 24 ++++++------ static/modal-delete-gallery.php | 2 +- static/modal-edit-gallery.php | 2 +- static/modal-new-gallery.html | 40 -------------------- static/modal-new-gallery.php | 40 ++++++++++++++++++++ 12 files changed, 186 insertions(+), 98 deletions(-) create mode 100644 cdn/originpull.php delete mode 100644 static/modal-new-gallery.html create mode 100644 static/modal-new-gallery.php diff --git a/action.php b/action.php index a4d47f1..c045deb 100644 --- a/action.php +++ b/action.php @@ -8,7 +8,7 @@ if ( ! isset($_GET["page"]) || $_GET["page"] != "action" ){ if ( ! isset($_GET["task"]) || $_GET["task"] == "" ){ header($_SERVER["SERVER_PROTOCOL"] . "400 Wrong Request"); - header("Location: /?page=index"); + header("Location: ".DOMAIN."?page=index"); ob_clean(); exit; } @@ -27,7 +27,7 @@ switch($_GET["task"]){ } else if ( $user->login($_POST["name"], $_POST["password"]) ){ $goto = preg_replace("/;/", "&", $_GET["goto"]); header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=" . $goto); + header("Location: ".DOMAIN."?page=" . $goto); ob_clean(); exit; } else { @@ -68,7 +68,7 @@ switch($_GET["task"]){ print_login("database"); else { header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=" . $_GET["goto"]); + header("Location: ".DOMAIN."?page=" . $_GET["goto"]); ob_clean(); exit; } @@ -97,7 +97,7 @@ switch($_GET["task"]){ } if ( $result = $db->doQuery($sql) ){ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=" . $_GET["goto"]); + header("Location: ".DOMAIN."?page=" . $_GET["goto"]); $c->flush(); } } @@ -120,7 +120,7 @@ switch($_GET["task"]){ } if ( $result = $db->doQuery($sql) ){ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=" . $_GET["goto"]); + header("Location: ".DOMAIN."?page=" . $_GET["goto"]); $c->flush(); } break; @@ -143,7 +143,7 @@ switch($_GET["task"]){ } if ( $result = $db->doQuery($sql) ){ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=liste"); + header("Location: ".DOMAIN."?page=liste"); $c->flush(); exit; } else { @@ -235,7 +235,7 @@ switch($_GET["task"]){ $body = "Hello, someone requested a new password for '".$result_ar[1]."' on https://jungegemeinde.iamfabulous.de. -The new password is '". $password ."'. Remember to change it immediately at https://jungegemeinde.iamfabulous.de/?page=account after successfull login. +The new password is '". $password ."'. Remember to change it immediately at ".DOMAIN."?page=account after successfull login. Kindly regards, JG Adlershof"; diff --git a/bootstrap.php b/bootstrap.php index 098288b..bb82db1 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -18,12 +18,17 @@ if ( ! defined('SCHEME') ){ # hostname if ( ! defined('HOST') ) define('HOST', $_SERVER['HTTP_HOST']); +if ( ! defined('URI') ) + define('URI', '/'); if ( ! defined('DOMAIN') ) - define('DOMAIN', SCHEME . HOST); + define('DOMAIN', SCHEME . HOST . URI); +if ( ! define('CDN') ){ + define('CDN', DOMAIN); +} define('PROTECTED_BASE', 'protected/'); define('IMAGE_PATH', ABSPATH . PROTECTED_BASE); - define('IMAGE_URL' , DOMAIN . '/images/'); + define('IMAGE_URL' , DOMAIN . 'images/'); # define session name if ( ! defined('SESSION') ) diff --git a/cdn/originpull.php b/cdn/originpull.php new file mode 100644 index 0000000..00f9a03 --- /dev/null +++ b/cdn/originpull.php @@ -0,0 +1,82 @@ +file($file); + + # hack to get correct mime type for .css and .js + $ext = pathinfo($file,PATHINFO_EXTENSION); + switch($ext){ + case 'css': + $mime = "text/css"; + break; + case'js': + $mime = "text/javascript"; + break; + default: + break; + } + + return $mime; +} + +foreach($basepath as $dir){ + + if ( URI . $dir . "/" == $path_parts['dirname'] . '/' ){ + + if ( !is_dir(ABSP . $dir) ){ + mkdir(ABSP . $dir, 0744, true); + } + + $request = str_replace(URI . $dir . "/", "",$_GET['url'] ); + $scan = array_diff( scandir($dir), array('.', '..') ); + + if ( in_array($request, $scan) ){ + header("Content-type: " . getMime($dir . '/' . $request)); + header("X-Accel-Redirect: " . LOCAL . $dir . '/' . $request); + exit; + } else { + $ch = curl_init(ORIGIN . $dir . "/" . $request); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_USERAGENT, 'Origin Pull/v0.1'); + curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ( $httpcode == 200 || $httpcode == 302 ) { + file_put_contents($dir . '/' . $request, file_get_contents(ORIGIN . $dir . "/" . $request) ); + header("Content-type: " . getMime($dir . '/' . $request)); + header("X-Accel-Redirect: " . LOCAL . $dir . '/' . $request); + exit; + } else { + continue; + } + } + } + +} + +header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found"); +header('X-Cache: Miss'); diff --git a/config-sample.php b/config-sample.php index 9535f54..23b947a 100644 --- a/config-sample.php +++ b/config-sample.php @@ -31,7 +31,8 @@ if ( ! defined('SESSION') ) ### hostname # define('HOST', 'jungegemeinde.iamfabulous.de'); -# define('DOMAIN', 'https://jungegemeinde.iamfabulous.de'); +# define('URI', '/jungegemeinde'); +# define('DOMAIN', 'https://jungegemeinde.iamfabulous.de/jg/'); #define('INVITEKEY', 'fadfhaoshfasodfhioadsfhadsofhpf'); define('INVITEKEY', 'secretkey'); diff --git a/functions.php b/functions.php index 17c2ce3..25c22b8 100644 --- a/functions.php +++ b/functions.php @@ -9,7 +9,7 @@ function lredirect($goto){ function redirect($goto){ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: /?page=".$goto); + header("Location: ".DOMAIN."?page=".$goto); ob_clean(); exit; } @@ -49,7 +49,7 @@ if( isset($_GET["goto"]) && $_GET["goto"] != "" ) { redirect("index"); } ?> -
+
@@ -105,7 +105,7 @@ if( isset($_GET["goto"]) && $_GET["goto"] != "" ) {

Mit * markierte Felder sind Pflichtfelder.

isLoggedIn() ){ $user->logout(); header($_SERVER["SERVER_PROTOCOL"] . " 301 Moved"); - header("Location: ".DOMAIN."/?page=logout"); + header("Location: ".DOMAIN."?page=logout"); } print_login("logout"); } @@ -129,7 +129,7 @@ function print_index(){
- praing kitten + praing kitten

@@ -149,7 +149,7 @@ function print_list($option = false){ global $moar; $moar->addHeader(''); - $moar->addFooter(' + $moar->addFooter(' '); + $moar->addFooter(''); if ( isset($_GET["edit"]) ){ $moar->addFooter(''); @@ -753,15 +753,15 @@ function show_gallery(){ } if ( $tab == $_GET["mode"] ) - echo '
  • '.$span.$msg.'
  • '; + echo '
  • '.$span.$msg.'
  • '; else - echo '
  • '.$span.$msg.'
  • '; + echo '
  • '.$span.$msg.'
  • '; } ?>
  • Ändern
  • Neu
  • Löschen
  • -
  • " role="tab"> +
  • " role="tab"> exists2(CACHEPREFIX . $_GET["gallery"]) ) $c->set2(CACHEPREFIX . $_GET["gallery"], $row['name']); ?> Download
  • @@ -835,8 +835,8 @@ function show_gallery(){ addFooter(''); - //$moar->addFooter(''); + $moar->addFooter(''); + //$moar->addFooter(''); if ( $c->exists2(CACHEPREFIX . "gallery_no_download_" . $_SESSION["gallery"]) ) $moar->addFooter(' - + diff --git a/static/header.php b/static/header.php index 69a9c4b..824d4c1 100644 --- a/static/header.php +++ b/static/header.php @@ -7,20 +7,20 @@ - Home + Home