"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 ' Web Calendar

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.

'; } // check if we're logging errors if ($log === 'on' || $log === '1' || $log === 1 || $log === 'true' || $log === true) { $result = error_log ($msg); // check for error while logging if (!$result) { throw new ErrorException ('Attempt to write message to error log failed in ReportError', 0, E_ERROR); } } } function create_user_data($uid, $pwd, $role) { $data = array(); $data['uid'] = $uid; $data['pwd'] = sha1($pwd); $data['userrole'] = $role; $keys = createKey(sha1("{$data['uid']}{$data['pwd']}")); $data['seckey'] = $keys[0]; $data['pubkey'] = $keys[1]; $data['timezone'] = TIMEZONE; $data['view'] = VIEW_STYLE; $data['timeout'] = TIMEOUT; $data['week_start'] = WEEK_START_SUNDAY; $data['start'] = START_HOUR; $data['end'] = END_HOUR; return $data; } function popup_window($text = '', $redirect = NULL, $form_elem = array(), $title = NULL) { $con = Persistens::getInstance(DBDRIVER); if (! is_array($res = $con->getVersion())) { ErrorReport($res); } $title = ($title) ? $title : TITLE; /* deprecated */ if (count($form_elem) < 1) { $form = NULL; $input = NULL; } else { $form = key($form_elem); $input = $form_elem[$form]; } /* end deprecated */ $referer = ($redirect) ? urldecode($redirect) : WEB_ROOT; //print "$referer
"; //exit; $pwd = WEB_ROOT; $head = <<<__HEAD $title
calendar.png Logout
Logout
DAViCal Web Calendar
- A Web Interface for DAViCal
__HEAD; $display = <<<_DISPLAY
$text


_DISPLAY; $foot = <<<_FOOTER _FOOTER; ob_start(); print $head; include TOP_FOLDER.'/include/menu.inc.php'; print "
 
"; print $foot; print $display; print ""; return ob_get_clean(); } function construct_URL($query_string, $attributes = array()) { $test = trim($query_string); if (empty($test)) return array(); $current = NULL; $query = array(); $query_str = urldecode($query_string); //print "$query_str
"; $q = explode('&', $query_str); //print_r($q); echo "
"; foreach ($q as $elem) { $s = explode('=', $elem); //print_r($s); echo "
"; if (! $current && in_array($s[0], $attributes)) { if (count($s) > 2) { $key = array_shift($s); $value = array_shift($s); $value .= '='; //print "kv: $key $value
"; while ($s) { $value .= array_shift($s); $value .= '&'; $value .= array_shift($s); } $current = $key; } else { $key = array_shift($s); $value = array_shift($s); } $query[$key] = $value; //print_r($query); echo "
"; } else if ($current) { $value = $query[$current]; while ($s) { $value .= array_shift($s); $value .= '='; $value .= array_shift($s); } $query[$current] = $value; $current = NULL; //print_r($query); echo "
"; } else { $key = array_shift($s); $value = array_shift($s); $query[$key] = $value; //print_r($query); echo "
"; } } //print_r($query); echo "
"; //exit; // urlencode if nessasary foreach ($query as $key => $value) { if (strpos($value, '&') !== FALSE) $value = urlencode($value); $query_array[$key] = $value; } return $query_array; } //Begin main function definition function ErrorsAsExceptions($level, $msg, $fileName, $lineNumber) { // do nothing if error reporting is turned off if (error_reporting() === 0) { return; } // be sure received error is supposed to be reported if (error_reporting() & $level) { try { // report error to appropriate channels ReportError(/*$reportMsg*/$msg); } catch (ErrorException $e) { // ignore errors while reporting } // go ahead and throw the exception throw new ErrorException($msg, 0, $level, $fileName, $lineNumber); } } set_error_handler('ErrorsAsExceptions');