Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FetchmailHandler.php 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. # $Id: FetchmailHandler.php 1824 2016-02-04 22:30:06Z christian_boltz $
  3. /**
  4. * Handler for fetchmail jobs
  5. */
  6. class FetchmailHandler extends PFAHandler {
  7. protected $db_table = 'fetchmail';
  8. protected $id_field = 'id';
  9. protected $domain_field = 'domain';
  10. protected $order_by = 'domain, mailbox';
  11. protected function initStruct() {
  12. $src_auth_options = array('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any');
  13. $src_protocol_options = array('POP3','IMAP','POP2','ETRN','AUTO');
  14. $extra = Config::intbool('fetchmail_extra_options');
  15. $this->struct=array(
  16. # field name allow display in... type $PALANG label $PALANG description default / options / ...
  17. # editing? form list
  18. 'id' => pacol( 0, 0, 1, 'num' , '' , '' , '', array(), 0, 1),
  19. 'domain' => pacol( 0, 0, 1, 'text', '' , '' ),
  20. 'mailbox' => pacol( 1, 1, 1, 'enum', 'pFetchmail_field_mailbox' , 'pFetchmail_desc_mailbox' ), # mailbox list
  21. 'src_server' => pacol( 1, 1, 1, 'text', 'pFetchmail_field_src_server' , 'pFetchmail_desc_src_server' ),
  22. 'src_auth' => pacol( 1, 1, 1, 'enum', 'pFetchmail_field_src_auth' , 'pFetchmail_desc_src_auth' , '', $src_auth_options),
  23. 'src_user' => pacol( 1, 1, 1, 'text', 'pFetchmail_field_src_user' , 'pFetchmail_desc_src_user' ),
  24. 'src_password' => pacol( 1, 1, 0, 'b64p', 'pFetchmail_field_src_password' , 'pFetchmail_desc_src_password' ),
  25. 'src_folder' => pacol( 1, 1, 1, 'text', 'pFetchmail_field_src_folder' , 'pFetchmail_desc_src_folder' ),
  26. 'poll_time' => pacol( 1, 1, 1, 'num' , 'pFetchmail_field_poll_time' , 'pFetchmail_desc_poll_time' , 10 ),
  27. 'fetchall' => pacol( 1, 1, 1, 'bool', 'pFetchmail_field_fetchall' , 'pFetchmail_desc_fetchall' ),
  28. 'keep' => pacol( 1, 1, 1, 'bool', 'pFetchmail_field_keep' , 'pFetchmail_desc_keep' ),
  29. 'protocol' => pacol( 1, 1, 1, 'enum', 'pFetchmail_field_protocol' , 'pFetchmail_desc_protocol' , '', $src_protocol_options),
  30. 'usessl' => pacol( 1, 1, 1, 'bool', 'pFetchmail_field_usessl' , 'pFetchmail_desc_usessl' ),
  31. 'sslcertck' => pacol( 1, 1, 1, 'bool', 'pFetchmail_field_sslcertck' , '' ),
  32. 'sslcertpath' => pacol( $extra, $extra, $extra, 'text', 'pFetchmail_field_sslcertpath' , '' ),
  33. 'sslfingerprint'=> pacol( $extra, $extra, $extra, 'text', 'pFetchmail_field_sslfingerprint','' ),
  34. 'extra_options' => pacol( $extra, $extra, $extra, 'text', 'pFetchmail_field_extra_options', 'pFetchmail_desc_extra_options' ),
  35. 'mda' => pacol( $extra, $extra, $extra, 'text', 'pFetchmail_field_mda' , 'pFetchmail_desc_mda' ),
  36. 'date' => pacol( 0, 0, 1, 'text', 'pFetchmail_field_date' , 'pFetchmail_desc_date' , 1 ),
  37. 'returned_text' => pacol( 0, 0, 1, 'text', 'pFetchmail_field_returned_text', 'pFetchmail_desc_returned_text' ),
  38. 'active' => pacol( 1, 1, 1, 'bool', 'active' , '' , 1 ),
  39. 'created' => pacol( 0, 0, 0, 'ts', 'created' , '' ),
  40. 'modified' => pacol( 0, 0, 1, 'ts', 'last_modified' , '' ),
  41. );
  42. # get list of mailboxes (for currently logged in user)
  43. $handler = new MailboxHandler(0, $this->admin_username);
  44. $handler->getList('1=1');
  45. $this->struct['mailbox']['options'] = array_keys($handler->result);
  46. }
  47. protected function initMsg() {
  48. $this->msg['error_already_exists'] = 'fetchmail_already_exists';
  49. $this->msg['error_does_not_exist'] = 'fetchmail_does_not_exist';
  50. $this->msg['confirm_delete'] = 'confirm_delete_fetchmail';
  51. if ($this->new) {
  52. $this->msg['logname'] = 'create_fetchmail';
  53. $this->msg['store_error'] = 'pFetchmail_database_save_error';
  54. $this->msg['successmessage'] = 'pFetchmail_database_save_success';
  55. } else {
  56. $this->msg['logname'] = 'edit_fetchmail';
  57. $this->msg['store_error'] = 'pFetchmail_database_save_error';
  58. $this->msg['successmessage'] = 'pFetchmail_database_save_success';
  59. }
  60. }
  61. public function webformConfig() {
  62. return array(
  63. # $PALANG labels
  64. 'formtitle_create' => 'pMenu_fetchmail',
  65. 'formtitle_edit' => 'pMenu_fetchmail',
  66. 'create_button' => 'pFetchmail_new_entry',
  67. # various settings
  68. 'required_role' => 'admin',
  69. 'listview' => 'list.php?table=fetchmail',
  70. 'early_init' => 0,
  71. 'prefill' => array('mailbox'),
  72. );
  73. }
  74. protected function domain_from_id() {
  75. # do nothing, setmore() does the work
  76. }
  77. protected function setmore($values) {
  78. # set domain based on the target mailbox
  79. if ($this->new || isset($values['mailbox']) ) {
  80. list(/*NULL*/,$domain) = explode('@', $values['mailbox']);
  81. $this->values['domain'] = $domain;
  82. $this->domain = $domain;
  83. }
  84. }
  85. protected function validate_new_id() {
  86. # auto_increment - any non-empty ID is an error
  87. if ($this->id != '') {
  88. $this->errormsg[$this->id_field] = 'auto_increment value, you must pass an empty string!';
  89. return false;
  90. }
  91. return true;
  92. }
  93. /**
  94. * @return true on success false on failure
  95. */
  96. public function delete() {
  97. if ( ! $this->view() ) {
  98. $this->errormsg[] = Config::lang($this->msg['error_does_not_exist']);
  99. return false;
  100. }
  101. db_delete($this->db_table, $this->id_field, $this->id);
  102. db_log ($this->id, 'delete_fetchmail', $this->result['id']);
  103. $this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->result['src_user'] . ' -> ' . $this->result['mailbox']);
  104. return true;
  105. }
  106. /*
  107. * validate src_server - must be non-empty and survive check_domain()
  108. */
  109. protected function _validate_src_server($field, $val) {
  110. if ($val == '') {
  111. $msg = Config::Lang('pFetchmail_server_missing');
  112. } else {
  113. $msg = check_domain($val);
  114. }
  115. if ($msg == '') {
  116. return true;
  117. } else {
  118. $this->errormsg[$field] = $msg;
  119. return false;
  120. }
  121. }
  122. /*
  123. * validate src_user and src_password - must be non-empty
  124. * (we can't assume anything about valid usernames and passwords on remote
  125. * servers, so the validation can't be more strict)
  126. */
  127. protected function _validate_src_user($field, $val) {
  128. if ($val == '') {
  129. $this->errormsg[$field] = Config::lang('pFetchmail_user_missing');
  130. return false;
  131. }
  132. return true;
  133. }
  134. protected function _validate_src_password($field, $val) {
  135. if ($val == '') {
  136. $this->errormsg[$field] = Config::lang('pFetchmail_password_missing');
  137. return false;
  138. }
  139. return true;
  140. }
  141. /*
  142. * validate poll interval - must be numeri and > 0
  143. */
  144. protected function _validate_poll_time($field, $val) {
  145. # must be > 0
  146. if ($val < 1) {
  147. $this->errormsg[$field] = Config::Lang_f('must_be_numeric_bigger_than_null', $field);
  148. return false;
  149. }
  150. return true;
  151. }
  152. }
  153. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */