added initial admin/admin account when sql/install is executed, also added the admin's functionality: libuserlist

This commit is contained in:
Quitta 2013-06-29 19:05:54 +02:00
parent 47a278636b
commit 6e04a001a7
10 changed files with 160 additions and 99 deletions

View file

@ -296,7 +296,7 @@ class Users{
try { try {
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer($cfg['db']['lib']);
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser", $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser",
"query" => json_encode(array($values["params"]["name"],$values["params"]["pass"],$values["params"]["mail"])))); "query" => json_encode(array($values["name"],$values["pass"],$values["mail"]))));
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { }catch (PDOException $e) {
print_r($e); print_r($e);

View file

@ -4,6 +4,11 @@
[home] [home]
[libuserlist] [libuserlist]
libuserlist_title = "LibDB-Query List"
libuserlist_info = "Here you can see the entire list of elements in the LibDB-Query table. You can easily remove elements and by pressing 'Synchronize' you can start the syncing process manually!"
libuserlist_sync = "Synchronize"
shard_online = "The shard seems to be <strong>online</strong>, manually syncing is possible: "
shard_offline = "The shard seems to be <strong>offline</strong>, manually syncing is not possible!"
[userlist] [userlist]
userlist_info = "welcome to the userlist" userlist_info = "welcome to the userlist"

View file

@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib';
$cfg['db']['lib']['user'] = 'root'; $cfg['db']['lib']['user'] = 'root';
$cfg['db']['lib']['pass'] = 'lol123'; $cfg['db']['lib']['pass'] = 'lol123';
$cfg['db']['shard']['host'] = 'localhosti'; $cfg['db']['shard']['host'] = 'localhost';
$cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['port'] = '3306';
$cfg['db']['shard']['name'] = 'nel'; $cfg['db']['shard']['name'] = 'nel';
$cfg['db']['shard']['user'] = 'shard'; $cfg['db']['shard']['user'] = 'shard';

View file

@ -46,13 +46,9 @@ function write_user($newUser){
'mail' => $newUser["mail"] 'mail' => $newUser["mail"]
); );
//print_r($params);
//make a $values array for passing all data to the Users::createUser() function.
$values["params"] = $params;
//Create the user on the shard + in case shard is offline put copy of query in query db //Create the user on the shard + in case shard is offline put copy of query in query db
//returns: ok, shardoffline or liboffline //returns: ok, shardoffline or liboffline
$result = WebUsers::createUser($values); $result = WebUsers::createUser($params);
try{ try{
//make connection with web db and put it in there //make connection with web db and put it in there

View file

@ -1,50 +1,60 @@
<?php <?php
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($_GET['pagenum']))){ function libuserlist(){
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($_GET['pagenum']))){
$pagenum = 1; $pagenum = 1;
}else{ }else{
$pagenum = $_GET['pagenum']; $pagenum = $_GET['pagenum'];
} }
//Here we count the number of results //Here we count the number of results
global $cfg; global $cfg;
$dbl = new DBLayer($cfg['db']['lib']); $dbl = new DBLayer($cfg['db']['lib']);
$rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount(); $rows = $dbl->executeWithoutParams("SELECT * FROM ams_querycache")->rowCount();
if($rows > 0){
//This is the number of results displayed per page
$page_rows = 2;
//This is the number of results displayed per page //This tells us the page number of our last page
$page_rows = 2; $last = ceil($rows/$page_rows);
//This tells us the page number of our last page //this makes sure the page number isn't below one, or more than our maximum pages
$last = ceil($rows/$page_rows); if ($pagenum < 1)
{
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1; $pagenum = 1;
}else if ($pagenum > $last) { }else if ($pagenum > $last) {
$pagenum = $last; $pagenum = $last;
} }
//This sets the range to display in our query //This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it //This is your query again, the same one... the only difference is we add $max into it
$data = $dbl->executeWithoutParams("SELECT * FROM ams_querycache $max"); $data = $dbl->executeWithoutParams("SELECT * FROM ams_querycache $max");
//This is where we put the results in a resultArray to be sent to smarty //This is where we put the results in a resultArray to be sent to smarty
$pageResult['liblist'] = Array(); $pageResult['liblist'] = Array();
$i = 0; $i = 0;
while($row = $data->fetch(PDO::FETCH_ASSOC)){ while($row = $data->fetch(PDO::FETCH_ASSOC)){
$decode = json_decode($row['query']); $decode = json_decode($row['query']);
$pageResult['liblist'][$i]['id'] = $row['SID']; $pageResult['liblist'][$i]['id'] = $row['SID'];
$pageResult['liblist'][$i]['type'] = $row['type']; $pageResult['liblist'][$i]['type'] = $row['type'];
$pageResult['liblist'][$i]['name'] = $decode[0]; $pageResult['liblist'][$i]['name'] = $decode[0];
$pageResult['liblist'][$i]['mail'] = $decode[2]; $pageResult['liblist'][$i]['mail'] = $decode[2];
$i++; $i++;
}
}
//check if shard is online
try{
$dbs = new DBLayer($cfg['db']['shard']);
$pageResult['shard'] = "online";
}catch(PDOException $e) {
$pageResult['shard'] = "offline";
}
return $pageResult;
} }
$pageResult['permission'] = 1;
$pageResult['no_visible_elements'] = 'FALSE';
helpers :: loadtemplate( 'libuserlist', $pageResult);
exit();

