From a0d8902d1316f1974d155f9b66144299d884ce81 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 9 Sep 2013 23:30:45 +0200 Subject: [PATCH] Added CreatePermissions + handling it while syncing + changed image path to refer to the image locations dir + other fixes --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/sync.php | 13 +- .../ryzom_ams/ams_lib/autoload/users.php | 24 ++++ .../ingame_templates/show_ticket_info.tpl | 32 ++--- .../drupal_module/ryzommanage/config.php | 6 +- .../ryzommanage/ryzommanage.module | 128 ++---------------- .../templates/show_ticket_info.tpl | 32 ++--- .../tools/server/ryzom_ams/www/config.php | 2 +- .../ryzom_ams/www/html/func/add_user.php | 1 + .../server/ryzom_ams/www/html/inc/logout.php | 4 +- .../server/ryzom_ams/www/html/sql/install.php | 25 +++- .../www/html/templates/show_ticket_info.tpl | 32 ++--- 11 files changed, 125 insertions(+), 174 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php index 12376d9b4..752ce7dd7 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php @@ -23,6 +23,17 @@ class Sync{ $db = new DBLayer($record['db']); switch($record['type']) { case 'createPermissions': + $decode = json_decode($record['query']); + $values = array('username' => $decode[0]); + //make connection with and put into shard db & delete from the lib + $sth = $db->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $result = $sth->fetchAll(); + foreach ($result as $UId) { + $ins_values = array('id' => $UId['UId']); + $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); + $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + } + break; case 'change_pass': $decode = json_decode($record['query']); $values = array('user' => $decode[0], 'pass' => $decode[1]); @@ -47,7 +58,7 @@ class Sync{ print('Syncing completed'); } catch (PDOException $e) { - print('Something went wrong!'); + print('Something went wrong! The shard is probably still offline!'); print_r($e); } 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 e03a8fdff..3eb67b97e 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 @@ -308,6 +308,30 @@ class Users{ } + public static function createPermissions($pvalues) { + + try { + $values = array('username' => $pvalues[0]); + $dbs = new DBLayer("shard"); + $sth = $dbs->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $result = $sth->fetchAll(); + foreach ($result as $UId) { + $ins_values = array('id' => $UId['UId']); + $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); + $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + } + } + catch (PDOException $e) { + //oh noooz, the shard is offline! Put it in query queue at ams_lib db! + $dbl = new DBLayer("lib"); + $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createPermissions", + "query" => json_encode(array($pvalues[0])), "db" => "shard")); + + + } + return true; + } + protected function checkLoginMatch($user,$pass){ print('This is the base class!'); diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_ticket_info.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_ticket_info.tpl index 4431331c4..f986bff5f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_ticket_info.tpl +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_ticket_info.tpl @@ -64,31 +64,31 @@ - + - + - + - + - + - + - +
Shard ID: {$shard_id}
User_Id: {$user_id}
User Position: {$user_position}
View Position: {$view_position}
Client_Version: {$client_version}
Patch_Version: {$patch_version}
Server_Tick: {$server_tick}
@@ -102,31 +102,31 @@ - + - + - + - + - + - + - +
Memory: {$memory}
Processor: {$processor}
Cpu_Id: {$cpu_id}
Cpu_Mask: {$cpu_mask}
HT: {$ht}
OS: {$os}
NeL3D: {$nel3d}
@@ -140,11 +140,11 @@ - + - +
Connect_State: {$connect_state}
Local_Address: {$local_address}
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php index ef2459117..130cee9a5 100644 --- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php @@ -15,8 +15,8 @@ $cfg['db']['web']['pass'] = variable_get('ryzommanage_webpassword', 'lol123') $cfg['db']['lib']['host'] = variable_get('ryzommanage_libserverurl', 'localhost'); $cfg['db']['lib']['port'] = variable_get('ryzommanage_libmysqlport', '3306'); $cfg['db']['lib']['name'] = variable_get('ryzommanage_libdbname', 'ryzom_ams_lib'); -$cfg['db']['lib']['user'] = variable_get('ryzommanage_libusername', 'shard'); -$cfg['db']['lib']['pass'] = variable_get('ryzommanage_libpassword', ''); +$cfg['db']['lib']['user'] = variable_get('ryzommanage_libusername', 'root'); +$cfg['db']['lib']['pass'] = variable_get('ryzommanage_libpassword', 'lol123'); $cfg['db']['shard']['host'] = variable_get('ryzommanage_shardserverurl', 'localhost'); $cfg['db']['shard']['port'] = variable_get('ryzommanage_shardmysqlport', '3306'); @@ -74,7 +74,7 @@ $AMS_TRANS = $AMS_LIB . '/translations'; $AMS_CACHEDIR = $AMS_LIB . '/cache'; $SITEBASE = dirname( __FILE__ ); $BASE_WEBPATH = 'http://localhost:40917/drupal'; -$IMAGELOC_WEBPATH = $BASE_WEBPATH. '/sites/all/modules/ryzommanage/' ; +$IMAGELOC_WEBPATH = $BASE_WEBPATH. '/sites/all/modules/ryzommanage/ams_lib/img' ; $WEBPATH = $BASE_WEBPATH .'/ams'; $INGAME_WEBPATH = $BASE_WEBPATH . '/ingame'; $CONFIG_PATH = dirname( __FILE__ ); diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module index e094aeceb..0bc14c908 100644 --- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module @@ -29,11 +29,11 @@ global $BASE_WEBPATH; global $INGAME_LAYOUT; global $FORCE_INGAME; +require 'config.php'; + require 'ams_lib/libinclude.php'; spl_autoload_register('__autoload'); -require 'config.php'; - /* Drupal 7 ryzom core module Copyright (C) 2013 Matthew Lagoe (Botanic) & Paige Offerdahl (Tobi) @@ -354,12 +354,13 @@ function _ams_handler($ingame = false) */ function _collect_register($nids, $collection) { - syncdata(); + Sync::syncdata(); //if not using ryzom core client show registration page if (Helpers::check_if_game_client()) { return_client_httpdata(); } else { //redirect to registration page + global $BASE_WEBPATH; header("Location: ".$BASE_WEBPATH. "/user/register"); } } @@ -368,7 +369,7 @@ function _collect_register($nids, $collection) /** * - * Function _collect_register + * Function _collect_ingame_ams * * @takes * @return Nothing @@ -486,10 +487,10 @@ function createUser($values, $user_id) //Create the user on the shard + in case shard is offline put copy of query in query db //returns: ok, shardoffline or liboffline $result = WebUsers::createUser($params, $user_id); - createPermissions(array($login)); + Users::createPermissions(array($login)); } -function createPermissions($values) { +/*function createPermissions($values) { try { $hostname = variable_get('ryzommanage_serverurl', 'localhost'); @@ -536,7 +537,7 @@ function createPermissions($values) { } return true; -} +}*/ function ryzommanage_user_login(&$edit, $account){ $_SESSION['user'] = $account->name; @@ -683,118 +684,15 @@ function user_edit($values) { $username = $values[0]; $newpassword = $values[1]; - $salt = generateSALT(); + $salt = WebUsers::generateSALT(); $pass = crypt($newpassword, $salt); - - try { - $hostname = variable_get('ryzommanage_serverurl', 'localhost'); - $port = variable_get('ryzommanage_mysqlport', '3306'); - $dbname = variable_get('ryzommanage_dbname', 'nel'); - $ryusername = variable_get('ryzommanage_username', 'root'); - $password = variable_get('ryzommanage_password', ''); - $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $ryusername, $password); - $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - catch (PDOException $e) { - watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); - $nid = db_insert('ryzommanage_querycache')->fields(array( - "SID" => NULL, - "type" => "user_edit", - "query" => json_encode(array( - $username, - $newpassword - )) - ))->execute(); - return true; - } - $sql = "UPDATE `nel`.`user` SET `Password` = ? WHERE `user`.`Login` = ?"; - - try { - $q = $dbh->prepare($sql); - } - catch (PDOException $e) { - watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); - $nid = db_insert('ryzommanage_querycache')->fields(array( - "SID" => NULL, - "type" => "user_edit", - "query" => json_encode(array( - $username, - $newpassword - )) - ))->execute(); - return true; - } - - try { - $q->execute(array( $pass, $username)); - } - catch (PDOException $e) { - watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); - $nid = db_insert('ryzommanage_querycache')->fields(array( - "SID" => NULL, - "type" => "user_edit", - "query" => json_encode(array( - $username, - $newpassword - )) - ))->execute(); - return true; - } - + $webUser = new WebUsers(); + $webUser->setAmsPassword($username,$pass); return true; } -/** - * - * Function syncdata - * - * @takes Nothing - * @return array $values - * - * Info: Runs functions to finish syncing data when shard is offline - * - */ -function syncdata () { - - try { - $hostname = variable_get('ryzommanage_serverurl', 'localhost'); - $port = variable_get('ryzommanage_mysqlport', '3306'); - $dbname = variable_get('ryzommanage_dbname', 'nel'); - $ryusername = variable_get('ryzommanage_username', 'root'); - $password = variable_get('ryzommanage_password', ''); - $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $ryusername, $password); - $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - catch (PDOException $e) { - watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); - return true; - } - - $query = db_select('ryzommanage_querycache', 'q') - ->fields('q', array('SID', 'type', 'query')); - - $result = $query->execute(); - - foreach ($result as $record) { - watchdog('ryzommanage_usersync', $record->query, NULL, WATCHDOG_ERROR); - - switch($record->type) { - case 'createPermissions': - case 'user_edit': - case 'createUser': - watchdog('ryzommanage_usersync', $record->type, NULL, WATCHDOG_INFO); - $SID = $record->SID; - $num_deleted = db_delete('ryzommanage_querycache') - ->condition('SID', $SID) - ->execute(); - $func = $record->type; - $func(json_decode($record->query)); - } - - } - -} + /** * * Function ryzommanage_cron @@ -807,7 +705,7 @@ function syncdata () { */ function ryzommanage_cron() { - syncdata(); + Sync::syncdata(); } diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl index 04384009e..b8100c158 100644 --- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl @@ -16,61 +16,61 @@
Ingame related
- Shard ID: {$shard_id} + Shard ID: {$shard_id} - User_Id: {$user_id} + User_Id: {$user_id} - User Position: {$user_position} + User Position: {$user_position} - View Position: {$view_position} + View Position: {$view_position} - Client_Version: {$client_version} + Client_Version: {$client_version} - Patch_Version: {$patch_version} + Patch_Version: {$patch_version} - Server_Tick: {$server_tick} + Server_Tick: {$server_tick}
Hardware & Software related
- Memory: {$memory} + Memory: {$memory} - Processor: {$processor} + Processor: {$processor} - Cpu_Id: {$cpu_id} + Cpu_Id: {$cpu_id} - Cpu_Mask: {$cpu_mask} + Cpu_Mask: {$cpu_mask} - HT: {$ht} + HT: {$ht} - OS: {$os} + OS: {$os} - NeL3D: {$nel3d} + NeL3D: {$nel3d}
Network related
- Connect_State: {$connect_state} + Connect_State: {$connect_state} - Local_Address: {$local_address} + Local_Address: {$local_address} diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 1867875ba..45acc4d40 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -76,7 +76,7 @@ $AMS_CACHEDIR = $AMS_LIB . '/cache'; $SITEBASE = dirname( __FILE__ ) . '/html/' ; $BASE_WEBPATH = 'http://localhost:40917/www/html'; -$IMAGELOC_WEBPATH = 'http://localhost:40917'; +$IMAGELOC_WEBPATH = 'http://localhost:40917/ams_lib/img'; $WEBPATH = $BASE_WEBPATH . '/index.php'; $INGAME_WEBPATH = $BASE_WEBPATH . '/index.php'; $CONFIG_PATH = dirname( __FILE__ ); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php index 2cb583061..a53208c5a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php @@ -55,6 +55,7 @@ function write_user($newUser){ //Create the user on the shard + in case shard is offline put copy of query in query db //returns: ok, shardoffline or liboffline $result = WebUsers::createUser($params, $user_id); + Users::createPermissions(array($newUser["name"])); }catch (PDOException $e) { diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/logout.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/logout.php index 83ed2080d..fb684f03e 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/logout.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/logout.php @@ -2,5 +2,5 @@ function logout(){ session_unset(); - session_destroy(); -} \ No newline at end of file + session_destroy(); +} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php index b63f0d4d1..aa113f81d 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php @@ -39,7 +39,7 @@ $sql = " CREATE DATABASE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`; USE `" . $cfg['db']['lib']['name'] ."`; - DROP TABLE IF EXISTS ams_querycache; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ams_querycache`; CREATE TABLE ams_querycache ( `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , @@ -48,7 +48,27 @@ `db` VARCHAR( 80 ) NOT NULL ); + -- ----------------------------------------------------------------------------------------------------------------------- + -- ----------------------------------------------------------------------------------------------------------------------- + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_log` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`tagged` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`tag` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`in_support_group` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`in_group` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_group` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_info` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`email` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`forwarded` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`assigned` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_reply` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_content` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`support_group` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_category` ; + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`ticket_user` ; + + -- ----------------------------------------------------- -- Table `" . $cfg['db']['lib']['name'] ."`.`ticket_category` -- ----------------------------------------------------- @@ -415,9 +435,6 @@ ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; - - - "; $dbl->executeWithoutParams($sql); print "The Lib & Web database were correctly installed!
"; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket_info.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket_info.tpl index d8a7420d5..ed09e1892 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket_info.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_ticket_info.tpl @@ -17,61 +17,61 @@
Ingame related
- Shard ID: {$shard_id} + Shard ID: {$shard_id} - User_Id: {$user_id} + User_Id: {$user_id} - User Position: {$user_position} + User Position: {$user_position} - View Position: {$view_position} + View Position: {$view_position} - Client_Version: {$client_version} + Client_Version: {$client_version} - Patch_Version: {$patch_version} + Patch_Version: {$patch_version} - Server_Tick: {$server_tick} + Server_Tick: {$server_tick}
Hardware & Software related
- Memory: {$memory} + Memory: {$memory} - Processor: {$processor} + Processor: {$processor} - Cpu_Id: {$cpu_id} + Cpu_Id: {$cpu_id} - Cpu_Mask: {$cpu_mask} + Cpu_Mask: {$cpu_mask} - HT: {$ht} + HT: {$ht} - OS: {$os} + OS: {$os} - NeL3D: {$nel3d} + NeL3D: {$nel3d}
Network related
- Connect_State: {$connect_state} + Connect_State: {$connect_state} - Local_Address: {$local_address} + Local_Address: {$local_address}