Merge with rc-botanic-webdev

This commit is contained in:
Quitta 2013-06-13 23:36:07 +02:00
commit 55372aef84
5 changed files with 263 additions and 308 deletions

View file

@ -1,7 +1,7 @@
<?php
class Helpers{
public function loadTemplate( $template, $vars = array () )
public function loadTemplate( $template, $vars = array (), $forcelibrender = false )
{
global $AMS_LIB;
global $SITEBASE;
@ -14,7 +14,10 @@ class Helpers{
// caching must be disabled for multi-language support
$smarty -> caching = false;
$smarty -> cache_lifetime = 120;
if ( !helpers :: check_if_game_client () ){
helpers :: create_folders ();
if ( !helpers :: check_if_game_client () or $forcelibrender = true ){
$smarty -> template_dir = $AMS_LIB . '/ingame_templates/';
$smarty -> setConfigDir( $AMS_LIB . '/configs' );
}else{
@ -44,6 +47,23 @@ class Helpers{
$smarty -> display( $template . '.tpl' );
}
public function create_folders(){
$arr = array( $AMS_LIB . '/ingame_templates/',
$AMS_LIB . '/configs',
$AMS_LIB . '/cache',
$SITEBASE . '/cache/',
$SITEBASE . '/templates/',
$SITEBASE . '/templates_c/',
$SITEBASE . '/configs'
);
foreach ( $arr as & $value ){
if ( !file_exists( $value ) ){
mkdir( $value );
}
}
}
public function check_if_game_client()
{
// if HTTP_USER_AGENT is not set then its ryzom core

View file

@ -1,7 +1,7 @@
<?php
class Users{
function add_user(){
public function add_user(){
// check if values exist
if ( isset( $_POST["Username"] ) and isset( $_POST["Password"] ) and isset( $_POST["Email"] ) )
{
@ -66,167 +66,168 @@ class Users{
$pageElements['TAC_ERROR'] = 'TRUE';
}
return $pageElements;
}
}
}
/**
* Function checkUser
*
* @takes $username
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
*/
public function checkUser( $username )
{
if ( isset( $username ) ){
if ( strlen( $username ) > 12 ){
return "Username must be no more than 12 characters.";
}elseif ( strlen( $username ) < 5 ){
return "Username must be 5 or more characters.";
}elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){
return "Username can only contain numbers and letters.";
}elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array(
':name' => $username
) ) -> fetchField() ){
return "Username " . $username . " is in use.";
}else{
return "success";
}
/**
* Function checkUser
*
* @takes $username
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
*/
public function checkUser( $username )
{
if ( isset( $username ) ){
if ( strlen( $username ) > 12 ){
return "Username must be no more than 12 characters.";
}elseif ( strlen( $username ) < 5 ){
return "Username must be 5 or more characters.";
}elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){
return "Username can only contain numbers and letters.";
}elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array(
':name' => $username
) ) -> fetchField() ){
return "Username " . $username . " is in use.";
}else{
return "success";
}
return "fail";
}
/**
* Function checkPassword
*
* @takes $pass
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
*/
public function checkPassword( $pass )
{
if ( isset( $pass ) ){
if ( strlen( $pass ) > 20 ){
return "Password must be no more than 20 characters.";
}elseif ( strlen( $pass ) < 5 ){
return "Password must be more than 5 characters.";
}else{
return "success";
}
}
return "fail";
}
/**
* Function confirmPassword
*
* @takes $pass
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
*/
public function confirmPassword()
{
if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){
return "Passwords do not match.";
}else{
return "success";
}
return "fail";
}
/**
* Function checkPassword
*
* @takes $pass
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
*/
public function checkPassword( $pass )
{
if ( isset( $pass ) ){
if ( strlen( $pass ) > 20 ){
return "Password must be no more than 20 characters.";
}elseif ( strlen( $pass ) < 5 ){
return "Password must be more than 5 characters.";
}else{
return "success";
}
return "fail";
}
/**
* Function checkEmail
*
* @takes $email
* @return
*/
public function checkEmail( $email )
{
if ( isset( $email ) ){
if ( !validEmail( $email ) ){
return "Email address is not valid.";
}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(
':mail' => $email
) ) -> fetchField() ){
return "Email is in use.";
}else{
return "success";
}
}
return "fail";
}
/**
* Function confirmPassword
*
* @takes $pass
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
*/
public function confirmPassword()
{
if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){
return "Passwords do not match.";
}else{
return "success";
}
return "fail";
}
/**
* Function checkEmail
*
* @takes $email
* @return
*/
public function checkEmail( $email )
{
if ( isset( $email ) ){
if ( !validEmail( $email ) ){
return "Email address is not valid.";
}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(
':mail' => $email
) ) -> fetchField() ){
return "Email is in use.";
}else{
return "success";
}
return "fail";
}
public function validEmail( $email )
{
$isValid = true;
$atIndex = strrpos( $email, "@" );
if ( is_bool( $atIndex ) && !$atIndex ){
$isValid = false;
}else{
$domain = substr( $email, $atIndex + 1 );
$local = substr( $email, 0, $atIndex );
$localLen = strlen( $local );
$domainLen = strlen( $domain );
if ( $localLen < 1 || $localLen > 64 ){
// local part length exceeded
$isValid = false;
}else if ( $domainLen < 1 || $domainLen > 255 ){
// domain part length exceeded
$isValid = false;
}else if ( $local[0] == '.' || $local[$localLen - 1] == '.' ){
// local part starts or ends with '.'
$isValid = false;
}else if ( preg_match( '/\\.\\./', $local ) ){
// local part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ){
// character not valid in domain part
$isValid = false;
}else if ( preg_match( '/\\.\\./', $domain ) ){
// domain part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\", "", $local ) ) ){
// character not valid in local part unless
// local part is quoted
if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ){
$isValid = false;
}
}
if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ){
// domain not found in DNS
$isValid = false;
}else{
return "success";
}
return "fail";
}
public function validEmail( $email )
{
$isValid = true;
$atIndex = strrpos( $email, "@" );
if ( is_bool( $atIndex ) && !$atIndex ){
$isValid = false;
}else{
$domain = substr( $email, $atIndex + 1 );
$local = substr( $email, 0, $atIndex );
$localLen = strlen( $local );
$domainLen = strlen( $domain );
if ( $localLen < 1 || $localLen > 64 ){
// local part length exceeded
$isValid = false;
}else if ( $domainLen < 1 || $domainLen > 255 ){
// domain part length exceeded
$isValid = false;
}else if ( $local[0] == '.' || $local[$localLen - 1] == '.' ){
// local part starts or ends with '.'
$isValid = false;
}else if ( preg_match( '/\\.\\./', $local ) ){
// local part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ){
// character not valid in domain part
$isValid = false;
}else if ( preg_match( '/\\.\\./', $domain ) ){
// domain part has two consecutive dots
$isValid = false;
}else if ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\", "", $local ) ) ){
// character not valid in local part unless
// local part is quoted
if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ){
$isValid = false;
}
}
return $isValid;
}
public function generateSALT( $length = 2 )
{
// start with a blank salt
$salt = "";
// define possible characters - any character in this string can be
// picked for use in the salt, so if you want to put vowels back in
// or add special characters such as exclamation marks, this is where
// you should do it
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
// we refer to the length of $possible a few times, so let's grab it now
$maxlength = strlen( $possible );
// check for length overflow and truncate if necessary
if ( $length > $maxlength ){
$length = $maxlength;
if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ){
// domain not found in DNS
$isValid = false;
}
// set up a counter for how many characters are in the salt so far
$i = 0;
// add random characters to $salt until $length is reached
while ( $i < $length ){
// pick a random character from the possible ones
$char = substr( $possible, mt_rand( 0, $maxlength - 1 ), 1 );
// have we already used this character in $salt?
if ( !strstr( $salt, $char ) ){
// no, so it's OK to add it onto the end of whatever we've already got...
$salt .= $char;
// ... and increase the counter by one
$i++;
}
}
return $isValid;
}
public function generateSALT( $length = 2 )
{
// start with a blank salt
$salt = "";
// define possible characters - any character in this string can be
// picked for use in the salt, so if you want to put vowels back in
// or add special characters such as exclamation marks, this is where
// you should do it
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
// we refer to the length of $possible a few times, so let's grab it now
$maxlength = strlen( $possible );
// check for length overflow and truncate if necessary
if ( $length > $maxlength ){
$length = $maxlength;
}
// set up a counter for how many characters are in the salt so far
$i = 0;
// add random characters to $salt until $length is reached
while ( $i < $length ){
// pick a random character from the possible ones
$char = substr( $possible, mt_rand( 0, $maxlength - 1 ), 1 );
// have we already used this character in $salt?
if ( !strstr( $salt, $char ) ){
// no, so it's OK to add it onto the end of whatever we've already got...
$salt .= $char;
// ... and increase the counter by one
$i++;
}
// done!
return $salt;
}
}
}
// done!
return $salt;
}
}

