├── .htaccess ├── wayback.sh ├── LICENSE └── index.php /.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | RewriteBase / 3 | RewriteRule ^index\.php$ - [L] 4 | RewriteRule . /index.php [L] 5 | -------------------------------------------------------------------------------- /wayback.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p repo/$1 4 | git -C repo/$1 init 5 | 6 | for d in websites/$1/*/ ; do 7 | TS="$(basename $d)" 8 | WILL_CLOBBER=`diff -qr $d repo/$1 | grep differ | wc -l` 9 | 10 | if (( $WILL_CLOBBER > 0 )); then 11 | git -C repo/$1 add . 12 | git -C repo/$1 commit -am "$d" 13 | GIT_DATE=`date -jf "%Y%m%d%H%M%S" $TS +"%s"` 14 | GIT_COMMITTER_DATE="$GIT_DATE" git -C repo/$1 commit --amend --no-edit --date="$GIT_DATE" 15 | fi 16 | 17 | rsync -a $d repo/$1 18 | done 19 | 20 | git -C repo/$1 add . 21 | git -C repo/$1 commit -am "$d" 22 | GIT_DATE=`date -jf "%Y%m%d%H%M%S" $TS +"%s"` 23 | GIT_COMMITTER_DATE="$GIT_DATE" git -C repo/$1 commit --amend --no-edit --date="$GIT_DATE" 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Tyler Hall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | = 0; $i--) { 36 | attempt_read_file($smaller[$i], $url_parts); 37 | } 38 | 39 | for($i = 0; $i < count($bigger); $i++) { 40 | attempt_read_file($bigger[$i], $url_parts); 41 | } 42 | 43 | do404(); 44 | 45 | // ############################################# 46 | 47 | function determine_start_date($url) { 48 | $match = match('/\/(current)\//', $url, 1); 49 | if($match !== false) { 50 | return date('YmdHis'); 51 | } else { 52 | $match = match('/\/([0-9]{8})\//', $url, 1); 53 | if($match !== false) { 54 | return $match . '000000'; 55 | } else { 56 | $match = match('/\/([0-9]{14})\//', $url, 1); 57 | if($match !== false) { 58 | return $match; 59 | } else { 60 | return false; 61 | } 62 | } 63 | } 64 | } 65 | 66 | function generate_smaller_bigger($start_date) { 67 | $ls = scandir(WEB_ROOT); 68 | $smaller = array(); 69 | $bigger = array(); 70 | foreach($ls as $dir) { 71 | if(substr($dir, 0, 1) === '.') { 72 | continue; 73 | } 74 | if(intval($dir) <= intval($start_date)) { 75 | $smaller[] = $dir; 76 | } else { 77 | $bigger[] = $dir; 78 | } 79 | } 80 | return array($smaller, $bigger); 81 | } 82 | 83 | function attempt_read_file($start_date, $url_parts) { 84 | $target = WEB_ROOT . $start_date . @$url_parts['path']; 85 | 86 | if(is_dir($target)) { 87 | if(file_exists($target . '/index.php')) { 88 | error_log($target . '/index.php'); 89 | readfile($target . '/index.php'); 90 | exit; 91 | } 92 | if(file_exists($target . '/index.html')) { 93 | error_log($target . '/index.html'); 94 | readfile($target . '/index.html'); 95 | exit; 96 | } 97 | if(file_exists($target . '/index.htm')) { 98 | error_log($target . '/index.htm'); 99 | readfile($target . '/index.htm'); 100 | exit; 101 | } 102 | 103 | return false; 104 | } 105 | 106 | if(is_readable($target)) { 107 | header('Content-Length: ' . filesize($target)); 108 | readfile($target); 109 | exit; 110 | } 111 | 112 | return false; 113 | } 114 | 115 | function do404() { 116 | http_response_code(404); 117 | exit; 118 | } 119 | 120 | function match($regex, $str, $i = 0) 121 | { 122 | if(preg_match($regex, $str, $match) == 1) 123 | return $match[$i]; 124 | else 125 | return false; 126 | } 127 | --------------------------------------------------------------------------------