You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.inc.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Postfixadmin (http://postfixadmin.sf.net) integration with Squirrelmail.
  4. * See http://squirrelmail-postfixadmin.palepurple.co.uk
  5. * @author David Goodwin and many others
  6. */
  7. function do_header() {
  8. global $color;
  9. displayPageHeader($color, 'None');
  10. }
  11. function do_footer() {
  12. echo "</body></html>";
  13. }
  14. function _display_password_form() {
  15. bindtextdomain('postfixadmin', SM_PATH . 'plugins/postfixadmin/locale');
  16. textdomain('postfixadmin');
  17. do_header('Postfixadmin Squirrelmail - Login');
  18. echo _('The PostfixAdmin plugin needs your current mailbox password');
  19. echo "<form action='' method='post'>";
  20. echo _('Password for');
  21. echo " " . $_SESSION['username'] . " :";
  22. echo "<input type='password' name='password' value=''>";
  23. echo "<input type='submit' value='" . _('Submit') . "'></form>";
  24. do_footer();
  25. }
  26. /**
  27. * This returns a Zend_XmlRpc_Client instance - unless we can't log you in...
  28. */
  29. function get_xmlrpc() {
  30. global $CONF;
  31. require_once('Zend/XmlRpc/Client.php');
  32. $client = new Zend_XmlRpc_Client($CONF['xmlrpc_url']);
  33. $http_client = $client->getHttpClient();
  34. $http_client->setCookieJar();
  35. $login_object = $client->getProxy('login');
  36. if (empty($_SESSION['password'])) {
  37. if (empty($_POST['password'])) {
  38. _display_password_form();
  39. exit(0);
  40. } else {
  41. try {
  42. $success = $login_object->login($_SESSION['username'], $_POST['password']);
  43. } catch (Exception $e) {
  44. //var_dump($client->getHttpClient()->getLastResponse()->getBody());
  45. error_log("Failed to login to xmlrpc instance - " . $e->getMessage());
  46. die('Failed to login to xmlrpc instance');
  47. }
  48. if ($success) {
  49. $_SESSION['password'] = $_POST['password'];
  50. // reload the current page as a GET request.
  51. header("Location: {$_SERVER['REQUEST_URI']}");
  52. exit(0);
  53. } else {
  54. _display_password_form();
  55. exit(0);
  56. }
  57. }
  58. } else {
  59. $success = $login_object->login($_SESSION['username'], $_SESSION['password']);
  60. }
  61. if (!$success) {
  62. unset($_SESSION['password']);
  63. die("Invalid details cached... refresh this page and re-enter your mailbox password");
  64. }
  65. return $client;
  66. }
  67. function include_if_exists($filename) {
  68. if (file_exists($filename)) {
  69. include_once($filename);
  70. }
  71. return;
  72. }
  73. global $optmode;
  74. $optmode = 'display';
  75. //
  76. // check_email
  77. // Action: Checks if email is valid and returns TRUE if this is the case.
  78. // Call: check_email (string email)
  79. //
  80. function check_email($email) {
  81. $return = filter_var($email, FILTER_VALIDATE_EMAIL);
  82. if ($return === false) {
  83. return false;
  84. }
  85. return true;
  86. }