Skip to content
Snippets Groups Projects
Commit e42d97b5 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

User module and DA modules:

  + Updated the documentation to use a Jabber or Drupal IDs instead of
    Deplhi IDs (as delphi.module won't be part of the default distro).
    Drupal and Jabber authentication make a better example.

  + added missing localization / t() functions in
    user_validate_authmaps()

  + applied coding convention:
      * fixed indentation
      * removed "EOF"; and <<EOFs from user module
      * changed some HTML into XHTML: use small letters, quote
        attributes
      * quoted some array indices: $edit[foo] --> $edit["foo"]

  + removed some useless sprintf()'s

  + removed hard-coded references to drop.org.

  + I don't think the authentication methods should /know/ there help
    link.  Instead, the user module should now where to find the help
    (it does by knowing the hook to look for), and it is the user
    module that should take care of exporting the help to the preferred
    location:
      * removed the "link" field from the $info field in drupal_info
        and jabber_info; it wasn't used anyway?

  + removed the "maintainer" and "maintaineremail" from the auth
    modules; we don't keep this info in the other modules either so
    I don't see a reason to do so here.
parent deaf0271
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
function drupal_info($field = 0) {
$info["name"] = "Drupal";
$info["protocol"] = "XML-RPC";
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
function drupal_auth($username, $password, $server) {
$message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string")));
$client = new xmlrpc_client("/xmlrpc.php", $server, 80);
$result = $client->send($message, 5);
if ($result && !$result->faultCode()) {
$value = $result->value();
$login = $value->scalarval();
}
return $login;
}
function drupal_page() {
global $theme;
$theme->header();
$theme->box("Drupal", drupal_auth_help());
$theme->footer();
}
function drupal_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "
<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>
<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drop.org</i>.</p>";
return sprintf(t($output), $site, $site);
}
?>
\ No newline at end of file
<?php
function drupal_info($field = 0) {
$info["name"] = "Drupal";
$info["protocol"] = "XML-RPC";
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
function drupal_auth($username, $password, $server) {
$message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string")));
$client = new xmlrpc_client("/xmlrpc.php", $server, 80);
$result = $client->send($message, 5);
if ($result && !$result->faultCode()) {
$value = $result->value();
$login = $value->scalarval();
}
return $login;
}
function drupal_page() {
global $theme;
$theme->header();
$theme->box("Drupal", drupal_auth_help());
$theme->footer();
}
function drupal_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "
<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>
<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drop.org</i>.</p>";
return sprintf(t($output), $site, $site);
}
?>
\ No newline at end of file
<?php
function jabber_info($field = 0) {
$info["name"] = "Jabber";
$info["protocol"] = "Jabber";
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
function startElement($parser, $name, $attributes) {
global $jabber;
if ($attributes["ID"]) {
$jabber["jid"] = $attributes["ID"];
}
if (stristr($name, "error") || ($attributes["ERROR"])) {
$jabber["error"] = true;
}
}
function endElement($parser, $name) {
}
function characterData($parser, $data) {
global $jabber;
$jabber["data"] = $data;
}
function jabber_send($session, $message) {
// print "SEND: ". htmlentities($message) ."<br />";
fwrite($session, $message, strlen($message));
}
function jabber_recv($session, $timout = 50) {
/*
** Returns a chunk of data, read from the socket descriptor '$session'.
** If the call fails, or if no data is read after the specified timout,
** false will be returned.
*/
while ($count < $timout) {
$data = fread($session, 1);
if ($data) {
$message .= $data;
}
else {
usleep(100);
$count = $count + 1;
}
}
if ($message) {
// print "RECV: ". htmlentities($message) ."<br />";
return $message;
}
else {
return 0;
}
}
function jabber_auth($username, $password, $server) {
global $jabber;
watchdog("user", "starting jabber auth");
$session = fsockopen($server, 5222, &$errno, &$errstr, 5);
if ($session) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
/*
** Switch the given socket descriptor '$session' to non-blocking mode:
*/
set_socket_blocking($session, false);
/*
** A jabber session consists of two parallel XML streams, one from
** the client to the server and one from the server to the client.
** On connecting to a Jabber server, a Jabber client initiates the
** client-to-server XML stream and the server responds by initiating
** the server-to-client XML stream:
*/
jabber_send($session, "<?xml version='1.0'?>");
jabber_send($session, "<stream:stream to='$server' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>");
$data = jabber_recv($session);
if (!xml_parse($xml_parser, $data, 0)) {
watchdog("error", "XML error: '". xml_error_string(xml_get_error_code($xml_parser)) ."' at line ". xml_get_current_line_number($xml_parser));
return 0;
}
if ($jabber["error"]) {
watchdog("error", "protocol error: ". $jabber["data"]);
return 0;
}
/*
** Hash the password:
*/
jabber_send($session, "<iq type='set' id='". $jabber["jid"] ."'><query xmlns='jabber:iq:auth'><username>$username</username><password>$password</password><resource>drupal</resource></query></iq>");
$data = jabber_recv($session);
if (!xml_parse($xml_parser, $data, 0)) {
watchdog("error", "XML error: '". xml_error_string(xml_get_error_code($xml_parser)) ."' at line ". xml_get_current_line_number($xml_parser));
}
if ($jabber["error"]) {
watchdog("error", "protocol error: ". $jabber["data"]);
return 0;
}
xml_parser_free($xml_parser);
return 1;
}
else {
watchdog("error", "failed to open socket to jabber server:\n $errno, $errstr");
return 0;
}
}
function jabber_page() {
global $theme;
$theme->header();
$theme->box("Jabber", jabber_auth_help());
$theme->footer();
}
function jabber_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "
<p>You may login to %s using a <b>Jabber ID</b>. The format of a Jabber ID is the same as an email address: <b>name</b><i>@server</i> An example of valid Jabber ID is <b>mwlily</b><i>@jabber.com</i>.</p>
<p>Jabber is an <a href=\"http://www.opensource.org\">open source</a> instant messaging system designed to give the power of choice and freedom back to the users of instant messaging. By creating an extensible and powerful server and protocol, Jabber has succeeded in this goal. Not only does Jabber allow its users to use (and create) clients for numerous platforms, but it allows people to communicate to whomever they want in the way which is most convenient for them.</p>";
return sprintf(t($output), $site);
}
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -155,18 +155,22 @@ ALTER TABLE book DROP pid;
# visit http://www.yoursite.com/3.00-to-x.xx.php?part=3
#
## work in progress
# ALTER TABLE users ADD session TEXT DEFAULT '' NOT NULL;
# ALTER TABLE users ADD data TEXT DEFAULT '' NOT NULL;
#CREATE TABLE mail (
# mid tinyint(10) DEFAULT '0' NOT NULL auto_increment,
# subject varchar(255) DEFAULT '' NOT NULL,
# recepient varchar(255) DEFAULT '' NOT NULL,
# sender varchar(255) DEFAULT '' NOT NULL,
# header text,
# body text,
# timestamp int(11) DEFAULT '0' NOT NULL,
# PRIMARY KEY (mid)
#);
# 08/11/01:
ALTER TABLE watchdog CHANGE message message text NOT NULL;
# 14/11/01:
CREATE TABLE authmap (
aid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
authname varchar(128) DEFAULT '' NOT NULL,
uid int(10) DEFAULT '' NOT NULL,
module varchar(128) DEFAULT '' NOT NULL,
UNIQUE authname (authname),
PRIMARY KEY (aid)
);
DELETE FROM variable WHERE name = 'user_jabber';
DELETE FROM variable WHERE name = 'user_drupal';
# TODO:
# write some PHP code that moves the 'jabber' and 'drupal' fields
# to the new 'authmap' table.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment