"db_upgrade_0_7_3.sql",
"174" => "db_upgrade_0_7_4.sql",
"175" => "db_upgrade_0_7_5.sql",
"180" => "db_upgrade_0_8_0.sql",
"181" => "db_upgrade_0_8_1.sql",
);
$pwd = WEB_ROOT;
if ($pwd[strlen($pwd)-1] == '/')
$pwd = substr($pwd, 0, -1);
function string2int($str) {
if (is_numeric($str))
return $str;
if (is_string($str)) {
$parts = explode(".", $str);
$str = 0;
for ($i = 0; $i < count($parts); $i++) {
$num = ($i == 0) ? $parts[$i] + 1 : $parts[$i];
$str += (pow(10, count($parts) - $i - 1) * $num);
}
}
return $str;
}
function getServerUrl($root = WEB_ROOT, $cwd = "") {
$root = (! empty($root) && $root[0] == '/') ? substr($root, 1) : $root;
$root = (! empty($root) && $root[strlen($root) - 1] == '/') ? substr($root, 0, -1) : $root;
$cwd = (! empty($cwd) && $cwd[0] == '/') ? substr($cwd, 1) : $cwd;
$cwd = (! empty($cwd) && $cwd[strlen($cwd) - 1] == '/') ? substr($cwd, 0, -1) : $cwd;
//echo var_export($_SERVER, true);
$protocol = ((isset($_SERVER['HTTPS']) && ! empty($_SERVER['HTTPS'])) || (isset($_SERVER['HTTPS']) && strcasecmp("on", $_SERVER['HTTPS']) === 0)
|| (isset($_SERVER['HTTP_SCHEME']) && strcasecmp("https", $_SERVER['HTTP_SCHEME']) === 0)) ? "https" : "http";
//echo "$protocol
";
$server = ($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443)?
$_SERVER['SERVER_NAME'] : $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
$url = (! empty($cwd)) ? "$protocol://$server/$cwd" : "$protocol://$server";
return "$url/$root";
}
function getServerUri() {
return TOP_FOLDER;
}
function createKey($key) {
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$public = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
mcrypt_module_close($td);
/* Create key */
$secret = substr($key, 0, $ks);
return array($secret, $public);
}
function encode($text) {
/* Intialize encryption */
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$iv = $_SESSION['authenticate']->getPublicKey();
$key = $_SESSION['authenticate']->getSecretKey();
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$ciffer = mcrypt_generic($td, $text);
$encrypted = quoted_printable_encode($ciffer);
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $encrypted;
}
function decode($text) {
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$iv = $_SESSION['authenticate']->getPublicKey();
$key = $_SESSION['authenticate']->getSecretKey();
/* Initialize encryption module for decryption */
mcrypt_generic_init($td, $key, $iv);
/* Decrypt encrypted string */
$ciffer = quoted_printable_decode($text);
$decrypted = mdecrypt_generic($td, $ciffer);
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted;
}
function implode_cal($text) {
$infos = explode("\n", $text);
foreach ($infos as $info) {
$row = explode('=', $info);
$result[$row[0]] = $row[1];
}
return $result;
}
// taken from roundcubemail
if (!function_exists("quoted_printable_encode")) {
function quoted_printable_encode($text) {
$length=strlen($text);
for ($whitespace= "", $line=0,$encode= "",
$index=0;$index<$length;$index++) {
$character=substr($text,$index,1);
$order=Ord($character);
$encode=0;
switch($order) {
case 9:
case 32:
if ($header_charset== "") {
$previous_whitespace=$whitespace;
$whitespace=$character;
$character= "";
}
else {
if ($order==32)
$character= "_";
else
$encode=1;
}
break;
case 10:
case 13:
if ($whitespace!= "") {
if ($line+3>75) {
$encoded.= "=\n";
$line=0;
}
$encoded.=sprintf( "=%02X",Ord($whitespace));
$line+=3;
$whitespace= "";
}
$encoded.=$character;
$line=0;
continue 2;
default:
if ($order > 127 || $order < 32 || $character == "="
|| ($character == "?" || $character == "_" ||
$character == "(" || $character== ")"))
$encode=1;
break;
}
if ($whitespace!= "") {
if ($line+1>75) {
$encoded.= "=\n";
$line=0;
}
$encoded.=$whitespace;
$line++;
$whitespace= "";
}
if ($character!= "") {
if($encode) {
$character=sprintf( "=%02X",$order);
$encoded_length=3;
}
else
$encoded_length=1;
if ($line+$encoded_length > 75) {
$encoded.= "=\n";
$line=0;
}
$encoded.=$character;
$line+=$encoded_length;
}
}
if ($whitespace!= "") {
if ($line+3>75)
$encoded.= "=\n";
$encoded.=sprintf( "=%02X",Ord($whitespace));
}
return $encoded;
}
}
function newUpdates() {
global $VERSION, $CURRENT_VERSION;
$con = Persistens::getInstance(DBDRIVER);
try {
$res = $con->getVersion();
}
catch (Exception $e) {
ReportError($e);
}
$version = $res['version'];
$version = string2int($version);
if (! is_numeric($version)) {
ReportError("Invalid version format");
exit;
}
$CURRENT_VERSION = $version;
//file_put_contents('/tmp/updates', string2int($VERSION)." > $version", FILE_APPEND);
return string2int($VERSION) > $version;
}
function upgrade() {
global $VERSION, $PATCH_SET, $CURRENT_VERSION, $PREFIX;
$table = 'backup';
$version = string2int($CURRENT_VERSION);
$con = Persistens::getInstance(DBDRIVER);
try {
$res = $con->getVersion();
}
catch (Exception $e) {
ReportError($e);
exit;
}
if (($num = $con->nextTableNumber('backup')) > 0)
$table .= $num;
if ($version < 173) {
if (($res = $con->execute(
"create table $table as select * from calendar")) !== true) {
ReportError($res);
exit;
}
$rows = $con->getCalendarConfig();
if (! is_array($rows)) {
ReportError($rows);
exit;
}
foreach($rows as $row) {
if (function_exists(quoted_printable_encode))
$ciffer = quoted_printable_encode($row['config']);
else
$ciffer = webcal_quoted_printable_encode($row['config']);
if (($res = $con->execute("begin transaction")) !== true) {
ReportError($res);
exit;
}
if (($res = $con->execute(
"update calendar set config = '$ciffer' where id = " .
$row['id'])) !== true) {
$con->execute("rollback");
ReportError($res."
A backup of your calendar data can be found in table backup");
exit;
}
}
$con->execute("commit");
}
if ($version >= 174) {
// remove pgsql.php from root. Accidentally placed there in release 0.7.4
if (file_exists(TOP_FOLDER."/pgsql.php"))
unlink(TOP_FOLDER."/pgsql.php");
// patch config.inc.php
if (substr(PHP_OS, 0, 3) !== 'WIN') {
$oldcwd = getcwd();
$cwd = TOP_FOLDER.'/install';
chdir($cwd);
if ($version < 181) {
exec("patch -p0 < config.inc.php.patch");
}
if ($version > 180) {
exec("patch -p0 < config.inc.php1.patch");
}
chdir($oldcwd);
}
}
foreach ($PATCH_SET as $set => $file) {
$content = array();
//echo "$set -> $file
";
if ($version < $set) {
//echo $PREFIX."_".$file."
";
if (! file_exists($PREFIX."_".$file))
continue;
$sql = file_get_contents($PREFIX."_".$file);
$raw_lines = explode("\n", $sql);
foreach ($raw_lines as $line) {
if (preg_match("/^--/", $line))
continue;
$content[] = $line;
}
$lines = explode(";", join("\n", $content));
if (count($lines) > 0) {
if (($res = $con->execute("begin transaction")) !== true) {
ReportError($res);
exit;
}
foreach ($lines as $line) {
$line = trim($line);
if (preg_match("/^\s*$/", $line) || preg_match("/^--/", $line))
continue;
if (($res = $con->execute($line)) !== true) {
ReportError($res);
$con->execute("rollback");
exit;
}
}
$con->execute("commit");
}
}
else
continue;
}
}
function ReportError($msg) {
// be sure that the supplied parameter is a string and not empty
if (empty ($msg) || !is_string ($msg)) {
throw new ErrorException ('Invalid parameter supplied to ReportError', 0, E_ERROR);
}
// retrieve error settings
$display = strtolower(ini_get('display_errors'));
$log = strtolower(ini_get('log_errors'));
// check if we're displaying errors
if ($display === 'on' || $display === '1' || $display === 1 || $display === 'true' || $display === true) {
echo $msg;
}
else {
$pwd = WEB_ROOT;
if ($pwd[strlen($pwd)-1] == '/')
$pwd = substr($pwd, 0, -1);
print '
The application has triggered an error which is not
recoverable. The execution has therefore been cancelled.
The error is logged and the webmaster will handle
the error in due time.
To help fix the application you are welcome to notify
the webmaster
by email with a detailed description containing the
following information:
1) What did you do just before this message occurred
2) What did you expect to happen
3) Your browser name and version number.
Logout |
DAViCal Web Calendar - A Web Interface for DAViCal |