| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | #!/usr/bin/env php
 | 
					
						
							|  |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-09-11 09:58:13 +03:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-15 04:10:29 +01:00
										 |  |  | define('INSTALLDIR', dirname(__DIR__)); | 
					
						
							|  |  |  | define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | $shortoptions = 'e::ay'; | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  | $longoptions = ['email=', 'all', 'yes']; | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | $self = basename($_SERVER['PHP_SELF']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $helptext = <<<END_OF_HELP | 
					
						
							|  |  |  | {$self} [options] | 
					
						
							|  |  |  | resends confirmation email either for a specific email (if found) or for | 
					
						
							|  |  |  | all lingering confirmations. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NOTE: You probably want to do something like this to your database first so | 
					
						
							|  |  |  | only relatively fresh accounts get resent this: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 09:58:13 +03:00
										 |  |  |     DELETE FROM confirm_address WHERE modified < (CURRENT_TIMESTAMP - INTERVAL '1' MONTH); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   -e --email        e-mail address to send for | 
					
						
							|  |  |  |   -a --all          send for all emails in confirm_address table | 
					
						
							|  |  |  |   -y --yes          skip interactive verification | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | END_OF_HELP; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  | require_once INSTALLDIR . '/scripts/commandline.inc'; | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | $all = false; | 
					
						
							|  |  |  | $ca = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (have_option('e', 'email')) { | 
					
						
							|  |  |  |     $email = get_option_value('e', 'email'); | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     if (is_null($email)) { | 
					
						
							|  |  |  |         echo "You must provide an email.\n"; | 
					
						
							|  |  |  |         exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-29 14:48:46 +02:00
										 |  |  |     try { | 
					
						
							|  |  |  |         $ca = Confirm_address::getByAddress($email, 'email'); | 
					
						
							|  |  |  |     } catch (NoResultException $e) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |         echo sprintf( | 
					
						
							|  |  |  |             "Can't find %s address %s in %s table.\n", | 
					
						
							|  |  |  |             $e->obj->address_type, | 
					
						
							|  |  |  |             $e->obj->address, | 
					
						
							|  |  |  |             $e->obj->tableName() | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |         exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } elseif (have_option('a', 'all')) { | 
					
						
							|  |  |  |     $all = true; | 
					
						
							|  |  |  |     $ca = new Confirm_address(); | 
					
						
							|  |  |  |     $ca->address_type = 'email'; | 
					
						
							|  |  |  |     if (!$ca->find()) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |         echo "confirm_address table contains no lingering email addresses\n"; | 
					
						
							|  |  |  |         exit(); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } else { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     echo "You must provide an email (or --all).\n"; | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |     exit(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!have_option('y', 'yes')) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     echo "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] "; | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |     $response = fgets(STDIN); | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     if (strcasecmp(trim($response), 'y') != 0) { | 
					
						
							|  |  |  |         echo "Aborting.\n"; | 
					
						
							|  |  |  |         exit(); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  | function mail_confirm_address(Confirm_address $ca): void | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         $user = User::getByID($ca->user_id); | 
					
						
							| 
									
										
										
										
											2016-03-06 16:45:29 +01:00
										 |  |  |         $profile = $user->getProfile(); | 
					
						
							|  |  |  |         if ($profile->isSilenced()) { | 
					
						
							|  |  |  |             $ca->delete(); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |         if ($user->email === $ca->address) { | 
					
						
							|  |  |  |             throw new AlreadyFulfilledException('User already has identical confirmed email address.'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } catch (AlreadyFulfilledException $e) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |         echo "\n User already had verified email: " . _ve($ca->address); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |         $ca->delete(); | 
					
						
							|  |  |  |     } catch (Exception $e) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |         echo "\n Failed to get user with ID " . _ve($user_id) | 
					
						
							|  |  |  |            . ', deleting confirm_address entry: ' . _ve($e->getMessage()); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |         $ca->delete(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     $ca->sendConfirmation(); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-23 13:36:02 +01:00
										 |  |  | require_once INSTALLDIR . '/lib/util/mail.php'; | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | if (!$all) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |     mail_confirm_address($ca); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  | } else { | 
					
						
							|  |  |  |     while ($ca->fetch()) { | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  |         mail_confirm_address($ca); | 
					
						
							| 
									
										
										
										
											2016-03-02 15:48:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:22:46 +03:00
										 |  |  | echo "\nDONE.\n"; |