Merge lp:~ubuntuforums-devel/vbulletin-openid-integration/version4-fixes into lp:vbulletin-openid-integration

Proposed by kyleabaker
Status: Needs review
Proposed branch: lp:~ubuntuforums-devel/vbulletin-openid-integration/version4-fixes
Merge into: lp:vbulletin-openid-integration
Diff against target: 2640 lines (+1482/-1043)
7 files modified
install.txt (+90/-23)
product-openid.xml (+315/-301)
readme.txt (+12/-6)
upload/openid_associate.php (+47/-34)
upload/openid_authenticate.php (+527/-311)
upload/openid_store.php (+276/-219)
upload/openid_utils.php (+215/-149)
To merge this branch: bzr merge lp:~ubuntuforums-devel/vbulletin-openid-integration/version4-fixes
Reviewer Review Type Date Requested Status
Canonical ISD hackers Pending
Review via email: mp+131238@code.launchpad.net

Description of the change

Initial vBulletin 4 compatibility.

To post a comment you must log in.

Unmerged revisions

2. By kyleabaker

vBulletin 4 fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'install.txt'
2--- install.txt 2012-07-23 16:21:45 +0000
3+++ install.txt 2012-10-24 17:05:24 +0000
4@@ -6,6 +6,7 @@
5 #
6 # Copyright 2009 William Norris
7 # Copyright 2009 Anthony Lenton
8+# Copyright 2012 Kyle Baker
9 # Copyright 2012 Canonical
10 #
11 # This file is part of vbulletin-openid-integration.
12@@ -27,29 +28,95 @@
13 the internet, or at least to the domains that you plan on allowing as
14 OpenID providers.
15
16-1) install the OpenID 2.x series libraries from openidenabled.com
17- - http://www.openidenabled.com/php-openid/
18-
19-2) install product-openid.xml using the vBulletin Product Manager
20-
21-3) Add a new User Profile Field -- a single-lined textbox named "OpenID"
22-
23-4) Find the 'OpenID' settings group in the vBulletin Options and configure as
24+1) Install the OpenID 2.x series libraries for PHP 5:
25+ - Download from http://www.openidenabled.com/php-openid/
26+ - Extract the archive and browse the contents.
27+ - Find the directory labeled 'Auth' and copy it to the
28+ base of your vBulletin 4.x installation.
29+ (ex. http://example.com/vbulletin/Auth)
30+
31+2) Install product-openid.xml using the vBulletin Product Manager:
32+ - Log in to the Admin Control Panel in vBulletin 4.x.
33+ - In the left panel, find 'Plugins & Products' near the bottom
34+ and click the arrow to expand.
35+ - Once expanded, click 'Manage Products'.
36+ - From this page, find '[Add/Import Product]' at the bottom of
37+ the Installed Products section and click it.
38+ - Under 'Import Product', select 'Choose File' and browse through
39+ the vBulletin OpenID Integration installation files for
40+ 'product-openid.xml' and open it.
41+ - Click 'Import'.
42+
43+3) Upload vBulletin OpenID Integration files:
44+ - From the installation vBulletin OpenID Integration files, find
45+ the directory labeled 'upload'.
46+ - Create a folder named 'vbopenid' in the root of your vBulletin
47+ 4.x installation. (ex. http://example.com/vbulletin/vbopenid)
48+ - Upload the contents of the 'upload' directory to your newly
49+ created 'vbopenid' directory.
50+
51+4) Add a new User Profile Field -- a single-lined textbox named "OpenID"
52+ - Log in to the Admin Control Panel in vBulletin 4.x.
53+ - In the left panel, find 'User Profile Fields' mid-way down and
54+ click the arrow to expand.
55+ - Once expanded, click 'Add New User Profile Field'.
56+ - From this page, the default Profile Field Type should be
57+ 'Single-Line Text Box'. Click continue.
58+ - User Profile Field Settings:
59+ * Title: | "OpenID"
60+ * Description: |
61+ * Profile Field: | "Uncategorized"
62+ * Default Value: |
63+ * Max length of allowed user input: | Default is 100
64+ * Field Length: | Default is 25
65+ * Profile Field Type: | "Single-Line Text Box"
66+ * Display Order: |
67+ * Field Required: |
68+ * Field Editable by User: | "No"
69+ * Private Field: | "Yes"
70+ * Field Searchable on Members List: | "No"
71+ * Show on Members List: | "No"
72+ * Regular Expression: |
73+ |
74+ * Which page displays this option?: | "Options: Other"
75+ - Click 'Save'.
76+
77+5) Find the 'OpenID' settings group in the vBulletin Options and configure as
78 appropriate. This is particularly important if you installed the libraries
79- in step 1 in a location that is not part of the standard php include_path
80+ in step 1 in a location that is not part of the standard php include_path or
81+ in a location that differs from step 1 instructions.
82+ - Log in to the Admin Control Panel in vBulletin 4.x.
83+ - In the left panel, find 'Settings' at the top and
84+ click the arrow to expand.
85+ - Once expanded, click 'Options'.
86+ - From this page, scroll through the list until you find 'OpenID',
87+ select it and click 'Edit Settings'.
88+ - Adjust settings as needed. Ensure that the OpenID Profile Field matches
89+ the title of the User Profile Field that you created in step 4.
90+ - Click 'Save'.
91
92-5) Edit your templates to add "$openid_login_box" somewhere. I recommend adding
93- it to the 'navbar' template -- inside the existing login box, just before the
94+6) Edit your templates to add the OpenID log in form somewhere. I recommend adding
95+ it to the 'header' template -- inside the existing login box area, just before the
96 submit button, and wrap it in a div that floats right. So you'd end up with
97-
98- <td>
99- <div style="float: right">
100- $openid_login_box
101- </div>
102- <input type="submit" class="button" value="$vbphrase[log_in]" tabindex="104"
103- title="$vbphrase[enter_username_to_login_or_register]" accesskey="s" />
104- </td>
105-
106- But of course, you can add it anywhere you want.
107-
108-
109+ - Log in to the Admin Control Panel in vBulletin 4.x.
110+ - In the left panel, find 'Styles & Templates' near the top and
111+ click the arrow to expand.
112+ - Once expanded, click 'Style Manager'.
113+ - From this page, you will find two sections labeled Style Manager. In
114+ the section containing 'Default Style', click the right most button
115+ to expand a list of all templates for this style.
116+ - Scroll through the list until you find 'header' or the template that
117+ you've decided to modify.
118+ - Make your changes and click 'Save'.
119+
120+ - If you decide to add to the 'header' template, insert the following
121+ immediately after the list item for Help. Find it by searching for
122+ "help" in the text area.
123+
124+ <li>
125+ {vb:phrase openid_login_box}
126+ </li>
127+
128+ But of course, you can add it anywhere you want.
129+
130+Congratulations! Installation is complete!
131
132=== modified file 'product-openid.xml'
133--- product-openid.xml 2012-07-23 16:21:45 +0000
134+++ product-openid.xml 2012-10-24 17:05:24 +0000
135@@ -1,6 +1,9 @@
136+<?xml version="1.0" encoding="ISO-8859-1"?>
137+
138 <!--
139 Copyright 2009 William Norris
140 Copyright 2009 Anthony Lenton
141+Copyright 2012 Kyle Baker
142 Copyright 2012 Canonical
143
144 This file is part of vbulletin-openid-integration.
145@@ -18,309 +21,320 @@
146 You should have received a copy of the GNU Lesser Public License
147 along with vbulletin-openid-integration. If not, see <http://www.gnu.org/licenses/>.
148 -->
149-<?xml version="1.0" encoding="ISO-8859-1"?>
150
151 <product productid="openid" active="1">
152- <title>OpenID</title>
153- <description>OpenID Authentication</description>
154- <version>1.0.0</version>
155- <codes>
156- <code version="1.0">
157- <installcode><![CDATA[
158-require_once('openid_utils.php');
159-$secret = generate_password(15);
160-$vbulletin->options['openid_secret'] = $secret;
161-require_once('openid_store.php');
162-_createDBTables($vbulletin);
163-]]></installcode>
164- <uninstallcode><![CDATA[
165-require_once('openid_store.php');
166-_removeDBTables($vbulletin);
167- ]]></uninstallcode>
168- </code>
169- </codes>
170- <templates>
171- <template name="openid_redirect_form" templatetype="template" username="achuni" version="1.0.0"><![CDATA[
172-<html><head><title>OpenID request</title></head>
173-<body onload="document.getElementById('$form_id').submit();"
174- style="text-align: center;">
175- <div style="background: lightyellow; border: 1px solid black; margin: 30px 20%; padding: 5px 15px;">
176- <p> $text_redirect </p>
177- </div>
178- $form_html
179-</body></html>]]></template>
180- <template name="openid_request_email" templatetype="template" username="achuni" version="1.0.0"><![CDATA[$stylevar[htmldoctype]
181-<html xmlns="http://www.w3.org/1999/xhtml" dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
182-<head>
183-$headinclude
184-<title>$vboptions[bbtitle] - $vbphrase[registration]</title>
185-</head>
186-<body>
187-
188-$header
189-
190-<br />
191-
192-<if condition="$show['errors']">
193- <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
194- <tr>
195- <td class="tcat">The following errors occurred during your registration:</td>
196- </tr>
197- <tr>
198- <td class="alt1"><ul>$errorlist</ul></td>
199- </tr>
200- </table>
201- <br />
202-</if>
203-
204-<form action="login.php?do=login" name="login" method="post">
205-<input type="hidden" name="do" value="login" />
206-<input type="hidden" name="openid" value="$openid" />
207-<input type="hidden" name="openid_confirm" value="$openid_confirm" />
208-<input type="hidden" name="openid_username" value="$openid_username" />
209-<input type="hidden" name="openid_action" value="request_email" />
210-<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
211-<tr>
212- <td class="tcat"><phrase 1="$vboptions[bbtitle]">$vbphrase[register_at_x]</phrase></td>
213-</tr>
214-<tr>
215- <td class="panelsurround" align="center">
216- <div class="panel">
217- <div style="width:$stylevar[formwidth]" align="$stylevar[left]">
218-
219- <fieldset class="fieldset">
220- <legend>$vbphrase[email_address]</legend>
221- <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="400">
222- <tr>
223- <td>
224- $vbphrase[email_address]:<br />
225- <input type="text" class="bginput" name="email" size="25" maxlength="50" value="$email" dir="ltr" />
226- </td>
227- <td>
228- Confirm email address:<br />
229- <input type="text" class="bginput" name="email_confirm" size="25" maxlength="50" value="$email_confirm" dir="ltr" />
230- </td>
231- </tr>
232- </table>
233- </fieldset>
234- </div>
235- </div>
236- <div style="margin-top:$stylevar[cellpadding]px">
237- <input type="submit" class="button" value="Complete Registration" accesskey="s" />
238- <input type="reset" class="button" name="Reset" value="$vbphrase[reset_fields]" />
239- </div>
240- </td>
241-</tr>
242-</table>
243-</form>
244-
245-$footer
246-
247-</body>
248-</html>]]></template>
249- <template name="openid_request_user_pass" templatetype="template" username="achuni" version="1.0.0"><![CDATA[
250-$stylevar[htmldoctype]
251-<html xmlns="http://www.w3.org/1999/xhtml" dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
252-<head>
253-$headinclude
254-<title>$vboptions[bbtitle] - $vbphrase[registration]</title>
255-</head>
256-<body>
257-
258-$header
259-
260-<br />
261-
262-<if condition="$show['errors']">
263- <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
264- <tr>
265- <td class="tcat">$vbphrase[openid_first_time]</td>
266- </tr>
267- <tr>
268- <td class="alt1"><ul>$errorlist</ul></td>
269- </tr>
270- </table>
271- <br />
272-</if>
273-
274-<form action="login.php?do=login" name="login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, $show[nopasswordempty])">
275-<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
276-<tr>
277- <td class="tcat">$vbphrase[openid_fieldset_assoc_address]</td>
278-</tr>
279-<tr>
280- <td class="panelsurround" align="center">
281- <ul>$vbphrase[openid_description_assoc]</ul>
282- <div class="panel" style="width:$stylevar[formwidth]">
283- <div style="width:$stylevar[formwidth]" align="$stylevar[left]">
284-
285- <!-- login form -->
286- <input type="hidden" name="do" value="login" />
287- <input type="hidden" name="openid" value="$openid" />
288- <input type="hidden" name="openid_confirm" value="$openid_confirm" />
289- <input type="hidden" name="openid_action" value="request_user" />
290- <script type="text/javascript" src="clientscript/vbulletin_md5.js?v=$vboptions[simpleversion]"></script>
291- <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
292- <tr>
293- <td style="white-space: nowrap;"><label for="navbar_username">$vbphrase[username]</label></td>
294- <td><input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="$openid_username" onfocus="if (this.value == '$vbphrase[username]') this.value = '';" /></td>
295- </tr>
296- <tr>
297- <td><label for="navbar_password">$vbphrase[password]</label></td>
298- <td><input type="password" class="bginput" style="font-size: 11px" name="vb_login_password" id="navbar_password" size="10" tabindex="102" /></td>
299- </tr>
300- <tr>
301- <td nowrap="nowrap" colspan="2"><label for="cb_cookieuser_navbar"><input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" />$vbphrase[remember_me]</label></td>
302- </tr>
303- </table>
304- <input type="hidden" name="s" value="$session[sessionhash]" />
305- <input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken] . "" />
306- <input type="hidden" name="do" value="login" />
307- <input type="hidden" name="vb_login_md5password" />
308- <input type="hidden" name="vb_login_md5password_utf" />
309- <!-- / login form -->
310- </div>
311- </div>
312- <div style="margin-top:$stylevar[cellpadding]px">
313- <input type="submit" class="button" tabindex="104" value="$vbphrase[openid_button_assoc]" accesskey="s" title="$vbphrase[enter_username_to_login_or_register]" />
314- <input type="reset" class="button" name="Reset" value="$vbphrase[reset_fields]" />
315- </div>
316- </td>
317-</tr>
318-</table>
319-</form>
320-<br/>
321-
322-<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
323-<tr>
324- <td class="tcat">$vbphrase[openid_fieldset_register]</td>
325-</tr>
326-<tr>
327- <td class="alt1"><ul>$vbphrase[openid_description_register]</ul></td>
328-</tr>
329-</table>
330-
331-$footer
332-
333-</body>
334-</html>
335-]]>
336-</template>
337- <template name="openid_login_box" templatetype="template" date="1152640721" username="wnorris" version="1.0.0"><![CDATA[
338+ <title>OpenID</title>
339+ <description>OpenID Authentication</description>
340+ <version>1.0.0</version>
341+ <url>https://launchpad.net/vbulletin-openid-integration</url>
342+ <!-- <versioncheckurl>https://code.launchpad.net/vbulletin-openid-integration/version.xml</versioncheckurl> -->
343+ <dependencies>
344+ <dependency dependencytype="vbulletin" minversion="4.2.0" maxversion=""/>
345+ </dependencies>
346+ <codes>
347+ <code version="1.0">
348+ <installcode><![CDATA[
349+ require_once('vbopenid/openid_utils.php');
350+
351+ $secret = generate_password(15);
352+ $vbulletin->options['openid_secret'] = $secret;
353+
354+ require_once('vbopenid/openid_store.php');
355+
356+ _createDBTables($vbulletin);
357+ ]]></installcode>
358+ <uninstallcode><![CDATA[
359+ require_once('vbopenid/openid_store.php');
360+
361+ _removeDBTables($vbulletin);
362+ ]]></uninstallcode>
363+ </code>
364+ </codes>
365+ <templates>
366+ <template name="openid_redirect_form" templatetype="template" username="achuni" version="1.0.0">
367+ <![CDATA[
368+<html>
369+<head>
370+ <title>OpenID request</title>
371+</head>
372+ <body onload="document.getElementById('{vb:raw form_id}').submit();" style="text-align: center;">
373+ <div style="background: lightyellow; border: 1px solid black; margin: 30px 20%; padding: 5px 15px;">
374+ <p> {vb:raw text_redirect} </p>
375+ </div>
376+ {vb:raw form_html}
377+ </body>
378+</html>
379+ ]]></template>
380+ <template name="openid_request_email" templatetype="template" username="achuni" version="1.0.0">
381+ <![CDATA[
382+{vb:stylevar htmldoctype}
383+<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}">
384+<head>
385+{vb:raw headinclude}
386+<title>{vb:raw vboptions.bbtitle} - {vb:phrase registration}</title>
387+</head>
388+<body>
389+
390+{vb:raw header}
391+{vb:raw navbar}
392+
393+<br />
394+
395+<vb:if condition="$show['errors']">
396+ <form action="profile.php?do=dismissnotice" method="post" id="notices" class="notices">
397+ <input type="hidden" name="do" value="dismissnotice">
398+ <input type="hidden" name="s" value="">
399+ <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}">
400+ <input type="hidden" id="dismiss_notice_hidden" name="dismiss_noticeid" value="">
401+ <input type="hidden" name="url" value="">
402+ <ol>
403+ <li class="restore" id="navbar_notice_1">{vb:phrase openid_following_errors_occurrred}</li>
404+ {vb:raw errorlist}
405+ </ol>
406+ </form>
407+</vb:if>
408+
409+<div class="standard_error">
410+ <h2 class="blockhead">{vb:phrase register}</h2>
411+ <form class="block vbform" method="post" action="login.php?do=login">
412+ <input type="hidden" name="do" value="login">
413+ <input type="hidden" name="openid" value="{vb:raw openid}">
414+ <input type="hidden" name="openid_confirm" value="{vb:raw openid_confirm}">
415+ <input type="hidden" name="openid_username" value="{vb:raw openid_username}" />
416+ <input type="hidden" name="openid_action" value="request_email" />
417+ <input type="hidden" name="vb_login_md5password" value="">
418+ <input type="hidden" name="vb_login_md5password_utf" value="">
419+ <input type="hidden" name="s" value="">
420+ <input type="hidden" name="s" value="{vb:raw session.sessionhash}">
421+ <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}">
422+ <input type="hidden" name="url" value="http://localhost/vbulletin/forum.php">
423+ <div class="blockbody formcontrols">
424+ <h3 class="blocksubhead"></h3>
425+ <div class="blockrow">
426+ <label for="vb_registration_email">{vb:phrase email_address}</label>
427+ <input type="text" class="primary textbox" id="email" name="email" value="{vb:raw email}" accesskey="u" tabindex="1">
428+ </div>
429+ <div class="blockrow">
430+ <label for="vb_registration_email_confirm">{vb:phrase openid_email_address_confirm}</label>
431+ <input type="text" class="primary textbox" id="email_confirm" name="email_confirm" value="{vb:raw email_confirm}" tabindex="1">
432+ </div>
433+ </div>
434+ <div class="blockfoot actionbuttons">
435+ <div class="group">
436+ <input type="submit" class="button" value="{vb:phrase openid_complete_registration}" accesskey="s" tabindex="1" title="{vb:phrase enter_username_to_login_or_register}">
437+ <input type="reset" class="button" value="{vb:phrase reset_fields}" accesskey="r" tabindex="1">
438+ </div>
439+ </div>
440+ </form>
441+</div>
442+
443+{vb:raw footer}
444+
445+</body>
446+</html>
447+ ]]></template>
448+ <template name="openid_request_user_pass" templatetype="template" username="achuni" version="1.0.0">
449+ <![CDATA[
450+{vb:stylevar htmldoctype}
451+<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}">
452+<head>
453+{vb:raw headinclude}
454+<title>{vb:raw vboptions.bbtitle} - {vb:phrase registration}</title>
455+</head>
456+<body>
457+
458+{vb:raw header}
459+{vb:raw navbar}
460+
461+<br />
462+
463+<vb:if condition="$show['errors']">
464+ <form action="profile.php?do=dismissnotice" method="post" id="notices" class="notices">
465+ <input type="hidden" name="do" value="dismissnotice">
466+ <input type="hidden" name="s" value="">
467+ <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}">
468+ <input type="hidden" id="dismiss_notice_hidden" name="dismiss_noticeid" value="">
469+ <input type="hidden" name="url" value="">
470+ <ol>
471+ <li class="restore" id="navbar_notice_1">{vb:phrase openid_first_time}</li>
472+ <li class="restore" id="navbar_notice_2">{vb:raw errorlist}</li>
473+ </ol>
474+ </form>
475+</vb:if>
476+
477+<div class="standard_error">
478+ <h2 class="blockhead">{vb:phrase openid_button_assoc}</h2>
479+ <form class="block vbform" method="post" action="login.php?do=login" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, {vb:raw show.nopasswordempty})">
480+ <input type="hidden" name="do" value="login">
481+ <input type="hidden" name="openid" value="{vb:raw openid}">
482+ <input type="hidden" name="openid_confirm" value="{vb:raw openid_confirm}">
483+ <input type="hidden" name="openid_action" value="request_user">
484+ <input type="hidden" name="vb_login_md5password" value="">
485+ <input type="hidden" name="vb_login_md5password_utf" value="">
486+ <input type="hidden" name="s" value="">
487+ <input type="hidden" name="s" value="{vb:raw session.sessionhash}">
488+ <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}">
489+ <input type="hidden" name="url" value="http://localhost/vbulletin/forum.php">
490+ <div class="blockbody formcontrols">
491+ <div class="blockrow restore">
492+ {vb:phrase openid_description_assoc}
493+ </div>
494+
495+ <h3 class="blocksubhead">{vb:raw log_in}</h3>
496+ <div class="blockrow">
497+ <label for="vb_login_username">{vb:phrase username}</label>
498+ <input type="text" class="primary textbox" id="vb_login_username" name="vb_login_username" value="{vb:raw openid_username}" accesskey="u" tabindex="1">
499+ </div>
500+ <div class="blockrow">
501+ <label for="vb_login_password">{vb:phrase password}</label>
502+ <input type="password" class="primary textbox" id="vb_login_password" name="vb_login_password" tabindex="1">
503+ </div>
504+ <div class="blockrow singlecheck">
505+ <label for="cb_cookieuser"><input type="checkbox" name="cookieuser" id="cb_cookieuser" value="1" tabindex="1"> {vb:phrase remember_me}</label>
506+ </div>
507+ </div>
508+ <div class="blockfoot actionbuttons">
509+ <div class="group">
510+ <input type="submit" class="button" value="{vb:phrase openid_button_assoc}" accesskey="s" tabindex="1" title="{vb:phrase enter_username_to_login_or_register}">
511+ <input type="reset" class="button" value="{vb:phrase reset_fields}" accesskey="r" tabindex="1">
512+ </div>
513+ </div>
514+ </form>
515+</div>
516+
517+<p>
518+ <em>{vb:phrase openid_fieldset_register}</em><br>
519+ {vb:phrase openid_description_register}
520+</p>
521+
522+{vb:raw footer}
523+
524+</body>
525+</html>
526+ ]]></template>
527+ </templates>
528+ <plugins>
529+ <plugin active="1">
530+ <title>OpenID Login Box</title>
531+ <hookname>cache_templates</hookname>
532+ <phpcode>
533+ <![CDATA[$globaltemplates = array_merge((array)$globaltemplates, array('openid_login_box', 'openid_request_email', 'openid_redirect_form'));]]>
534+ </phpcode>
535+ </plugin>
536+ <plugin active="1">
537+ <title>Fix OpenID POST vars</title>
538+ <hookname>global_bootstrap_init_start</hookname>
539+ <phpcode>
540+ <![CDATA[
541+if (THIS_SCRIPT == 'login' AND $_REQUEST['do'] == 'login' AND ($_REQUEST['openid'] OR $_REQUEST['openid.mode'] OR $_REQUEST['openid_mode']))
542+{
543+ $_POST['do'] = 'login';
544+ if (!$_POST['vb_login_username']) {
545+ $_POST['vb_login_username'] = '.';
546+ }
547+}
548+ ]]>
549+ </phpcode>
550+ </plugin>
551+ <plugin active="1">
552+ <title>OpenID Authentication</title>
553+ <hookname>login_failure</hookname>
554+ <phpcode>
555+ <![CDATA[include('vbopenid/openid_authenticate.php');]]>
556+ </phpcode>
557+ </plugin>
558+ <plugin active="1">
559+ <title>OpenID associate existing user </title>
560+ <hookname>login_process</hookname>
561+ <phpcode>
562+ <![CDATA[include('vbopenid/openid_associate.php');]]>
563+ </phpcode>
564+ </plugin>
565+ <plugin active="1">
566+ <title>OpenID Login Box</title>
567+ <hookname>parse_templates</hookname>
568+ <phpcode>
569+ <![CDATA[
570+ //$templater = vB_Template::create('openid_login_box');
571+ //$openid_login_box = $templater->render(true, true);
572+ //$template_hook['header'] .= $openid_login_box;
573+ ]]>
574+ </phpcode>
575+ </plugin>
576+ </plugins>
577+ <phrases>
578+ <phrasetype name="vBulletin Settings" fieldname="vbsettings">
579+ <phrase name="setting_openid_field_desc"><![CDATA[Name of the custom profile field used for storing OpenIDs.]]></phrase>
580+ <phrase name="setting_openid_field_title"><![CDATA[OpenID Profile Field]]></phrase>
581+ <phrase name="setting_openid_secret_desc"><![CDATA[A randomly generated secret to avoid OpenID tampering during automatic registration, after authenticating with the provider, but before we create the user.]]></phrase>
582+ <phrase name="setting_openid_secret_title"><![CDATA[A Random Secret]]></phrase>
583+ <phrase name="setting_openid_math_desc"><![CDATA[Does this PHP installation have advanced math support such as gmp or bcmath?]]></phrase>
584+ <phrase name="setting_openid_math_title"><![CDATA[Math Support]]></phrase>
585+ <phrase name="setting_openid_auto_register_desc"><![CDATA[Automatically register a new user when an unknown OpenID is authenticated?]]></phrase>
586+ <phrase name="setting_openid_auto_register_title"><![CDATA[Automatic User Registration]]></phrase>
587+ <phrase name="setting_openid_path_desc"><![CDATA[If the OpenID libraries aren't available on the standard include path, enter the directory where they are installed.]]></phrase>
588+ <phrase name="setting_openid_path_title"><![CDATA[Library Path]]></phrase>
589+ <phrase name="setting_openid_allowedproviders_desc"><![CDATA[Coma-separated list of allowed providers. Each provider is taken as a regex to check if a particular server should be allowed. Leave blank to allow all providers.]]></phrase>
590+ <phrase name="setting_openid_allowedproviders_title"><![CDATA[Allowed Providers]]></phrase>
591+ <phrase name="settinggroup_openid"><![CDATA[OpenID]]></phrase>
592+ </phrasetype>
593+ <phrasetype name="GLOBAL" fieldname="global">
594+ <phrase name="openid_fieldset_assoc_address"><![CDATA[Associate OpenID to an existing account]]></phrase>
595+ <phrase name="openid_fieldset_register"><![CDATA[Register a new account]]></phrase>
596+ <phrase name="openid_description_assoc"><![CDATA[If you already have a forum account and want to associate this ID to it, please fill in this form.]]></phrase>
597+ <phrase name="openid_description_register"><![CDATA[If you don't yet have a forum account and want to register a new one, please <a href="register.php">click here</a>.]]></phrase>
598+ <phrase name="openid_button_assoc"><![CDATA[Associate my ID to this account]]></phrase>
599+ <phrase name="openid_following_errors_occurrred"><![CDATA[The following errors occurred during your registration:]]></phrase>
600+ <phrase name="openid_first_time"><![CDATA[It's the first time that you've signed in using this OpenID]]></phrase>
601+ <phrase name="openid_no_auto_register"><![CDATA[Sorry, you'll need to first associate this OpenID to an existing forum user, <em>or</em> register a new account to be able to sign in with your OpenID, as automatic user registration is disabled.]]></phrase>
602+ <phrase name="openid_email_address_confirm"><![CDATA[Confirm Email Address:]]></phrase>
603+ <phrase name="openid_complete_registration"><![CDATA[Complete Registration]]></phrase>
604+ <phrase name="openid_login_box">
605+ <![CDATA[
606 <!-- OpenID Login Box -->
607-<div id="openid_login">
608- <a href="#"><img style="border:0" src="$stylevar[imgdir_button]/openid.png" alt="OpenID" /></a>
609- <script type="text/javascript">vbmenu_register("openid_login");</script>
610-</div>
611-
612-<div class="vbmenu_popup" id="openid_login_menu" style="display:none">
613- <table cellpadding="4" cellspacing="1" border="0">
614- <tr>
615- <td class="thead">OpenID Login</td>
616- </tr>
617- <tr>
618- <td class="vbmenu_option" title="nohilite">
619- <form action="login.php" method="post">
620- <input type="hidden" name="do" value="login" />
621- <input type="text" style="background:white url(http://openid.net/login-bg.gif) no-repeat 1px 1px; padding-left:20px" class="bginput" name="openid" size="20" />&nbsp;<input type="submit" class="button" value="Go" /><br />
622- </form>
623- </td>
624- </tr>
625- </table>
626-</div>
627+ <form class="logindetails" action="login.php" method="post">
628+ <input type="hidden" name="do" value="login" />
629+ <input type="text" style="background:white url(http://openid.net/login-bg.gif) no-repeat 1px 1px; padding-left:20px" class="bginput" name="openid" size="20" />&nbsp;<input type="submit" class="button" value="Go" /><br />
630+ </form>
631 <!-- / OpenID Login Box -->
632- ]]></template>
633- </templates>
634- <plugins>
635- <plugin active="1">
636- <title>OpenID Login Box</title>
637- <hookname>cache_templates</hookname>
638- <phpcode><![CDATA[$globaltemplates = array_merge($globaltemplates, array('openid_login_box', 'openid_request_email', 'openid_redirect_form'));]]></phpcode>
639- </plugin>
640- <plugin active="1">
641- <title>Fix OpenID POST vars</title>
642- <hookname>global_start</hookname>
643- <phpcode><![CDATA[if (THIS_SCRIPT == 'login' AND $_REQUEST['do'] == 'login' AND ($_REQUEST['openid'] OR $_REQUEST['openid.mode'] OR $_REQUEST['openid_mode']))
644-{
645- $_POST['do'] = 'login';
646- if (!$_POST['vb_login_username']) {
647- $_POST['vb_login_username'] = '.';
648- }
649-}]]></phpcode>
650- </plugin>
651- <plugin active="1">
652- <title>OpenID Authentication</title>
653- <hookname>login_failure</hookname>
654- <phpcode><![CDATA[include('openid_authenticate.php');]]></phpcode>
655- </plugin>
656- <plugin active="1">
657- <title>OpenID associate existing user </title>
658- <hookname>login_process</hookname>
659- <phpcode><![CDATA[include('openid_associate.php');]]></phpcode>
660- </plugin>
661- <plugin active="1">
662- <title>OpenID Login Box</title>
663- <hookname>parse_templates</hookname>
664- <phpcode><![CDATA[eval('$openid_login_box = "' . fetch_template('openid_login_box') . '";');]]></phpcode>
665- </plugin>
666- </plugins>
667- <phrases>
668- <phrasetype name="vBulletin Settings" fieldname="vbsettings">
669- <phrase name="setting_openid_field_desc"><![CDATA[Name of the custom profile field used for storing OpenIDs.]]></phrase>
670- <phrase name="setting_openid_field_title"><![CDATA[OpenID Profile Field]]></phrase>
671- <phrase name="setting_openid_secret_desc"><![CDATA[A randomly generated secret to avoid OpenID tampering during automatic registration, after authenticating with the provider, but before we create the user.]]></phrase>
672- <phrase name="setting_openid_secret_title"><![CDATA[A Random Secret]]></phrase>
673- <phrase name="setting_openid_math_desc"><![CDATA[Does this PHP installation have advanced math support such as gmp or bcmath?]]></phrase>
674- <phrase name="setting_openid_math_title"><![CDATA[Math Support]]></phrase>
675- <phrase name="setting_openid_auto_register_desc"><![CDATA[Automatically register a new user when an unknown OpenID is authenticated?]]></phrase>
676- <phrase name="setting_openid_auto_register_title"><![CDATA[Automatic User Registration]]></phrase>
677- <phrase name="setting_openid_path_desc"><![CDATA[If the OpenID libraries aren't available on the standard include path, enter the directory where they are installed.]]></phrase>
678- <phrase name="setting_openid_path_title"><![CDATA[Library Path]]></phrase>
679- <phrase name="setting_openid_allowedproviders_desc"><![CDATA[Coma-separated list of allowed providers. Each provider is taken as a regex to check if a particular server should be allowed. Leave blank to allow all providers.]]></phrase>
680- <phrase name="setting_openid_allowedproviders_title"><![CDATA[Allowed Providers]]></phrase>
681- <phrase name="settinggroup_openid"><![CDATA[OpenID]]></phrase>
682- </phrasetype>
683- <phrasetype name="GLOBAL" fieldname="global">
684- <phrase name="openid_fieldset_assoc_address"><![CDATA[Associate OpenID to an existing account]]></phrase>
685- <phrase name="openid_fieldset_register"><![CDATA[Register a new account]]></phrase>
686- <phrase name="openid_description_assoc"><![CDATA[If you already have a forum account and want to associate this ID to it, please fill in this form.]]></phrase>
687- <phrase name="openid_description_register"><![CDATA[If you don't yet have a forum account and want to register a new one, please <a href="register.php">click here</a>.]]></phrase>
688- <phrase name="openid_button_assoc"><![CDATA[Associate my ID to this account]]></phrase>
689- <phrase name="openid_first_time"><![CDATA[It's the first time you sign in using this OpenID]]></phrase>
690- <phrase name="openid_no_auto_register"><![CDATA[Sorry, you'll need to first associate this OpenID to an existing forum user, <b><big>or</big></b> register a new account to be able to sign in with your OpenID, as automatic user registration is disabled.]]></phrase>
691- </phrasetype>
692- <phrasetype name="Error Messages" fieldname="error">
693- <phrase name="openid_tamperedform"><![CDATA[Inconsistencies were detected in your form values. Please re-authenticate with your OpenID provider]]></phrase>
694- <phrase name="openid_server_not_allowed"><![CDATA[Sorry, we currently don't accept OpenIDs from your server ({1})]]></phrase>
695- <phrase name="openid_redirect"><![CDATA[You are about to be redirected to your OpenID provider. If you are not redirected automatically, please click the continue button below.]]></phrase>
696- </phrasetype>
697- </phrases>
698- <options>
699- <settinggroup name="openid" displayorder="999">
700- <setting varname="openid_path" displayorder="10">
701- <datatype>free</datatype>
702- </setting>
703- <setting varname="openid_math" displayorder="20">
704- <datatype>boolean</datatype>
705- <optioncode>yesno</optioncode>
706- <defaultvalue>0</defaultvalue>
707- </setting>
708- <setting varname="openid_auto_register" displayorder="30">
709- <datatype>boolean</datatype>
710- <optioncode>yesno</optioncode>
711- <defaultvalue>0</defaultvalue>
712- </setting>
713- <setting varname="openid_field" displayorder="50">
714- <datatype>free</datatype>
715- <defaultvalue>OpenID</defaultvalue>
716- </setting>
717- <setting varname="openid_allowedproviders" displayorder="60">
718- <datatype>free</datatype>
719- </setting>
720- <setting varname="openid_secret" displayorder="70">
721- <datatype>free</datatype>
722- <defaultvalue>CHANGEME</defaultvalue>
723- </setting>
724- </settinggroup>
725- </options>
726+ ]]>
727+ </phrase>
728+ </phrasetype>
729+ <phrasetype name="Error Messages" fieldname="error">
730+ <phrase name="openid_tamperedform"><![CDATA[Inconsistencies were detected in your form values. Please re-authenticate with your OpenID provider]]></phrase>
731+ <phrase name="openid_server_not_allowed"><![CDATA[Sorry, we currently don't accept OpenIDs from your server ({1})]]></phrase>
732+ <phrase name="openid_redirect"><![CDATA[You are about to be redirected to your OpenID provider. If you are not redirected automatically, please click the continue button below.]]></phrase>
733+ </phrasetype>
734+ </phrases>
735+ <options>
736+ <settinggroup name="openid" displayorder="999">
737+ <setting varname="openid_path" displayorder="10">
738+ <datatype>free</datatype>
739+ </setting>
740+ <setting varname="openid_math" displayorder="20">
741+ <datatype>boolean</datatype>
742+ <optioncode>yesno</optioncode>
743+ <defaultvalue>0</defaultvalue>
744+ </setting>
745+ <setting varname="openid_auto_register" displayorder="30">
746+ <datatype>boolean</datatype>
747+ <optioncode>yesno</optioncode>
748+ <defaultvalue>0</defaultvalue>
749+ </setting>
750+ <setting varname="openid_field" displayorder="50">
751+ <datatype>free</datatype>
752+ <defaultvalue>OpenID</defaultvalue>
753+ </setting>
754+ <setting varname="openid_allowedproviders" displayorder="60">
755+ <datatype>free</datatype>
756+ </setting>
757+ <setting varname="openid_secret" displayorder="70">
758+ <datatype>free</datatype>
759+ <defaultvalue>CHANGEME</defaultvalue>
760+ </setting>
761+ </settinggroup>
762+ </options>
763+ <!-- <helptopics/> -->
764+ <!-- <cronentries/> -->
765+ <!-- <faqentries/> -->
766 </product>
767
768=== modified file 'readme.txt'
769--- readme.txt 2012-07-23 16:21:45 +0000
770+++ readme.txt 2012-10-24 17:05:24 +0000
771@@ -1,5 +1,6 @@
772 # Copyright 2009 William Norris
773 # Copyright 2009 Anthony Lenton
774+# Copyright 2012 Kyle Baker
775 # Copyright 2012 Canonical
776 #
777 # This file is part of vbulletin-openid-integration.
778@@ -21,13 +22,18 @@
779 work with current versions of vBulletin and to add a few often-requested
780 features.
781
782-It has been tested on vBulletin 3.8.1.
783+It has been tested on vBulletin 4.2.0.
784
785 Its main features are:
786- - Optional automatic registration of users if an unknown openid is
787- provided.
788- - If automatic registration is disabled, users can still associate existing
789- forum accounts to their OpenID the first time they sign in.
790- - Optional restriction of allowed OpenID providers.
791+ - Automatic User Registration
792+ * Enabled: OpenID users can authenticate with your vBulletin Board
793+ with no previous vBulletin username. If the OpenID provider does
794+ not return an email address, the user will be prompted for an
795+ email address to link to their account.
796+ * Disabled: OpenID users can authenticate with your vBulletin Board
797+ using any OpenID provider of their choice. However, they MUST have
798+ an existing vBulletin username to link their OpenID authentication
799+ with the first time they sign in.
800+ - Allowed Providers: Optional restriction of allowed OpenID providers.
801
802
803
804=== modified file 'upload/openid_associate.php'
805--- upload/openid_associate.php 2012-07-23 16:21:45 +0000
806+++ upload/openid_associate.php 2012-10-24 17:05:24 +0000
807@@ -1,6 +1,8 @@
808-<!--
809+<?php
810+/**
811 Copyright 2009 William Norris
812 Copyright 2009 Anthony Lenton
813+Copyright 2012 Kyle Baker
814 Copyright 2012 Canonical
815
816 This file is part of vbulletin-openid-integration.
817@@ -17,37 +19,48 @@
818
819 You should have received a copy of the GNU Lesser Public License
820 along with vbulletin-openid-integration. If not, see <http://www.gnu.org/licenses/>.
821--->
822-<?php
823-/*
824- * This file is connected to the login_process hook.
825- *
826- * Here we handle the case where a user attempts to log in for the first time,
827- * and automatic user creation is disabled. The user then cooses to associate
828- * an existing forum user to the provided OpenID by sending a user/pass,
829- * and the credentials are successfully verified. We can therefore safely
830- * modify the user profile to associate it to the provided OpenID, for future
831- * logins.
832- */
833-
834-require_once('openid_utils.php');
835-
836-$vbulletin->input->clean_array_gpc('r', array(
837- 'openid' => TYPE_STR,
838- 'openid_confirm' => TYPE_STR,
839-));
840-
841-if ($vbulletin->GPC['openid_confirm']) {
842- $openid = $vbulletin->GPC['openid'];
843- $checksum = crypt($openid, $vbulletin->options['openid_secret']);
844- if ($vbulletin->GPC['openid_confirm'] == $checksum) {
845- $username = $vbulletin->GPC['vb_login_username'];
846- $userid = $vbulletin->userinfo['userid'];
847- vBOpenID_setOpenID ($userid, $openid, $vbulletin);
848- $vbulletin->url = $vbulletin->options['homeurl'];
849- }
850- /*else {
851- Let the error silently pass, simply don't associate anything.
852- }*/
853-}
854+*/
855+
856+ /*
857+ * This file is connected to the login_process hook.
858+ *
859+ * Here we handle the case where a user attempts to log in for the first time,
860+ * and automatic user creation is disabled. The user then cooses to associate
861+ * an existing forum user to the provided OpenID by sending a user/pass,
862+ * and the credentials are successfully verified. We can therefore safely
863+ * modify the user profile to associate it to the provided OpenID, for future
864+ * logins.
865+ */
866+
867+ require_once('vbopenid/openid_utils.php');
868+
869+ $vbulletin->input->clean_array_gpc('r', array(
870+ 'openid' => TYPE_STR,
871+ 'openid_confirm' => TYPE_STR,
872+ ));
873+
874+ error_log("Entering openid_associate.php...", 0);
875+ if ($vbulletin->GPC['openid_confirm'])
876+ {
877+ $openid = $vbulletin->GPC['openid'];
878+ $checksum = crypt($openid, $vbulletin->options['openid_secret']);
879+
880+ error_log("GPC openid_confirm: " . $vbulletin->GPC['openid_confirm'] . ":" . $checksum, 0);
881+ if ($vbulletin->GPC['openid_confirm'] == $checksum)
882+ {
883+ $username = $vbulletin->GPC['vb_login_username'];
884+ $userid = $vbulletin->userinfo['userid'];
885+ error_log("username: " . $username, 0);
886+ error_log("userid: " . $userid, 0);
887+
888+ vBOpenID_setOpenID ($userid, $openid, $vbulletin);
889+ $vbulletin->url = $vbulletin->options['homeurl'];
890+ error_log("vbulletin url: " . $vbulletin->url, 0);
891+ }
892+ /*else
893+ {
894+ Let the error silently pass, simply don't associate anything.
895+ }*/
896+ }
897+ error_log("Exiting openid_associate.php...", 0);
898 ?>
899
900=== modified file 'upload/openid_authenticate.php'
901--- upload/openid_authenticate.php 2012-07-23 16:21:45 +0000
902+++ upload/openid_authenticate.php 2012-10-24 17:05:24 +0000
903@@ -1,6 +1,8 @@
904-<!--
905+<?php
906+/**
907 Copyright 2009 William Norris
908 Copyright 2009 Anthony Lenton
909+Copyright 2012 Kyle Baker
910 Copyright 2012 Canonical
911
912 This file is part of vbulletin-openid-integration.
913@@ -17,314 +19,528 @@
914
915 You should have received a copy of the GNU Lesser Public License
916 along with vbulletin-openid-integration. If not, see <http://www.gnu.org/licenses/>.
917--->
918-<?php
919-/*
920- * This file is connected to the login_failure hook.
921- *
922- * Here we handle all signing in via OpenID. If the user provides a valid
923- * OpenID but not a user/pass the login callback will fail, giving us a chance
924- * to perform additional authentication.
925- */
926-require_once 'openid_utils.php';
927-vBOpenID_init ($vbulletin);
928-
929-require_once 'Auth/OpenID.php';
930-require_once 'Auth/OpenID/Consumer.php';
931-require_once 'Auth/OpenID/SReg.php';
932-
933-require_once 'openid_store.php';
934-session_name('vbulletin-openid');
935-session_start();
936-
937-$loginSuccess = False;
938-
939-$dbStore = new vBulletin_OpenID_OptionStore($vbulletin);
940-$dbStore->cleanupNonces();
941-$auth = new Auth_OpenID_Consumer($dbStore);
942-
943-$vbulletin->input->clean_array_gpc('r', array(
944- 'openid' => TYPE_STR,
945- 'openid_mode' => TYPE_STR,
946- 'openid_confirm' => TYPE_STR,
947- 'email' => TYPE_STR,
948- 'email_confirm' => TYPE_STR,
949- 'openid_username' => TYPE_STR,
950- 'openid_action' => TYPE_STR,
951-));
952-
953-/*
954- * Picks an available username based on any username.
955- * (Search for the lowest numerical suffix we need to append to get an
956- * available username)
957- */
958-function pick_username($basename, $vbulletin) {
959- $result = $basename;
960- $usedNames = $vbulletin->db->query_read("
961- SELECT username FROM " . TABLE_PREFIX . "user
962- WHERE username LIKE '" . $basename . "%'
963- ");
964- if ($usedNames->num_rows > 0) {
965- $used = array();
966- for ($i = 0; $i < $usedNames->num_rows; $i++) {
967- $row = $usedNames->fetch_array();
968- $used[] = $row['username'];
969- }
970- $suffix = 2;
971- $found = False;
972- while (!$found) {
973- if (!in_array($basename . $suffix, $used)) {
974- $result = $basename . $suffix;
975- $found = True;
976- }
977- else {
978- $suffix++;
979- }
980- }
981- }
982- return $result;
983-}
984-
985-/*
986- * This function creates a user with the provided data.
987- * $username might or might not exist in the DB, we'll just do our best.
988- * $email should not exist in the DB
989- */
990-function vBOpenID_createUser ($username, $email, $url, $vbulletin) {
991- // init user datamanager class
992- $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
993-
994- $username = pick_username($username, $vbulletin);
995-
996- $userdata->set('username', $username);
997-
998- $newusergroupid = $vbulletin->options['moderatenewmembers'] ? 4 : 2;
999-
1000-
1001- //generate random password
1002- $userdata->set('password', generate_password());
1003-
1004- // set usergroupid
1005- $userdata->set('usergroupid', $newusergroupid);
1006-
1007- // set languageid
1008- $userdata->set('languageid', $vbulletin->userinfo['languageid']);
1009-
1010- // set user title
1011- $ugroup = $vbulletin->usergroupcache["$newusergroupid"];
1012- $userdata->set_usertitle('', false, $ugroup, false, false);
1013-
1014- // register IP address
1015- $userdata->set('ipaddress', IPADDRESS);
1016- $userdata->set('email', $email);
1017- $userdata->pre_save();
1018- // check for errors
1019- if (!empty($userdata->errors))
1020- {
1021- $errorlist = '';
1022- foreach ($userdata->errors AS $index => $error)
1023- {
1024- $errorlist .= "<li>$error</li>";
1025- }
1026- return $errorlist;
1027- }
1028- else
1029- {
1030- // save the data
1031- $vbulletin->userinfo['userid'] = $userid = $userdata->save();
1032- // set OpenID field
1033- vBOpenID_setOpenID ($userid, $url, $vbulletin);
1034- }
1035- return False;
1036-}
1037-$return_to = $vbulletin->options['bburl'] . '/login.php?do=login';
1038-if ($vbulletin->GPC['openid_mode'] == 'id_res') {
1039- // Coming back from the provider
1040- $return = $auth->complete($return_to);
1041- $openid = $return->getDisplayIdentifier();
1042-
1043- if ($return->status == Auth_OpenID_SUCCESS) {
1044- // Coming back from the provider with a successfull authentication.
1045- $fieldname = find_openid_fieldname($vbulletin);
1046- $alternate = ereg_replace('https?://(.+)/', '\\1', $openid);
1047- $queryResult = $vbulletin->db->query_first("
1048- SELECT userid FROM userfield
1049- WHERE $fieldname='$openid' OR $fieldname='$alternate'
1050- ");
1051-
1052- if ($queryResult['userid'] > 0) {
1053- // Coming back from the provider with a successful authentication
1054- // we find that the openid is already associated to a forum user
1055- $vbulletin->userinfo = $vbulletin->db->query_first("
1056- SELECT userid, usergroupid, membergroupids, username
1057- FROM " . TABLE_PREFIX . "user
1058- WHERE userid = '" . $queryResult['userid'] . "'
1059- ");
1060- $vbulletin->url = $vbulletin->options['homeurl'];
1061- $loginSuccess = True;
1062- }
1063- else if ($vbulletin->options['openid_auto_register']) {
1064- // Coming back from the provider with a successful authentication
1065- // we find that the openid is not associated to a forum user, but
1066- // autoregistration is enabled
1067- $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($return);
1068-
1069- $sreg = $sreg_resp->contents();
1070-
1071- if (@$sreg['nickname']) {
1072- $openid_username = $sreg['nickname'];
1073- }
1074- else {
1075- $openid_username = munge_url($return->getDisplayIdentifier());
1076- }
1077-
1078- if (@$sreg['email']) {
1079- // Coming back from the provider with a successful authentication
1080- // we find that the openid is not associated to a forum user.
1081- // Autoregistration is enabled, and an email was provided
1082- // so attempt to create the user.
1083- $errorlist = vBOpenID_createUser ($openid_username,
1084- $sreg['email'], $openid, $vbulletin);
1085- if ($errorlist === False) {
1086- // Success! User created, continue to the forum
1087- $vbulletin->url = $vbulletin->options['homeurl'];
1088- $loginSuccess = True;
1089- }
1090- else {
1091- // Automatic registration failed. It should be a duplicate
1092- // email problem, so we'll need to ask the user for a
1093- // different email.
1094- $openid_confirm = crypt($openid,
1095- $vbulletin->options['openid_secret']);
1096- $email = $email_confirm = $sreg['email'];
1097- $openid_username = htmlspecialchars_uni($openid_username);
1098- $show['errors'] = True;
1099- $template = fetch_template('openid_request_email');
1100- eval('print_output("' . $template . '");');
1101- $loginSuccess = False;
1102- }
1103- }
1104- else {
1105- // Coming back from the provider with a successful authentication
1106- // we find that the openid is not associated to a forum user, but
1107- // autoregistration is enabled. Unluckily, no email was provided
1108- // so we must ask the user.
1109- $openid_confirm = crypt($openid,
1110- $vbulletin->options['openid_secret']);
1111- $errorlist = "<li>Your OpenID provider didn't send us your
1112- email address. Please provide a valid email
1113- address to continue:</li>";
1114- $show['errors'] = True;
1115- $template = fetch_template('openid_request_email');
1116- eval('print_output("' . $template . '");');
1117-
1118- $loginSuccess = False;
1119- }
1120- }
1121- else {
1122- // Coming back from the provider with a successful authentication
1123- // we find that the openid is not associated to a forum user.
1124- // Autoregistration is disabled, so offer the user to associate the
1125- // account to an existing forum user, or forward to the registration
1126- // form.
1127- $openid_confirm = crypt($openid,
1128- $vbulletin->options['openid_secret']);
1129- $errorlist = $vbphrase[openid_no_auto_register];
1130- $show['errors'] = True;
1131- $template = fetch_template('openid_request_user_pass');
1132- eval('print_output("' . $template . '");');
1133-
1134- $loginSuccess = False;
1135- }
1136- } else {
1137- // Coming back from the provider with a failed authentication.
1138- // Just leave things as they are and the system will tell the user.
1139- session_destroy();
1140- }
1141-} else if ($vbulletin->GPC['openid_confirm'] &&
1142- $vbulletin->GPC['openid_action']=='request_email') {
1143- // Coming back from the email request form
1144- $openid = $vbulletin->GPC['openid'];
1145- $openid_confirm = $vbulletin->GPC['openid_confirm'];
1146- $openid_username = $vbulletin->GPC['openid_username'];
1147- $email = $vbulletin->GPC['email'];
1148- $email_confirm = $vbulletin->GPC['email_confirm'];
1149- if (crypt($openid, $vbulletin->options['openid_secret']) != $openid_confirm) {
1150- // Coming back from the email request form, the openid checksum
1151- // is wrong
1152- eval(standard_error(fetch_error('openid_tamperedform')));
1153- }
1154- else if ($email != $email_confirm) {
1155- // Coming back from the email request form, the provided emails
1156- // don't match
1157- $errorlist="<li>The email addresses you provided did not match.
1158- Please try again.</li>";
1159- $show['errors'] = true;
1160- $template = fetch_template('openid_request_email');
1161- eval('print_output("' . $template . '");');
1162- $loginSuccess = False;
1163- }
1164- else {
1165- // Coming back from the email request form, everything seems ok
1166- // so we can attempt to create a user
1167- $errorlist = vBOpenID_createUser($openid_username, $email, $openid,
1168- $vbulletin);
1169- if ($errorlist === False) {
1170- // Success! Continue to the forum
1171- $vbulletin->url = $vbulletin->options['homeurl'];
1172- $loginSuccess = True;
1173- }
1174- else {
1175- // User creation failed, so we need to ask again
1176- $openid_username = htmlspecialchars_uni($openid_username);
1177- $show['errors'] = true;
1178- $template = fetch_template('openid_request_email');
1179- eval('print_output("' . $template . '");');
1180- $loginSuccess = False;
1181- }
1182- }
1183-} else if ($vbulletin->GPC['openid_confirm'] &&
1184- $vbulletin->GPC['openid_action']=='request_user') {
1185- // Coming back from user/pass request form. This is already bad, as
1186- // the user/pass form should authenticate successfully.
1187- // A bad user/pass must have been provided, so ask again.
1188- $openid_confirm = $vbulletin->GPC['openid_confirm'];
1189- $errorlist = fetch_error('badlogin', $vbulletin->options['bburl'], $vbulletin->session->vars['sessionurl']);
1190- $show['errors'] = True;
1191- $template = fetch_template('openid_request_user_pass');
1192- eval('print_output("' . $template . '");');
1193-
1194- $loginSuccess = False;
1195-} else if ($vbulletin->GPC['openid']) {
1196- // Start an OpenID authentication
1197- $authRequest = $auth->begin($vbulletin->GPC['openid']);
1198-
1199- $allowed = $vbulletin->options['openid_allowedproviders'];
1200- $endpoint = $authRequest->endpoint->server_url;
1201- if (strlen($allowed) > 0 && !server_allowed($endpoint, $allowed)) {
1202- // The provided OpenID's server is not allowed
1203- eval(standard_error(fetch_error('openid_server_not_allowed', $endpoint)));
1204- }
1205- else {
1206- // Start an OpenID authentication with an allowed server
1207- $error = vBOpenID_sendRequest ($vbulletin, $authRequest, $return_to);
1208- if ($error !== False) {
1209- eval(standard_error($error));
1210- }
1211- }
1212-} else {
1213- session_destroy();
1214-}
1215-
1216-if ($loginSuccess) {
1217- exec_unstrike_user($vbulletin->userinfo['username']);
1218- // create new session
1219- process_new_login($vbulletin->GPC['logintype'],
1220- $vbulletin->GPC['cookieuser'],
1221- $vbulletin->GPC['cssprefs']);
1222- session_destroy();
1223- // do redirect
1224- do_login_redirect();
1225-}
1226-
1227+*/
1228+
1229+ /*
1230+ * This file is connected to the login_failure hook.
1231+ *
1232+ * Here we handle all signing in via OpenID. If the user provides a valid
1233+ * OpenID but not a user/pass the login callback will fail, giving us a chance
1234+ * to perform additional authentication.
1235+ */
1236+ require_once 'vbopenid/openid_utils.php';
1237+ vBOpenID_init ($vbulletin);
1238+
1239+ require_once 'Auth/OpenID.php';
1240+ require_once 'Auth/OpenID/Consumer.php';
1241+ require_once 'Auth/OpenID/SReg.php';
1242+
1243+ require_once 'vbopenid/openid_store.php';
1244+ session_name('vbulletin-openid');
1245+ session_start();
1246+
1247+ $loginSuccess = false;
1248+
1249+ $dbStore = new vBulletin_OpenID_OptionStore($vbulletin);
1250+ $dbStore->cleanupNonces();
1251+ $auth = new Auth_OpenID_Consumer($dbStore);
1252+
1253+ $vbulletin->input->clean_array_gpc('r', array(
1254+ 'openid' => TYPE_STR,
1255+ 'openid_mode' => TYPE_STR,
1256+ 'openid_confirm' => TYPE_STR,
1257+ 'email' => TYPE_STR,
1258+ 'email_confirm' => TYPE_STR,
1259+ 'openid_username' => TYPE_STR,
1260+ 'openid_action' => TYPE_STR,
1261+ ));
1262+
1263+ /*
1264+ * Picks an available username based on any username.
1265+ * (Search for the lowest numerical suffix we need to append to get an
1266+ * available username)
1267+ */
1268+ function pick_username($basename, $vbulletin)
1269+ {
1270+ $result = $basename;
1271+ $usedNames = $vbulletin->db->query_read("
1272+ SELECT username FROM " . TABLE_PREFIX . "user
1273+ WHERE username LIKE '" . $basename . "%'
1274+ ");
1275+
1276+ if ($usedNames->num_rows > 0)
1277+ {
1278+ $used = array();
1279+ for ($i = 0; $i < $usedNames->num_rows; $i++)
1280+ {
1281+ $row = $usedNames->fetch_array();
1282+ $used[] = $row['username'];
1283+ }
1284+
1285+ $suffix = 2;
1286+ $found = false;
1287+ while (!$found)
1288+ {
1289+ if (!in_array($basename . $suffix, $used))
1290+ {
1291+ $result = $basename . $suffix;
1292+ $found = true;
1293+ }
1294+ else
1295+ {
1296+ $suffix++;
1297+ }
1298+ }
1299+ }
1300+
1301+ error_log("pick_username: " . $result, 0);
1302+ return $result;
1303+ }
1304+
1305+ /*
1306+ * This function creates a user with the provided data.
1307+ * $username might or might not exist in the DB, we'll just do our best.
1308+ * $email should not exist in the DB
1309+ */
1310+ function vBOpenID_createUser ($username, $email, $url, $vbulletin)
1311+ {
1312+ // init user datamanager class
1313+ $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
1314+
1315+ $username = pick_username($username, $vbulletin);
1316+
1317+ $userdata->set('username', $username);
1318+
1319+ $newusergroupid = $vbulletin->options['moderatenewmembers'] ? 4 : 2;
1320+
1321+
1322+ //generate random password
1323+ $userdata->set('password', generate_password());
1324+
1325+ // set usergroupid
1326+ $userdata->set('usergroupid', $newusergroupid);
1327+
1328+ // set languageid
1329+ $userdata->set('languageid', $vbulletin->userinfo['languageid']);
1330+
1331+ // set user title
1332+ $ugroup = $vbulletin->usergroupcache["$newusergroupid"];
1333+ $userdata->set_usertitle('', false, $ugroup, false, false);
1334+
1335+ // register IP address
1336+ $userdata->set('ipaddress', IPADDRESS);
1337+ $userdata->set('email', $email);
1338+ $userdata->pre_save();
1339+
1340+ // check for errors
1341+ if (!empty($userdata->errors))
1342+ {
1343+ $errorlist = '';
1344+ foreach ($userdata->errors AS $index => $error)
1345+ {
1346+ $errorlist .= "<li>$error</li>";
1347+ }
1348+
1349+ return $errorlist;
1350+ }
1351+ else
1352+ {
1353+ // save the data
1354+ $vbulletin->userinfo['userid'] = $userid = $userdata->save();
1355+ // set OpenID field
1356+ vBOpenID_setOpenID ($userid, $url, $vbulletin);
1357+ }
1358+
1359+ error_log("vBOpenID_createUser: false", 0);
1360+ return false;
1361+ }
1362+
1363+
1364+ $return_to = $vbulletin->options['bburl'] . '/login.php?do=login';
1365+ if ($vbulletin->GPC['openid_mode'] == 'id_res')
1366+ {
1367+ // Coming back from the provider
1368+ $return = $auth->complete($return_to);
1369+
1370+ // The DisplayIdentifier is the Claimed ID, whereas the Local ID is
1371+ // the ID that the provider refers to you as. Its safer to just keep
1372+ // track of the Local ID, but we can switch back to the Display ID
1373+ // if necessary.
1374+ //$openid = $return->getDisplayIdentifier();
1375+ $openid = $return->endpoint->getLocalID();
1376+
1377+ error_log("return_to return: " . $return, 0);
1378+ error_log("return_to openid: " . $openid, 0);
1379+
1380+ // Was the authentication successful? If not, lets destroy the session.
1381+ if ($return->status == Auth_OpenID_SUCCESS)
1382+ {
1383+ // Coming back from the provider with a successful authentication.
1384+ $fieldname = find_openid_fieldname($vbulletin);
1385+ $alternate = ereg_replace('https?://(.+)/', '\\1', $openid);
1386+
1387+ // We need to make sure that our fieldname was found, otherwise abort.
1388+ if ($fieldname)
1389+ {
1390+ $queryResult = $vbulletin->db->query_first("
1391+ SELECT userid FROM " . TABLE_PREFIX . "userfield
1392+ WHERE $fieldname='$openid' OR $fieldname='$alternate'
1393+ ");
1394+ }
1395+
1396+ if (isset($queryResult) && $queryResult['userid'] > 0)
1397+ {
1398+ // Coming back from the provider with a successful authentication
1399+ // we find that the openid is already associated to a forum user
1400+ $vbulletin->userinfo = $vbulletin->db->query_first("
1401+ SELECT userid, usergroupid, membergroupids, username
1402+ FROM " . TABLE_PREFIX . "user
1403+ WHERE userid = '" . $queryResult['userid'] . "'
1404+ ");
1405+ $vbulletin->url = $vbulletin->options['homeurl'];
1406+ $loginSuccess = true;
1407+ }
1408+ else if ($vbulletin->options['openid_auto_register'])
1409+ {
1410+ // Coming back from the provider with a successful authentication
1411+ // we find that the openid is not associated to a forum user, but
1412+ // autoregistration is enabled
1413+ $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($return);
1414+
1415+ $sreg = $sreg_resp->contents();
1416+
1417+ if (@$sreg['nickname'])
1418+ {
1419+ $openid_username = $sreg['nickname'];
1420+ error_log("openid_username 'nickname': " . $openid_username, 0);
1421+ }
1422+ else
1423+ {
1424+ $openid_username = munge_url($return->getDisplayIdentifier());
1425+ error_log("openid_username: " . $openid_username, 0);
1426+ }
1427+
1428+ // Did the provider send use the users email address?
1429+ if (@$sreg['email'])
1430+ {
1431+ // Coming back from the provider with a successful authentication
1432+ // we find that the openid is not associated to a forum user.
1433+ // Autoregistration is enabled, and an email was provided
1434+ // so attempt to create the user.
1435+ $errorlist = vBOpenID_createUser ($openid_username,
1436+ $sreg['email'], $openid, $vbulletin);
1437+
1438+ if ($errorlist === false)
1439+ {
1440+ // Success! User created, continue to the forum
1441+ $vbulletin->url = $vbulletin->options['homeurl'];
1442+ $loginSuccess = true;
1443+ }
1444+ else
1445+ {
1446+ // Automatic registration failed. It should be a duplicate
1447+ // email problem, so we'll need to ask the user for a
1448+ // different email.
1449+ $openid_confirm = crypt($openid, $vbulletin->options['openid_secret']);
1450+ $email = $email_confirm = $sreg['email'];
1451+ $openid_username = htmlspecialchars_uni($openid_username);
1452+ $show['errors'] = true;
1453+
1454+ // We need to build up our basic template sections
1455+ $templater = vB_Template::create('headinclude');
1456+ $headinclude = $templater->render(true, true);
1457+ $templater = vB_Template::create('header');
1458+ $header = $templater->render(true, true);
1459+ $templater = vB_Template::create('navbar');
1460+ $navbar = $templater->render(true, true);
1461+ $templater = vB_Template::create('footer');
1462+ $footer = $templater->render(true, true);
1463+
1464+ // Create our custom template and populate our variables
1465+ $templater = vB_Template::create('openid_request_email');
1466+ $templater->register('headinclude', $headinclude);
1467+ $templater->register('header', $header);
1468+ $templater->register('navbar', $navbar);
1469+ $templater->register('footer', $footer);
1470+ $templater->register('errorlist', $errorlist);
1471+ $templater->register('openid', $openid);
1472+ $templater->register('openid_confirm', $openid_confirm);
1473+ $templater->register('openid_username', $openid_username);
1474+ $templater->register('email', $email);
1475+ $templater->register('email_confirm', $email_confirm);
1476+ $template = $templater->render(true, true);
1477+ print_output($template);
1478+
1479+ $loginSuccess = false;
1480+ }
1481+ }
1482+ else
1483+ {
1484+ // Coming back from the provider with a successful authentication
1485+ // we find that the openid is not associated to a forum user, but
1486+ // autoregistration is enabled. Unluckily, no email was provided
1487+ // so we must ask the user.
1488+ $openid_confirm = crypt($openid, $vbulletin->options['openid_secret']);
1489+ $errorlist = "<li>Your OpenID provider didn't send us your
1490+ email address. Please provide a valid email
1491+ address to continue:</li>";
1492+ $show['errors'] = true;
1493+
1494+ // We need to build up our basic template sections
1495+ $templater = vB_Template::create('headinclude');
1496+ $headinclude = $templater->render(true, true);
1497+ $templater = vB_Template::create('header');
1498+ $header = $templater->render(true, true);
1499+ $templater = vB_Template::create('navbar');
1500+ $navbar = $templater->render(true, true);
1501+ $templater = vB_Template::create('footer');
1502+ $footer = $templater->render(true, true);
1503+
1504+ // Create our custom template and populate our variables
1505+ $templater = vB_Template::create('openid_request_email');
1506+ $templater->register('headinclude', $headinclude);
1507+ $templater->register('header', $header);
1508+ $templater->register('navbar', $navbar);
1509+ $templater->register('footer', $footer);
1510+ $templater->register('errorlist', $errorlist);
1511+ $templater->register('openid', $openid);
1512+ $templater->register('openid_confirm', $openid_confirm);
1513+ $templater->register('openid_username', $openid_username);
1514+ $templater->register('email', "");
1515+ $templater->register('email_confirm', "");
1516+ $template = $templater->render(true, true);
1517+ print_output($template);
1518+
1519+ $loginSuccess = false;
1520+ }
1521+ }
1522+ else
1523+ {
1524+ // Coming back from the provider with a successful authentication
1525+ // we find that the openid is not associated to a forum user.
1526+ // Autoregistration is disabled, so offer the user to associate the
1527+ // account to an existing forum user, or forward to the registration
1528+ // form.
1529+ $openid_confirm = crypt($openid, $vbulletin->options['openid_secret']);
1530+ $errorlist = $vbphrase[openid_no_auto_register];
1531+ $show['errors'] = true;
1532+
1533+ // We need to build up our basic template sections
1534+ $templater = vB_Template::create('headinclude');
1535+ $headinclude = $templater->render(true, true);
1536+ $templater = vB_Template::create('header');
1537+ $header = $templater->render(true, true);
1538+ $templater = vB_Template::create('navbar');
1539+ $navbar = $templater->render(true, true);
1540+ $templater = vB_Template::create('footer');
1541+ $footer = $templater->render(true, true);
1542+
1543+ // Create our custom template and populate our variables
1544+ $templater = vB_Template::create('openid_request_user_pass');
1545+ $templater->register('headinclude', $headinclude);
1546+ $templater->register('header', $header);
1547+ $templater->register('navbar', $navbar);
1548+ $templater->register('footer', $footer);
1549+ $templater->register('errorlist', $errorlist);
1550+ $templater->register('openid', $openid);
1551+ $templater->register('openid_confirm', $openid_confirm);
1552+ $templater->register('openid_username', $openid_username);
1553+ $template = $templater->render(true, true);
1554+ print_output($template);
1555+
1556+ $loginSuccess = false;
1557+ }
1558+ }
1559+ else
1560+ {
1561+ // Coming back from the provider with a failed authentication.
1562+ // Just leave things as they are and the system will tell the user.
1563+ session_destroy();
1564+ }
1565+ }
1566+ else if ($vbulletin->GPC['openid_confirm'] &&
1567+ $vbulletin->GPC['openid_action']=='request_email')
1568+ {
1569+ // Coming back from the email request form
1570+ $openid = $vbulletin->GPC['openid'];
1571+ $openid_confirm = $vbulletin->GPC['openid_confirm'];
1572+ $openid_username = $vbulletin->GPC['openid_username'];
1573+ $email = $vbulletin->GPC['email'];
1574+ $email_confirm = $vbulletin->GPC['email_confirm'];
1575+
1576+ // Let's make sure that the openid checksum is correct and the confirmed
1577+ // email addresses match. If so, we can attempt to create the user.
1578+ if (crypt($openid, $vbulletin->options['openid_secret']) != $openid_confirm)
1579+ {
1580+ // Coming back from the email request form, the openid checksum
1581+ // is wrong
1582+ eval(standard_error(fetch_error('openid_tamperedform')));
1583+ }
1584+ else if ($email != $email_confirm)
1585+ {
1586+ // Coming back from the email request form, the provided emails
1587+ // don't match
1588+ $errorlist="<li>The email addresses you provided did not match.
1589+ Please try again.</li>";
1590+ $show['errors'] = true;
1591+
1592+ // We need to build up our basic template sections
1593+ $templater = vB_Template::create('headinclude');
1594+ $headinclude = $templater->render(true, true);
1595+ $templater = vB_Template::create('header');
1596+ $header = $templater->render(true, true);
1597+ $templater = vB_Template::create('navbar');
1598+ $navbar = $templater->render(true, true);
1599+ $templater = vB_Template::create('footer');
1600+ $footer = $templater->render(true, true);
1601+
1602+ // Create our custom template and populate our variables
1603+ $templater = vB_Template::create('openid_request_email');
1604+ $templater->register('headinclude', $headinclude);
1605+ $templater->register('header', $header);
1606+ $templater->register('navbar', $navbar);
1607+ $templater->register('footer', $footer);
1608+ $templater->register('errorlist', $errorlist);
1609+ $templater->register('openid', $openid);
1610+ $templater->register('openid_confirm', $openid_confirm);
1611+ $templater->register('openid_username', $openid_username);
1612+ $templater->register('email', "");
1613+ $templater->register('email_confirm', "");
1614+ $template = $templater->render(true, true);
1615+ print_output($template);
1616+
1617+ $loginSuccess = false;
1618+ }
1619+ else
1620+ {
1621+ // Coming back from the email request form, everything seems ok
1622+ // so we can attempt to create a user
1623+ $errorlist = vBOpenID_createUser($openid_username, $email,
1624+ $openid, $vbulletin);
1625+
1626+ if ($errorlist === false)
1627+ {
1628+ // Success! Continue to the forum
1629+ $vbulletin->url = $vbulletin->options['homeurl'];
1630+ $loginSuccess = true;
1631+ }
1632+ else
1633+ {
1634+ // User creation failed, so we need to ask again
1635+ $openid_username = htmlspecialchars_uni($openid_username);
1636+ $show['errors'] = true;
1637+
1638+ // We need to build up our basic template sections
1639+ $templater = vB_Template::create('headinclude');
1640+ $headinclude = $templater->render(true, true);
1641+ $templater = vB_Template::create('header');
1642+ $header = $templater->render(true, true);
1643+ $templater = vB_Template::create('navbar');
1644+ $navbar = $templater->render(true, true);
1645+ $templater = vB_Template::create('footer');
1646+ $footer = $templater->render(true, true);
1647+
1648+ // Create our custom template and populate our variables
1649+ $templater = vB_Template::create('openid_request_email');
1650+ $templater->register('headinclude', $headinclude);
1651+ $templater->register('header', $header);
1652+ $templater->register('navbar', $navbar);
1653+ $templater->register('footer', $footer);
1654+ $templater->register('errorlist', $errorlist);
1655+ $templater->register('openid', $openid);
1656+ $templater->register('openid_confirm', $openid_confirm);
1657+ $templater->register('openid_username', $openid_username);
1658+ $templater->register('email', $email);
1659+ $templater->register('email_confirm', $email_confirm);
1660+ $template = $templater->render(true, true);
1661+ print_output($template);
1662+
1663+ $loginSuccess = false;
1664+ }
1665+ }
1666+ }
1667+ else if ($vbulletin->GPC['openid_confirm'] &&
1668+ $vbulletin->GPC['openid_action']=='request_user')
1669+ {
1670+ // Coming back from user/pass request form. This is already bad, as
1671+ // the user/pass form should authenticate successfully.
1672+ // A bad user/pass must have been provided, so ask again.
1673+ $openid_confirm = $vbulletin->GPC['openid_confirm'];
1674+ $errorlist = fetch_error('badlogin', $vbulletin->options['bburl'],
1675+ $vbulletin->session->vars['sessionurl']);
1676+ $show['errors'] = true;
1677+
1678+ // We need to build up our basic template sections
1679+ $templater = vB_Template::create('headinclude');
1680+ $headinclude = $templater->render(true, true);
1681+ $templater = vB_Template::create('header');
1682+ $header = $templater->render(true, true);
1683+ $templater = vB_Template::create('navbar');
1684+ $navbar = $templater->render(true, true);
1685+ $templater = vB_Template::create('footer');
1686+ $footer = $templater->render(true, true);
1687+
1688+ // Create our custom template and populate our variables
1689+ $templater = vB_Template::create('openid_request_user_pass');
1690+ $templater->register('headinclude', $headinclude);
1691+ $templater->register('header', $header);
1692+ $templater->register('navbar', $navbar);
1693+ $templater->register('footer', $footer);
1694+ $templater->register('errorlist', $errorlist);
1695+ $template = $templater->render(true, true);
1696+ print_output($template);
1697+
1698+ $loginSuccess = false;
1699+ }
1700+ else if ($vbulletin->GPC['openid'])
1701+ {
1702+ // Start an OpenID authentication
1703+ $authRequest = $auth->begin($vbulletin->GPC['openid']);
1704+
1705+ // Make sure we have a valid auth request. Invalid OpenID urls
1706+ // can cause problems if we don't check first.
1707+ if (isset($authRequest))
1708+ {
1709+ $allowed = $vbulletin->options['openid_allowedproviders'];
1710+ $endpoint = $authRequest->endpoint->server_url;
1711+ if (strlen($allowed) > 0 && !server_allowed($endpoint, $allowed))
1712+ {
1713+ // The provided OpenID's server is not allowed
1714+ eval(standard_error(fetch_error('openid_server_not_allowed', $endpoint)));
1715+ }
1716+ else
1717+ {
1718+ // Start an OpenID authentication with an allowed server
1719+ $error = vBOpenID_sendRequest ($vbulletin, $authRequest, $return_to);
1720+ if ($error !== false)
1721+ {
1722+ eval(standard_error($error));
1723+ }
1724+ }
1725+ }
1726+ /*else
1727+ {
1728+ We smoothly let this invalid login attempt fail and warn the user
1729+ }*/
1730+ }
1731+ else
1732+ {
1733+ session_destroy();
1734+ }
1735+
1736+ // If the openid authentication was successful, we can process
1737+ // the users login and smoothly send them back to the forums.
1738+ if ($loginSuccess)
1739+ {
1740+ exec_unstrike_user($vbulletin->userinfo['username']);
1741+
1742+ // create new session
1743+ process_new_login($vbulletin->GPC['logintype'],
1744+ $vbulletin->GPC['cookieuser'],
1745+ $vbulletin->GPC['cssprefs']);
1746+ session_destroy();
1747+
1748+ // do redirect
1749+ do_login_redirect();
1750+ }
1751 ?>
1752
1753=== modified file 'upload/openid_store.php'
1754--- upload/openid_store.php 2012-07-23 16:21:45 +0000
1755+++ upload/openid_store.php 2012-10-24 17:05:24 +0000
1756@@ -1,6 +1,8 @@
1757-<!--
1758+<?php
1759+/**
1760 Copyright 2009 William Norris
1761 Copyright 2009 Anthony Lenton
1762+Copyright 2012 Kyle Baker
1763 Copyright 2012 Canonical
1764
1765 This file is part of vbulletin-openid-integration.
1766@@ -17,222 +19,277 @@
1767
1768 You should have received a copy of the GNU Lesser Public License
1769 along with vbulletin-openid-integration. If not, see <http://www.gnu.org/licenses/>.
1770--->
1771-<?php
1772-/**
1773- * store.php
1774- *
1775- * Database Connector for vBulletin OpenID
1776- * Dual Licence: GPL & Modified BSD
1777- */
1778-
1779-require_once 'Auth/OpenID/Interface.php';
1780-require_once 'Auth/OpenID/Association.php';
1781-
1782-define ('OPENID_ASSOCIATIONS', 'openid_associations');
1783-define ('OPENID_NONCES', 'openid_nonces');
1784-
1785-function escape_string($connection, $string) {
1786- if (is_a($connection, 'mysqli')) {
1787- return mysqli_real_escape_string($connection, $string);
1788- }
1789- elseif (@get_resource_type($connection)) {
1790- return mysql_real_escape_string($string, $connection);
1791- }
1792-}
1793-
1794-function query($connection, $sql) {
1795- if (is_a($connection, 'mysqli')) {
1796- return mysqli_query($connection, $sql);
1797- }
1798- elseif (@get_resource_type($connection)) {
1799- return mysql_query($sql, $connection);
1800- }
1801-}
1802-
1803-function commit($connection) {
1804- if (is_a($connection, 'mysqli')) {
1805- return mysqli_commit($connection);
1806- }
1807- // plain MySQL connections don't need committing
1808-}
1809-
1810-function fetch_row($result) {
1811- if (is_a($result, 'mysqli_result')) {
1812- return mysqli_fetch_row($result);
1813- }
1814- elseif (@get_resource_type($result)) {
1815- return mysql_fetch_row($result);
1816- }
1817-}
1818-
1819-function _createDBTables($vbulletin) {
1820- $connection = $vbulletin->db->connection_master;
1821- $assoc_name = OPENID_ASSOCIATIONS;
1822- $nonce_name = OPENID_NONCES;
1823- query($connection,
1824- "CREATE TABLE `$assoc_name` (
1825- `value` mediumtext,
1826- `server_url` varchar(500),
1827- `handle` varchar(200),
1828- `expires` timestamp,
1829- PRIMARY KEY (`server_url`, `handle`)
1830- )"
1831- );
1832- query($connection,
1833- "CREATE TABLE `$nonce_name` (
1834- `keyname` varchar(200) NOT NULL default '',
1835- `value` timestamp,
1836- PRIMARY KEY (`keyname`)
1837- )"
1838- );
1839-}
1840-
1841-function _removeDBTables($vbulletin) {
1842- $connection = $vbulletin->db->connection_master;
1843- $assoc_name = OPENID_ASSOCIATIONS;
1844- $nonce_name = OPENID_NONCES;
1845- query($connection, "DROP TABLE $assoc_name");
1846- query($connection, "DROP TABLE $nonce_name");
1847-}
1848-
1849-/**
1850- * OpenID store that uses the vBulletin options table for storage.
1851- * Originally written by Simon Willison for use in the mu-open-id
1852- * plugin. Modified a fair amount for use in WordPress OpenID,
1853- * then ported to use with vBulletin.
1854- */
1855-class vBulletin_OpenID_OptionStore extends Auth_OpenID_OpenIDStore {
1856- function vBulletin_OpenID_OptionStore($vbulletin,
1857- $associations_table = null,
1858- $nonces_table = null)
1859- {
1860- /* DB tables are created during product installation */
1861- $this->connection = $vbulletin->db->connection_master;
1862- }
1863-
1864- function _fetchNonceFromDB($key) {
1865- $nonce_name = OPENID_NONCES;
1866- if ($result = query($this->connection,
1867- "SELECT value FROM $nonce_name WHERE keyname='$key'")) {
1868- $row = fetch_row($result);
1869- return $row[0];
1870- }
1871- }
1872-
1873- function _fetchAssocFromDB($server_url, $handle=null) {
1874- $table = OPENID_ASSOCIATIONS;
1875- $server_url = escape_string($this->connection, $server_url);
1876- if ($handle) {
1877- $handle = escape_string($this->connection, $handle);
1878- $sql = "SELECT value FROM $table WHERE
1879- server_url='$server_url'
1880- AND handle='$handle'";
1881- }
1882- else {
1883- $sql = "SELECT value FROM $table WHERE
1884- server_url='$server_url' AND
1885- expires > NOW()
1886- ORDER BY expires DESC LIMIT 1";
1887- }
1888- $result = query($this->connection, $sql);
1889- if ($result) {
1890- $row = fetch_row($result);
1891- return $row[0];
1892- }
1893- }
1894-
1895- function _storeNonceToDB($key, $value) {
1896- $table = OPENID_NONCES;
1897- query($this->connection,
1898- "DELETE FROM $table WHERE keyname='$key'");
1899- query($this->connection, "INSERT INTO $table
1900- (`keyname`, `value`) VALUES ('$key', '$value')");
1901- commit($this->connection);
1902- }
1903-
1904- function _storeAssocToDB($server_url, $handle, $value, $expires) {
1905- $table = OPENID_ASSOCIATIONS;
1906- $server_url = escape_string($this->connection, $server_url);
1907- $handle = escape_string($this->connection, $handle);
1908- query($this->connection, "DELETE FROM $table WHERE
1909- server_url='$server_url'");
1910- query($this->connection, "INSERT INTO $table
1911- (`server_url`, `handle`, `value`, `expires`) VALUES
1912- ('$server_url', '$handle', '$value', '$expires')");
1913- commit($this->connection);
1914- }
1915-
1916- function storeAssociation($server_url, $association) {
1917- $value = $association->serialize();
1918- $handle = $association->handle;
1919- if ($handle === null) {
1920- $handle = '';
1921- }
1922- $expires = $association->issued + $association->lifetime;
1923- $expires = strftime('%F %T', $expires);
1924- $this->_storeAssocToDB($server_url, $handle, $value, $expires);
1925- }
1926-
1927- function getAssociation($server_url, $handle = null) {
1928- $association = $this->_fetchAssocFromDB($server_url, $handle);
1929- if ($association) {
1930- return Auth_OpenID_Association::deserialize(
1931- 'Auth_OpenID_Association', $association
1932- );
1933- }
1934- return null;
1935- }
1936-
1937- function removeAssociation($server_url, $handle) {
1938- // Remove the matching association if it's found, and
1939- // returns whether the association was removed or not.
1940- $assoc = $this->getAssociation($server_url, $handle);
1941- if ($assoc === null) {
1942- return false;
1943- } else {
1944- $table = OPENID_ASSOCIATIONS;
1945- $server_url = escape_string($this->connection, $server_url);
1946- $handle = escape_string($this->connection, $handle);
1947- query($this->connection, "DELETE FROM $table WHERE
1948- server_url='$server_url' AND handle='$handle'");
1949- return true;
1950- }
1951- }
1952-
1953- function useNonce($server_url, $timestamp, $salt) {
1954- if ( abs($timestamp - time()) > 1200 ) {
1955- return false;
1956- }
1957- $key = $this->_getNonceKey($server_url, $timestamp, $salt);
1958- $nonce = $this->_fetchNonceFromDB($key);
1959- if ($nonce) {
1960- return false;
1961- } else {
1962- $value = strftime('%F %T', $timestamp);
1963- $this->_storeNonceToDB($key, $value);
1964- return true;
1965- }
1966- }
1967-
1968- function _getNonceKey($server_url, $timestamp, $salt) {
1969- $url_hash = base64_encode($server_url);
1970- $salt_hash = base64_encode($salt);
1971- return sprintf('%08x-%s-%s', $timestamp, $url_hash, $salt_hash);
1972- }
1973-
1974- function cleanupNonces() {
1975- $table = OPENID_NONCES;
1976- query($this->connection, "DELETE FROM $table
1977- WHERE value < NOW() - INTERVAL 20 MINUTE");
1978- }
1979-
1980- function cleanupAssociations() {
1981- $table = OPENID_ASSOCIATIONS;
1982- query($this->connection, "DELETE FROM $table
1983- WHERE expires < NOW()");
1984- }
1985-
1986-}
1987-
1988+*/
1989+
1990+ /**
1991+ * store.php
1992+ *
1993+ * Database Connector for vBulletin OpenID
1994+ * Dual Licence: GPL & Modified BSD
1995+ */
1996+
1997+ require_once 'Auth/OpenID/Interface.php';
1998+ require_once 'Auth/OpenID/Association.php';
1999+
2000+ define ('OPENID_ASSOCIATIONS', 'openid_associations');
2001+ define ('OPENID_NONCES', 'openid_nonces');
2002+
2003+ function escape_string($connection, $string)
2004+ {
2005+ if (is_a($connection, 'mysqli'))
2006+ {
2007+ error_log("escape_string is_a: " . mysqli_real_escape_string($connection, $string), 0);
2008+ return mysqli_real_escape_string($connection, $string);
2009+ }
2010+ elseif (@get_resource_type($connection))
2011+ {
2012+ error_log("escape_string get_resource_type: " . mysql_real_escape_string($string, $connection), 0);
2013+ return mysql_real_escape_string($string, $connection);
2014+ }
2015+ error_log("escape_string: none", 0);
2016+ }
2017+
2018+ function query($connection, $sql)
2019+ {
2020+ if (is_a($connection, 'mysqli'))
2021+ {
2022+ return mysqli_query($connection, $sql);
2023+ }
2024+ elseif (@get_resource_type($connection))
2025+ {
2026+ return mysql_query($sql, $connection);
2027+ }
2028+ }
2029+
2030+ function commit($connection)
2031+ {
2032+ if (is_a($connection, 'mysqli'))
2033+ {
2034+ error_log("commit is_a: " . mysqli_commit($connection), 0);
2035+ return mysqli_commit($connection);
2036+ }
2037+ error_log("commit: none", 0);
2038+ // plain MySQL connections don't need committing
2039+ }
2040+
2041+ function fetch_row($result)
2042+ {
2043+ if (is_a($result, 'mysqli_result'))
2044+ {
2045+ return mysqli_fetch_row($result);
2046+ }
2047+ elseif (@get_resource_type($result))
2048+ {
2049+ return mysql_fetch_row($result);
2050+ }
2051+ }
2052+
2053+ function _createDBTables($vbulletin)
2054+ {
2055+ $connection = $vbulletin->db->connection_master;
2056+ $assoc_name = OPENID_ASSOCIATIONS;
2057+ $nonce_name = OPENID_NONCES;
2058+
2059+ query($connection,
2060+ "CREATE TABLE `$assoc_name` (
2061+ `value` mediumtext,
2062+ `server_url` varchar(500),
2063+ `handle` varchar(200),
2064+ `expires` timestamp,
2065+ PRIMARY KEY (`server_url`, `handle`)
2066+ )"
2067+ );
2068+ query($connection,
2069+ "CREATE TABLE `$nonce_name` (
2070+ `keyname` varchar(200) NOT NULL default '',
2071+ `value` timestamp,
2072+ PRIMARY KEY (`keyname`)
2073+ )"
2074+ );
2075+ }
2076+
2077+ function _removeDBTables($vbulletin)
2078+ {
2079+ $connection = $vbulletin->db->connection_master;
2080+ $assoc_name = OPENID_ASSOCIATIONS;
2081+ $nonce_name = OPENID_NONCES;
2082+
2083+ query($connection, "DROP TABLE $assoc_name");
2084+ query($connection, "DROP TABLE $nonce_name");
2085+ }
2086+
2087+ /**
2088+ * OpenID store that uses the vBulletin options table for storage.
2089+ * Originally written by Simon Willison for use in the mu-open-id
2090+ * plugin. Modified a fair amount for use in WordPress OpenID,
2091+ * then ported to use with vBulletin.
2092+ */
2093+ class vBulletin_OpenID_OptionStore extends Auth_OpenID_OpenIDStore
2094+ {
2095+ function vBulletin_OpenID_OptionStore($vbulletin,
2096+ $associations_table = null,
2097+ $nonces_table = null)
2098+ {
2099+ /* DB tables are created during product installation */
2100+ $this->connection = $vbulletin->db->connection_master;
2101+ }
2102+
2103+ function _fetchNonceFromDB($key)
2104+ {
2105+ $nonce_name = OPENID_NONCES;
2106+ $result = query($this->connection,
2107+ "SELECT value FROM $nonce_name WHERE keyname='$key'");
2108+
2109+ if ($result)
2110+ {
2111+ $row = fetch_row($result);
2112+ error_log("_fetchNonceFromDB: " . $row[0], 0);
2113+ return $row[0];
2114+ }
2115+ }
2116+
2117+ function _fetchAssocFromDB($server_url, $handle=null)
2118+ {
2119+ $table = OPENID_ASSOCIATIONS;
2120+ $server_url = escape_string($this->connection, $server_url);
2121+
2122+ if ($handle)
2123+ {
2124+ $handle = escape_string($this->connection, $handle);
2125+ $sql = "SELECT value FROM $table WHERE
2126+ server_url='$server_url'
2127+ AND handle='$handle'";
2128+ }
2129+ else
2130+ {
2131+ $sql = "SELECT value FROM $table WHERE
2132+ server_url='$server_url' AND
2133+ expires > NOW()
2134+ ORDER BY expires DESC LIMIT 1";
2135+ }
2136+
2137+ $result = query($this->connection, $sql);
2138+ if ($result)
2139+ {
2140+ $row = fetch_row($result);
2141+ error_log("_fetchAssocFromDB: " . $row[0], 0);
2142+ return $row[0];
2143+ }
2144+ }
2145+
2146+ function _storeNonceToDB($key, $value)
2147+ {
2148+ $table = OPENID_NONCES;
2149+ query($this->connection,
2150+ "DELETE FROM $table WHERE keyname='$key'");
2151+ query($this->connection, "INSERT INTO $table
2152+ (`keyname`, `value`) VALUES ('$key', '$value')");
2153+ commit($this->connection);
2154+ }
2155+
2156+ function _storeAssocToDB($server_url, $handle, $value, $expires)
2157+ {
2158+ $table = OPENID_ASSOCIATIONS;
2159+ $server_url = escape_string($this->connection, $server_url);
2160+ $handle = escape_string($this->connection, $handle);
2161+
2162+ query($this->connection, "DELETE FROM $table WHERE
2163+ server_url='$server_url'");
2164+ query($this->connection, "INSERT INTO $table
2165+ (`server_url`, `handle`, `value`, `expires`) VALUES
2166+ ('$server_url', '$handle', '$value', '$expires')");
2167+ commit($this->connection);
2168+ }
2169+
2170+ function storeAssociation($server_url, $association)
2171+ {
2172+ $value = $association->serialize();
2173+ $handle = $association->handle;
2174+
2175+ if ($handle === null)
2176+ {
2177+ $handle = '';
2178+ }
2179+
2180+ $expires = $association->issued + $association->lifetime;
2181+ $expires = strftime('%F %T', $expires);
2182+ $this->_storeAssocToDB($server_url, $handle, $value, $expires);
2183+ }
2184+
2185+ function getAssociation($server_url, $handle = null)
2186+ {
2187+ $association = $this->_fetchAssocFromDB($server_url, $handle);
2188+ if ($association)
2189+ {
2190+ return Auth_OpenID_Association::deserialize(
2191+ 'Auth_OpenID_Association', $association
2192+ );
2193+ }
2194+ return null;
2195+ }
2196+
2197+ function removeAssociation($server_url, $handle)
2198+ {
2199+ // Remove the matching association if it's found, and
2200+ // returns whether the association was removed or not.
2201+ $assoc = $this->getAssociation($server_url, $handle);
2202+ if ($assoc === null)
2203+ {
2204+ return false;
2205+ }
2206+ else
2207+ {
2208+ $table = OPENID_ASSOCIATIONS;
2209+ $server_url = escape_string($this->connection, $server_url);
2210+ $handle = escape_string($this->connection, $handle);
2211+ query($this->connection, "DELETE FROM $table WHERE
2212+ server_url='$server_url' AND handle='$handle'");
2213+ return true;
2214+ }
2215+ }
2216+
2217+ function useNonce($server_url, $timestamp, $salt)
2218+ {
2219+ if ( abs($timestamp - time()) > 1200 )
2220+ {
2221+ return false;
2222+ }
2223+
2224+ $key = $this->_getNonceKey($server_url, $timestamp, $salt);
2225+ $nonce = $this->_fetchNonceFromDB($key);
2226+
2227+ if ($nonce)
2228+ {
2229+ return false;
2230+ }
2231+ else
2232+ {
2233+ $value = strftime('%F %T', $timestamp);
2234+ $this->_storeNonceToDB($key, $value);
2235+ return true;
2236+ }
2237+ }
2238+
2239+ function _getNonceKey($server_url, $timestamp, $salt)
2240+ {
2241+ $url_hash = base64_encode($server_url);
2242+ $salt_hash = base64_encode($salt);
2243+ error_log("_getNonceKey: " . sprintf('%08x-%s-%s', $timestamp, $url_hash, $salt_hash), 0);
2244+ return sprintf('%08x-%s-%s', $timestamp, $url_hash, $salt_hash);
2245+ }
2246+
2247+ function cleanupNonces()
2248+ {
2249+ $table = OPENID_NONCES;
2250+ query($this->connection, "DELETE FROM $table
2251+ WHERE value < NOW() - INTERVAL 20 MINUTE");
2252+ }
2253+
2254+ function cleanupAssociations()
2255+ {
2256+ $table = OPENID_ASSOCIATIONS;
2257+ query($this->connection, "DELETE FROM $table
2258+ WHERE expires < NOW()");
2259+ }
2260+ }
2261 ?>
2262
2263=== modified file 'upload/openid_utils.php'
2264--- upload/openid_utils.php 2012-07-23 16:21:45 +0000
2265+++ upload/openid_utils.php 2012-10-24 17:05:24 +0000
2266@@ -1,6 +1,8 @@
2267-<!--
2268+<?php
2269+/**
2270 Copyright 2009 William Norris
2271 Copyright 2009 Anthony Lenton
2272+Copyright 2012 Kyle Baker
2273 Copyright 2012 Canonical
2274
2275 This file is part of vbulletin-openid-integration.
2276@@ -17,152 +19,216 @@
2277
2278 You should have received a copy of the GNU Lesser Public License
2279 along with vbulletin-openid-integration. If not, see <http://www.gnu.org/licenses/>.
2280--->
2281-<?php
2282-
2283-/*
2284- * Generates a random password
2285- */
2286-function generate_password($passwordLength=10) {
2287- $letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
2288- $lettersLength = strlen($letters);
2289- $pass = '';
2290- for($i = 0; $i < $passwordLength; $i++) {
2291- $pass .= $letters[rand(0, $lettersLength)];
2292- }
2293- return $pass;
2294-}
2295-
2296-/*
2297- * Returns something that could be used as a username based on an OpenID url.
2298- */
2299-function munge_url($url) {
2300- $letters = "0123456789abcdefghijklmnopqrstuvwxyz";
2301- $parts = array_reverse(explode('/', $url));
2302- $found = FALSE;
2303- foreach($parts as $part) {
2304- $munged = '';
2305- for($i = 0; $i < strlen($part); $i++) {
2306- if (stripos($letters, $part[$i]) !== FALSE) {
2307- $munged .= $part[$i];
2308- $found = TRUE;
2309- }
2310- if ($part[$i] == '#') break; // Skip from the hash onwards
2311- }
2312- if ($found) {
2313- return $munged;
2314- }
2315- }
2316-}
2317-
2318-/**
2319- * fnmatch function is not available on non-posix system. This should be a
2320- * suitable replacement for our purposes (ie: wildcard pattern matching for
2321- * server addresses like '*.php.net')
2322- */
2323-if (!function_exists('fnmatch')) {
2324- function fnmatch($pattern, $string) {
2325- return @preg_match(
2326- '/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'),
2327- array('*' => '.*', '?' => '.?')) . '$/i', $string
2328- );
2329- }
2330-}
2331-
2332-/**
2333- * Check if a particular openid provider's server is allowed be used
2334- *
2335- * This may be particularly useful if you want to limit openid servers to those
2336- * which you know meet your authentication requirements or if you are using
2337- * openid as a single sign-on mechanism.
2338- * @param string Name of the server to check
2339- * @param string Coma-separated list of allowed servers. Each server is taken
2340- * as a regex to check if a particular server is allowed.
2341- */
2342-function server_allowed($server, $servers) {
2343- $servers = explode(",", $servers);
2344- foreach ($servers as $allowed_server) {
2345- $allowed_server = trim($allowed_server);
2346- if (empty($allowed_server)) {
2347- next;
2348- }
2349- if (true === fnmatch($allowed_server, $server)) {
2350- return true;
2351- }
2352- }
2353- return false;
2354-}
2355-
2356-/*
2357- * Retrieve the name of the profile field in which we're storing the
2358- * OpenID
2359- */
2360-function find_openid_fieldname($vbulletin) {
2361- $title = $vbulletin->options['openid_field'];
2362- $row = $vbulletin->db->query_first("
2363- SELECT varname FROM phrase
2364- WHERE text='$title' AND varname LIKE 'field%_title'
2365- ");
2366- $varname = $row['varname'];
2367- return substr($varname, 0, strpos($varname, '_'));
2368-}
2369-
2370-/*
2371- * Set the OpenID profile field for a given user
2372- */
2373-function vBOpenID_setOpenID ($userid, $url, $vbulletin) {
2374- $fieldname = find_openid_fieldname($vbulletin);
2375- $vbulletin->db->query_write("
2376- UPDATE userfield SET $fieldname = '$url' WHERE userid=$userid
2377- ");
2378-}
2379-
2380-/*
2381- * Set up global variables
2382- */
2383-function vBOpenID_init ($vbulletin) {
2384- if (!$vbulletin->options['openid_math']) {
2385- define('Auth_OpenID_NO_MATH_SUPPORT', 1);
2386- }
2387- if ($vbulletin->options['openid_path']) {
2388- $path = $vbulletin->options['openid_path'] . ':' . ini_get('include_path');
2389- ini_set('include_path', $path);
2390- }
2391-}
2392-
2393-
2394-function vBOpenID_sendRequest ($vbulletin, $authRequest, $return_to) {
2395- $sreg_request = Auth_OpenID_SRegRequest::build(
2396- array('nickname'),
2397- array('fullname', 'email'));
2398- $authRequest->addExtension($sreg_request);
2399-
2400- if ($authRequest->shouldSendRedirect()) {
2401- $redirect_url = $authRequest->redirectURL($vbulletin->options['homeurl'], $return_to);
2402-
2403- // If the redirect URL can't be built, display an error message.
2404- if (Auth_OpenID::isFailure($redirect_url)) {
2405- return $redirect_url->message;
2406- }
2407- else {
2408- header("Location: $redirectURL");
2409- }
2410- }
2411- else {
2412- $form_id = 'openid_message';
2413- $message = $authRequest->getMessage($vbulletin->options['homeurl'], $return_to, False);
2414- if (Auth_OpenID::isFailure($message)) {
2415- return $message->message;
2416- }
2417- else {
2418- $text_redirect = fetch_error('openid_redirect');
2419- $form_html = $message->toFormMarkup($authRequest->endpoint->server_url,
2420- array('id' => $form_id));
2421- $template = fetch_template('openid_redirect_form');
2422- eval('print_output("' . $template . '");');
2423- }
2424- }
2425- return False;
2426-}
2427-
2428+*/
2429+
2430+ /*
2431+ * Generates a random password
2432+ */
2433+ function generate_password($passwordLength=10)
2434+ {
2435+ $letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
2436+ $lettersLength = strlen($letters);
2437+
2438+ $pass = '';
2439+ for($i = 0; $i < $passwordLength; $i++)
2440+ {
2441+ $pass .= $letters[rand(0, $lettersLength-1)];
2442+ }
2443+
2444+ error_log("generate_password: " . $pass, 0);
2445+ return $pass;
2446+ }
2447+
2448+ /*
2449+ * Returns something that could be used as a username based on an OpenID url.
2450+ */
2451+ function munge_url($url)
2452+ {
2453+ $letters = "0123456789abcdefghijklmnopqrstuvwxyz";
2454+ $parts = array_reverse(explode('/', $url));
2455+
2456+ $found = false;
2457+ foreach($parts as $part)
2458+ {
2459+ $munged = '';
2460+ for($i = 0; $i < strlen($part); $i++)
2461+ {
2462+ if (stripos($letters, $part[$i]) !== false)
2463+ {
2464+ $munged .= $part[$i];
2465+ $found = true;
2466+ }
2467+ if ($part[$i] == '#') break; // Skip from the hash onwards
2468+ }
2469+
2470+ if ($found)
2471+ {
2472+ error_log("munge_url: " . $munged, 0);
2473+ return $munged;
2474+ }
2475+
2476+ error_log("munge_url: none", 0);
2477+ }
2478+ }
2479+
2480+ /**
2481+ * fnmatch function is not available on non-posix system. This should be a
2482+ * suitable replacement for our purposes (ie: wildcard pattern matching for
2483+ * server addresses like '*.php.net')
2484+ */
2485+ if (!function_exists('fnmatch'))
2486+ {
2487+ function fnmatch($pattern, $string)
2488+ {
2489+ return @preg_match(
2490+ '/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'),
2491+ array('*' => '.*', '?' => '.?')) . '$/i', $string
2492+ );
2493+ }
2494+ }
2495+
2496+ /**
2497+ * Check if a particular openid provider's server is allowed be used
2498+ *
2499+ * This may be particularly useful if you want to limit openid servers to those
2500+ * which you know meet your authentication requirements or if you are using
2501+ * openid as a single sign-on mechanism.
2502+ * @param string Name of the server to check
2503+ * @param string Coma-separated list of allowed servers. Each server is taken
2504+ * as a regex to check if a particular server is allowed.
2505+ */
2506+ function server_allowed($server, $servers)
2507+ {
2508+ $servers = explode(",", $servers);
2509+
2510+ foreach ($servers as $allowed_server)
2511+ {
2512+ $allowed_server = trim($allowed_server);
2513+
2514+ if (empty($allowed_server))
2515+ {
2516+ next;
2517+ }
2518+
2519+ if (true === fnmatch($allowed_server, $server))
2520+ {
2521+ error_log("server_allowed: true", 0);
2522+ return true;
2523+ }
2524+ }
2525+
2526+ error_log("server_allowed: false", 0);
2527+ return false;
2528+ }
2529+
2530+ /*
2531+ * Retrieve the name of the profile field in which we're storing the
2532+ * OpenID
2533+ */
2534+ function find_openid_fieldname($vbulletin)
2535+ {
2536+ $title = $vbulletin->options['openid_field'];
2537+ $row = $vbulletin->db->query_first("
2538+ SELECT varname FROM " . TABLE_PREFIX . "phrase
2539+ WHERE text='$title' AND varname LIKE 'field%_title'
2540+ ");
2541+
2542+ $varname = $row['varname'];
2543+
2544+ error_log("find_openid_fieldname: " . substr($varname, 0, strpos($varname, '_')), 0);
2545+ return substr($varname, 0, strpos($varname, '_'));
2546+ }
2547+
2548+ /*
2549+ * Set the OpenID profile field for a given user
2550+ */
2551+ function vBOpenID_setOpenID ($userid, $url, $vbulletin)
2552+ {
2553+ $fieldname = find_openid_fieldname($vbulletin);
2554+
2555+ error_log("vBOpenID_setOpenID fieldname: " . $fieldname, 0);
2556+ $vbulletin->db->query_write("
2557+ UPDATE " . TABLE_PREFIX . "userfield SET $fieldname = '$url' WHERE userid=$userid
2558+ ");
2559+ }
2560+
2561+ /*
2562+ * Set up global variables
2563+ */
2564+ function vBOpenID_init ($vbulletin)
2565+ {
2566+ if (!$vbulletin->options['openid_math'])
2567+ {
2568+ define('Auth_OpenID_NO_MATH_SUPPORT', 1);
2569+ }
2570+ if ($vbulletin->options['openid_path'])
2571+ {
2572+ $path = $vbulletin->options['openid_path'] . ':' . ini_get('include_path');
2573+ ini_set('include_path', $path);
2574+ }
2575+ }
2576+
2577+ function vBOpenID_sendRequest ($vbulletin, $authRequest, $return_to)
2578+ {
2579+ $sreg_request = Auth_OpenID_SRegRequest::build(
2580+ array('nickname'),
2581+ array('fullname', 'email'));
2582+
2583+ $authRequest->addExtension($sreg_request);
2584+
2585+ if ($authRequest->shouldSendRedirect())
2586+ {
2587+ $redirect_url = $authRequest->redirectURL($vbulletin->options['homeurl'], $return_to);
2588+ error_log("redirect url: " . $redirect_url, 0);
2589+
2590+ // If the redirect URL can't be built, display an error message.
2591+ if (Auth_OpenID::isFailure($redirect_url))
2592+ {
2593+ return $redirect_url->message;
2594+ }
2595+ else
2596+ {
2597+ header("Location: $redirectURL");
2598+ }
2599+ }
2600+ else
2601+ {
2602+ $form_id = 'openid_message';
2603+ $message = $authRequest->getMessage($vbulletin->options['homeurl'], $return_to, false);
2604+ if (Auth_OpenID::isFailure($message))
2605+ {
2606+ return $message->message;
2607+ }
2608+ else
2609+ {
2610+ $text_redirect = fetch_error('openid_redirect');
2611+
2612+ // We need to urlencode our localid url for launchpad to preserve
2613+ // the plus char in our uri (ex. https://login.launchpad.net/+id/<random_user_string>)
2614+ $bkp_values = $message->args->values;
2615+ foreach ($bkp_values as $tmp_value)
2616+ {
2617+ // replace + with %2B: https://login.launchpad.net/%2Bid/<random_user_string>
2618+ $tmp_values[] = str_replace("/+id/", "/%2Bid/", $tmp_value);
2619+ }
2620+ $message->args->values = $tmp_values;
2621+
2622+ $form_html = $message->toFormMarkup($authRequest->endpoint->server_url,
2623+ array('id' => $form_id));
2624+ error_log("form_html: " . $form_html, 0);
2625+
2626+ // Let's restore our Message stack in case we decide to use it again later.
2627+ $message->args->values = $bkp_values;
2628+
2629+ $templater = vB_Template::create('openid_redirect_form');
2630+ $templater->register('form_id', $form_id);
2631+ $templater->register('text_redirect', $text_redirect);
2632+ $templater->register('form_html', $form_html);
2633+ $template = $templater->render(true, true);
2634+ print_output($template);
2635+ }
2636+ }
2637+
2638+ return false;
2639+ }
2640 ?>

Subscribers

People subscribed via source and target branches