1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Ajax_Imple_PassphraseDialog extends Horde_Core_Ajax_Imple
16: {
17: 18: 19: 20: 21:
22: static protected $_passphraseId = 0;
23:
24: 25: 26: 27: 28:
29: protected $_domid;
30:
31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: public function __construct($params)
46: {
47: if (!isset($params['id'])) {
48: $params['id'] = 'imp_passphrase_' . ++self::$_passphraseId;
49: }
50:
51: $this->_domid = $params['id'];
52:
53: parent::__construct($params);
54: }
55:
56: 57: 58:
59: public function attach()
60: {
61: $params = isset($this->_params['params'])
62: ? $this->_params['params']
63: : array();
64: $params['type'] = $this->_params['type'];
65:
66: switch ($this->_params['type']) {
67: case 'pgpPersonal':
68: $text = _("Enter your personal PGP passphrase.");
69: break;
70:
71: case 'pgpSymmetric':
72: $text = _("Enter the passphrase used to encrypt this message.");
73: break;
74:
75: case 'smimePersonal':
76: $text = _("Enter your personal S/MIME passphrase.");
77: break;
78: }
79:
80: if (defined('SID')) {
81: parse_str(SID, $sid);
82: $params = array_merge($params, $sid);
83: }
84:
85: $js_params = array(
86: 'cancel_text' => _("Cancel"),
87: 'ok_text' => _("OK"),
88: 'params' => $params,
89: 'password' => true,
90: 'text' => $text,
91: 'type' => $this->_params['type'],
92: 'uri' => strval($this->_getUrl('PassphraseDialog', 'imp', array('sessionWrite' => 1)))
93: );
94:
95: if (isset($this->_params['reloadurl'])) {
96: $js_params['reloadurl'] = strval($this->_params['reloadurl']);
97: }
98:
99: Horde::addScriptFile('effects.js', 'horde');
100: Horde::addScriptFile('redbox.js', 'horde');
101: Horde::addScriptFile('dialog.js', 'imp');
102:
103: $js = 'IMPDialog.display(' . Horde::escapeJson($js_params, array('urlencode' => true)) . ');';
104:
105: if (empty($this->_params['onload'])) {
106: $js = '$("' . $this->_domid . '").observe("click", function(e) { ' . $js . 'e.stop(); })';
107: }
108:
109: Horde::addInlineScript(array($js), 'dom');
110: }
111:
112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: public function handle($args, $post)
131: {
132: $result = new stdClass;
133: $result->success = 0;
134:
135: $vars = Horde_Variables::getDefaultVariables();
136:
137: try {
138: Horde::requireSecureConnection();
139:
140: switch ($vars->type) {
141: case 'pgpPersonal':
142: case 'pgpSymmetric':
143: if ($vars->dialog_input) {
144: $imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
145: if ((($vars->type == 'pgpPersonal') &&
146: $imp_pgp->storePassphrase('personal', $vars->dialog_input)) ||
147: (($vars->type == 'pgpSymmetric') &&
148: $imp_pgp->storePassphrase('symmetric', $vars->dialog_input, $vars->symmetricid))) {
149: $result->success = 1;
150: } else {
151: $result->error = _("Invalid passphrase entered.");
152: }
153: } else {
154: $result->error = _("No passphrase entered.");
155: }
156: break;
157:
158: case 'smimePersonal':
159: if ($vars->dialog_input) {
160: $imp_smime = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime');
161: if ($imp_smime->storePassphrase($vars->dialog_input)) {
162: $result->success = 1;
163: } else {
164: $result->error = _("Invalid passphrase entered.");
165: }
166: } else {
167: $result->error = _("No passphrase entered.");
168: }
169: break;
170: }
171: } catch (Horde_Exception $e) {
172: $result->error = $e->getMessage();
173: }
174:
175: return Horde::prepareResponse($result);
176: }
177:
178: 179: 180: 181: 182:
183: public function getPassphraseId()
184: {
185: return $this->_domid;
186: }
187:
188: }
189: