remove old network class from Trunk/16.1

This commit is contained in:
Ralf Becker 2016-02-01 12:50:34 +00:00
parent cd9b6b77fe
commit b137f4710c
3 changed files with 15 additions and 383 deletions

View File

@ -41,6 +41,8 @@
* eGroupWare datetime class that contains common date/time functions * eGroupWare datetime class that contains common date/time functions
* *
* renamed to egw_datetime to support php5.2 * renamed to egw_datetime to support php5.2
*
* @deprecated use egw_time class!!
*/ */
class egw_datetime class egw_datetime
{ {
@ -566,27 +568,14 @@
var $users_localtime; var $users_localtime;
var $cv_gmtdate; var $cv_gmtdate;
/**
* Calling the constructor of the renamed class
*
* @return egw_datetime
*/
function datetime()
{
return $this->egw_datetime();
}
/** /**
* Constructor of the renamed class * Constructor of the renamed class
*
* @return egw_datetime
*/ */
function egw_datetime() function __construct()
{ {
$this->tz_offset = 3600 * @$GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; $this->tz_offset = 3600 * @$GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
print_debug('datetime::datetime::gmtnow',$this->gmtnow,'api'); print_debug('datetime::datetime::gmtnow',$this->gmtnow,'api');
$error_occured = True;
// If we already have a GMT time, no need to do this again. // If we already have a GMT time, no need to do this again.
if(!$this->gmtnow) if(!$this->gmtnow)
{ {
@ -597,98 +586,21 @@
} }
else else
{ {
$this->gmtnow = time() - ($this->getbestguess() * 3600); $this->gmtnow = time() - date('Z');
print_debug('datetime::datetime::bestguess',"set via bestguess=".$this->getbestguess().": gmtnow=".date('Y/m/d H:i',$this->gmtnow),'api'); print_debug('datetime::datetime::bestguess',"set via date('Z')=".date('Z').": gmtnow=".date('Y/m/d H:i',$this->gmtnow),'api');
} }
} }
$this->users_localtime = time() + $this->tz_offset; $this->users_localtime = time() + $this->tz_offset;
} }
function getntpoffset() /**
* Calling the constructor of the renamed class
*
* @return egw_datetime
*/
function datetime()
{ {
$error_occured = False; return $this->__construct();
if(!@is_object($GLOBALS['egw']->network))
{
$GLOBALS['egw']->network = createobject('phpgwapi.network');
}
$server_time = time();
if($GLOBALS['egw']->network->open_port('129.6.15.28',13,5))
{
$line = $GLOBALS['egw']->network->bs_read_port(64);
$GLOBALS['egw']->network->close_port();
$array = explode(' ',$line);
// host: 129.6.15.28
// Value returned is 52384 02-04-20 13:55:29 50 0 0 9.2 UTC(NIST) *
print_debug('Server datetime',time(),'api');
print_debug('Temporary NTP datetime',$line,'api');
if ($array[5] == 4)
{
$error_occured = True;
}
else
{
$date = explode('-',$array[1]);
$time = explode(':',$array[2]);
$this->gmtnow = mktime((int)$time[0],(int)$time[1],(int)$time[2],(int)$date[1],(int)$date[2],(int)$date[0] + 2000);
print_debug('Temporary RFC epoch',$this->gmtnow,'api');
print_debug('GMT',date('Ymd H:i:s',$this->gmtnow),'api');
}
}
else
{
$error_occured = True;
}
if($error_occured == True)
{
return $this->getbestguess();
}
else
{
return (int)(($server_time - $this->gmtnow) / 3600);
}
}
function gethttpoffset()
{
$error_occured = False;
if(!@is_object($GLOBALS['egw']->network))
{
$GLOBALS['egw']->network = createobject('phpgwapi.network');
}
$server_time = time();
$filename = 'http://132.163.4.213/timezone.cgi?GMT';
$file = $GLOBALS['egw']->network->gethttpsocketfile($filename);
if(!$file)
{
return $this->getbestguess();
}
$time = strip_tags($file[55]);
$date = strip_tags($file[56]);
print_debug('GMT DateTime',$date.' '.$time,'api');
$dt_array = explode(' ',$date);
$temp_datetime = $dt_array[0].' '.substr($dt_array[2],0,-1).' '.substr($dt_array[1],0,3).' '.$dt_array[3].' '.$time.' GMT';
print_debug('Reformulated GMT DateTime',$temp_datetime,'api');
$this->gmtnow = $this->convert_rfc_to_epoch($temp_datetime);
print_debug('this->gmtnow',$this->gmtnow,'api');
print_debug('server time',$server_time,'api');
print_debug('server DateTime',date('D, d M Y H:i:s',$server_time),'api');
return (int)(($server_time - $this->gmtnow) / 3600);
}
function getbestguess()
{
print_debug('datetime::datetime::debug: Inside getting from local server','api');
$server_time = time();
// Calculate GMT time...
// If DST, add 1 hour...
// - (date('I') == 1?3600:0)
$this->gmtnow = $this->convert_rfc_to_epoch(gmdate('D, d M Y H:i:s',$server_time).' GMT');
return (int)(($server_time - $this->gmtnow) / 3600);
} }
function convert_rfc_to_epoch($date_str) function convert_rfc_to_epoch($date_str)
@ -998,4 +910,3 @@
return $this->localdates($localtime - $this->tz_offset); return $this->localdates($localtime - $this->tz_offset);
} }
} }
?>

View File

@ -1,265 +0,0 @@
<?php
/**************************************************************************\
* eGroupWare API - Network *
* This file written by Mark Peters <skeeter@phpgroupware.org> *
* Handles opening network socket connections, taking proxy into account *
* Copyright (C) 2000, 2001 Mark Peters *
* ------------------------------------------------------------------------ *
* This library is part of the eGroupWare API *
* http://www.egroupware.org/api *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class network
{
var $socket;
var $addcrlf = TRUE;
var $error;
var $errorset = 0;
function network($addcrlf=true)
{
$this->errorset = 0;
$this->set_addcrlf($addcrlf);
}
function set_addcrlf($value)
{
$this->addcrlf = $value;
}
function add_crlf($str)
{
if($this->addcrlf)
{
$str .= "\r\n";
}
return $str;
}
function set_error($code,$msg,$desc)
{
$this->error = array('code','msg','desc');
$this->error['code'] = $code;
$this->error['msg'] = $msg;
$this->error['desc'] = $desc;
// $this->close_port();
$this->errorset = 1;
return 0;
}
function open_port($server,$port,$timeout=15)
{
switch($port)
{
case 80:
case 443:
if((isset($GLOBALS['egw_info']['server']['httpproxy_server']) && $GLOBALS['egw_info']['server']['httpproxy_server']) &&
(isset($GLOBALS['egw_info']['server']['httpproxy_port']) && $GLOBALS['egw_info']['server']['httpproxy_port']))
{
$server = $GLOBALS['egw_info']['server']['httpproxy_server'];
$port = (int)$GLOBALS['egw_info']['server']['httpproxy_port'];
}
break;
}
if(version_compare(phpversion(),'4.3.0') >= 0)
{
$this->socket = @fsockopen($server,$port,$errcode,$errmsg,$timeout);
if($this->socket)
{
stream_set_timeout($this->socket,$timeout,0);
}
}
else
{
$this->socket = @fsockopen($server,$port,$errcode,$errmsg);
}
if(!$this->socket)
{
return $this->set_error('Error',$errcode.':'.$errmsg,'Connection to '.$server.':'.$port.' failed - could not open socket.');
}
else
{
return 1;
}
}
function close_port()
{
return fclose($this->socket);
}
function read_port()
{
return fgets($this->socket, 1024);
}
function bs_read_port($bytes)
{
return fread($this->socket, $bytes);
}
function write_port($str)
{
$ok = fputs($this->socket,$this->add_crlf($str));
if(!$ok)
{
return $this->set_error('Error','Connection Lost','lost connection to server');
}
else
{
return 1;
}
}
function bs_write_port($str,$bytes=0)
{
if($bytes)
{
$ok = fwrite($this->socket,$this->add_crlf($str),$bytes);
}
else
{
$ok = fwrite($this->socket,$this->add_crlf($str));
}
if(!$ok)
{
return $this->set_error('Error','Connection Lost','lost connection to server');
}
else
{
return 1;
}
}
function msg2socket($str,$expected_response,&$response)
{
if(!$this->socket)
{
return $this->set_error('521','socket does not exist',
'The required socket does not exist. The settings for your mail server may be wrong.');
}
if(!$this->write_port($str))
{
if(substr($expected_response,1,1) == '+')
{
return $this->set_error('420','lost connection','Lost connection to pop server.');
}
else
{
return 0;
}
}
$response = $this->read_port();
if(!ereg(strtoupper($expected_response),strtoupper($response)))
{
if(substr($expected_response,1,1) == '+')
{
return $this->set_error('550','','');
}
$pos = strpos(' ',$response);
return $this->set_error(substr($response,0,$pos),
'invalid response('.$expected_response.')',
substr($response,($pos + 1),(strlen($response)-$pos)));
}
else
{
return 1;
}
}
// return contents of a web url as an array (or string) or false if timeout
function gethttpsocketfile($file,$user='',$passwd='',$string=False)
{
$server = str_replace('http://','',$file);
$file = @strstr($server,'/');
$server = str_replace($file,'',$server);
//allows for access to http-auth pages - added by Dave Hall <dave.hall@mbox.com.au>
if(!((empty($user))&&(empty($passwd))))
{
$auth = 'Authorization: Basic '.base64_encode("$user:$passwd")."\r\n";
}
else
{
$auth = '';
}
if($GLOBALS['egw_info']['server']['httpproxy_server'])
{
$proxyAuth = '';
if(!empty($GLOBALS['egw_info']['server']['httpproxy_server_username']))
{
$proxyUsername = $GLOBALS['egw_info']['server']['httpproxy_server_username'];
$proxyPassword = $GLOBALS['egw_info']['server']['httpproxy_server_password'];
$proxyAuth = 'Proxy-Authorization: Basic '.base64_encode("$proxyUsername:$proxyPassword")."\r\n";
}
if($this->open_port($server,80, 15))
{
if(!$this->write_port('GET http://' . $server . $file . ' HTTP/1.0'."\r\n".$proxyAuth.$auth."\r\n\r\n"))
{
return False;
}
$i = 0;
while($line = $this->read_port())
{
if(feof($this->socket))
{
break;
}
$lines[] = $line;
$i++;
}
$this->close_port();
if($string)
{
return implode("\n",$lines);
}
return $lines;
}
else
{
return False;
}
}
else
{
if($this->open_port($server, 80, 30))
{
$lines = array();
if(!$this->write_port('GET '.$file.' HTTP/1.0'."\r\n".'Host: '.$server."\r\nAccept: */*".($auth?"\r\n".$auth:'')."\r\n\r\n"))
{
return 0;
}
while($line = $this->read_port())
{
$lines[] = $line;
}
$this->close_port();
if($string)
{
return implode("\n",$lines);
}
return $lines;
}
else
{
return 0;
}
}
}
}
?>

View File

@ -57,21 +57,7 @@ if(@get_var('submit',Array('POST')) && @$newsettings)
/* Load hook file with functions to validate each config (one/none/all) */ /* Load hook file with functions to validate each config (one/none/all) */
$GLOBALS['egw_setup']->hook('config_validate','setup'); $GLOBALS['egw_setup']->hook('config_validate','setup');
$datetime = CreateObject('phpgwapi.egw_datetime'); $newsettings['tz_offset'] = date('Z')/3600;
switch((int)$newsettings['daytime_port'])
{
case 13:
$newsettings['tz_offset'] = $datetime->getntpoffset();
break;
case 80:
$newsettings['tz_offset'] = $datetime->gethttpoffset();
break;
default:
$newsettings['tz_offset'] = $datetime->getbestguess();
break;
}
unset($datetime);
print_debug('TZ_OFFSET',$newsettings['tz_offset']); print_debug('TZ_OFFSET',$newsettings['tz_offset']);
$GLOBALS['egw_setup']->db->transaction_begin(); $GLOBALS['egw_setup']->db->transaction_begin();