File: Application.php

package info (click to toggle)
php-horde 5.2.1%2Bdebian0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 12,196 kB
  • sloc: php: 11,089; xml: 6,460; sh: 96; makefile: 33; sql: 1
file content (352 lines) | stat: -rw-r--r-- 12,252 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
/**
 * Horde application API.
 *
 * This file defines Horde's core API interface. Other core Horde libraries
 * can interact with Horde through this API.
 *
 * Copyright 2010-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @category  Horde
 * @copyright 2010-2014 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl LGPL-2
 * @package   Horde
 */

/* Load the Horde Framework core (needed to autoload
 * Horde_Registry_Application::). */
require_once __DIR__ . '/core.php';

class Horde_Application extends Horde_Registry_Application
{
    /**
     */
    public $version = '5.2.1';

    /**
     */
    public $features = array(
        'smartmobileView' => true
    );

    /**
     */
    public function logout()
    {
        // Destroy any session-only temp files (since Horde_Core 1.7.0).
        foreach ($GLOBALS['session']->get('horde', 'gc_tempfiles', Horde_Session::TYPE_ARRAY) as $file) {
            @unlink($file);
        }
    }

    /**
     */
    public function perms()
    {
        $permissions = array(
            'max_blocks' => array(
                'title' => _("Maximum Number of Portal Blocks"),
                'type' => 'int'
            ),
            'administration' => array(
                'title' => _("Administration"),
            )
        );

        if (!empty($GLOBALS['conf']['activesync']['enabled'])) {
            $this->_addActiveSyncPerms($permissions);
        }

        try {
            foreach ($GLOBALS['registry']->callByPackage('horde', 'admin_list') as $perm_key => $perm_details) {
                $permissions['administration:' . $perm_key] = array('title' => Horde::stripAccessKey($perm_details['name']));
            }
        } catch (Horde_Exception $e) {/*what to do if this fails?*/}

        return $permissions;
    }

    /**
     */
    public function hasPermission($permission, $allowed, $opts = array())
    {
        if (is_array($allowed)) {
            switch ($permission) {
            case 'max_blocks':
                $allowed = max($allowed);
                break;
            }
        }
        return $allowed;
    }

    /**
     */
    public function configSpecialValues($what)
    {
        switch ($what) {
        case 'apps':
            $apps = Horde_Array::valuesToKeys($GLOBALS['registry']->listApps(array('active')));
            asort($apps);
            return $apps;

        case 'languages':
            $convert_numeric = function($num) {
                return Horde_String::convertCharset(pack('H*', $num[1]),
                                                    'ucs-2',
                                                    'UTF-8');
            };
            $convert_symbolic = function($symbol) {
                return Horde_String::convertCharset(
                    html_entity_decode($symbol[1], ENT_COMPAT, 'iso-8859-1'),
                    'iso-8859-1',
                    'UTF-8');
            };
            return array_map(
                function($val) {
                    return preg_replace_callback(
                        array('/&#x([0-9a-f]{4});/i',
                              '/(&[^;]+;)/'),
                        array($convert_numeric,
                              $convert_symbolic),
                        $val
                    );
                },
                $GLOBALS['registry']->nlsconfig->languages
            );

        case 'blocks':
            return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlocksList();

        case 'mapsources':
            return array(
                'Google' => 'Google',
                'Bing' => 'Bing',
                'Yahoo' => 'Yahoo',
                'Cloudmade' => 'CloudMade',
                // @TODO: API has evidently changed somewhat. Disable until
                // I can get an API key to fully test.
                'Mytopo' => 'MyTopo',
                'Osm' => 'OpenStreetMap',
                'Ocm' => 'OpenCycleMap',
                'Mapquest' => 'OpenMapquest'
            );

        case 'geocoders':
            return array(
                'None' => null,
                'Google' => 'Google',
                'Yahoo' => 'Yahoo'
            );
        }
    }

    /**
     */
    public function removeUserData($user)
    {
        $error = false;

        /* Remove user from all groups */
        $groups = $GLOBALS['injector']->getInstance('Horde_Group');
        if (!$groups->readOnly()) {
            try {
                $allGroups = $groups->listGroups($user);
                foreach (array_keys($allGroups) as $id) {
                    $groups->removeUser($id, $user);
                }
            } catch (Horde_Group_Exception $e) {
                Horde::log($e, 'NOTICE');
                $error = true;
            }
        }

        /* Remove the user from all application permissions */
        $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
        try {
            $tree = $perms->getTree();
        } catch (Horde_Perms_Exception $e) {
            Horde::log($e, 'NOTICE');
            $error = true;
            $tree = array();
        }

        foreach (array_keys($tree) as $id) {
            try {
                $perm = $perms->getPermissionById($id);
                if ($perms->getPermissions($perm, $user)) {
                    // The Horde_Perms::ALL is used if this is a matrix perm,
                    // otherwise it's ignored in the method and the entry is
                    // totally removed.
                    $perm->removeUserPermission($user, Horde_Perms::ALL, true);
                }
            } catch (Horde_Perms_Exception $e) {
                Horde::log($e, 'NOTICE');
                $error = true;
            }
        }

        // Remove any activesync device pairings.
        if ($GLOBALS['conf']['activesync']['enabled']) {
            try {
                $GLOBALS['injector']->getInstance('Horde_ActiveSyncState')
                    ->removeState(array('user' => $user));
            } catch (Horde_ActiveSync_Exception $e) {
                Horde::log($e, 'NOTICE');
                $error = true;
            }
        }

        if ($error) {
            throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user));
        }
    }

    protected function _addActiveSyncPerms(&$permissions)
    {
        $prefix = 'activesync:provisioning:';

        $permissions['activesync'] = array(
            'title' => _("ActiveSync"),
            'type' => 'boolean'
        );

        $permissions['activesync:max_devices'] = array(
            'title' => _("Maximum number of devices"),
            'type' => 'int'
        );

        $permissions['activesync:provisioning'] = array(
            'title' => _("Provisioning"),
            'type' => 'enum',
            'params' => array(array(
                false => '',
                'true' => _("Enable"),
                'allow' => _("Allow non-provisionable devices"),
                'false' => _("Disable (not recommended)")
            ))
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_PIN] = array(
            'title' => _("Require PIN"),
            'type' => 'boolean'
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_MINLENGTH] = array(
            'title' => _("Minimum PIN length"),
            'type' => 'int'
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_COMPLEXITY] = array(
            'title' => _("Password Complexity"),
            'type' => 'enum',
            'params' => array(array(
                false => '',
                0 => _("Allow only numeric"),
                1 => _("Allow alphanumeric"),
                2 => _("Allow any"))
            )
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_AEFVALUE] = array(
            'title' => _("Seconds of inactivity before device should lock"),
            'type' => 'int'
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_MAXFAILEDATTEMPTS] = array(
            'title' => _("Failed unlock attempts before device is wiped"),
            'type' => 'int'
        );

        $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_CODEFREQ] = array(
            'title' => _("Codeword frequency"),
            'type' => 'int'
        );

        // EAS 12.0 and above.
        if ($GLOBALS['conf']['activesync']['version'] >= Horde_ActiveSync::VERSION_TWELVE) {
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ATC] = array(
                'title' => _("Attachment Download"),
                'type' => 'boolean'
            );

            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_MAXATCSIZE] = array(
                'title' => _("Maximum attachment size in bytes"),
                'type' => 'int'
            );

            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ENCRYPTION] = array(
                'title' => _("SD card encryption"),
                'type' => 'boolean'
            );
        }

        if ($GLOBALS['conf']['activesync']['version'] > Horde_ActiveSync::VERSION_TWELVE) {
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_SDCARD] = array(
                'title' => _("SD card"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_CAMERA] = array(
                'title' => _("Camera"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_SMS] = array(
                'title' => _("SMS Text messages"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_WIFI] = array(
                'title' => _("Wifi"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_BLUETOOTH] = array(
                'title' => _("Bluetooth"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_POPIMAP] = array(
                'title' => _("POP/IMAP Email accounts"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_BROWSER] = array(
                'title' => _("Web browser"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_REQUIRE_SMIME_ENCRYPTED] = array(
                'title' => _("Require S/MIME Encryption"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_REQUIRE_SMIME_SIGNED] = array(
                'title' => _("Require S/MIME Signature"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_DEVICE_ENCRYPTION] = array(
                'title' => _("Device encryption"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ALLOW_HTML] = array(
                'title' => _("HTML Email"),
                'type' => 'boolean'
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_MAX_EMAIL_AGE] = array(
                'title' => _("Maximum Email age"),
                'type' => 'enum',
                'params' => array(array(
                    false => '',
                    0 => _("Sync all"),
                    1 => _("1 Day"),
                    2 => _("3 Days"),
                    3 => _("1 Week"),
                    4 => _("2 Weeks"),
                    5 => _("1 Month"))
                )
            );
            $permissions[$prefix . Horde_ActiveSync_Policies::POLICY_ROAMING_NOPUSH] = array(
                'title' => _("No push while roaming"),
                'type' => 'boolean'
            );
        }
    }

}