From c22e1de52de7560f3f884738d6e57153a7087ece Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 19 Jun 2013 21:05:12 +0200 Subject: [PATCH 1/5] small fixes of last night, still have to figure out a way to get the mkdir warning dissapear! --HG-- branch : quitta-gsoc-2013 --- .../tools/server/ryzom_ams/ams_lib/autoload/helpers.php | 4 ++-- .../ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php | 1 + code/ryzom/tools/server/ryzom_ams/www/html/index.php | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php index daed71db8..2712e0aee 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php @@ -44,9 +44,9 @@ class Helpers{ foreach ( $variables[$template] as $key => $value ){ $smarty -> assign( $key, $value ); } - if( $vars['permission'] == 2 ){ + if( isset($vars['permission']) && $vars['permission'] == 2 ){ $inherited = "extends:layout_admin.tpl|"; - }else if($vars['permission'] == 1){ + }else if( isset($vars['permission']) && $vars['permission'] == 1){ $inherited = "extends:layout_user.tpl|"; }else{ $inherited =""; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php index da92e14f9..96b90acb4 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php @@ -25,6 +25,7 @@ function add_user(){ $result['prevEmail'] = $_POST["Email"]; $result['no_visible_elements'] = 'TRUE'; helpers :: loadtemplate( 'register', $result); + exit; } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index 941f9d628..eada82bb2 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -1,5 +1,6 @@ Date: Wed, 19 Jun 2013 23:53:53 +0200 Subject: [PATCH 2/5] first attempt to get register up and running --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 23 ++++++++- .../ryzom_ams/www/html/inc/add_user.php | 49 +++++++++++++++++-- .../server/ryzom_ams/www/html/sql/db.sql | 18 +++++++ 3 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 69dd98ccc..3c9a64ece 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -234,6 +234,27 @@ class Users{ } // done! return $salt; - } } + + function create_Server_User($params) + { + try { + $hostname = 'localhost'; + $port = '3306'; + $dbname = 'nel'; + $username = 'shard'; + $password = ''; + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbh->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($params); + return "success"; + } + catch (PDOException $e) { + return "fail"; + } + // createPermissions(array($login)); + } +} + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php index 96b90acb4..38e90efeb 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php @@ -12,7 +12,7 @@ function add_user(){ 'init' => $_POST["Email"], 'unhashpass' => $_POST["Password"], 'status' => 1, - 'access' => REQUEST_TIME + 'access' => $_SERVER['REQUEST_TIME'] ); //header( 'Location: email_sent.php' ); write_user( $edit ); @@ -30,9 +30,50 @@ function add_user(){ } -function write_user(){ - - +function write_user($newUser){ + $login = $newUser["name"]; + $pass = $newUser["pass"]; + $email = $newUser["mail"]; + + $salt = Users::generateSALT(); + $hashpass = crypt($pass, $salt); + + $params = array( + $login, + $hashpass, + $email + ); + + $result = Users :: create_Server_User($params); + //test purpose + $result = "fail"; + + $hostname = 'localhost'; + $port = '3306'; + $dbname = 'ryzom_ams'; + $username = 'shard'; + $password = ''; + + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try { + $statement = $dbh->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($params); + + if($result == "fail"){ + print('so far'); + $params = array("type" => "createUser","query" => json_encode(array($login,$pass,$email))); + $statement = $dbh->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)"); + $statement->execute($params); + } + } + catch (PDOException $e) { + //go to error page or something + print_r($e); + exit; + } + + // add user locally here print('Awesome'); } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql new file mode 100644 index 000000000..5c8864545 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql @@ -0,0 +1,18 @@ +CREATE DATABASE IF NOT EXISTS `ryzom_ams`; +USE `ryzom_ams`; +DROP TABLE IF EXISTS ams_user; +DROP TABLE IF EXISTS ams_querycache; + +CREATE TABLE IF NOT EXISTS `ams_user` ( + `UId` int(10) NOT NULL AUTO_INCREMENT, + `Login` varchar(64) NOT NULL DEFAULT '', + `Password` varchar(13) DEFAULT NULL, + `Email` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`UId`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; + +CREATE TABLE ams_querycache ( + `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `type` VARCHAR( 64 ) NOT NULL , + `query` VARCHAR( 512 ) NOT NULL +); \ No newline at end of file From 761d7b2775c34c8c2241eb3b32cc7445a31e6158 Mon Sep 17 00:00:00 2001 From: Quitta Date: Thu, 20 Jun 2013 01:02:27 +0200 Subject: [PATCH 3/5] Register seems to work :) Next step permissions and login --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 57 ++++++++++++++++ .../tools/server/ryzom_ams/www/config.php | 18 +++-- .../ryzom_ams/www/html/inc/add_user.php | 66 ++++++++----------- 3 files changed, 97 insertions(+), 44 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 3c9a64ece..2bd042f74 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -255,6 +255,63 @@ class Users{ } // createPermissions(array($login)); } + + function createUser($values){ + $login = $values["name"]; + $pass = $values["pass"]; + $email = $values["mail"]; + + $webhost = $values["webhost"]; + $webport = $values["webport"]; + $webdbname = $values["webdbname"]; + $webusername = $values["webusername"]; + $webpassword = $values["webpassword"]; + + $shardhost = $values["shardhost"]; + $shardport = $values["shardport"]; + $sharddbname = $values["sharddbname"]; + $shardusername = $values["shardusername"]; + $shardpassword = $values["shardpassword"]; + + $salt = Users::generateSALT(); + $hashpass = crypt($pass, $salt); + + $params = array( + $login, + $hashpass, + $email + ); + + try{ + //make connection with web db + $dbw = new PDO("mysql:host=$webhost;port=$webport;dbname=$webdbname", $webusername, $webpassword); + $dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + //put into web db + $statement = $dbw->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($params); + try { + //make connection with and put into shard db + $dbs = new PDO("mysql:host=$shardhost;port=$shardport;dbname=$sharddbname", $shardusername, $shardpassword); + $dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbs->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($params); + } + catch (PDOException $e) { + //print_r($e); + //oh noooz, the shard is offline! Put in query queue at web db! + $params = array("type" => "createUser","query" => json_encode(array($login,$pass,$email))); + $statement = $dbw->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)"); + $statement->execute($params); + } + + }catch (PDOException $e) { + //go to error page or something, because can't access website db + print_r($e); + exit; + } + + } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index db2571b3a..8a6728dd6 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -5,10 +5,20 @@ // Variables for database access // ---------------------------------------------------------------------------------------- // where we can find the mysql database -$DBHOST = 'localhost' ; - $DBNAME = 'nel' ; - $DBUSERNAME = 'shard' ; - $DBPASSWORD = '' ; + +$WEBDBHOST = 'localhost'; +$WEBDBPORT = '3306'; +$WEBDBNAME = 'ryzom_ams'; +$WEBDBUSERNAME = 'shard'; +$WEBDBPASSWORD = '' ; + +$SHARDDBHOST = 'localhost' ; +$SHARDDBPORT = '3306'; +$SHARDDBNAME = 'nel' ; +$SHARDDBUSERNAME = 'shard' ; +$SHARDDBPASSWORD = '' ; + + // If true= the server will add automatically unknown user in the database // (in nel.user= nel.permission= ring.ring_user and ring.characters diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php index 38e90efeb..81639130f 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php @@ -31,50 +31,36 @@ function add_user(){ function write_user($newUser){ - $login = $newUser["name"]; - $pass = $newUser["pass"]; - $email = $newUser["mail"]; + global $WEBDBHOST; + global $WEBDBPORT; + global $WEBDBNAME; + global $WEBDBUSERNAME; + global $WEBDBPASSWORD; + global $SHARDDBHOST; + global $SHARDDBPORT; + global $SHARDDBNAME; + global $SHARDDBUSERNAME; + global $SHARDDBPASSWORD; + + $values["name"] = $newUser["name"]; + $values["pass"] = $newUser["pass"]; + $values["mail"] = $newUser["mail"]; + + $values["webhost"] = $WEBDBHOST; + $values["webport"] = $WEBDBPORT; + $values["webdbname"] = $WEBDBNAME; + $values["webusername"] = $WEBDBUSERNAME; + $values["webpassword"] = $WEBDBPASSWORD ; - $salt = Users::generateSALT(); - $hashpass = crypt($pass, $salt); - - $params = array( - $login, - $hashpass, - $email - ); + $values["shardhost"] = $SHARDDBHOST; + $values["shardport"] = $SHARDDBPORT; + $values["sharddbname"] = $SHARDDBNAME; + $values["shardusername"] = $SHARDDBUSERNAME; + $values["shardpassword"] = $SHARDDBPASSWORD; - $result = Users :: create_Server_User($params); - //test purpose - $result = "fail"; - $hostname = 'localhost'; - $port = '3306'; - $dbname = 'ryzom_ams'; - $username = 'shard'; - $password = ''; - - $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); - $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - try { - $statement = $dbh->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (?, ?, ?)"); - $statement->execute($params); - - if($result == "fail"){ - print('so far'); - $params = array("type" => "createUser","query" => json_encode(array($login,$pass,$email))); - $statement = $dbh->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)"); - $statement->execute($params); - } - } - catch (PDOException $e) { - //go to error page or something - print_r($e); - exit; - } + $result = Users :: createUser($values); - - // add user locally here print('Awesome'); } From 8f2f0a3ad7644102f817e9820232e34c46f02b43 Mon Sep 17 00:00:00 2001 From: Quitta Date: Tue, 25 Jun 2013 20:57:10 +0200 Subject: [PATCH 4/5] Loging in match searching seems to work :) --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/helpers.php | 5 ++- .../ryzom_ams/ams_lib/autoload/users.php | 36 +++++++++++++++ .../tools/server/ryzom_ams/www/html/index.php | 5 --- .../tools/server/ryzom_ams/www/html/login.php | 44 ------------------- .../ryzom_ams/www/html/templates/login.tpl | 5 ++- .../ryzom_ams/www/html/templates/register.tpl | 1 - 6 files changed, 42 insertions(+), 54 deletions(-) delete mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/login.php diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php index 2712e0aee..bedd1e2b8 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php @@ -60,7 +60,7 @@ class Helpers{ global $SITEBASE; $arr = array( $AMS_LIB . '/ingame_templates/', $AMS_LIB . '/configs', - $AMS_LIB . '/cache', + //$AMS_LIB . '/cache', $SITEBASE . '/cache/', $SITEBASE . '/templates/', $SITEBASE . '/templates_c/', @@ -68,7 +68,8 @@ class Helpers{ ); foreach ( $arr as & $value ){ if ( !file_exists( $value ) ){ - mkdir( $value ); + echo $value; + mkdir( $value); } } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 2bd042f74..c0d956d46 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -312,6 +312,42 @@ class Users{ } } + + public function login($params){ + $webhost = $params["webhost"]; + $webport = $params["webport"]; + $webdbname = $params["webdbname"]; + $webusername = $params["webusername"]; + $webpassword = $params["webpassword"]; + + try{ + $dbw = new PDO("mysql:host=$webhost;port=$webport;dbname=$webdbname", $webusername, $webpassword); + $dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $statement = $dbw->prepare("SELECT * FROM ams_user WHERE Login=:user"); + $statement->execute(array('user' => $params['name'])); + $count = $statement->rowCount(); + + if ($count==1) { + $row = $statement->fetch(); + $salt = substr($row['Password'],0,2); + $hashed_input_pass = crypt($params["pass"], $salt); + if($hashed_input_pass == $row['Password']){ + //handle successful login + print("nice welcome!"); + return "success"; + }else{ + //handle login failure + print("Login failed"); + return "failure"; + } + } + }catch (PDOException $e) { + //go to error page or something, because can't access website db + print_r($e); + exit; + } + } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index eada82bb2..e63155170 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -10,11 +10,6 @@ $page = 'login'; if ( isset( $_POST["function"] ) ){ require( "inc/" . $_POST["function"] . ".php" ); $tempReturn = $_POST["function"](); - /*$functionReturn = array_merge($tempReturn,$_POST); - if ( isset($_POST["callBack"])){ - $page = $_POST["callBack"]; - - }*/ } function loadpage ( $page ){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/login.php b/code/ryzom/tools/server/ryzom_ams/www/html/login.php deleted file mode 100644 index 9bb640c2c..000000000 --- a/code/ryzom/tools/server/ryzom_ams/www/html/login.php +++ /dev/null @@ -1,44 +0,0 @@ - - -
- -
- -
- -
- diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl index 2c36c3ce3..fdf5c2d2c 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl @@ -15,12 +15,12 @@
- +
- +
@@ -30,6 +30,7 @@

+

diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl index bd5e92788..5a154bb92 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register.tpl @@ -106,7 +106,6 @@ {/if} -
From e72eac888890fc37d56f05ae2bd53042af9058c2 Mon Sep 17 00:00:00 2001 From: Quitta Date: Tue, 25 Jun 2013 21:33:49 +0200 Subject: [PATCH 5/5] Reworked index.php a little, though something is going wrong with my session variables --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 3 ++ .../tools/server/ryzom_ams/www/html/index.php | 52 ++++++++++++------- .../server/ryzom_ams/www/html/sql/db.sql | 1 + 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index c0d956d46..731eb5cdd 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -335,6 +335,9 @@ class Users{ if($hashed_input_pass == $row['Password']){ //handle successful login print("nice welcome!"); + $_SESSION['user'] = $params['name']; + $_SESSION['permission'] = $row['Permission']; + print( $_SESSION['user']); return "success"; }else{ //handle login failure diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index e63155170..d15dbee03 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -3,33 +3,49 @@ error_reporting(E_ALL); ini_set('display_errors', 'on'); require( '../config.php' ); require( '../../ams_lib/libinclude.php' ); -//default page -$page = 'login'; +session_start(); - -if ( isset( $_POST["function"] ) ){ - require( "inc/" . $_POST["function"] . ".php" ); - $tempReturn = $_POST["function"](); +print("[" . $_SESSION['user'] . "] "); + +//Decide what page to load +if(isset($_SESSION['user'])){ + $page = 'home'; +}else{ + //default page + $page = 'login'; } -function loadpage ( $page ){ - require_once( 'autoload/' . $page . '.php' ); - } - if ( isset( $_GET["page"] ) ){ $page = $_GET["page"]; } -//Page Handling -if($page == 'login' || $page == 'register'){ - $no_visible_elements = 'TRUE'; +//perform an action in case one is specified +if ( isset( $_POST["function"] ) ){ + require( "inc/" . $_POST["function"] . ".php" ); + $return = $_POST["function"](); } -if ( isset($functionReturn) ){ - $return = array_merge(array( 'permission' => 1, 'no_visible_elements' => $no_visible_elements ),$functionReturn); -}else{ - $return = array( 'permission' => 1, 'no_visible_elements' => $no_visible_elements ); + +function loadpage ( $page ){ + require_once( 'autoload/' . $page . '.php' ); +} + +//Set permission +if(isset($_SESSION['Permission'])){ + $return['permission'] = $_SESSION['Permission']; +}else{ + //default permission + $return['permission'] = 0; +} + + +//hide sidebar + topbar in case of login/register +if($page == 'login' || $page == 'register'){ + $return['no_visible_elements'] = 'TRUE'; +}else{ + $return['no_visible_elements'] = 'FALSE'; } -//print_r($return); helpers :: loadTemplate( $page , $return ); + +session_destroy(); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql index 5c8864545..44daf16e5 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql @@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS `ams_user` ( `Login` varchar(64) NOT NULL DEFAULT '', `Password` varchar(13) DEFAULT NULL, `Email` varchar(255) NOT NULL DEFAULT '', + `Permission` int(3) NOT NULL DEFAULT 1, PRIMARY KEY (`UId`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams';