|
| 1 | +<?php |
| 2 | +/* |
| 3 | +This script is meant to ease the migration of a webCAT instance to another domain by parsing the workspace cookies |
| 4 | +and redirecting to the share endpoint with multiple workspaces, causing webCAT to assign the history cookie to that new domain. |
| 5 | +Please note, that this method DOES NOT automatically copy the files in the storage directory. |
| 6 | +Also it requires to have the context variable ALLOW_SHARING_HISTORY set to true, to enable mentioned /share/history endpoint. |
| 7 | +*/ |
| 8 | + |
| 9 | +// base location of new webCAT installation |
| 10 | +define("WEBCAT_LOCATION", "https://localhost/"); |
| 11 | +// location to redirect to, with trailing slash and history endpoint path |
| 12 | +define("REDIRECT_LOCATION", WEBCAT_LOCATION . "/rest/history/"); |
| 13 | +// Show information page first and not directly redirect via HTTP header |
| 14 | +define("SHOW_INFO_PAGE", false); |
| 15 | + |
| 16 | +// path of the current workspace |
| 17 | +define("COOKIE_PATH", "combinearchiveweba"); |
| 18 | +// workspace history |
| 19 | +define("COOKIE_HISTORY", "combinearchivewebhist"); |
| 20 | +// user vcard |
| 21 | +define("COOKIE_USER", "combinearchivewebuser"); |
| 22 | + |
| 23 | +// ---------------------------------------------------------------------------- |
| 24 | + |
| 25 | +$success = false; |
| 26 | + |
| 27 | +if( isset($_COOKIE[COOKIE_HISTORY]) and $_COOKIE[COOKIe_HISTORY] != "" ) { |
| 28 | + // history cookie is set -> decode it |
| 29 | + $history = base64_decode($_COOKIE[COOKIE_HISTORY]); |
| 30 | + $history = json_decode($history); |
| 31 | + |
| 32 | + $result = array(); |
| 33 | + foreach( $history as $history_entry ) { |
| 34 | + if( isset($history_entry['current']) and $history_entry['current'] == true ) { |
| 35 | + // this entry is the current workspace entry, so put it on the beginning of the result array |
| 36 | + array_unshift( $result, $history_entry ); |
| 37 | + } |
| 38 | + else { |
| 39 | + // normal, not current, entry. |
| 40 | + array_push( $result, $history_entry ); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + $redirect_url = REDIRECT_LOCATION . implode(",", $result); |
| 45 | + $success = true; |
| 46 | + if( !SHOW_INFO_PAGE ) { |
| 47 | + header("Location", $redirect_url); |
| 48 | + exit(); |
| 49 | + } |
| 50 | +} |
| 51 | +?><!DOCTYPE html> |
| 52 | +<html> |
| 53 | + <head> |
| 54 | + <title>webCAT moved</title> |
| 55 | + <style> |
| 56 | + </style> |
| 57 | + </head> |
| 58 | + |
| 59 | + <body> |
| 60 | + |
| 61 | + </body> |
| 62 | +</html> |
0 commit comments