1
0

Initial Upload of User Info Module for G3.0

This commit is contained in:
Charles Knowlton 2011-01-17 15:21:33 -06:00
parent 13e0d4aea4
commit d537136570
9 changed files with 644 additions and 0 deletions

View File

@ -0,0 +1,250 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_User_info_Controller extends Admin_Controller {
public function index() {
// Generate a new admin page.
$view = new Admin_View("admin.html");
$view->page_title = t("User Information Settings");
$view->content = new View("admin_user_info.html");
$view->content->user_info_form = $this->_get_admin_form();
print $view;
}
public function saveprefs() {
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Figure out the values of the text boxes
$str_per_page = Input::instance()->post("per_page");
$str_default_sort_column = Input::instance()->post("default_sort_column");
$str_default_sort_order = Input::instance()->post("default_sort_order");
$str_use_default_gallery_date_format = Input::instance()->post("use_default_gallery_date_format");
$str_date_format = Input::instance()->post("date_format");
$str_log_logins = Input::instance()->post("log_logins");
$str_color_login = Input::instance()->post("color_login");
$str_log_logouts = Input::instance()->post("log_logouts");
$str_color_logout = Input::instance()->post("color_logout");
$str_log_failed_logins = Input::instance()->post("log_failed_logins");
$str_color_failed_login = Input::instance()->post("color_failed_login");
$str_log_re_authenticate_logins = Input::instance()->post("log_re_authenticate_logins");
$str_color_re_authenticate_login = Input::instance()->post("color_re_authenticate_login");
$str_log_user_created = Input::instance()->post("log_user_created");
$str_color_user_created = Input::instance()->post("color_user_created");
// Save Settings.
module::set_var("user_info", "per_page", $str_per_page);
module::set_var("user_info", "default_sort_column", $str_default_sort_column);
module::set_var("user_info", "default_sort_order", $str_default_sort_order);
module::set_var("user_info", "use_default_gallery_date_format", $str_use_default_gallery_date_format);
module::set_var("user_info", "date_format", $str_date_format);
module::set_var("user_info", "log_logins", $str_log_logins);
module::set_var("user_info", "color_login", $str_color_login);
module::set_var("user_info", "log_logouts", $str_log_logouts);
module::set_var("user_info", "color_logout", $str_color_logout);
module::set_var("user_info", "log_failed_logins", $str_log_failed_logins);
module::set_var("user_info", "color_failed_login", $str_color_failed_login);
module::set_var("user_info", "log_re_authenticate_logins", $str_log_re_authenticate_logins);
module::set_var("user_info", "color_re_authenticate_login", $str_color_re_authenticate_login);
module::set_var("user_info", "log_user_created", $str_log_user_created);
module::set_var("user_info", "color_user_created", $str_color_user_created);
message::success(t("Your Settings Have Been Saved."));
// Load Admin page.
$view = new Admin_View("admin.html");
$view->page_title = t("User Information Settings");
$view->content = new View("admin_user_info.html");
$view->content->user_info_form = $this->_get_admin_form();
print $view;
}
private function _get_admin_form() {
// Make a new Form.
$form = new Forge("admin/user_info/saveprefs", "", "post",
array("id" => "g-user_info-admin-form"));
// Create the input boxes for the User Information Settings
$user_infoGroup = $form->group("UserInformationSettings");
$user_infoGroup->dropdown("per_page")
->label(t("Number of records to display per page"))
->options(array("5" => t("5"),
"10" => t("10"),
"15" => t("15"),
"25" => t("25"),
"50" => t("50"),
"75" => t("75"),
"100" => t("100"),
"125" => t("125")))
->selected(module::get_var("user_info", "per_page"));
$user_infoGroup->dropdown("default_sort_column")
->label(t("Default Column to Sort By"))
->options(array("id" => t("id"),
"user_id" => t("user_id"),
"user_name" => t("user_name"),
"ip_address" => t("ip_address"),
"time_stamp" => t("time_stamp"),
"action" => t("action")))
->selected(module::get_var("user_info", "default_sort_column"));
$user_infoGroup->dropdown("default_sort_order")
->label(t("Default Sort Order"))
->options(array("ASC" => t("Ascending"),
"DESC" => t("Descending")))
->selected(module::get_var("user_info", "default_sort_order"));
$user_infoGroup->dropdown("use_default_gallery_date_format")
->label(t("Use Default Gallery Date/Time Format"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "use_default_gallery_date_format"));
$user_infoGroup->input("date_format")
->label(t("Format of the Date & Time - <a href='http://php.net/manual/en/function.date.php' target='_blank'>PHP Date</a>"))
->value(module::get_var("user_info", "date_format"));
$user_infoGroup->dropdown("log_logins")
->label(t("Log Logins"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "log_logins"));
$user_infoGroup->input("color_login")
->label(t("<font color='%color_login'>Login Color</font> - Hex Only - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>",array("color_login" => module::get_var("user_info", "color_login"))))
->value(module::get_var("user_info", "color_login"));
$user_infoGroup->dropdown("log_logouts")
->label(t("Log Logouts"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "log_logouts"));
$user_infoGroup->input("color_logout")
->label(t("<font color='%color_logout'>Logout Color</font> - Hex Only - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>",array("color_logout" => module::get_var("user_info", "color_logout"))))
->value(module::get_var("user_info", "color_logout"));
$user_infoGroup->dropdown("log_failed_logins")
->label(t("Log Failed Logins"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "log_failed_logins"));
$user_infoGroup->input("color_failed_login")
->label(t("<font color='%color_failed_login'>Failed Login Color</font> - Hex Only - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>",array("color_failed_login" => module::get_var("user_info", "color_failed_login"))))
->value(module::get_var("user_info", "color_failed_login"));
$user_infoGroup->dropdown("log_re_authenticate_logins")
->label(t("Log Re-Authenticate Logins"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "log_re_authenticate_logins"));
$user_infoGroup->input("color_re_authenticate_login")
->label(t("<font color='%color_re_authenticate_login'>Re-Authenticate Login Color</font> - Hex Only - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>",array("color_re_authenticate_login" => module::get_var("user_info", "color_re_authenticate_login"))))
->value(module::get_var("user_info", "color_re_authenticate_login"));
$user_infoGroup->dropdown("log_user_created")
->label(t("Log User Created"))
->options(array("Yes" => t("Yes"),
"No" => t("No")))
->selected(module::get_var("user_info", "log_user_created"));
$user_infoGroup->input("color_user_created")
->label(t("<font color='%color_user_created'>User Created Color</font> - Hex Only - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>",array("color_user_created" => module::get_var("user_info", "color_user_created"))))
->value(module::get_var("user_info", "color_user_created"));
// Add a save button to the form.
$form->submit("SaveSettings")->value(t("Save"));
// Return the newly generated form.
return $form;
}
public function lookupip() {
// Generate a new admin page.
$view = new Admin_View("admin.html");
$view->page_title = t("User Info: Lookup IP Address");
$view->content = new View("admin_user_info_lookupip.html");
// $view->content->block_ip_address = $this->_get_block_ip_address_form();
print $view;
}
public function blockip() {
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Figure out the values of the text boxes
// Figure out the ip address to block
$str_per_page = Input::instance()->post("per_page");
$str_default_sort_column = Input::instance()->post("default_sort_column");
// Block IP Addresss.
module::set_var("user_info", "per_page", $str_per_page);
message::success(t("Your Settings Have Been Saved."));
// Load Admin page.
// $view = new Admin_View("admin.html");
// $view->page_title = t("User Information Settings");
// $view->content = new View("admin_user_info.html");
// $view->content->user_info_form = $this->_get_admin_form();
// print $view;
$view = new Admin_View("admin.html");
$view->page_title = t("User Info: Lookup IP Address");
$view->content = new View("admin_user_info_lookupip.html");
$view->content->block_ip_address = $this->_get_block_ip_address_form();
print $view;
}
private function _get_block_ip_address_form() {
// Make a new Form.
// $form = new Forge("admin/user_info/blockip", "", "post",
// array("id" => "g-user_info-block-ip-address-form"));
//
// // Create the input boxes for the User Information Settings
// $block_ipGroup = $form->group("BlockIPAddress");
// $block_ipGroup->dropdown("per_page")
// ->label(t("Number of records to display per page"))
// ->options(array("25" => t("25"),
// "50" => t("50"),
// "75" => t("75"),
// "100" => t("100"),
// "125" => t("125"),
// "150" => t("150")))
// ->selected(module::get_var("user_info", "per_page"));
// $block_ipGroup->input("date_format")
// ->label(t("Format of the Date & Time - <a href='http://php.net/manual/en/function.date.php' target='_blank'>PHP Date</a>"))
// ->value(module::get_var("user_info", "date_format"));
// $block_ipGroup->input("color_login")
// ->label(t("Login Color - <a href='http://www.w3schools.com/HTML/html_colornames.asp' target='_blank'>HTML Colors</a>"))
// ->value(module::get_var("user_info", "color_login"));
// ->value(module::get_var("user_info", "color_failed_login"));
//
// // Add a save button to the form.
// $form->submit("SaveSettings")->value(t("Block IP Address"));
//
// // Return the newly generated form.
// return $form;
}
}

View File

@ -0,0 +1,56 @@
<?php defined("SYSPATH") or die("No direct script access.");
class user_info_block_Core {
static function get_admin_list() {
return array("user_info" => t("User Information"));
}
static function get($block_id) {
$block = new Block();
switch ($block_id) {
case "user_info":
$block->css_id = "g-user_info";
$block->title = t("User Information");
$block->content = new View("admin_block_user_info.html");
$block->content->number_of_records = ORM::factory("user_info")->count_all();
// helps build the pagniation
$page_size = module::get_var("user_info", "per_page");
$page = Input::instance()->get("page", "1");
$builder = db::build();
$user_count = $builder->from("user_infos")->count_records();
$block->content->pager = new Pagination();
$block->content->pager->initialize(
array("query_string" => "page",
"total_items" => $user_count,
"items_per_page" => $page_size,
"style" => "classic"));
// Make sure that the page references a valid offset
if ($page < 1) {
// This prevents the admin page from displaying if there are no records in the database, commented out to temp. fix
// url::redirect(url::merge(array("page" => 1)));
url::site("admin"); //This should fix the issue I think
} else if ($page > $block->content->pager->total_pages) {
url::redirect(url::merge(array("page" => $block->content->pager->total_pages)));
}
// Get the user defined settings for sort by and sort order
$default_sort_column = module::get_var("user_info", "default_sort_column");
$default_sort_order = module::get_var("user_info", "default_sort_order");
$block->content->data = ORM::factory("user_info")
->order_by($default_sort_column, $default_sort_order)
->find_all($page_size, $block->content->pager->sql_offset);
// $block->content->data = ORM::factory("user_info")->find_all();
$block->content->use_default_gallery_date_format = module::get_var("user_info", "use_default_gallery_date_format");
$block->content->date_format = module::get_var("user_info", "date_format");
$block->content->color_login = module::get_var("user_info", "color_login");
$block->content->color_logout = module::get_var("user_info", "color_logout");
$block->content->color_failed_login = module::get_var("user_info", "color_failed_login");
$block->content->color_re_authenticate_login = module::get_var("user_info", "color_re_authenticate_login");
$block->content->color_user_created = module::get_var("user_info", "color_user_created");
break;
}
return $block;
}
}

View File

@ -0,0 +1,100 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_info_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("user_info")
->label(t("User Info"))
->url(url::site("admin/user_info")));
}
static function user_login() {
$log_logins = module::get_var("user_info", "log_logins");
if ($log_logins == "Yes") {
$user_info = ORM::factory("user_info");
$user_info->user_id = identity::active_user()->id;
$user_info->user_name = identity::active_user()->name;
$user_info->ip_address = $_SERVER['REMOTE_ADDR'];
$user_info->time_stamp = time();
$user_info->action = "Login";
$user_info->save();
}
}
static function user_logout($user) {
$log_logouts = module::get_var("user_info", "log_logouts");
if ($log_logouts == "Yes") {
$user_info = ORM::factory("user_info");
$user_info->user_id = $user->id;
$user_info->user_name = $user->name;
$user_info->ip_address = $_SERVER['REMOTE_ADDR'];
$user_info->time_stamp = time();
$user_info->action = "Logout";
$user_info->save();
}
}
static function user_auth_failed($user_name) {
$log_failed_logins = module::get_var("user_info", "log_failed_logins");
if ($log_failed_logins == "Yes") {
$user_info = ORM::factory("user_info");
if (identity::lookup_user_by_name($user_name)) {
$user_info->user_id = identity::lookup_user_by_name($user_name)->id;
} else {
$user_info->user_id = "";
}
$user_info->user_name = $user_name;
$user_info->ip_address = $_SERVER['REMOTE_ADDR'];
$user_info->time_stamp = time();
$user_info->action = "Failed Login";
$user_info->save();
}
}
static function user_auth($user) {
$log_re_authenticate_logins = module::get_var("user_info", "log_re_authenticate_logins");
if ($log_re_authenticate_logins == "Yes") {
$user_info = ORM::factory("user_info");
$user_info->user_id = $user->id;
$user_info->user_name = $user->name;
$user_info->ip_address = $_SERVER['REMOTE_ADDR'];
$user_info->time_stamp = time();
$user_info->action = "Re-Authenticate Login";
$user_info->save();
}
}
static function user_created($pending_user) {
$log_user_created = module::get_var("user_info", "log_user_created");
if ($log_user_created == "Yes") {
$user_info = ORM::factory("user_info");
$user_info->user_id = $pending_user->id;
$user_info->user_name = $pending_user->name;
$user_info->ip_address = $_SERVER['REMOTE_ADDR'];
$user_info->time_stamp = time();
$user_info->action = "User Created";
$user_info->save();
}
}
}

