1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: if (!defined('INGO_BASE')) {
18: define('INGO_BASE', dirname(__FILE__) . '/..');
19: }
20:
21: if (!defined('HORDE_BASE')) {
22: 23:
24: if (file_exists(INGO_BASE . '/config/horde.local.php')) {
25: include INGO_BASE . '/config/horde.local.php';
26: } else {
27: define('HORDE_BASE', INGO_BASE . '/..');
28: }
29: }
30:
31: 32:
33: require_once HORDE_BASE . '/lib/core.php';
34:
35: 36: 37: 38:
39: class Ingo_Application extends Horde_Registry_Application
40: {
41: 42:
43: public $version = 'H4 (2.0.11-git)';
44:
45: 46: 47: 48: 49: 50:
51: protected function _init()
52: {
53:
54: $GLOBALS['ingo_storage'] = Ingo_Storage::factory();
55:
56:
57: Ingo::createSession();
58:
59:
60: $transport = Ingo::getTransport();
61: if ($transport->supportShares()) {
62: $GLOBALS['ingo_shares'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();
63: $GLOBALS['all_rulesets'] = Ingo::listRulesets();
64:
65:
66: $signature = $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth();
67: if (!$GLOBALS['ingo_shares']->exists($signature)) {
68: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
69: $name = $identity->getValue('fullname');
70: if (trim($name) == '') {
71: $name = $GLOBALS['registry']->getAuth('original');
72: }
73: $share = $GLOBALS['ingo_shares']->newShare($GLOBALS['registry']->getAuth(), $signature, $name);
74: $GLOBALS['ingo_shares']->addShare($share);
75: $GLOBALS['all_rulesets'][$signature] = $share;
76: }
77:
78:
79: $GLOBALS['session']->set('ingo', 'current_share', Horde_Util::getFormData('ruleset', $GLOBALS['session']->get('ingo', 'current_share')));
80: if (!$GLOBALS['session']->get('ingo', 'current_share') ||
81: empty($GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]) ||
82: !$GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
83: $GLOBALS['session']->set('ingo', 'current_share', $signature);
84: }
85: } else {
86: $GLOBALS['ingo_shares'] = null;
87: }
88: }
89:
90: 91:
92: public function perms()
93: {
94: return array(
95: 'allow_rules' => array(
96: 'title' => _("Allow Rules"),
97: 'type' => 'boolean'
98: ),
99: 'max_rules' => array(
100: 'title' => _("Maximum Number of Rules"),
101: 'type' => 'int'
102: )
103: );
104: }
105:
106: 107:
108: public function ($menu)
109: {
110: try {
111: $menu->add(Horde::url('filters.php'), _("Filter _Rules"), 'ingo.png', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
112: $menu->add(Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->link('mail/showWhitelist')), _("_Whitelist"), 'whitelist.png');
113: $menu->add(Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->link('mail/showBlacklist')), _("_Blacklist"), 'blacklist.png');
114: } catch (Horde_Exception $e) {
115: Horde::logMessage($e->getMessage(), 'ERR');
116: }
117:
118: $s_categories = $GLOBALS['session']->get('ingo', 'script_categories');
119:
120: if (in_array(Ingo_Storage::ACTION_VACATION, $s_categories)) {
121: $menu->add(Horde::url('vacation.php'), _("_Vacation"), 'vacation.png');
122: }
123:
124: if (in_array(Ingo_Storage::ACTION_FORWARD, $s_categories)) {
125: $menu->add(Horde::url('forward.php'), _("_Forward"), 'forward.png');
126: }
127:
128: if (in_array(Ingo_Storage::ACTION_SPAM, $s_categories)) {
129: $menu->add(Horde::url('spam.php'), _("S_pam"), 'spam.png');
130: }
131:
132: if ($GLOBALS['session']->get('ingo', 'script_generate') &&
133: (!$GLOBALS['prefs']->isLocked('auto_update') ||
134: !$GLOBALS['prefs']->getValue('auto_update'))) {
135: $menu->add(Horde::url('script.php'), _("_Script"), 'script.png');
136: }
137:
138: if (!empty($GLOBALS['ingo_shares']) && empty($GLOBALS['conf']['share']['no_sharing'])) {
139: $menu->add('#', _("_Permissions"), 'perms.png', null, '', Horde::popupJs(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/shares/edit.php', true), array('params' => array('app' => 'ingo', 'share' => $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth()), 'urlencode' => true)) . 'return false;');
140: }
141: }
142:
143: 144:
145: public function hasPermission($permission, $allowed, $opts = array())
146: {
147: if (is_array($allowed)) {
148: switch ($permission) {
149: case 'allow_rules':
150: $allowed = (bool)count(array_filter($allowed));
151: break;
152:
153: case 'max_rules':
154: $allowed = max($allowed);
155: break;
156: }
157: }
158: return $allowed;
159: }
160:
161: 162:
163: public function removeUserData($user)
164: {
165:
166: try {
167: $GLOBALS['ingo_storage']->removeUserData($user);
168: } catch (Ingo_Exception $e) {
169: Horde::logMessage($e, 'ERR');
170: throw $e;
171: }
172:
173:
174: if (!empty($GLOBALS['ingo_shares'])) {
175:
176: try {
177: $share = $GLOBALS['ingo_shares']->getShare($user);
178: $GLOBALS['ingo_shares']->removeShare($share);
179: } catch (Horde_Share_Exception $e) {
180: Horde::logMessage($e, 'ERR');
181: throw new Ingo_Exception($e);
182: }
183:
184: 185:
186: try {
187: $shares = $GLOBALS['ingo_shares']->listShares($user);
188: foreach ($shares as $share) {
189: $share->removeUser($user);
190: }
191: } catch (Horde_Share_Exception $e) {
192: Horde::logMessage($e, 'ERR');
193: }
194:
195: 196:
197: try {
198: $shares = $GLOBALS['ingo_shares']->listShares($user, array('perm' => Horde_Perms::DELETE,
199: 'attributes' => $user));
200: } catch (Horde_Share_Exception $e) {
201: Horde::logMessage($e, 'ERR');
202: throw new Ingo_Exception($e);
203: }
204:
205: foreach ($shares as $share) {
206: $GLOBALS['ingo_shares']->removeShare($share);
207: }
208: }
209: }
210:
211: 212:
213: public function prefsInit($ui)
214: {
215: if (!$GLOBALS['session']->get('ingo', 'script_generate')) {
216: $ui->suppressGroups[] = 'script';
217: }
218: }
219: }
220: