| 231 | | function modifyAccount() { |
|---|
| 232 | | |
|---|
| 233 | | // Make sure account was supplied |
|---|
| 234 | | if (!isset($_REQUEST['account'])) { |
|---|
| 235 | | return PEAR::raiseError(_("Error: no account supplied")); |
|---|
| 236 | | } |
|---|
| 237 | | $account = $_REQUEST['account']; |
|---|
| 238 | | |
|---|
| 239 | | // Check privs |
|---|
| 240 | | if (!$this->user->isUserAdmin($account, $this->domain)) { |
|---|
| 241 | | return PEAR::raiseError(_('Error: you do not have edit privileges on domain ') . $this->domain); |
|---|
| 242 | | } |
|---|
| 243 | | |
|---|
| 244 | | // See what user_info to use |
|---|
| 245 | | if ($this->user->isDomainAdmin($this->domain)) { |
|---|
| 246 | | $account_info = $this->user->userInfo($this->domain, $_REQUEST['account']); |
|---|
| 247 | | if (PEAR::isError($account_info)) return $account_info; |
|---|
| 248 | | } else { |
|---|
| 249 | | $account_info = $this->user->loginUser; |
|---|
| 250 | | } |
|---|
| 251 | | |
|---|
| 252 | | // Get .qmail info if it exists |
|---|
| 253 | | try { |
|---|
| 254 | | $dot_qmail = $this->user->readFile($this->domain, $_REQUEST['account'], '.qmail'); |
|---|
| 255 | | } catch (Net_Vpopmaild_Exception $e) { |
|---|
| 256 | | } |
|---|
| 257 | | $defaults = $this->parseHomeDotqmail($dot_qmail, $account_info); |
|---|
| 258 | | $this->user->recordio(print_r($defaults, 1)); |
|---|
| 259 | | $form = $this->modifyAccountForm($account, $defaults); |
|---|
| 260 | | $renderer =& new HTML_QuickForm_Renderer_AssocArray(); |
|---|
| 261 | | $form->accept($renderer); |
|---|
| 262 | | if(isset($_REQUEST['modified'])) { |
|---|
| 263 | | $this->setData('message', _('Account Modified Successfully')); |
|---|
| 264 | | } |
|---|
| 265 | | $this->setData('form', $renderer->toAssocArray()); |
|---|
| 266 | | $this->tplFile = 'modifyAccount.tpl'; |
|---|
| 267 | | return; |
|---|
| 268 | | } |
|---|
| 269 | | |
|---|
| 270 | | private function modifyAccountForm($account, $defaults) { |
|---|
| 271 | | |
|---|
| 272 | | // Language stuff |
|---|
| 273 | | $this->setData('LANG_Modify_Account', _("Modify Account")); |
|---|
| 274 | | $this->setData('LANG_Domain_Menu', _("Domain Menu")); |
|---|
| 275 | | if ($this->user->isDomainAdmin($this->domain)) { |
|---|
| 276 | | $this->setData('isDomainAdmin', 1); |
|---|
| 277 | | $this->setData('LANG_Main_Menu', _("Main Menu")); |
|---|
| 278 | | } |
|---|
| 279 | | $this->setData('account', $account); |
|---|
| 280 | | |
|---|
| 281 | | $form = new HTML_QuickForm('formModifyAccount', 'post', "./?module=Accounts&event=modifyAccountNow&domain={$this->domain}&account=$account"); |
|---|
| 282 | | |
|---|
| 283 | | $form->setDefaults($defaults); |
|---|
| 284 | | |
|---|
| 285 | | $form->addElement('text', 'comment', _("Real Name/Comment")); |
|---|
| 286 | | $form->addElement('password', 'password', _("Password")); |
|---|
| 287 | | $form->addElement('password', 'password2', _("Re-Type Password")); |
|---|
| 288 | | $form->addElement('radio', 'routing', 'Mail Routing', _('Standard (No Forwarding)'), 'routing_standard'); |
|---|
| 289 | | $form->addElement('radio', 'routing', '', _('All Mail Deleted'), 'routing_deleted'); |
|---|
| 290 | | $form->addElement('radio', 'routing', '', _('Forward to:'), 'routing_forwarded'); |
|---|
| 291 | | $form->addElement('text', 'forward'); |
|---|
| 292 | | $form->addElement('checkbox', 'save_a_copy', _('Save A Copy')); |
|---|
| 293 | | |
|---|
| 294 | | $form->addElement('checkbox', 'vacation', _('Send a Vacation Auto-Response')); |
|---|
| 295 | | $form->addElement('text', 'vacation_subject', _('Vacation Subject:')); |
|---|
| 296 | | $form->addElement('textarea', 'vacation_body', _('Vacation Message:'), 'rows="10" cols="40"'); |
|---|
| 297 | | $form->addElement('submit', 'submit', _('Modify Account')); |
|---|
| 298 | | |
|---|
| 299 | | $form->addRule(array('password', 'password2'), _('The passwords do not match'), 'compare', null, 'client'); |
|---|
| 300 | | $form->addRule('routing', _('Please select a mail routing type'), 'required', null, 'client'); |
|---|
| 301 | | $form->addRule('forward', _('"Forward to" must be a valid email address'), 'email', null, 'client'); |
|---|
| 302 | | |
|---|
| 303 | | return $form; |
|---|
| 304 | | } |
|---|
| 305 | | |
|---|
| 306 | | |
|---|
| 307 | | function modifyAccountNow() { |
|---|
| 308 | | |
|---|
| 309 | | // Make sure account was supplied |
|---|
| 310 | | if (!isset($_REQUEST['account'])) { |
|---|
| 311 | | return PEAR::raiseError(_("Error: no account supplied")); |
|---|
| 312 | | } |
|---|
| 313 | | $account = $_REQUEST['account']; |
|---|
| 314 | | |
|---|
| 315 | | // Check privs |
|---|
| 316 | | if (!$this->user->isUserAdmin($account, $this->domain)) { |
|---|
| 317 | | return PEAR::raiseError(_('Error: you do not have edit privileges on domain ') . $this->domain); |
|---|
| 318 | | } |
|---|
| 319 | | |
|---|
| 320 | | // See what user_info to use |
|---|
| 321 | | $account_info = $this->user->userInfo($this->domain, $_REQUEST['account']); |
|---|
| 322 | | if (PEAR::isError($account_info)) { |
|---|
| 323 | | return $account_info; |
|---|
| 324 | | } |
|---|
| 325 | | |
|---|
| 326 | | // Get .qmail info if it exists |
|---|
| 327 | | try { |
|---|
| 328 | | $dot_qmail = $this->user->readFile($this->domain, $_REQUEST['account'], '.qmail'); |
|---|
| 329 | | } catch (Net_Vpopmaild_Exception $e) { |
|---|
| 330 | | } |
|---|
| 331 | | $defaultsOrig = $this->parseHomeDotqmail($dot_qmail, $account_info); |
|---|
| 332 | | $form = $this->modifyAccountForm($account, $defaultsOrig); |
|---|
| 333 | | if (!$form->validate()) { |
|---|
| 334 | | $this->setData('message', _("Error Modifying Account")); |
|---|
| 335 | | $renderer =& new HTML_QuickForm_Renderer_AssocArray(); |
|---|
| 336 | | $form->accept($renderer); |
|---|
| 337 | | $this->setData('form', $renderer->toAssocArray()); |
|---|
| 338 | | $this->tplFile = 'modifyAccount.tpl'; |
|---|
| 339 | | return; |
|---|
| 340 | | } |
|---|
| 341 | | |
|---|
| 342 | | // Determine new routing |
|---|
| 343 | | $routing = ''; |
|---|
| 344 | | $save_a_copy = 0; |
|---|
| 345 | | if ($_REQUEST['routing'] == 'routing_standard') { |
|---|
| 346 | | $routing = 'standard'; |
|---|
| 347 | | } else if ($_REQUEST['routing'] == 'routing_deleted') { |
|---|
| 348 | | $routing = 'deleted'; |
|---|
| 349 | | } else if ($_REQUEST['routing'] == 'routing_forwarded') { |
|---|
| 350 | | if (empty($_REQUEST['forward'])) { |
|---|
| 351 | | $this->setData('message', _('Error: you must supply a forward address')); |
|---|
| 352 | | return $this->modifyAccount(); |
|---|
| 353 | | } else { |
|---|
| 354 | | $forward = $_REQUEST['forward']; |
|---|
| 355 | | } |
|---|
| 356 | | $routing = 'forwarded'; |
|---|
| 357 | | if (isset($_REQUEST['save_a_copy'])) $save_a_copy = 1; |
|---|
| 358 | | } else { |
|---|
| 359 | | $this->setData('message', _('Error: unsupported routing selection')); |
|---|
| 360 | | return $this->modifyAccount(); |
|---|
| 361 | | } |
|---|
| 362 | | |
|---|
| 363 | | // Check for vacation |
|---|
| 364 | | $vacation = 0; |
|---|
| 365 | | if (isset($_REQUEST['vacation']) && $_REQUEST['vacation'] == 1) { |
|---|
| 366 | | $vacation = 1; |
|---|
| 367 | | $vacation_subject = $_REQUEST['vacation_subject']; |
|---|
| 368 | | $vacation_body = $_REQUEST['vacation_body']; |
|---|
| 369 | | } |
|---|
| 370 | | |
|---|
| 371 | | // Are we deleting a vacation message? |
|---|
| 372 | | if ($vacation == 0 && $defaultsOrig['vacation'] == ' checked') { |
|---|
| 373 | | // Kill old message |
|---|
| 374 | | $this->user->rmDir($this->domain, $account_info['name'], 'vacation'); |
|---|
| 375 | | } |
|---|
| 376 | | |
|---|
| 377 | | // Build .qmail contents |
|---|
| 378 | | $dot_qmail_contents = ''; |
|---|
| 379 | | if ($routing == 'deleted') { |
|---|
| 380 | | $dot_qmail_contents = "# delete"; |
|---|
| 381 | | } else if ($routing == 'forwarded') { |
|---|
| 382 | | $dot_qmail_contents = "&$forward"; |
|---|
| 383 | | if ($save_a_copy == 1) $dot_qmail_contents .= "\n./Maildir/"; |
|---|
| 384 | | } |
|---|
| 385 | | |
|---|
| 386 | | if ($vacation == 1) { |
|---|
| 387 | | if (strlen($dot_qmail_contents) > 0) $dot_qmail_contents .= "\n"; |
|---|
| 388 | | $vacation_dir = $account_info['user_dir'] . '/vacation'; |
|---|
| 389 | | $dot_qmail_contents .= '| ' . $this->user->vpopmailRobotProgram; |
|---|
| 390 | | $dot_qmail_contents .= ' ' . $this->user->vpopmailRobotTime; |
|---|
| 391 | | $dot_qmail_contents .= ' ' . $this->user->vpopmailRobotNumber; |
|---|
| 392 | | $dot_qmail_contents .= " $vacation_dir/message $vacation_dir"; |
|---|
| 393 | | } |
|---|
| 394 | | |
|---|
| 395 | | $dot_qmail_file = '.qmail'; |
|---|
| 396 | | if (strlen($dot_qmail_contents) > 0) { |
|---|
| 397 | | $contents = explode("\n", $dot_qmail_contents); |
|---|
| 398 | | // Write .qmail file |
|---|
| 399 | | $result = $this->user->writeFile($contents, $this->domain, $account_info['name'], $dot_qmail_file); |
|---|
| 400 | | |
|---|
| 401 | | // Add vacation files |
|---|
| 402 | | if ($vacation == 1) { |
|---|
| 403 | | $vcontents = "From: " . $account_info['name'] . "@{$this->domain}\n"; |
|---|
| 404 | | $vcontents .= "Subject: $vacation_subject\n\n"; |
|---|
| 405 | | $vcontents .= $vacation_body; |
|---|
| 406 | | $contents = explode("\n", $vcontents); |
|---|
| 407 | | $vdir = 'vacation'; |
|---|
| 408 | | $message = 'vacation/message'; |
|---|
| 409 | | // Delete existing file |
|---|
| 410 | | try { |
|---|
| 411 | | $this->user->rmDir($this->domain, $account_info['name'], $vdir); |
|---|
| 412 | | } catch (Net_Vpopmaild_Exception $e) { |
|---|
| 413 | | } |
|---|
| 414 | | // Make vacation directory |
|---|
| 415 | | $result = $this->user->mkDir($this->domain, $account_info['name'], $vdir); |
|---|
| 416 | | // Write vacation message |
|---|
| 417 | | $result = $this->user->writeFile($contents, $this->domain, $account_info['name'], $message); |
|---|
| 418 | | } |
|---|
| 419 | | } else { |
|---|
| 420 | | try { |
|---|
| 421 | | $this->user->rmFile($this->domain, $account_info['name'], $dot_qmail_file); |
|---|
| 422 | | } catch (Net_Vpopmaild_Exception $e) { |
|---|
| 423 | | } |
|---|
| 424 | | } |
|---|
| 425 | | |
|---|
| 426 | | $url = "./?module=Accounts&event=modifyAccount&domain={$this->domain}&account={$account_info['name']}&modified=1"; |
|---|
| 427 | | header("Location: $url"); |
|---|
| 428 | | return $this->modifyAccount(); |
|---|
| 429 | | } |
|---|
| 430 | | |
|---|
| 431 | | /** |
|---|
| 432 | | * Parse Home dot-qmail |
|---|
| 433 | | * |
|---|
| 434 | | * Evaluate contents of a .qmail file in a user's home directory. |
|---|
| 435 | | * Looking for routing types standard, delete, or forward, with optional |
|---|
| 436 | | * saving of messages, as well as vacation messages. |
|---|
| 437 | | * |
|---|
| 438 | | * @param mixed $contents .qmail contents |
|---|
| 439 | | * @param mixed $account_info user account info |
|---|
| 440 | | * |
|---|
| 441 | | * @access protected |
|---|
| 442 | | * @return array $defaults |
|---|
| 443 | | */ |
|---|
| 444 | | protected function parseHomeDotqmail($contents, $account_info) |
|---|
| 445 | | { |
|---|
| 446 | | $is_standard = false; |
|---|
| 447 | | $is_deleted = false; |
|---|
| 448 | | $is_forwarded = false; |
|---|
| 449 | | // Set default template settings |
|---|
| 450 | | $defaults['comment'] = $account_info['comment']; |
|---|
| 451 | | $defaults['forward'] = ''; |
|---|
| 452 | | $defaults['save_a_copy'] = ''; |
|---|
| 453 | | $defaults['vacation'] = ''; |
|---|
| 454 | | $defaults['vacation_subject'] = ''; |
|---|
| 455 | | $defaults['vacation_body'] = ''; |
|---|
| 456 | | if (empty($contents)) { |
|---|
| 457 | | $is_standard = true; |
|---|
| 458 | | } |
|---|
| 459 | | if ((is_array($contents) |
|---|
| 460 | | && count($contents) == 1 |
|---|
| 461 | | && $contents[0] == '# delete')) { |
|---|
| 462 | | $is_deleted = true; |
|---|
| 463 | | } |
|---|
| 464 | | if ($is_standard) { |
|---|
| 465 | | $defaults['routing'] = 'routing_standard'; |
|---|
| 466 | | } else if ($is_deleted) { |
|---|
| 467 | | $defaults['routing'] = 'routing_deleted'; |
|---|
| 468 | | } else { |
|---|
| 469 | | // now let's parse it |
|---|
| 470 | | while (list($key, $val) = each($contents)) { |
|---|
| 471 | | if ($val == $account_info['user_dir'].'/Maildir/' |
|---|
| 472 | | || $val == './Maildir/') { |
|---|
| 473 | | |
|---|
| 474 | | $defaults['save_a_copy'] = ' checked'; |
|---|
| 475 | | continue; |
|---|
| 476 | | } |
|---|
| 477 | | if (preg_match("({$this->user->vpopmailRobotProgram})", $val)) { |
|---|
| 478 | | $vacation_array = $this->user->getVacation($account_info, $val); |
|---|
| 479 | | |
|---|
| 480 | | while (list($vacKey, $vacVal) = each($vacation_array)) { |
|---|
| 481 | | $defaults[$vacKey] = $vacVal; |
|---|
| 482 | | } |
|---|
| 483 | | continue; |
|---|
| 484 | | } else { |
|---|
| 485 | | if (Validate::email(preg_replace('/^&/', '', $val), |
|---|
| 486 | | array('use_rfc822' => 1))) { |
|---|
| 487 | | |
|---|
| 488 | | $is_forwarded = true; |
|---|
| 489 | | $defaults['routing'] = 'routing_forwarded'; |
|---|
| 490 | | $defaults['forward'] = preg_replace('/^&/', '', $val); |
|---|
| 491 | | } |
|---|
| 492 | | } |
|---|
| 493 | | } |
|---|
| 494 | | // See if default routing select applies |
|---|
| 495 | | if (!$is_standard && !$is_deleted && !$is_forwarded) { |
|---|
| 496 | | $defaults['routing'] = 'routing_standard'; |
|---|
| 497 | | } |
|---|
| 498 | | } |
|---|
| 499 | | return $defaults; |
|---|
| 500 | | } |
|---|
| 501 | | |
|---|