1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EGroupware: CalDAV/CardDAV/GroupDAV access: hooks eg. preferences |
4
|
|
|
* |
5
|
|
|
* @link http://www.egroupware.org |
6
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
7
|
|
|
* @package api |
8
|
|
|
* @subpackage groupdav |
9
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
10
|
|
|
* @copyright (c) 2010-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de> |
11
|
|
|
* @version $Id$ |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace EGroupware\Api\CalDAV; |
15
|
|
|
|
16
|
|
|
use EGroupware\Api; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* GroupDAV hooks: eg. preferences |
20
|
|
|
*/ |
21
|
|
|
class Hooks |
22
|
|
|
{ |
23
|
|
|
public $public_functions = array( |
24
|
|
|
'log' => true, |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Show GroupDAV preferences link in preferences |
29
|
|
|
* |
30
|
|
|
* @param string|array $args |
31
|
|
|
*/ |
32
|
|
|
public static function menus($args) |
33
|
|
|
{ |
34
|
|
|
$appname = 'groupdav'; |
35
|
|
|
$location = is_array($args) ? $args['location'] : $args; |
36
|
|
|
|
37
|
|
|
if ($location == 'preferences') |
38
|
|
|
{ |
39
|
|
|
$file = array( |
40
|
|
|
'Preferences' => Api\Framework::link('/index.php','menuaction=preferences.preference_settings.index&appname='.$appname), |
41
|
|
|
); |
42
|
|
|
if ($location == 'preferences') |
43
|
|
|
{ |
44
|
|
|
display_section($appname,$file); |
45
|
|
|
} |
46
|
|
|
else |
47
|
|
|
{ |
48
|
|
|
display_sidebox($appname,lang('Preferences'),$file); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* populates $settings for the preferences |
55
|
|
|
* |
56
|
|
|
* @param array|string $hook_data |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
static function settings($hook_data) |
60
|
|
|
{ |
61
|
|
|
$settings = array(); |
62
|
|
|
|
63
|
|
|
if ($hook_data['setup']) |
64
|
|
|
{ |
65
|
|
|
$apps = array('addressbook','calendar','infolog'); |
66
|
|
|
} |
67
|
|
|
else |
68
|
|
|
{ |
69
|
|
|
$apps = array_keys($GLOBALS['egw_info']['user']['apps']); |
70
|
|
|
} |
71
|
|
|
foreach($apps as $app) |
72
|
|
|
{ |
73
|
|
|
$class_name = $app.'_groupdav'; |
74
|
|
|
if (class_exists($class_name, true)) |
75
|
|
|
{ |
76
|
|
|
$settings[] = array( |
77
|
|
|
'type' => 'section', |
78
|
|
|
'title' => $app, |
79
|
|
|
); |
80
|
|
|
$settings += call_user_func(array($class_name,'get_settings'), $hook_data); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$settings[] = array( |
85
|
|
|
'type' => 'section', |
86
|
|
|
'title' => 'Logging / debuging', |
87
|
|
|
); |
88
|
|
|
$settings['debug_level'] = array( |
89
|
|
|
'type' => 'select', |
90
|
|
|
'label' => 'Enable logging', |
91
|
|
|
'name' => 'debug_level', |
92
|
|
|
'help' => 'Enables logging of CalDAV/CardDAV traffic to diagnose problems with devices.', |
93
|
|
|
'values' => array( |
94
|
|
|
'0' => lang('Off'), |
95
|
|
|
'r' => lang('Requests and truncated responses to Apache error-log'), |
96
|
|
|
'f' => lang('Requests and full responses to files directory'), |
97
|
|
|
), |
98
|
|
|
'xmlrpc' => true, |
99
|
|
|
'admin' => false, |
100
|
|
|
'default' => '0', |
101
|
|
|
); |
102
|
|
|
if ($GLOBALS['type'] === 'forced' || $GLOBALS['type'] === 'user' && |
103
|
|
|
$GLOBALS['egw_info']['user']['preferences']['groupdav']['debug-log'] !== 'never') |
104
|
|
|
{ |
105
|
|
|
if ($GLOBALS['type'] === 'user') |
106
|
|
|
{ |
107
|
|
|
$logs = array(); |
108
|
|
|
$relativ_log_dir .= 'groupdav/'.Api\CalDAV::sanitize_filename(Api\Accounts::id2name($hook_data['account_id'])); |
|
|
|
|
109
|
|
|
$log_dir = $GLOBALS['egw_info']['server']['files_dir'].'/'.$relativ_log_dir; |
110
|
|
|
if (file_exists($log_dir) && ($files = scandir($log_dir))) |
111
|
|
|
{ |
112
|
|
|
foreach($files as $log) |
113
|
|
|
{ |
114
|
|
|
if (substr($log, -4) == '.log') |
115
|
|
|
{ |
116
|
|
|
$logs[$relativ_log_dir.'/'.$log] = Api\DateTime::to(filemtime($log_dir.'/'.$log)).': '. |
117
|
|
|
str_replace('!', '/', $log); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
$link = Api\Framework::link('/index.php',array( |
122
|
|
|
'menuaction' => 'api.'.__CLASS__.'.log', |
123
|
|
|
'filename' => '', |
124
|
|
|
)); |
125
|
|
|
$onchange = "egw_openWindowCentered('$link'+encodeURIComponent(this.value), '_blank', 1000, 500); this.value=''"; |
126
|
|
|
} |
127
|
|
|
else // allow to force users to NOT be able to delete their profiles |
128
|
|
|
{ |
129
|
|
|
$logs = array('never' => lang('Never')); |
130
|
|
|
} |
131
|
|
|
$settings['show-log'] = array( |
132
|
|
|
'type' => 'select', |
133
|
|
|
'label' => 'Show log of following device', |
134
|
|
|
'name' => 'show-log', |
135
|
|
|
'help' => lang('You need to set enable logging to "%1" to create/update a log.', |
136
|
|
|
lang('Requests and full responses to files directory')), |
|
|
|
|
137
|
|
|
'values' => $logs, |
138
|
|
|
'xmlrpc' => True, |
139
|
|
|
'admin' => False, |
140
|
|
|
'onchange' => $onchange, |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
return $settings; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Open log window for log-file specified in GET parameter filename (relative to files_dir) |
148
|
|
|
* |
149
|
|
|
* $_GET['filename'] has to be in groupdav sub-dir of files_dir and start with account_lid of current user |
150
|
|
|
* |
151
|
|
|
* @throws Api\Exception\WrongParameter |
152
|
|
|
*/ |
153
|
|
|
public static function log() |
154
|
|
|
{ |
155
|
|
|
$filename = $_GET['filename']; |
156
|
|
|
$matches = null; |
157
|
|
|
if (!preg_match('|^groupdav/'.($GLOBALS['egw_info']['user']['apps']['admin'] ? '[^/]+/' : |
158
|
|
|
preg_quote(Api\CalDAV::sanitize_filename($GLOBALS['egw_info']['user']['account_lid']), '|')).'(.*)\.log$|', $filename, $matches)) |
159
|
|
|
{ |
160
|
|
|
throw new Api\Exception\WrongParameter("Access denied to file '$filename'!"); |
161
|
|
|
} |
162
|
|
|
$GLOBALS['egw_info']['flags']['css'] = ' |
163
|
|
|
body { background-color: #e0e0e0; overflow: hidden; } |
164
|
|
|
pre.tail { background-color: white; padding-left: 5px; margin-left: 5px; } |
165
|
|
|
'; |
166
|
|
|
$tail = new Api\Json\Tail($filename); |
167
|
|
|
$GLOBALS['egw']->framework->render($tail->show(str_replace('!', '/', $matches[1])),false,false); |
168
|
|
|
} |
169
|
|
|
} |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.