Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

functions.inc.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }
  41. else {
  42. try {
  43. $success = $login_object->login($_SESSION['username'], $_POST['password']);
  44. }
  45. catch(Exception $e) {
  46. //var_dump($client->getHttpClient()->getLastResponse()->getBody());
  47. error_log("Failed to login to xmlrpc instance - " . $e->getMessage());
  48. die('Failed to login to xmlrpc instance');
  49. }
  50. if($success) {
  51. $_SESSION['password'] = $_POST['password'];
  52. // reload the current page as a GET request.
  53. header("Location: {$_SERVER['REQUEST_URI']}");
  54. exit(0);
  55. }
  56. else {
  57. _display_password_form();
  58. exit(0);
  59. }
  60. }
  61. }
  62. else {
  63. $success = $login_object->login($_SESSION['username'], $_SESSION['password']);
  64. }
  65. if(!$success) {
  66. unset($_SESSION['password']);
  67. die("Invalid details cached... refresh this page and re-enter your mailbox password");
  68. }
  69. return $client;
  70. }
  71. function include_if_exists($filename) {
  72. if(file_exists($filename)) {
  73. include_once($filename);
  74. }
  75. return;
  76. }
  77. global $optmode;
  78. $optmode = 'display';
  79. //
  80. // check_email
  81. // Action: Checks if email is valid and returns TRUE if this is the case.
  82. // Call: check_email (string email)
  83. //
  84. function check_email($email) {
  85. $return = filter_var($email, FILTER_VALIDATE_EMAIL);
  86. if($return === false) {
  87. return false;
  88. }
  89. return true;
  90. }