diff --git a/app/os/webserver-entrypoint b/app/os/webserver-entrypoint index 05aa914..c5102ca 100644 --- a/app/os/webserver-entrypoint +++ b/app/os/webserver-entrypoint @@ -10,6 +10,7 @@ ASD_BINDIR="/home/${DDNINJA_AUTHOR}/private/${DDNINJA_BUILDNAME}/bin" mkdir -p "/tmp/${DDNINJA_AUTHOR}/${DDNINJA_BUILDNAME}" chown -R www-data:www-data "/tmp/${DDNINJA_AUTHOR}/${DDNINJA_BUILDNAME}" +chown -R www-data:www-data /var/log/${DDNINJA_AUTHOR} asdphp-entrypoint & wait exit $? diff --git a/app/private/bin/convertStats.php b/app/private/bin/convertStats.php new file mode 100644 index 0000000..08007f0 --- /dev/null +++ b/app/private/bin/convertStats.php @@ -0,0 +1,40 @@ +#!/usr/bin/php +query( + StatisticModel::class, + [], + [ + 'skip' => $iteration * $size, + 'limit' => $size + ] + ); + $iteration++; + return $ret; +} + +exit; +// WIP + +$models = getModels(); +while (sizeof($models)>0) { + foreach ($models as $model) { + + } + $models = getModels(); +} + +?> diff --git a/app/private/common/config.php b/app/private/common/config.php index e19f7b8..78d701a 100644 --- a/app/private/common/config.php +++ b/app/private/common/config.php @@ -10,17 +10,45 @@ $project->buildName = "fdn2"; $project->defaultLocale = "it"; +$database = new stdClass(); +$database->dbName = getenv("DDNINJA_MONGO_DBNAME"); +$database->user = getenv("DDNINJA_MONGO_USER"); +$database->pass = getenv("DDNINJA_MONGO_PASSWORD"); +$database->useAuth = $database->user != false || $database->pass != false; +$database->location = getenv("DDNINJA_MONGO_LOCATION"); -if (file_exists(dirname(__FILE__)."/config.local.php") ){ - require_once (dirname(__FILE__)."/config.local.php"); +if ($database->useAuth) { + $database->connectionString = "mongodb://".$database->user.":".$database->pass."@".$database->location."/".$database->dbName; } -else if (file_exists(dirname(__FILE__)."/config.test.php") ){ - require_once (dirname(__FILE__)."/config.test.php"); -} -else{ - require_once (dirname(__FILE__)."/config.prod.php"); +else { + $database->connectionString = "mongodb://".$database->location."/".$database->dbName; } +$currentSystem = new stdClass(); +$currentSystem->storageBaseDir = "/home/ddninja/storage"; // Il path con storage ecc in cui mettere immagini, file temporanei ecc +$currentSystem->privateBaseDir = "/home/ddninja/private"; // Il path in cui inserire la cartella con lib, task, binari ecc +$currentSystem->tmpBaseDir = "/tmp/ddninja"; +$currentSystem->logBaseDir = "/var/log/ddninja"; // Il path dei log.... +$currentSystem->xSendFileDir = "/tmp/xsend"; + +$currentSystem->apache = new StdClass(); +$currentSystem->apache->user = "var-www"; +$currentSystem->apache->group = "var-www"; +$currentSystem->apache->workdir = "/var/www"; // Il path in cui inserire la cartella con le pagine html + +$currentSystem->remoteLocationPath = getenv('ASD_PUBLIC_URL')."/"; + +// Deprecato in quanto CBS2 è stato dismesso +$backupSystem = new stdClass(); +$backupSystem->account = "1582528f056a7ea7f391149fddc75553"; +$backupSystem->passphrase = "232728b3e504a400a62a9f94893a9a962ecc6543ed7d3c293340414b259aac727f14d60a4f2cd52e228c9694a55774ff5652520b38d120a299394715247645b8293a880901162f268c8c8777a3ee9c6e410455cb4c8137f58f9d7162d45582ab363679ed456e56bf3b36d0384368b62eced40abd0fe117f04c9322f07ee33a7c"; + +// Deprecato in quanto CBS2 è stato dismesso +$cbs2 = new stdClass(); +$cbs2->keyfile = "id_rsa_cbs_prod"; +$cbs2->serverPort = "22"; + + // Generic voices $config = new stdClass(); @@ -63,6 +91,8 @@ $config->paths->xsendfile = $currentSystem->xSendFileDir . "/" . $project->build // FILES $config->files = new StdClass(); +$config->files->system_log = $config->paths->log . "/sys.log"; + $config->files->core_log = $config->paths->log . "/core.log"; $config->files->dao_log = $config->paths->log . "/dao.log"; $config->files->task_log = $config->paths->log . "/task.log"; diff --git a/app/private/common/config.prod.php b/app/private/common/config.prod.php index 6460d22..32e9d7a 100644 --- a/app/private/common/config.prod.php +++ b/app/private/common/config.prod.php @@ -1,17 +1,10 @@ dbname = "cbs"; -// $dbconn->dbtype = "mysql"; -// $dbconn->location = "localhost"; -// $dbconn->username = "root"; -// $dbconn->password = "root"; +/** + * Author: Riccardo Di Dato + * Creation Date: 19/nov/2013 + * + * @deprecated In favore di unica config con variabili d'ambiente + */ // Password mongo produzione: p14n3ll1FDN2 $database = new stdClass(); @@ -28,7 +21,6 @@ $currentSystem->tmpBaseDir = "/tmp/ddninja"; $currentSystem->logBaseDir = "/var/log/ddninja"; // Il path dei log.... $currentSystem->xSendFileDir = "/tmp/xsend"; -// $currentSystem->safeStorage = "/home/cbs/storage"; $currentSystem->apache = new StdClass(); $currentSystem->apache->user = "var-www"; @@ -45,10 +37,4 @@ $cbs2 = new stdClass(); $cbs2->keyfile = "id_rsa_cbs_prod"; $cbs2->serverPort = "22"; -// $config->locations = new stdClass(); - -// $config->application->applicationInterfacePath = "/tnc15"; - -// $config->application->systemTmp = "/tmp"; - ?> \ No newline at end of file diff --git a/app/private/common/config.test.php b/app/private/common/config.test.php deleted file mode 100644 index 9b53d18..0000000 --- a/app/private/common/config.test.php +++ /dev/null @@ -1,50 +0,0 @@ -dbname = "cbs"; -// $dbconn->dbtype = "mysql"; -// $dbconn->location = "localhost"; -// $dbconn->username = "root"; -// $dbconn->password = "root"; -$database = new stdClass(); -$database->dbName = "fdn2"; -$database->user = "test"; -$database->pass = "test"; -$database->useAuth = false; -$database->connectionString = "mongodb://".$database->user.":".$database->pass."@localhost/".$database->dbname; - -$currentSystem = new stdClass(); -$currentSystem->storageBaseDir = "/home"; // Il path con storage ecc in cui mettere immagini, file temporanei ecc -$currentSystem->privateBaseDir = "/home/ddninja"; // Il path in cui inserire la cartella con lib, task, binari ecc -$currentSystem->tmpBaseDir = "/tmp/ddninja"; -$currentSystem->logBaseDir = "/var/log"; // Il path dei log.... -$currentSystem->xSendFileDir = "/tmp/xsend"; - -// $currentSystem->safeStorage = "/home/cbs/storage"; - -$currentSystem->apache = new StdClass(); -$currentSystem->apache->user = "var-www"; -$currentSystem->apache->group = "var-www"; -$currentSystem->apache->workdir = "/var/www"; // Il path in cui inserire la cartella con le pagine html - -$currentSystem->remoteLocationPath = "http://db.ifattidinapoli.it/"; - -$backupSystem = new stdClass(); -$backupSystem->account = "40a911e14db8ad6faf0a0e7385e7c267"; -$backupSystem->passphrase = "a54af48c2ec44bba903666b6d12290750178154a6965c9165d3b387e7fd0f14c5f2d62cb93f468be640d469c80f1260feed3ad98f5f52d52c045b0487e59981bf365f4037f6c7cb93572cdd5d20daeb8185afcc65dba1bd2067829f827d9b795451f6e5e8fafe5e1fbe29675feb93e7d208a6b53a14df5aeec62d97fbf34d56a"; - -$cbs2 = new stdClass(); -$cbs2->keyfile = "id_rsa_cbs_test"; -$cbs2->serverPort = "22"; - -// $config->locations = new stdClass(); - -// $config->application->applicationInterfacePath = "/tnc15"; - -// $config->application->systemTmp = "/tmp"; -?> \ No newline at end of file diff --git a/app/private/lib/dao/GenericDao.php b/app/private/lib/dao/GenericDao.php index fc65e2f..bbebc8b 100644 --- a/app/private/lib/dao/GenericDao.php +++ b/app/private/lib/dao/GenericDao.php @@ -248,17 +248,20 @@ class GenericDao{ } } - $command = new \MongoDB\Driver\Command( [ 'aggregate' => $collectionName, 'pipeline' => $pipeline ] ); + $command = new \MongoDB\Driver\Command( [ + 'aggregate' => $collectionName, + 'pipeline' => $pipeline, + 'cursor' => [ + 'batchSize' => 100 + ], + 'allowDiskUse' => true + ] ); $cursor = $this->client->executeCommand( $this->dbName, $command ); - + $rval = []; foreach ($cursor as $ele){ // inganniamo il cursore, in realtà il risultato è uno //TODO CHECK - if (!is_null($ele->result)){ - $rval = $ele->result; - - $rval = json_decode( json_encode($rval) ,true ); - } + $rval[] = json_decode( json_encode($ele) ,true ); } return $rval; diff --git a/app/private/lib/gui/ASDSessionHandler.php b/app/private/lib/gui/ASDSessionHandler.php index 5cdcae1..da107c5 100644 --- a/app/private/lib/gui/ASDSessionHandler.php +++ b/app/private/lib/gui/ASDSessionHandler.php @@ -5,8 +5,8 @@ Creation Date: 13/gen/2016 */ class ASDSessionHandler { - private static $isSessionStarted; - private static $sessId; + private static $isSessionStarted = false; + private static $sessId = null; public static function getSessionId(){ self::prepareToOperate(); @@ -14,12 +14,12 @@ class ASDSessionHandler { } private static function prepareToOperate(){ - if (!isset(self::$isSessionStarted) || !self::$isSessionStarted){ - self::$isSessionStarted = session_start(); - } - if (!isset(self::$sessId) || is_null(self::$sessId)){ - self::$sessId = session_id(); - } + if ( !self::$isSessionStarted ){ + self::$isSessionStarted = session_start(); + } + if ( is_null(self::$sessId) ){ + self::$sessId = session_id(); + } } public static function sessionValueExists($val){ @@ -48,6 +48,10 @@ class ASDSessionHandler { self::prepareToOperate(); session_unset(); } + + private static function isApacheSession(){ + return preg_match("/apache/", php_sapi_name()); + } } ?> \ No newline at end of file diff --git a/app/private/lib/gui/GUIHandler.php b/app/private/lib/gui/GUIHandler.php index 88beff9..82332d5 100644 --- a/app/private/lib/gui/GUIHandler.php +++ b/app/private/lib/gui/GUIHandler.php @@ -19,6 +19,9 @@ class GUIHandler { private static $onLoadEvents = array(); public static function generateHtmlHeaders(array $data = array(), $admin = false){ + if ($admin) { + ASDSessionHandler::getSessionId(); + } $conf = GlobalVariables::get("config"); $title = $conf->info->projectName; diff --git a/app/private/lib/lib.inclusions.php b/app/private/lib/lib.inclusions.php index eaedbdf..e8b96e8 100644 --- a/app/private/lib/lib.inclusions.php +++ b/app/private/lib/lib.inclusions.php @@ -23,10 +23,10 @@ require_once(dirname(__FILE__)."/lib.instances.php"); require_once(dirname(__FILE__)."/gui/lib.inclusion.php"); -require_once(dirname(__FILE__)."/logger/lib.inclusion.php"); - require_once(dirname(__FILE__)."/system/lib.inclusion.php"); +require_once(dirname(__FILE__)."/logger/lib.inclusion.php"); + require_once(dirname(__FILE__)."/mail/lib.inclusion.php"); require_once(dirname(__FILE__)."/media/lib.inclusion.php"); diff --git a/app/private/lib/logger/FileLogger.php b/app/private/lib/logger/FileLogger.php index c4e3583..32e522c 100644 --- a/app/private/lib/logger/FileLogger.php +++ b/app/private/lib/logger/FileLogger.php @@ -4,11 +4,15 @@ Author: Riccardo Di Dato Creation Date: 14/feb/2013 */ +use ASD\FileSystemManager; + class FileLogger extends LoggingFacility{ private $filePath; public function __construct($name,$catalogManager,$filePath,$usedate=false) { $this->filePath = $filePath; + touch($this->filePath); + chown($this->filePath, "www-data"); parent::__construct($name,$catalogManager,$usedate); } diff --git a/app/private/lib/logger/lib.inclusion.php b/app/private/lib/logger/lib.inclusion.php index 95cfcf5..61eedf5 100644 --- a/app/private/lib/logger/lib.inclusion.php +++ b/app/private/lib/logger/lib.inclusion.php @@ -17,11 +17,11 @@ require_once(dirname(__FILE__)."/FileLogger.php"); // |_____\___/ \__, |\__, |\___|_| |___/ // |___/ |___/ // -$sysLog = new SyslogLogger("System",$systemCatalogManager,true); + +$sysLog = new FileLogger("System",$systemCatalogManager,$config->files->system_log,true); LoggingFacilityManager::addLogger( "system", $sysLog ); LoggingFacilityManager::getLogger("system")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG); - $coreLog = new FileLogger("Core",$systemCatalogManager,$config->files->core_log,true); LoggingFacilityManager::addLogger( "core", $coreLog ); LoggingFacilityManager::getLogger("core")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG); diff --git a/app/public/admin/login.php b/app/public/admin/login.php index 56fec29..9cd3d24 100644 --- a/app/public/admin/login.php +++ b/app/public/admin/login.php @@ -9,7 +9,7 @@ require_once(dirname(__FILE__)."/../load.php"); GUIHandler::generateHtmlHeaders(array(),true); -if (AdminLoginManager::isLogged()){ +if (AdminLoginManager::isLogged()) { GUIHandler::redirect("admin/index.php"); } @@ -25,6 +25,7 @@ if (!is_null($action) && strcmp($action,"login")==0){ $errMsg = "Invalid Data"; } else { + GUIHandler::redirect("admin/index.php"); } } diff --git a/app/public/sendCommentoBackend.php b/app/public/sendCommentoBackend.php index 6d0ddee..635b63c 100644 --- a/app/public/sendCommentoBackend.php +++ b/app/public/sendCommentoBackend.php @@ -5,7 +5,7 @@ require_once(dirname(__FILE__)."/load.php"); try { // if(UserLoginManager::isLogged()){ - var_dump($_POST); + // var_dump($_POST); $id = PostHandler::get("id"); $titolo = PostHandler::get("titolo"); $commento = PostHandler::get("commento"); diff --git a/cicd/docker-compose.yml b/cicd/docker-compose.yml deleted file mode 100644 index a01b028..0000000 --- a/cicd/docker-compose.yml +++ /dev/null @@ -1,65 +0,0 @@ -version: "3" -services: - mongo: - image: mongo:4.4.0 - restart: "no" - networks: - db-network: - aliases: - - §PROJECT_BUILDNAME§.§ENVIRONMENT_TYPE§.database - volumes: - - §PROJECT_BUILDNAME§-db-persist:/usr/local/mongodb - webserver: - image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§ - env_file: - - environments/common/webserver.env - - environments/local/webserver.env - restart: "no" - ports: - - "8800:80" - networks: - db-network: - §PROJECT_BUILDNAME§-network: - links: - - mongo:database - volumes: - - §PROJECT_BUILDNAME§-storage:/home/§PROJECT_AUTHOR§/storage/§PROJECT_BUILDNAME§ - - §PROJECT_BUILDNAME§-log:/var/log/§PROJECT_AUTHOR§/ - - §DEBUG_HOST_PROJECT_FOLDER§/app/public:/var/www/§PROJECT_BUILDNAME§:ro - - §DEBUG_HOST_PROJECT_FOLDER§/app/private:/home/§PROJECT_AUTHOR§/private/§PROJECT_BUILDNAME§:ro - - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ - # worker: - # image: 662348923997.dkr.ecr.eu-west-1.amazonaws.com/§PROJECT_GROUP§/edenlandia-worker:§TAG_NAME§ - # env_file: worker.env - # restart: "no" - # networks: - # db-network: - # §PROJECT_BUILDNAME§-network: - # links: - # - mongo:database - # volumes: - # - §PROJECT_BUILDNAME§-storage:/home/asdynamics/storage/edenlandia-worker - # - edenlandia-worker-log:/var/log/asdynamics/ - # - ~/workspace-azzurro/webapps/edenlandia-worker/app/private:/home/asdynamics/private/§PROJECT_BUILDNAME§:ro - # - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ - memcached: - image: memcached:1.6.9-alpine - restart: "no" - networks: - §PROJECT_BUILDNAME§-network: - -networks: - nginx-network: - external: - name: - nginx-network - db-network: - §PROJECT_BUILDNAME§-network: - - -volumes: - §PROJECT_BUILDNAME§-storage: - §PROJECT_BUILDNAME§-log: - # edenlandia-worker-log: - §PROJECT_BUILDNAME§-db-persist: - §PROJECT_BUILDNAME§-job-comms: \ No newline at end of file diff --git a/cicd/docker-compose/local-live.yml b/cicd/docker-compose/local-live.yml index 720aecb..2e96070 100644 --- a/cicd/docker-compose/local-live.yml +++ b/cicd/docker-compose/local-live.yml @@ -1,7 +1,7 @@ version: "3" services: mongo: - image: mongo:4.4.0 + image: mongo:3 restart: "no" networks: db-network: @@ -24,7 +24,7 @@ services: - mongo:database volumes: - §PROJECT_BUILDNAME§-storage:/home/§PROJECT_AUTHOR§/storage/§PROJECT_BUILDNAME§ - - §PROJECT_BUILDNAME§-log:/var/log/§PROJECT_AUTHOR§/ + - ./webserver-logs:/var/log/§PROJECT_AUTHOR§/ - §DEBUG_HOST_PROJECT_FOLDER§/app/public:/var/www/§PROJECT_BUILDNAME§:ro - §DEBUG_HOST_PROJECT_FOLDER§/app/private:/home/§PROJECT_AUTHOR§/private/§PROJECT_BUILDNAME§:ro - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ diff --git a/cicd/environments/common/webserver.env b/cicd/environments/common/webserver.env index e491c56..d4f7a3a 100644 --- a/cicd/environments/common/webserver.env +++ b/cicd/environments/common/webserver.env @@ -1,2 +1,2 @@ -ASD_PROJECTNAME=FDN2 -ASD_BUILDNAME=fdn2 +DDNINJA_PROJECTNAME=FDN2 +DDNINJA_BUILDNAME=fdn2 diff --git a/cicd/environments/local/webserver.env b/cicd/environments/local/webserver.env index 3861489..0fae887 100644 --- a/cicd/environments/local/webserver.env +++ b/cicd/environments/local/webserver.env @@ -1,7 +1,7 @@ -ASD_ENVIRONMENT_NAME=local -ASD_IS_PRODUCTION=false +DDNINJA_ENVIRONMENT_NAME=local +DDNINJA_IS_PRODUCTION=false -ASD_MONGO_DBNAME=fdn2 -ASD_MONGO_LOCATION=database +DDNINJA_MONGO_DBNAME=fdn2 +DDNINJA_MONGO_LOCATION=database -ASD_PUBLIC_URL=http://local.fdn2.loc:8800 +DDNINJA_PUBLIC_URL=http://www.fdn2.loc:8800 diff --git a/cicd/environments/production/webserver.env b/cicd/environments/production/webserver.env new file mode 100644 index 0000000..ae45225 --- /dev/null +++ b/cicd/environments/production/webserver.env @@ -0,0 +1,9 @@ +DDNINJA_ENVIRONMENT_NAME=production +DDNINJA_IS_PRODUCTION=true + +DDNINJA_MONGO_DBNAME=fdn2 +DDNINJA_MONGO_LOCATION=database +DDNINJA_MONGO_USER=fdn2 +DDNINJA_MONGO_PASSWORD=p14n3ll1FDN2 + +DDNINJA_PUBLIC_URL=http://www.ifattidinapoli.it diff --git a/cicd/environments/test/webserver.env b/cicd/environments/test/webserver.env new file mode 100644 index 0000000..b9c6c5a --- /dev/null +++ b/cicd/environments/test/webserver.env @@ -0,0 +1,7 @@ +DDNINJA_ENVIRONMENT_NAME=test +DDNINJA_IS_PRODUCTION=false + +DDNINJA_MONGO_DBNAME=fdn2_test +DDNINJA_MONGO_LOCATION=database + +DDNINJA_PUBLIC_URL=http://test.ifattidinapoli.it diff --git a/scripts/core.sh b/scripts/core.sh index a98d862..025be53 100755 --- a/scripts/core.sh +++ b/scripts/core.sh @@ -71,6 +71,8 @@ if [[ $SELECTED_MODES -ne 1 ]]; then usage fi +./aws-login.sh + if [[ $UNIT_MODE -eq 1 ]]; then BUILDOPT+="u" UNITOPT="" diff --git a/scripts/generateComposeFolder.sh b/scripts/generateComposeFolder.sh index 62b2403..8b345db 100755 --- a/scripts/generateComposeFolder.sh +++ b/scripts/generateComposeFolder.sh @@ -87,7 +87,7 @@ if [[ $OUT_DIRECTORY == "" ]]; then usage fi -cp -r "$DIR/../cicd/environments" "$OUT_DIRECTORY/environments" +cp -rT "$DIR/../cicd/environments" "$OUT_DIRECTORY/environments" buildTemplate -f "$CFGFILE" -t "$STARTING_FILE" -o "$OUT_DIRECTORY/docker-compose.yml" --add TAG_NAME=$TAG