View file

@ -8,7 +8,6 @@ session_start();
//Decide what page to load //Decide what page to load
if(isset($_SESSION['user'])){ if(isset($_SESSION['user'])){
$page = 'home'; $page = 'home';
$return['username'] = $_SESSION['user'];
}else{ }else{
//default page //default page
$page = 'login'; $page = 'login';
@ -23,19 +22,18 @@ if ( isset( $_POST["function"] ) ){
$filename = 'inc/' . $_GET["page"] . '.php'; $filename = 'inc/' . $_GET["page"] . '.php';
if(is_file($filename)){ if(is_file($filename)){
require_once($filename); require_once($filename);
$return = $_GET["page"]();
} }
$page = $_GET["page"]; $page = $_GET["page"];
} }
//add username to the return array in case logged in.
/*function loadpage ( $page ){ if(isset($_SESSION['user'])){
$filename = 'autoload/' . $page . '.php'; $return['username'] = $_SESSION['user'];
if(is_file($filename)){
require_once($filename);
}
} }
loadpage($page);*/
//Set permission //Set permission
if(isset($_SESSION['permission'])){ if(isset($_SESSION['permission'])){

View file

@ -1,21 +1,15 @@
<?php <?php
require( '../../config.php' ); require( '../../config.php' );
require( '../../../ams_lib/libinclude.php' );
ini_set( "display_errors", true ); ini_set( "display_errors", true );
error_reporting( E_ALL ); error_reporting( E_ALL );
global $WEBDBHOST; global $cfg;
global $WEBDBUSERNAME;
global $WEBDBPASSWORD;
global $LIBDBHOST;
global $LIBDBUSERNAME;
global $LIBDBPASSWORD;
try{ try{
//SETUP THE WWW DB //SETUP THE WWW DB
$dbw = new PDO("mysql:host=$WEBDBHOST;", $WEBDBUSERNAME, $WEBDBPASSWORD); $dbw = new DBLayer($cfg['db']['web']);
$dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = " $sql = "
CREATE DATABASE IF NOT EXISTS `ryzom_ams`; CREATE DATABASE IF NOT EXISTS `ryzom_ams`;
USE `ryzom_ams`; USE `ryzom_ams`;
@ -32,12 +26,10 @@
); );
"; ";
$statement = $dbw->prepare($sql); $dbw->executeWithoutParams($sql);
$statement->execute();
//SETUP THE AMS_LIB DB //SETUP THE AMS_LIB DB
$dbl = new PDO("mysql:host=$LIBDBHOST;", $LIBDBUSERNAME, $LIBDBPASSWORD); $dbl = new DBLayer($cfg['db']['lib']);
$dbl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = " $sql = "
CREATE DATABASE IF NOT EXISTS `ryzom_ams_lib`; CREATE DATABASE IF NOT EXISTS `ryzom_ams_lib`;
USE `ryzom_ams_lib`; USE `ryzom_ams_lib`;
@ -49,16 +41,34 @@
`query` VARCHAR( 512 ) NOT NULL `query` VARCHAR( 512 ) NOT NULL
); );
"; ";
$statement = $dbl->prepare($sql); $dbl->executeWithoutParams($sql);
$statement->execute(); print "The Lib & Web database were correctly installed! <br />";
print('Install completed successful!');
//Now create an admin account!
$hashpass = crypt("admin", Users::generateSALT());
$params = array(
'name' => "admin",
'pass' => $hashpass,
'mail' => "admin@admin.com",
);
Users::createUser($params);
try{
$params['permission'] = 2;
$dbw = new DBLayer($cfg['db']['web']);
$dbw->execute("INSERT INTO ams_user (Login, Password, Email, Permission) VALUES (:name, :pass, :mail, :permission)",$params);
print "The admin account is created, you can login with id: admin, pass: admin!";
}catch (PDOException $e){
print "There was an error while creating the admin account! ";
}
}catch (PDOException $e) { }catch (PDOException $e) {
//go to error page or something, because can't access website db //go to error page or something, because can't access website db
print('There was an error while installing'); print "There was an error while installing";
print_r($e); print_r($e);
} }

View file