View File

@ -0,0 +1,82 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_info_installer {
static function activate() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {user_infos} (
`id` int(11) NOT NULL auto_increment,
`user_id` varchar(128) default NULL,
`user_name` varchar(128) default NULL,
`ip_address` varchar(255) default NULL,
`time_stamp` varchar(128) default NULL,
`action` varchar(128) default NULL,
PRIMARY KEY (`id`))
DEFAULT CHARSET=utf8;");
module::set_var("user_info", "per_page", 25);
module::set_var("user_info", "default_sort_column", "id");
module::set_var("user_info", "default_sort_order", "DESC");
module::set_var("user_info", "use_default_gallery_date_format", "Yes");
module::set_var("user_info", "date_format", "D d M Y h:i:s A T");
module::set_var("user_info", "log_logins", "Yes");
module::set_var("user_info", "color_login", "#008000");
module::set_var("user_info", "log_logouts", "Yes");
module::set_var("user_info", "color_logout", "#0000FF");
module::set_var("user_info", "log_failed_logins", "Yes");
module::set_var("user_info", "color_failed_login", "#FF0000");
module::set_var("user_info", "log_re_authenticate_logins", "No");
module::set_var("user_info", "color_re_authenticate_login", "#800080");
module::set_var("user_info", "log_user_created", "No");
module::set_var("user_info", "color_user_created", "#FF8C00");
module::set_version("user_info", 1);
}
// static function upgrade($version) {
// $db = Database::instance();
// if ($version == 1) {
// $db->query("ALTER TABLE {comments} CHANGE `state` `state` varchar(15) default 'unpublished'");
// module::set_version("comment", $version = 2);
// }
//
// if ($version == 2) {
// module::set_var("comment", "access_permissions", "everybody");
// module::set_version("comment", $version = 3);
// }
// }
// static function uninstall() {
// $db = Database::instance();
// $db->query("DROP TABLE IF EXISTS {userinfo};");
// /* @todo Put database table drops here */
// module::delete("userinfo");
// }
static function deactivate() {
site_status::clear("user_info");
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {user_infos};");
}
}

View File

