Creato nuovo sistema di task configurabile

Creato admin model
Aggiunte alcune classi di utility gui
iniziato login manager
creato session handler
This commit is contained in:
Riccardo Di Dato
2016-01-13 17:00:18 +01:00
parent 47e4a083ee
commit dbcdd1fcad
26 changed files with 743 additions and 36 deletions
+1 -1
View File
@@ -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"
}
+273
View File
@@ -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"
}
+6
View File
@@ -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;
+5 -4
View File
@@ -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);
}
@@ -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;
}
+12 -2
View File
@@ -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 {
+3
View File
@@ -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);
+63
View File
@@ -0,0 +1,63 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class AdminModel extends Model{
const ADMIN_TYPE_SUPERADMIN = 1;
const ADMIN_TYPE_BANNER = 2;
const ADMIN_TYPE_ROLEADMIN = 4;
const ADMIN_TYPE_COMMENTI = 8;
const ADMIN_TYPE_STATISTICHE = 16;
const ADMIN_TYPE_NEWSLETTER = 32;
const ADMIN_TYPE_SONDAGGI = 64;
const ADMIN_TYPE_EDITORE = 128;
const ADMIN_TYPE_EDITORE_SUPERVISOR = 256;
public static $ROLE_ADMIN_HANDLED = array(
self::ADMIN_TYPE_EDITORE => 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;
}
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class ConfigModel extends Model{
public static function getCollectionName(){
return "genconfig";
}
}
?>
+22
View File
@@ -0,0 +1,22 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class TaskModel extends Model{
public function __construct($saveableObject = null){
parent::__construct($saveableObject);
if (!$this->hasProperty("isActive")){
$this->isActive = false;
}
}
public static function getCollectionName(){
return "task";
}
}
?>
+48
View File
@@ -0,0 +1,48 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class ASDSessionHandler {
private static $isSessionStarted;
private static $sessId;
public static function getSessionId(){
self::prepareToOperate();
return self::$sessId;
}
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();
}
}
public static function getSessionValue($val){
self::prepareToOperate();
return (array_key_exists($val,$_SESSION)?$_SESSION[$val]:null);
}
public static function setSessionValue($key,$val){
self::prepareToOperate();
$_SESSION[$key] = $val;
}
public static function unsetSessionValue($key){
self::prepareToOperate();
if (array_key_exists($key,$_SESSION)){
unset($_SESSION[$key]);
}
}
public static function flush(){
self::prepareToOperate();
session_unset();
}
}
?>
+50
View File
@@ -0,0 +1,50 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class GUIHandler {
public static function generateHtmlHeaders(array $data = array()){
$conf = GlobalVariables::get("config");
$title = $conf->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 "<!DOCTYPE html>\n";
echo "<html class=\"sidebar_default no-js\" lang=\"en\">\n<head>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
echo "<title>$title</title>\n";
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
echo "<meta name=\"description\" content=\"$description\">\n";
echo "<meta name=\"author\" content=\"$author\">\n";
echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">";
echo '<link rel="shortcut icon" href="'.self::getImagesUrl().'/favicon.png">'."\n";
// foreach (self::$inclusions as $incl){
// $incl->render();
// }
echo '</head>';
}
public static function getImagesUrl(){
return "./images";
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
class PostHandler {
public static function get($name,$strict = false){
$rval = null;
if (array_key_exists($name,$_POST)){
$rval = $_POST[$name];
// if ($strict){
// $rval = $_POST[$name];
// }
// else {
// $rval = preg_replace('/[\\\]/','',$_POST[$name]);
// $rval = preg_replace('/["]/','\"',$rval);
// // echo $rval."<br/>";
// }
}
return $rval;
}
public static function getComplete($exclude = array()){
$rval = array();
if (sizeof($_POST)>0){
foreach ($_POST as $key=>$val){
$rval[$key] = self::get($key,in_array($key,$exclude));
}
}
return $rval;
}
}
?>
+5 -2
View File
@@ -5,12 +5,15 @@ Creation Date: 07/gen/2016
*/
// Include GUI Handler
// require_once(dirname(__FILE__)."/gui/GUIHandler.php");
// require_once(dirname(__FILE__)."/gui/ThumbnailGenerator.php");
require_once(dirname(__FILE__)."/CatalogManager.php");
require_once(dirname(__FILE__)."/StaticCatalogManager.php");
// require_once(dirname(__FILE__)."/LoginManager.php");
require_once(dirname(__FILE__)."/GUIHandler.php");
require_once(dirname(__FILE__)."/PostHandler.php");
require_once(dirname(__FILE__)."/ASDSessionHandler.php");
// GUIHandler::setCatalogManager(new StaticCatalogManager($catalog[$config->locale->gui]));
@@ -0,0 +1,13 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class AdminLoginManager {
}
?>
@@ -0,0 +1,11 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class UserLoginManager {
}
?>
+2
View File
@@ -29,6 +29,8 @@ require_once(dirname(__FILE__)."/system/lib.inclusion.php");
require_once(dirname(__FILE__)."/dao/lib.inclusion.php");
require_once(dirname(__FILE__)."/task/lib.inclusion.php");
// require_once(dirname(__FILE__)."/media/lib.inclusion.php");
// asdasdasd
+4 -4
View File
@@ -37,10 +37,10 @@ class SystemController {
return self::shellExec($binpath."/".$cmdName,$cmdParams,$sudo);
}
public static function executeTask($cmdName,$cmdParams="",$sudo=false){
$basePath = GlobalVariables::get("config")->paths->task;
return self::shellExec($basePath."/".$cmdName,$cmdParams,$sudo);
}
// public static function executeTask($cmdName,$cmdParams="",$sudo=false){
// $basePath = GlobalVariables::get("config")->paths->task;
// return self::shellExec($basePath."/".$cmdName,$cmdParams,$sudo);
// }
public static function mountRo($path) {
return self::executeCustomCommand("mountro",'"'.$path.'"');
+38
View File
@@ -0,0 +1,38 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
abstract class Task {
public abstract static function getName();
public abstract static function getLabel();
public abstract static function execute();
public static function isActive(){
$model = static::getModel();
return $model->isActive;
}
public static function setActive($state){
$model = static::getModel();
$model->isActive = $state;
GlobalVariables::get("dao")->save($model);
}
protected static function getModel(){
$dao = GlobalVariables::get("dao");
$model = $dao->getFirst("TaskModel",array("name"=>static::getName()));
if (is_null($model)){
$saveable = array();
$saveable["name"] = static::getName();
$model = new TaskModel($saveable);
}
return $model;
}
}
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
class TestTask extends Task {
public static function getName(){
return "test";
}
public static function getLabel(){
return "Un task di test";
}
public static function execute(){
LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_DEBUG,"Execution of task '".self::getLabel()."'");
}
}
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
require_once(dirname(__FILE__)."/Task.php");
require_once(dirname(__FILE__)."/TestTask.php");
?>
-23
View File
@@ -1,23 +0,0 @@
#!/usr/bin/php
<?php
/*
Author: Riccardo Di Dato
Creation Date: 12/gen/2016
*/
require_once(dirname(__FILE__). "/../load.php");
try {
LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_DEBUG,"Execution of task 'test' begins");
echo "OK";
LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_DEBUG,"Execution of task 'test' completed");
}catch (CoreException $ex){
$msg = "Error while executing task '$task' 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()."'";
LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,$msg);
}
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
?>
+60
View File
@@ -0,0 +1,60 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
require_once(dirname(__FILE__)."/../load.php");
GUIHandler::generateHtmlHeaders();
$action = PostHandler::get("action");
$errMsg = "";
if (!is_null($action) && strcmp($action,"login")==0){
$username = PostHandler::get("username");
$pass = PostHandler::get("pass");
if (!is_null($username) && strcmp($username,"")!=0 && !is_null($pass) && strcmp($pass,"")!=0){
$dao = GlobalVariables::get("dao");
$dao->getFirst("AdminModel",array("username"=>$username,"password"=>sha1($pass)));
if (!LoginManager::loginUser($username,$pass)){
$errMsg = "Invalid Data";
}
else {
GUIHandler::changeLocation($config->pages->index);
}
}
}
echo '<body class="white">';
GUIHandler::generateLoadingOverlay();
?>
<div id="login_page">
<div class="pageHead">
<img class="scritta" src="style/images/cbsLogo.png" />
</div>
<div class="loginArea">
<p>Login</p>
<div style="text-align:center;">
<table style="margin-left:auto;margin-right:auto;"><tr><td>
<div id="loginformdiv">
<div style="color:red;"><?php echo $errMsg;?></div>
<form action="" target="_self" method="POST">
<input type="hidden" name="action" value="login"/>
<div class="formRow">
<input type="text" name="username" value="" placeholder="Username"></input>
</div>
<div class="formRow">
<input id="pass_fld" type="password" name="pass" value="" placeholder="Password"></input>
</div>
<div class="btnDiv">
<a href="#" onClick="javascript:$('#loginformdiv form').submit();return false;" class="btn">Login</a>
</div>
</form>
</div>
</td></tr></table>
</div>
</div>
<div class="pageClosure"></div>
</div>
+9
View File
@@ -0,0 +1,9 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 13/gen/2016
*/
?>
+9
View File
@@ -8,6 +8,8 @@ require_once(dirname(__FILE__)."/load.php");
try {
// var_dump($dao->query("notizia"));
TestTask::setActive(false);
echo "<br><br>";
$models = $dao->query("NotiziaModel");
$model = reset($models);
@@ -21,6 +23,13 @@ try {
$model->immagini[] = "2.jpg";
$model->about->giorno = "boh";
if ($model->hasProperty("about")){
echo "esiste";
}
else {
echo "non esiste";
}
var_dump($model);
echo "<br><br>";