@ -1,15 +1,11 @@
{extends file="layout.tpl"} {extends file="layout.tpl"}
{block name=menu} {block name=menu}
<li class="nav-header hidden-tablet">Main</li> <li class="nav-header hidden-tablet">Main</li>
<li><a class="ajax-link" href="index.php"><i class="icon-home"></i><span class="hidden-tablet"> Dashboard</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php"><i class="icon-home"></i><span class="hidden-tablet"> Dashboard</span></a></li>
<li><a class="ajax-link" href="settings.php"><i class="icon-cog"></i><span class="hidden-tablet"> Settings</span></a></li>
<li><a href="logout.php"><i class="icon-lock"></i><span class="hidden-tablet"> Logout</span></a></li>
<li class="nav-header hidden-tablet">Admin</li> <li class="nav-header hidden-tablet">Admin</li>
<li><a class="ajax-link" href="checkuser.php"><i class="icon-user"></i><span class="hidden-tablet">UserList</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=libuserlist"><i class="icon-th-list"></i><span class="hidden-tablet"> Liblist</span></a></li>
<li><a class="ajax-link" href="banlist.php"><i class="icon-remove"></i><span class="hidden-tablet"> BanList</span></a></li> <li class="nav-header hidden-tablet">Actions</li>
<li class="nav-header hidden-tablet">Ticketing</li> <li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li>
<li><a class="ajax-link" href="generalqueue.php"><i class="icon-th-list"></i><span class="hidden-tablet"> General Queue</span></a></li>
<li><a class="ajax-link" href="personalQueue.php"><i class="icon-tag"></i><span class="hidden-tablet"> Personal Queue</span></a></li>
<li><a class="ajax-link" href="archive.php"><i class="icon-folder-open"></i><span class="hidden-tablet"> Ticket Archive</span></a></li>
{/block} {/block}

View file

@ -2,9 +2,8 @@
{block name=menu} {block name=menu}
<li class="nav-header hidden-tablet">Main</li> <li class="nav-header hidden-tablet">Main</li>
<li style="margin-left: -2px;" class="active"><a class="ajax-link" href="index.php"><i class="icon-home"></i><span class="hidden-tablet"> Dashboard</span></a></li> <li style="margin-left: -2px;" class="active"><a class="ajax-link" href="index.php"><i class="icon-home"></i><span class="hidden-tablet"> Dashboard</span></a></li>
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=userlist"><i class="icon-home"></i><span class="hidden-tablet"> Userlist</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=userlist"><i class="icon-home"></i><span class="hidden-tablet"> Demo Userlist</span></a></li>
<li class="nav-header hidden-tablet">Sample Section</li> <li class="nav-header hidden-tablet">Actions</li>
<li style="margin-left: -2px;"><a href="?page=login"><i class="icon-lock"></i><span class="hidden-tablet"> Login Page</span></a></li>
<li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li> <li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li>
{/block} {/block}

View file

@ -3,7 +3,7 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="box span12"> <div class="box span12">
<div class="box-header well"> <div class="box-header well">
<h2><i class="icon-info-sign"></i>The users in the libDB</h2> <h2><i class="icon-info-sign"></i>{$libuserlist_title}</h2>
<div class="box-icon"> <div class="box-icon">
<a href="#" class="btn btn-round" onclick="javascript:show_help('intro');return false;"><i class="icon-info-sign"></i></a> <a href="#" class="btn btn-round" onclick="javascript:show_help('intro');return false;"><i class="icon-info-sign"></i></a>
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a> <a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
@ -12,15 +12,62 @@
</div> </div>
</div> </div>
<div class="box-content"> <div class="box-content">
<table border="1" cellpadding="5"> <center>
<tr><td><strong>ID</strong></td><td><strong>type</strong></td><td><strong>user</strong></td><td><strong>email</strong></td><td><strong>remove</strong></td></tr> <p>{$libuserlist_info}</p>
{foreach from=$liblist item=element} {if $shard eq "online"}
<tr><td>{$element.id}</td><td>{$element.type}</td><td>{$element.name}</td><td>{$element.mail}</td><td><a class="btn btn-danger" href="index.php?page=libuserlist&action=remove&id={$element.id}"><i class="icon-trash icon-white"></i>Delete</a></td></tr> <div class="alert alert-success">
{/foreach} <i class="icon-refresh icon-white"></i>{$shard_online}<a href="index.php?page=libuserlist&action=remove&id=haha">{$libuserlist_sync}</a>
</table> </div>
{else}
<div class="alert alert-error">
<strong><i class="icon-refresh icon-white"></i></strong> {$shard_offline}
</div>
{/if}
</center>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
</div> </div>
</div> </div>
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header well" data-original-title>
<h2><i class="icon-user"></i> Members</h2>
<div class="box-icon">
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>ID</th>
<th>Type</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{foreach from=$liblist item=element}
<tr>
<td>{$element.id}</td>
<td class="center">{$element.type}</td>
<td class="center">{$element.name}</td>
<td class="center">{$element.mail}</td>
<td class="center">
<a class="btn btn-danger" href="index.php?page=libuserlist&action=remove&id={$element.id}"><i class="icon-trash icon-white"></i>Delete</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
{/block} {/block}