View file

@ -1,14 +1,5 @@
<?php
/*
Here is the current code and progress on the drupal 7 ryzom core module
//////////////////////////
todo
//////////////////////////
disable user hook
delete user hook --- ring_open -> ring users ---- nel user & nel permission ---- hook_user_cancel ---- remove character data on server
menu items that do stuff
*/
/*
Drupal 7 ryzom core module
Copyright (C) 2013 Matthew Lagoe (Botanic) & Paige Offerdahl (Tobi)
@ -26,6 +17,9 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once("/ams_lib/libinclude.php");
//output template
function loadTemplate($template,$vars)
{

View file

@ -10,16 +10,6 @@ $DBHOST = 'localhost' ;
$DBUSERNAME = 'shard' ;
$DBPASSWORD = '' ;
$RINGDBNAME = 'ring_open' ;
$RINGDBUSERNAME = 'shard' ;
$RINGDBPASSWORD = '' ;
$NTDBName = 'nel_tool' ;
$NTUserName = 'shard' ;
$NTPassword = '' ;
$LOGRELATIVEPATH = 'logs/' ;
// If true= the server will add automatically unknown user in the database
// (in nel.user= nel.permission= ring.ring_user and ring.characters
$ALLOW_UNKNOWN = true ;
@ -27,57 +17,8 @@ $ALLOW_UNKNOWN = true ;
$CREATE_RING = true ;
// site paths definitions
$AMS_LIB = dirname(dirname( __FILE__ )) . '/ams_lib';
$AMS_LIB = dirname( dirname( __FILE__ ) ) . '/ams_lib';
$AMS_TRANS = $AMS_LIB . '/translations';
$AMS_CACHEDIR = $AMS_LIB . '/cache';
$SITEBASE = dirname( __FILE__ ) . '/html/' ;
$NELTOOL_SYSTEMBASE = dirname( dirname( __FILE__ ) ) . '/admin/' ;
$NELTOOL_LOGBASE = $NELTOOL_SYSTEMBASE . '/logs/' ;
$NELTOOL_IMGBASE = $NELTOOL_SYSTEMBASE . '/imgs/' ;
$NELTOOL_RRDTOOL = '/usr/bin/rrdtool' ;
$NELTOOL_RRDSYSBASE = $NELTOOL_SYSTEMBASE . 'graphs_output/' ;
$NELTOOL_RRDWEBBASE = $SITEBASE . 'graphs_output/' ;
// SQL table names
$NELDB_PREFIX = 'neltool_' ;
// for later use
// the config table will gather some of the settings
// that are currently written in this config.php file
$NELDB_CONFIG_TABLE = $NELDB_PREFIX . 'config';
$NELDB_USER_TABLE = $NELDB_PREFIX . 'users' ;
$NELDB_GROUP_TABLE = $NELDB_PREFIX . 'groups' ;
$NELDB_LOG_TABLE = $NELDB_PREFIX . 'logs' ;
$NELDB_NOTE_TABLE = $NELDB_PREFIX . 'notes' ;
$NELDB_STAT_HD_TIME_TABLE = $NELDB_PREFIX . 'stats_hd_times' ;
$NELDB_STAT_HD_TABLE = $NELDB_PREFIX . 'stats_hd_datas' ;
$NELDB_ANNOTATION_TABLE = $NELDB_PREFIX . 'annotations' ;
$NELDB_LOCK_TABLE = $NELDB_PREFIX . 'locks' ;
$NELDB_APPLICATION_TABLE = $NELDB_PREFIX . 'applications' ;
$NELDB_GROUP_APPLICATION_TABLE = $NELDB_PREFIX . 'group_applications' ;
$NELDB_USER_APPLICATION_TABLE = $NELDB_PREFIX . 'user_applications' ;
$NELDB_DOMAIN_TABLE = $NELDB_PREFIX . 'domains' ;
$NELDB_USER_DOMAIN_TABLE = $NELDB_PREFIX . 'user_domains' ;
$NELDB_GROUP_DOMAIN_TABLE = $NELDB_PREFIX . 'group_domains' ;
$NELDB_SHARD_TABLE = $NELDB_PREFIX . 'shards' ;
$NELDB_USER_SHARD_TABLE = $NELDB_PREFIX . 'user_shards' ;
$NELDB_GROUP_SHARD_TABLE = $NELDB_PREFIX . 'group_shards' ;
$NELDB_RESTART_GROUP_TABLE = $NELDB_PREFIX . 'restart_groups' ;
$NELDB_RESTART_MESSAGE_TABLE = $NELDB_PREFIX . 'restart_messages' ;
$NELDB_RESTART_SEQUENCE_TABLE = $NELDB_PREFIX . 'restart_sequences' ;
$VIEW_DELAY = 0 ;
$HARDWARE_REFRESH = 600 ;
$LOCK_TIMEOUT = 1800 ;
$BG_IMG = 'imgs/bg_live.png' ;
$DEFAULT_LANGUAGE = 'en';
$DEFAULT_LANGUAGE = 'en';

View file

@ -1,13 +1,12 @@
<?php
function add_user(){
//add user locally here
$return = users::add_user();
return $return;
}
// add user locally here
$return = users :: add_user();
return $return;
}
function checkUser(){
}
}