| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: ipauth.module,v 1.10 2009/04/21 12:31:44 jonfrancisskydiver Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Module code for an IP based authenticator |
* Module code for an IP based authenticator |
| 291 |
); |
); |
| 292 |
$form['import_fieldset']['belowmarkup'] = array( |
$form['import_fieldset']['belowmarkup'] = array( |
| 293 |
'#value' => t('The format of the CSV file is as follows:') .'<Br/><ul><li>' . |
'#value' => t('The format of the CSV file is as follows:') .'<Br/><ul><li>' . |
| 294 |
t('"Row ID","Drupal User ID","IP Address","IP Address","description","0 for disabled, or 1 for enabled","unix timestamp"') ."</li></ul><br/>", |
t('"Drupal User ID","IP Address","IP Address","description","0 for disabled, or 1 for enabled","unix timestamp"') ."</li></ul><br/>", |
| 295 |
|
|
| 296 |
); |
); |
| 297 |
$form['import_fieldset']['submit'] = array( |
$form['import_fieldset']['submit'] = array( |
| 340 |
$CSV_file = file($file->filepath); |
$CSV_file = file($file->filepath); |
| 341 |
//id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created |
//id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created |
| 342 |
foreach ($CSV_file AS $CSV_file_line) { |
foreach ($CSV_file AS $CSV_file_line) { |
| 343 |
list($row["id"], $row["uid"], $row["ip1"], $row["ip2"], $row["description"], $row["enabled"], $row["created"]) = split(",", $CSV_file_line); |
list($row["uid"], $row["ip1"], $row["ip2"], $row["description"], $row["enabled"], $row["created"]) = split(",", $CSV_file_line); |
| 344 |
array_walk($row, '_ipauth_strip_quotes'); |
array_walk($row, '_ipauth_strip_quotes'); |
| 345 |
|
$row["created"] = preg_replace("/\n|\"/","",$row["created"]); |
| 346 |
if (_ipauth_check_import($row)) { |
if (_ipauth_check_import($row)) { |
| 347 |
$sql = "INSERT INTO {ip_authenticator} (uid, ip1, ip2, description, enabled, created) VALUES ('%s','%s','%s','%s', '%d', '%s')"; |
$sql = "INSERT INTO {ip_authenticator} (uid, ip1, ip2, description, enabled, created) VALUES ('%s', '%s','%s','%s', '%d', FROM_UNIXTIME(%s))"; |
| 348 |
db_query($sql, $row["uid"], sprintf("%u", ip2long(trim($row['ip1']))), sprintf("%u", ip2long(trim($row['ip2']))), $row["description"], $row["enabled"], $row["created"]); |
db_query($sql, $row["uid"], sprintf("%u", ip2long(trim($row['ip1']))), sprintf("%u", ip2long(trim($row['ip2']))), $row["description"], $row["enabled"], $row["created"]); |
| 349 |
} |
} |
| 350 |
} |
} |
| 1026 |
header("Content-Disposition: attachment; filename=IP_Authenticator_Export_".date("Y-m-d").".csv;" ); |
header("Content-Disposition: attachment; filename=IP_Authenticator_Export_".date("Y-m-d").".csv;" ); |
| 1027 |
$result = ipauth_get_ip_authenticators(NULL, "id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created"); |
$result = ipauth_get_ip_authenticators(NULL, "id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created"); |
| 1028 |
while ($row = db_fetch_array($result)) { |
while ($row = db_fetch_array($result)) { |
| 1029 |
printf('"%s","%s","%s","%s","%s","%s","%s" |
printf('"%s","%s","%s","%s","%s","%s" |
| 1030 |
', $row["id"],$row["uid"],long2ip($row["ip1"]),long2ip($row["ip2"]),$row["description"],$row["enabled"],$row["created"]); |
', $row["uid"],long2ip($row["ip1"]),long2ip($row["ip2"]),$row["description"],$row["enabled"],$row["created"]); |
| 1031 |
} |
} |
| 1032 |
|
|
| 1033 |
module_invoke_all('exit', $url); |
module_invoke_all('exit', $url); |