diff --git a/buildLibs b/buildLibs index 591624a..b012e75 100644 --- a/buildLibs +++ b/buildLibs @@ -117,7 +117,7 @@ function deploy(){ chmod -R a+x "$APPLICATION_BINARY_PATH" chmod -R a+x "$APPLICATION_CRON_PATH" - chmod -R a+x "$APPLICATION_TASK_PATH" +# chmod -R a+x "$APPLICATION_TASK_PATH" } diff --git a/buildLibs~ b/buildLibs~ new file mode 100644 index 0000000..591624a --- /dev/null +++ b/buildLibs~ @@ -0,0 +1,273 @@ +#!/bin/bash + +## Funzioni utilizzate da build + +#Stampa i comandi possibili +function help() { + printf "\n" + printf "build [-h] -[ptl] -[DCcfs] [config_file]\n" + printf "\n" + printf "Specificare il config_file solo se non si desidera utilizzare quello di default.\n" + printf "E' obbligatorio specificare l'environment. In caso di environment multipli sarà utilizzato solo quello a priorità maggiore.\n" + printf "L'opzione default di database è -f (fix).\n" + printf "\n" + printf "Possibili valori di option\n" + printf "\t -h questa schermata\n" + printf "\n" + printf "Lista environment (per deployare la configurazione) in ordine di priorità\n" + printf "\t -p Produzione\n" + printf "\t -t Test\n" + printf "\t -l Locale\n" + printf "\n" + printf "Opzioni database\n" + printf "\t -D Droppa tutto il database e lo rebuilda\n" + printf "\t -C Droppa le tabelle di contenuti e le rebuilda\n" + printf "\t -c Droppa le tabelle di configurazione e le rebuilda\n" + printf "\t -f Aggiunge le tabelle mancanti\n" + printf "\t -s Skip db fix\n" +} + +#Stampa il nome del comando in esecuzione +function printcmd () { + printf "*-----------------------------------------*\n" + printf " PROJECT: $PROJECT_NAME\n" + printf " EXECUTING: $1\n" + printf "\n" + printf "*-----------------------------------------*\n" +} + + + +# Imposta come proprietario della cartella l'utente apache +function chown_folder() { + if [[ -z "$1" ]] || [[ "$1" == "/" ]] || [[ "$1" == "./" ]]; then + exit 1 + else + chown -R $APACHE2_USER:$APACHE2_GROUP "$1" + fi +} + +function svncleanup() { + if [[ -z "$1" ]] || [[ "$1" == "/" ]] || [[ "$1" == "./" ]]; then + exit 1 + else + for i in `find "$1" -name .svn`; + do + printf "Deleting .. $i\n" + rm -rf "$i" + done + fi +} + +# Crea le cartelle di sistema +function create_project_fs(){ + # CREATES APPLICATION PRIVATE FOLDER + mkdir -p $APPLICATION_PRIVATE + chown_folder $APPLICATION_PRIVATE + + # CREATES APPLICATION PUBLIC FOLDER + mkdir -p $APPLICATION_PUBLIC + chown_folder $APPLICATION_PUBLIC + + # CREATES APPLICATION STORAGE FOLDER + mkdir -p $APPLICATION_STORAGE + chown_folder $APPLICATION_STORAGE + + # CREATES APPLICATION LOG FOLDER + mkdir -p $APPLICATION_LOG_PATH + chown_folder $APPLICATION_LOG_PATH + + # CREATES XSENDFILE FOLDER + mkdir -p $APPLICATION_XSENDFILE_PATH + chown_folder $APPLICATION_XSENDFILE_PATH + + # CREATES APPLICATION MEDIA FOLDER + mkdir -p $APPLICATION_MEDIA_PATH + chown_folder $APPLICATION_MEDIA_PATH + + # CREATES APPLICATION BACKUP FOLDER + mkdir -p $APPLICATION_BACKUPS_PATH + chown_folder $APPLICATION_BACKUPS_PATH + + # CREATES APPLICATION TEMPORARY FOLDER + mkdir -p $APPLICATION_TMP_PATH + chown_folder $APPLICATION_TMP_PATH +} + + +# Deploya i sorgenti +function deploy(){ + echo "Deleting old build (Private)" + rm -rf "$APPLICATION_PRIVATE/*" + + echo "Deleting old build (Public)" + rm -rf "$APPLICATION_PUBLIC/*" + + + echo "Deploying new build (Private)" + cp -a "./private/"* "$APPLICATION_PRIVATE" + svncleanup "$APPLICATION_PRIVATE" + chown_folder "$APPLICATION_PRIVATE" + + echo "Deploying new build (Public)" + cp -a "./public/"* "$APPLICATION_PUBLIC" + svncleanup "$APPLICATION_PUBLIC" + chown_folder "$APPLICATION_PUBLIC" + + + chmod -R a+x "$APPLICATION_BINARY_PATH" + chmod -R a+x "$APPLICATION_CRON_PATH" + chmod -R a+x "$APPLICATION_TASK_PATH" +} + + + +# Deploya il progetto e mantiene solo la configurazione di produzione +function deploy_production_env(){ + create_project_fs + deploy + if [[ -f "$APPLICATION_CONFIG_PATH/config.local.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.local.php" + fi + if [[ -f "$APPLICATION_CONFIG_PATH/config.test.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.test.php" + fi +} + +# Deploya il progetto e mantiene solo la configurazione del server di test +function deploy_test_env(){ + create_project_fs + deploy + if [[ -f "$APPLICATION_CONFIG_PATH/config.local.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.local.php" + fi + if [[ -f "$APPLICATION_CONFIG_PATH/config.prod.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.prod.php" + fi +} + +# Deploya il progetto e mantiene solo la configurazione locale +function deploy_local_env(){ + create_project_fs + deploy + if [[ -f "$APPLICATION_CONFIG_PATH/config.prod.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.prod.php" + fi + if [[ -f "$APPLICATION_CONFIG_PATH/config.test.php" ]];then + rm "$APPLICATION_CONFIG_PATH/config.test.php" + fi +} + +function database_rebuild_content(){ + echo "Function not implemented... faking execution" + for collection_name in "${!MONGO_DB_CONTENT_COLLECTIONS[@]}"; do + echo "Rebuilding collection $collection_name - ${MONGO_DB_CONTENT_COLLECTIONS["$collection_name"]}"; + done + + for table_name in "${!MYSQL_DB_CONTENT_TABLES[@]}"; do + echo "Rebuilding table '$table_name' using query '${MYSQL_DB_CONTENT_TABLES["$table_name"]}'"; + done +} + +function database_rebuild_config(){ + echo "Function not implemented... faking execution" + for collection_name in "${!MONGO_DB_CONFIG_COLLECTIONS[@]}"; do + echo "Rebuilding collection $collection_name - ${MONGO_DB_CONFIG_COLLECTIONS["$collection_name"]}"; + done + + for table_name in "${!MYSQL_DB_CONFIG_TABLES[@]}"; do + echo "Rebuilding table '$table_name' using query '${MYSQL_DB_CONFIG_TABLES["$table_name"]}'"; + done +} + +function database_add_missing(){ + echo "Function not implemented... faking execution" + for collection_name in "${!MONGO_DB_CONFIG_COLLECTIONS[@]}"; do + echo "Checking collection $collection_name - ${MONGO_DB_CONFIG_COLLECTIONS["$collection_name"]}"; + done + + for table_name in "${!MYSQL_DB_CONFIG_TABLES[@]}"; do + echo "Checking table '$table_name' using query '${MYSQL_DB_CONFIG_TABLES["$table_name"]}'"; + done +} + + + +# Droppa e ricrea solo le tabelle dei dati +function regenerate_db(){ + EXDIR=`pwd` + cd "$APPLICATION_BINARY_PATH" + + ./createDatabase + DBCONN=`./getDbConnectionString` + + QUERY="CREATE TABLE campagna (id bigint auto_increment PRIMARY KEY, nome VARCHAR(64), owner bigint not null, creation_date TIMESTAMP default CURRENT_TIMESTAMP, current boolean default false, deleted boolean default false)" + TABNAME="campagna" + EXISTS=`echo "show tables" | $DBCONN | grep "$TABNAME" | wc -l` + if [[ "$EXISTS" -gt 0 ]];then + echo "Dropping table $TABNAME" + echo "DROP TABLE $TABNAME" | $DBCONN + fi + echo "Executing query '$QUERY'" + echo $QUERY | $DBCONN + + QUERY="CREATE TABLE personaggio ( id bigint auto_increment PRIMARY KEY, deleted boolean default false, campagna bigint, active boolean default true, nome varchar(128), giocatore varchar(128), vita_cur smallint, vita_max smallint, forza tinyint unsigned, destrezza tinyint unsigned, costituzione tinyint unsigned, intelligenza tinyint unsigned, saggezza tinyint unsigned, carisma tinyint unsigned, ts_tempra smallint, ts_tempra_note varchar(128), ts_riflessi smallint, ts_riflessi_note varchar(128), ts_volonta smallint, ts_volonta_note varchar(128), ca_base tinyint, ca_contatto tinyint, ca_sprovvista tinyint, iniziativa int not null default 0, ascoltare int, ascoltare_note varchar(128), cercare int, cercare_note varchar(128), diplomazia int, diplomazia_note varchar(128), muov_sil int, muov_sil_note varchar(128), nascondersi int, nascondersi_note varchar(128), osservare int, osservare_note varchar(128), perc_intenz int, perc_intenz_note varchar(128), raggirare int, raggirare_note varchar(128), valutare int, valutare_note varchar(128), conoscenze varchar(256), lingue varchar(256), melee_atk_short varchar(512), melee_atk_complete varchar(512), ranged_atk_short varchar(512), ranged_atk_complete varchar(512), unarmed_atk_short varchar(512), unarmed_atk_complete varchar(512), resist_incant smallint default 0, combat_note varchar(512), details TEXT, INDEX(campagna) )" + TABNAME="personaggio" + EXISTS=`echo "show tables" | $DBCONN | grep "$TABNAME" | wc -l` + if [[ "$EXISTS" -gt 0 ]];then + echo "Dropping table $TABNAME" + echo "DROP TABLE $TABNAME" | $DBCONN + fi + echo "Executing query '$QUERY'" + echo $QUERY | $DBCONN + + + QUERY="CREATE TABLE npc( id bigint auto_increment PRIMARY KEY, deleted boolean default false, nome varchar(128), tipo varchar(128), dadi_vita smallint, vita_max smallint, allineamento varchar(32), grado_sfida smallint, forza tinyint unsigned, destrezza tinyint unsigned, costituzione tinyint unsigned, intelligenza tinyint unsigned, saggezza tinyint unsigned, carisma tinyint unsigned, ts_tempra smallint, ts_tempra_note varchar(128), ts_riflessi smallint, ts_riflessi_note varchar(128), ts_volonta smallint, ts_volonta_note varchar(128), ca_base tinyint, ca_contatto tinyint, ca_sprovvista tinyint, iniziativa int not null default 0, ascoltare int, ascoltare_note varchar(128), cercare int, cercare_note varchar(128), muov_sil int, muov_sil_note varchar(128), nascondersi int, nascondersi_note varchar(128), osservare int, osservare_note varchar(128), perc_intenz int, perc_intenz_note varchar(128), raggirare int, raggirare_note varchar(128), valutare int, valutare_note varchar(128), conoscenze varchar(256), lingue varchar(256), melee_atk_short varchar(512), melee_atk_complete varchar(512), ranged_atk_short varchar(512), ranged_atk_complete varchar(512), unarmed_atk_short varchar(512), unarmed_atk_complete varchar(512), resist_incant smallint default 0, combat_note varchar(512), details TEXT )" + TABNAME="npc" + EXISTS=`echo "show tables" | $DBCONN | grep "$TABNAME" | wc -l` + if [[ "$EXISTS" -gt 0 ]];then + echo "Dropping table $TABNAME" + echo "DROP TABLE $TABNAME" | $DBCONN + fi + echo "Executing query '$QUERY'" + echo $QUERY | $DBCONN + + cd "$EXDIR" +} + +# Droppa e ricrea le tabelle base (tipo admin e config) +function regenerate_db_hard(){ + EXDIR=`pwd` + cd "$APPLICATION_BINARY_PATH" + + ./createDatabase + DBCONN=`./getDbConnectionString` + + + QUERY="CREATE TABLE general_configuration (config_key varchar(128) primary key, config_value varchar(128), INDEX(config_key))" + TABNAME="general_configuration" + EXISTS=`echo "show tables" | $DBCONN | grep "$TABNAME" | wc -l` + if [[ "$EXISTS" -gt 0 ]];then + echo "Dropping table $TABNAME" + echo "DROP TABLE $TABNAME" | $DBCONN + fi + echo "Executing query '$QUERY'" + echo $QUERY | $DBCONN + + + QUERY="CREATE TABLE user (id bigint auto_increment PRIMARY KEY, login varchar(64) not null, password varchar(64) not null, last_session_id varchar(64) default null, is_admin boolean not null default false, INDEX(login), INDEX(last_session_id))" + TABNAME="user" + EXISTS=`echo "show tables" | $DBCONN | grep "$TABNAME" | wc -l` + if [[ "$EXISTS" -gt 0 ]];then + echo "Dropping table $TABNAME" + echo "DROP TABLE $TABNAME" | $DBCONN + fi + echo "Executing query '$QUERY'" + echo $QUERY | $DBCONN + + + cd "$EXDIR" +} + + + diff --git a/private/common/config.php b/private/common/config.php index bc20133..be65f7d 100644 --- a/private/common/config.php +++ b/private/common/config.php @@ -24,6 +24,12 @@ else{ // Generic voices $config = new stdClass(); +$config->info = new stdClass(); +$config->info->projectName = "I Fatti di Napoli"; +$config->info->projectDescription = "Il giornale della terza metropoli italiana"; +$config->info->owner = "Antonio Pianelli"; +$config->info->author = "ASDynamics"; + $config->locale = new stdClass(); $config->locale->gui = $project->defaultLocale; $config->locale->system = $project->defaultLocale; diff --git a/private/crontab/core.minute.php b/private/crontab/core.minute.php index b2cdfc4..c7dd3a8 100644 --- a/private/crontab/core.minute.php +++ b/private/crontab/core.minute.php @@ -8,14 +8,15 @@ Creation Date: 12/gen/2016 require_once(dirname(__FILE__). "/../load.php"); try { - $task = "test"; - SystemController::executeTask("$task.php"); + if (TestTask::isActive()){ + TestTask::execute(); + } }catch (CoreException $ex){ - $msg = "Error while executing task '$task' with message '".$ex->getMessage()."'"; + $msg = "Error while executing task '".TestTask::getLabel()."' with message '".$ex->getMessage()."'"; LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,$msg); } catch (Exception $ex){ - $msg = "Unexpected error while executing task '$task' with message '".$ex->getMessage()."'"; + $msg = "Unexpected error while executing task '".TestTask::getLabel()."' with message '".$ex->getMessage()."'"; LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,$msg); } diff --git a/private/lib/dao/DaoSaveableDefaultImplementation.php b/private/lib/dao/DaoSaveableDefaultImplementation.php index 910af05..8b10c44 100644 --- a/private/lib/dao/DaoSaveableDefaultImplementation.php +++ b/private/lib/dao/DaoSaveableDefaultImplementation.php @@ -16,10 +16,19 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable { } public function __set($attr,$value){ + if (strcmp($attr,"id")==0){ + $attr = "_id"; + if (!($value instanceof MongoId)){ + $value = new MongoId($value); + } + } $this->saveableObject->$attr = $value; } public function &__get($attr){ + if (strcmp($attr,"id")==0){ + $attr = "_id"; + } $rval = &$this->saveableObject->$attr; return $rval; } @@ -28,6 +37,13 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable { unset($this->saveableObject->$attr); } + public function hasProperty($attr){ + if (strcmp($attr,"id")==0){ + $attr = "_id"; + } + return property_exists($this->saveableObject, $attr); + } + /** * (non-PHPdoc) * @see DaoSaveable::getSaveableObj() @@ -69,6 +85,9 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable { */ public function updateFromSaveableObj($saveableObject){ $this->saveableObject = $this->toObject($saveableObject); + if (!property_exists($this->saveableObject, "deleted")){ + $this->saveableObject->deleted = false; + } // $this->saveableObject = $saveableObject; } diff --git a/private/lib/dao/GenericDao.php b/private/lib/dao/GenericDao.php index 5d1fa95..1b99fba 100644 --- a/private/lib/dao/GenericDao.php +++ b/private/lib/dao/GenericDao.php @@ -61,12 +61,22 @@ class GenericDao{ $rval = array(); foreach ($cursor as $element){ - var_dump($element); $rval[] = $modelClass::buildFromSaveableObj($element); } return $rval; } + + public function getFirst($modelClass, array $filter = array(), array $options = array()){ + $rval = $this->query($modelClass,$filter,$options); + if (sizeof($rval)>0){ + $rval = reset($rval); + } + else { + $rval = null; + } + return $rval; + } public function save(DaoSaveable $model){ @@ -75,7 +85,7 @@ class GenericDao{ $saveObj = $model->getSaveableObj(); - if ( !is_null($saveObj["_id"]) ){ + if ( array_key_exists("_id", $saveObj) && !is_null($saveObj["_id"]) ){ $collection->update( array("_id"=>$saveObj["_id"] ), $saveObj ); } else { diff --git a/private/lib/dao/lib.inclusion.php b/private/lib/dao/lib.inclusion.php index 58e89e3..908c27b 100644 --- a/private/lib/dao/lib.inclusion.php +++ b/private/lib/dao/lib.inclusion.php @@ -13,7 +13,10 @@ require_once(dirname(__FILE__)."/GenericDao.php"); require_once(dirname(__FILE__)."/Model.php"); +require_once(dirname(__FILE__)."/models/ConfigModel.php"); +require_once(dirname(__FILE__)."/models/TaskModel.php"); require_once(dirname(__FILE__)."/models/NotiziaModel.php"); +require_once(dirname(__FILE__)."/models/AdminModel.php"); $dao = new GenericDao($database->dbName,$database->connectionString); GlobalVariables::set("dao", $dao); diff --git a/private/lib/dao/models/AdminModel.php b/private/lib/dao/models/AdminModel.php new file mode 100644 index 0000000..80ce434 --- /dev/null +++ b/private/lib/dao/models/AdminModel.php @@ -0,0 +1,63 @@ + array("label"=>"Editore") + ); + + public static $ROLE_SUPERADMIN_HANDLED = array( + self::ADMIN_TYPE_BANNER => array("label"=>"Banner"), + self::ADMIN_TYPE_ROLEADMIN => array("label"=>"Amministratore"), + self::ADMIN_TYPE_COMMENTI => array("label"=>"Commenti"), + self::ADMIN_TYPE_STATISTICHE => array("label"=>"Statistiche"), + self::ADMIN_TYPE_NEWSLETTER => array("label"=>"Newsletter"), + self::ADMIN_TYPE_SONDAGGI => array("label"=>"Sondaggi"), + self::ADMIN_TYPE_EDITORE => array("label"=>"Editore"), + self::ADMIN_TYPE_EDITORE_SUPERVISOR => array("label"=>"Supervisione Editori") + ); + + + public function __construct($saveableObject = null){ + parent::__construct($saveableObject); + if (!$this->hasProperty("roles")){ + $this->roles = false; + } + } + + public static function getCollectionName(){ + return "administrators"; + } + + public function hasRole($role){ + return $role & $this->role == $role; + } + + public function addRole($role){ + $this->role = $this->role | $role; + } + + public function removeRole($role){ + $this->role = $this->role & ~$role; + } + + public function setRole($role){ + $this->role = $role; + } + +} + +?> \ No newline at end of file diff --git a/private/lib/dao/models/ConfigModel.php b/private/lib/dao/models/ConfigModel.php new file mode 100644 index 0000000..6cec19d --- /dev/null +++ b/private/lib/dao/models/ConfigModel.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/private/lib/dao/models/TaskModel.php b/private/lib/dao/models/TaskModel.php new file mode 100644 index 0000000..df24ff8 --- /dev/null +++ b/private/lib/dao/models/TaskModel.php @@ -0,0 +1,22 @@ +hasProperty("isActive")){ + $this->isActive = false; + } + } + + public static function getCollectionName(){ + return "task"; + } + +} + +?> \ No newline at end of file diff --git a/private/lib/gui/ASDSessionHandler.php b/private/lib/gui/ASDSessionHandler.php new file mode 100644 index 0000000..d714f8e --- /dev/null +++ b/private/lib/gui/ASDSessionHandler.php @@ -0,0 +1,48 @@ + \ No newline at end of file diff --git a/private/lib/gui/GUIHandler.php b/private/lib/gui/GUIHandler.php new file mode 100644 index 0000000..3e92e22 --- /dev/null +++ b/private/lib/gui/GUIHandler.php @@ -0,0 +1,50 @@ +info->projectName; + if (array_key_exists("title", $data)){ + $title = $data["title"]; + } + + $description = $conf->info->projectDescription; + if (array_key_exists("description", $data)){ + $description = $data["description"]; + } + + $author = $conf->info->author; + if (array_key_exists("author", $data)){ + $author = $data["author"]; + } + + header("Content-type: text/html; charset=utf-8"); + + echo "\n"; + echo "\n
\n"; + echo "\n"; + echo "
+ Login
+|
+
+
+
+
+ |