@ -0,0 +1,21 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class User_Info_Model_Core extends ORM {
}

View File

@ -0,0 +1,3 @@
name = "User Info"
description = "Login Information"
version = 1

View File

@ -0,0 +1,118 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div>
<p><?= t("This will display information about users when they Login, Logout, Failed Login Attempts, Admin Re-Authenticate, and User Created.
It can be configured <a href=\"%user_info_configure\">here</a>.<br><br> User Created - Logs users that the Admin creates and can log the users that are created by visitors when using the Registration Module and the Registration Module is set to 'Visitors can create accounts and no administrator approval is required'.",
array("user_info_configure" => html::mark_clean(url::site("admin/user_info")))) ?></p>
</div>
<div>
<table border="2">
<!-- First Row - Displays Number of Records -->
<tr>
<? if ($number_of_records > 0) { ?>
<td align="center" colspan="6"><?= t("Number of Records: %number_of_records",array("number_of_records" => $number_of_records)) ?></td>
<? } else { ?>
<td align="center" colspan="6"><?= t("Number of Records: 0") ?></td>
<? } ?>
</tr>
<!--Second Row - List the Page Numbers for Pagination if there are records in the Database -->
<? if ($number_of_records) { ?>
<tr>
<td align="center" colspan="6"><?= $pager ?></td>
</tr>
<? } ?>
<!--Third Row - Headers -->
<tr>
<th><?= t("ID") ?></th>
<th><?= t("User ID") ?></th>
<th><?= t("User Name") ?></th>
<th><?= t("IP Address") ?></th>
<th><?= t("Time Stamp") ?></th>
<th><?= t("Action") ?></th>
</tr>
<!--Forth Row etc.. - Lists the actual data -->
<? if ($number_of_records > 0) { ?>
<? foreach($data as $myData) { ?>
<tr>
<td><? echo $myData->id ?></td>
<td><? echo $myData->user_id ?></td>
<td>
<? if ($myData->user_id){ ?>
<a href="<?= url::site("user_profile/show/$myData->user_id") ?>" target="_blank"><?= html::clean($myData->user_name) ?> </a>
<? } else { ?>
<? echo $myData->user_name ?><br>
<? } ?>
</td>
<td>
<a href="<?= url::site("admin/user_info/lookupip?ip=$myData->ip_address") ?>" target="_blank"><?= html::clean($myData->ip_address) ?> </a>
</td>
<td>
<? if ($use_default_gallery_date_format == "Yes") { ?>
<?= gallery::date_time($myData->time_stamp) ?>
<?
} else {
echo date($date_format,$myData->time_stamp);
}
?>
</td>
<td>
<?
switch ($myData->action)
{
case "Failed Login":
echo "<font color=$color_failed_login>";
echo $myData->action;
echo "</font>";
break;
case "Login":
echo "<font color=$color_login>";
echo $myData->action;
echo "</font>";
break;
case "Logout":
echo "<font color=$color_logout>";
echo $myData->action;
echo "</font>";
break;
case "Re-Authenticate Login":
echo "<font color=$color_re_authenticate_login>";
echo $myData->action;
echo "</font>";
break;
case "User Created":
echo "<font color=$color_user_created>";
echo $myData->action;
echo "</font>";
break;
default:
echo "<font color='#000000'>";
echo $myData->action;
echo "</font>";
}
?>
</td>
</tr>
<? } ?>
<? } else { ?>
<tr>
<td colspan="6"><center><b><?= t("No Records in Database") ?></b></center></td>
</tr>
<? } ?>
</table>
</div>

View File

@ -0,0 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="g-user_info-admin">
<h2> <?= t("User Information Settings") ?> </h2>
<?= $user_info_form ?>
</div>

View File

@ -0,0 +1,8 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script type="text/javascript">
window.resizeTo(1000, 500);
</script>
<p align="center"><?php echo $_GET['ip']; ?></p>
<p align="center"><?php echo gethostbyaddr($_GET['ip']); ?></p>
<p align="center" class="copyText"><strong>[<a href="javascript:window.close();" class="txtLink">x</a>]</strong></p>