diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-25 03:01:39 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-25 03:01:39 +0200 |
commit | 251c0a135a4153453030dc0e2c132e57934c0095 (patch) | |
tree | e7ab615568cdfe2526b508e483b2a6c6cad4350e /modules/private/websites/tools/tools/landing/ldap_password.php | |
parent | c54f73c385dcdb7458759b36b62fa0e6895a30d7 (diff) | |
download | Nix-251c0a135a4153453030dc0e2c132e57934c0095.tar.gz Nix-251c0a135a4153453030dc0e2c132e57934c0095.tar.zst Nix-251c0a135a4153453030dc0e2c132e57934c0095.zip |
Migrate manual scripts from tools.immae.eu
Landing page
BIP39
ldap/myip scripts
webhooks
Diffstat (limited to 'modules/private/websites/tools/tools/landing/ldap_password.php')
-rw-r--r-- | modules/private/websites/tools/tools/landing/ldap_password.php | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/modules/private/websites/tools/tools/landing/ldap_password.php b/modules/private/websites/tools/tools/landing/ldap_password.php new file mode 100644 index 0000000..54448a4 --- /dev/null +++ b/modules/private/websites/tools/tools/landing/ldap_password.php | |||
@@ -0,0 +1,137 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * LDAP PHP Change Password Webpage | ||
5 | * @author: Matt Rude <http://mattrude.com> | ||
6 | * @website: http://technology.mattrude.com/2010/11/ldap-php-change-password-webpage/ | ||
7 | * | ||
8 | * | ||
9 | * GNU GENERAL PUBLIC LICENSE | ||
10 | * Version 2, June 1991 | ||
11 | * | ||
12 | * Copyright (C) 1989, 1991 Free Software Foundation, Inc., | ||
13 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
14 | * Everyone is permitted to copy and distribute verbatim copies | ||
15 | * of this license document, but changing it is not allowed. | ||
16 | */ | ||
17 | |||
18 | $message = array(); | ||
19 | $message_css = ""; | ||
20 | |||
21 | function changePassword($user,$oldPassword,$newPassword,$newPasswordCnf){ | ||
22 | global $message; | ||
23 | global $message_css; | ||
24 | |||
25 | $server = "ldaps://ldap.immae.eu"; | ||
26 | |||
27 | error_reporting(0); | ||
28 | $con = ldap_connect($server); | ||
29 | ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
30 | |||
31 | $user_dn = "uid=$user,ou=users,dc=immae,dc=eu"; | ||
32 | |||
33 | if (ldap_bind($con, $user_dn, $oldPassword) === false) { | ||
34 | $message[] = "Error E101 - Current Username or Password is wrong."; | ||
35 | return false; | ||
36 | } | ||
37 | if ($newPassword != $newPasswordCnf ) { | ||
38 | $message[] = "Error E102 - Your New passwords do not match!"; | ||
39 | return false; | ||
40 | } | ||
41 | if (strlen($newPassword) < 6 ) { | ||
42 | $message[] = "Error E103 - Your new password is too short.<br/>Your password must be at least 6 characters long."; | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | $salt = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',4)),0,4); | ||
47 | $encoded_newPassword = "{SSHA}" . base64_encode(pack("H*", sha1($newPassword.$salt)).$salt); | ||
48 | |||
49 | $user_search = ldap_search($con,"dc=immae,dc=eu","(uid=$user)"); | ||
50 | $auth_entry = ldap_first_entry($con, $user_search); | ||
51 | |||
52 | $mail_addresses = ldap_get_values($con, $auth_entry, "mail"); | ||
53 | $given_names = ldap_get_values($con, $auth_entry, "givenName"); | ||
54 | $mail_address = $mail_addresses[0]; | ||
55 | $first_name = $given_names[0]; | ||
56 | |||
57 | /* And Finally, Change the password */ | ||
58 | $entry = array(); | ||
59 | $entry["userPassword"] = "$encoded_newPassword"; | ||
60 | |||
61 | if (ldap_modify($con,$user_dn,$entry) === false){ | ||
62 | $error = ldap_error($con); | ||
63 | $errno = ldap_errno($con); | ||
64 | $message[] = "E201 - Your password cannot be changed, please contact the administrator."; | ||
65 | $message[] = "$errno - $error"; | ||
66 | } else { | ||
67 | $message_css = "yes"; | ||
68 | mail($mail_address,"Password change notice","Dear $first_name, | ||
69 | Your password on https://tools.immae.eu/ldap_password.php for account $user was just changed. | ||
70 | If you did not make this change, please contact me. | ||
71 | If you were the one who changed your password, you may disregard this message. | ||
72 | |||
73 | Thanks | ||
74 | -- | ||
75 | Immae / Ismaël", "From: " . getenv("CONTACT_EMAIL")); | ||
76 | $message[] = "The password for $user has been changed.<br/>An informational email has been sent to $mail_address.<br/>Your new password is now fully active."; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | ?> | ||
81 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
82 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
83 | <head> | ||
84 | <title>Password Change Page</title> | ||
85 | <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
86 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" integrity="sha256-2YQRJMXD7pIAPHiXr0s+vlRWA7GYJEK0ARns7k2sbHY=" crossorigin="anonymous" /> | ||
87 | <style type="text/css"> | ||
88 | body { font-family: Verdana,Arial,Courier New; margin: auto; } | ||
89 | |||
90 | .msg_yes { margin: 0 auto; text-align: center; color: green; background: #D4EAD4; border: 1px solid green; border-radius: 10px; margin: 2px; } | ||
91 | .msg_no { margin: 0 auto; text-align: center; color: red; background: #FFF0F0; border: 1px solid red; border-radius: 10px; margin: 2px; } | ||
92 | </style> | ||
93 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
94 | </head> | ||
95 | <body> | ||
96 | <div class="container"> | ||
97 | <form action="<?php print $_SERVER['PHP_SELF']; ?>" name="passwordChange" method="post"> | ||
98 | <h3>Password Change Page</h3> | ||
99 | <?php | ||
100 | if (isset($_POST["submitted"])) { | ||
101 | echo '<div class="row">'; | ||
102 | changePassword($_POST['username'],$_POST['oldPassword'],$_POST['newPassword1'],$_POST['newPassword2']); | ||
103 | global $message_css; | ||
104 | if ($message_css == "yes") { | ||
105 | echo '<div class="msg_yes">'; | ||
106 | } else { | ||
107 | echo '<div class="msg_no">'; | ||
108 | $message[] = "Your password was not changed."; | ||
109 | } | ||
110 | foreach ( $message as $one ) { echo "<p>$one</p>"; } | ||
111 | ?></div></div><?php | ||
112 | } ?> | ||
113 | <div class="row"> | ||
114 | <div class="one-third column"><label for="username">Username</label></div> | ||
115 | <div class="two-thirds column"><input id="username" name="username" type="text" autocomplete="off" /></div> | ||
116 | </div> | ||
117 | <div class="row"> | ||
118 | <div class="one-third column"><label for="oldPassword">Current password</label></div> | ||
119 | <div class="two-thirds column"><input id="oldPassword" name="oldPassword" type="password" /></div> | ||
120 | </div> | ||
121 | <div class="row"> | ||
122 | <div class="one-third column"><label for="newPassword1">New password</label></div> | ||
123 | <div class="two-thirds column"><input id="newPassword1" name="newPassword1" type="password" /></div> | ||
124 | </div> | ||
125 | <div class="row"> | ||
126 | <div class="one-third column"><label for="newPassword2">New password (again)</label></div> | ||
127 | <div class="two-thirds column"><input id="newPassword2" name="newPassword2" type="password" /></div> | ||
128 | </div> | ||
129 | <div class="row"> | ||
130 | <div class="column"> | ||
131 | <input name="submitted" type="submit" value="Change Password"/> | ||
132 | </div> | ||
133 | </div> | ||
134 | </form> | ||
135 | </div> | ||
136 | </body> | ||
137 | </html> | ||