/[drupal]/contributions/modules/movino/optional/movino_remote_auth.module
ViewVC logotype

Contents of /contributions/modules/movino/optional/movino_remote_auth.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Jan 3 21:00:28 2008 UTC (22 months, 3 weeks ago) by tomsun
Branch: MAIN
CVS Tags: DRUPAL-5--1-1, HEAD
Changes since 1.2: +1 -2 lines
File MIME type: text/x-php
By Mans Adler: Bugfix, movino_remote_auth now respects the user status - blocked users are no longer allowed access.
1 <?php // $Id: movino_remote_auth.module,v 1.1 2007/07/13 10:32:52 tomsun Exp $
2 /*
3 Movino Web Frontend
4 Copyright 2006, 2007 Tom Sundström
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20
21 /**
22 * Implementation of hook_help().
23 */
24 function movino_remote_auth_help($section) {
25 switch ($section) {
26 case 'admin/help#help':
27 // TODO: expand
28 $output = '<p>'. t('Allows the Movino videoserver to authenticate stream sources against the user database of your Drupal site.') . '</p>';
29 return $output;
30 }
31 }
32
33
34 /**
35 * Implementation of hook_menu().
36 */
37 function movino_remote_auth_menu($may_cache) {
38 global $user;
39 $items = array();
40
41 if (!$may_cache) {
42
43 $items[] = array(
44 'path' => 'movino/auth',
45 'title' => t('Movino remote authentication'),
46 'access' => TRUE,
47 'callback' => 'movino_remote_auth_callback',
48 'type' => MENU_CALLBACK
49 );
50 }
51
52 return $items;
53 }
54
55
56 /**
57 * Provides remote authentication.
58 *
59 * The Movino server is allowed to use this callback to verify that
60 * the stream source has a Drupal account with sufficient permissions,
61 * by making an http request to "http://yourdrupalinstall/movino/auth".
62 *
63 */
64 function movino_remote_auth_callback() {
65 header('Content-type: text/plain');
66
67 // Input from server.
68 $user_name = ($_POST['username'] ? $_POST['username']: $_GET['username']);
69 $challenge = pack("H*", ($_POST['challenge'] ? $_POST['challenge']: $_GET['challenge']));
70 $response = pack("H*", ($_POST['response'] ? $_POST['response']: $_GET['response']));
71
72 // Find the user DB record by username.
73 $result = db_query("SELECT name, pass FROM {users} WHERE LOWER(name) = LOWER('%s') AND status = 1 ", $user_name);
74 while ($usr = db_fetch_array($result)) {
75
76 // Compare the password hashes according to the Movino authentication protocol.
77 if ($usr['name'] == $user_name && (pack("H*", md5(pack("H*", $usr['pass']) . $challenge)) == $response)) {
78
79 // Check that the user has proper user permissions.
80 $user_account = user_load(array('name' => $user_name));
81 if (user_access('upload Movino content', $user_account)) {
82 // User permissions verified.
83 echo 'ok';
84 return;
85 }
86 }
87 }
88
89 // Invalid user, password or insufficient permissions.
90 echo 'denied';
91 }

  ViewVC Help
Powered by ViewVC 1.1.2