Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
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.

90 lines
2.6KB

  1. <?php
  2. require_once ("config.php");
  3. require_once "resources/PHPMailer/class.phpmailer.php";
  4. require_once "book.php";
  5. function checkConfiguration () {
  6. global $config;
  7. if (is_null ($config['cops_mail_configuration']) ||
  8. !is_array ($config['cops_mail_configuration']) ||
  9. empty ($config['cops_mail_configuration']["smtp.host"]) ||
  10. empty ($config['cops_mail_configuration']["address.from"])) {
  11. return "NOK. bad configuration.";
  12. }
  13. return False;
  14. }
  15. function checkRequest ($idData, $emailDest) {
  16. if (empty ($idData)) {
  17. return 'No data sent.';
  18. }
  19. if (empty ($emailDest)) {
  20. return 'No email sent.';
  21. }
  22. return False;
  23. }
  24. if (php_sapi_name() === 'cli') { return; }
  25. global $config;
  26. if ($error = checkConfiguration ()) {
  27. echo $error;
  28. exit;
  29. }
  30. $idData = $_REQUEST["data"];
  31. $emailDest = $_REQUEST["email"];
  32. if ($error = checkRequest ($idData, $emailDest)) {
  33. echo $error;
  34. exit;
  35. }
  36. $book = Book::getBookByDataId($idData);
  37. $data = $book->getDataById ($idData);
  38. if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
  39. echo 'Attachment too big';
  40. exit;
  41. }
  42. $mail = new PHPMailer;
  43. $mail->IsSMTP();
  44. $mail->Timeout = 30; // 30 seconds as some files can be big
  45. $mail->Host = $config['cops_mail_configuration']["smtp.host"];
  46. if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
  47. $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
  48. $mail->Port = 465;
  49. }
  50. $mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
  51. if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"];
  52. if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"];
  53. if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
  54. $mail->From = $config['cops_mail_configuration']["address.from"];
  55. $mail->FromName = $config['cops_title_default'];
  56. foreach (explode (";", $emailDest) as $emailAddress) {
  57. if (empty ($emailAddress)) { continue; }
  58. $mail->AddAddress($emailAddress);
  59. }
  60. $mail->AddAttachment($data->getLocalPath ());
  61. $mail->IsHTML(true);
  62. $mail->Subject = 'Sent by COPS : ' . $data->getUpdatedFilename ();
  63. $mail->Body = "<h1>" . $book->title . "</h1><h2>" . $book->getAuthorsName () . "</h2>" . $book->getComment ();
  64. $mail->AltBody = "Sent by COPS";
  65. if (!$mail->Send()) {
  66. echo localize ("mail.messagenotsent");
  67. echo 'Mailer Error: ' . $mail->ErrorInfo;
  68. exit;
  69. }
  70. echo localize ("mail.messagesent");