resend_confirm_address.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. define('INSTALLDIR', dirname(__DIR__));
  18. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  19. $shortoptions = 'e::ay';
  20. $longoptions = array('email=', 'all', 'yes');
  21. $self = basename($_SERVER['PHP_SELF']);
  22. $helptext = <<<END_OF_HELP
  23. {$self} [options]
  24. resends confirmation email either for a specific email (if found) or for
  25. all lingering confirmations.
  26. NOTE: You probably want to do something like this to your database first so
  27. only relatively fresh accounts get resent this:
  28. DELETE FROM confirm_address WHERE modified < (CURRENT_TIMESTAMP - INTERVAL '1' MONTH);
  29. Options:
  30. -e --email e-mail address to send for
  31. -a --all send for all emails in confirm_address table
  32. -y --yes skip interactive verification
  33. END_OF_HELP;
  34. require_once INSTALLDIR.'/scripts/commandline.inc';
  35. $all = false;
  36. $ca = null;
  37. if (have_option('e', 'email')) {
  38. $email = get_option_value('e', 'email');
  39. try {
  40. $ca = Confirm_address::getByAddress($email, 'email');
  41. } catch (NoResultException $e) {
  42. print sprintf("Can't find %s address %s in %s table.\n", $e->obj->address_type, $e->obj->address, $e->obj->tableName());
  43. exit(1);
  44. }
  45. } elseif (have_option('a', 'all')) {
  46. $all = true;
  47. $ca = new Confirm_address();
  48. $ca->address_type = 'email';
  49. if (!$ca->find()) {
  50. print "confirm_address table contains no lingering email addresses\n";
  51. exit(0);
  52. }
  53. } else {
  54. print "You must provide an email (or --all).\n";
  55. exit(1);
  56. }
  57. if (!have_option('y', 'yes')) {
  58. print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
  59. $response = fgets(STDIN);
  60. if (strtolower(trim($response)) != 'y') {
  61. print "Aborting.\n";
  62. exit(0);
  63. }
  64. }
  65. function mailConfirmAddress(Confirm_address $ca)
  66. {
  67. try {
  68. $user = User::getByID($ca->user_id);
  69. $profile = $user->getProfile();
  70. if ($profile->isSilenced()) {
  71. $ca->delete();
  72. return;
  73. }
  74. if ($user->email === $ca->address) {
  75. throw new AlreadyFulfilledException('User already has identical confirmed email address.');
  76. }
  77. } catch (AlreadyFulfilledException $e) {
  78. print "\n User already had verified email: "._ve($ca->address);
  79. $ca->delete();
  80. } catch (Exception $e) {
  81. print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
  82. $ca->delete();
  83. return;
  84. }
  85. mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
  86. }
  87. require_once INSTALLDIR . '/lib/util/mail.php';
  88. if (!$all) {
  89. mailConfirmAddress($ca);
  90. } else {
  91. while ($ca->fetch()) {
  92. mailConfirmAddress($ca);
  93. }
  94. }
  95. print "\nDONE.\n";