Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge with development #988

Merged
merged 16 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions backend/commands/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ public function actionInstances($pfonly=false)
{
try {
$dc->destroy();
} catch (\Exception $e) {

}
} catch (\Exception $e) { }
$dc->pull();
$dc->spin();
}
Expand Down Expand Up @@ -280,7 +278,7 @@ public function actionInstances($pfonly=false)
if(method_exists($e,'getErrorResponse'))
echo $e->getErrorResponse()->getMessage(),"\n";
else
echo $e->getFile(),":",$e->getLine()," ",$e->getMessage(),"\n";
echo $e->getMessage(),"\n";
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions backend/commands/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ protected function playerList(array $players)
/*
Mail Users their activation URL
*/
public function actionMail($baseURL=null, $active=false, $email=false)
public function actionMail($active=false, $email=false,$status=9)
{
// Get innactive players
if($email !== false)
{
$players=Player::find()->where(['active'=>$active, 'email'=>trim(str_replace(array("\xc2\xa0", "\r\n", "\r"), "", $email))])->all();
$players=Player::find()->where(['active'=>$active, 'status'=>$status, 'email'=>trim(str_replace(array("\xc2\xa0", "\r\n", "\r"), "", $email))])->all();
$this->stdout("Mailing user: ".trim(str_replace(array("\xc2\xa0", "\r\n", "\r"), "", $email))."\n", Console::BOLD);
}
else
{
$players=Player::find()->where(['active'=>$active])->all();
$players=Player::find()->where(['active'=>$active,'status'=>$status])->all();
$this->stdout("Mailing Registered users:\n", Console::BOLD);
}
$event_name=Sysconfig::findOne('event_name')->val;
Expand All @@ -179,6 +179,7 @@ public function actionMail($baseURL=null, $active=false, $email=false)
['user' => $player,'verifyLink'=>$activationURL]
)
->setFrom([Yii::$app->sys->mail_from => Yii::$app->sys->mail_fromName])
->setBcc([Yii::$app->sys->mail_from => Yii::$app->sys->mail_fromName])
->setTo([$player->email => $player->fullname])
->setSubject(trim(Yii::$app->sys->event_name). ' Account approved')
->send();
Expand Down
2 changes: 1 addition & 1 deletion backend/components/Pf.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function load_anchor_file($anchor, $file)
*/
public static function store($file, $contents)
{
if(empty($contents)) return false;
if(empty($contents)) return file_put_contents($file, "\n")!==false;
try
{
return file_put_contents($file, implode("\n", $contents)."\n")!==false;
Expand Down
3 changes: 2 additions & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.2.0",
"yiisoft/yii2": "2.0.47",
"docker-php/docker-php": "^2.0",
"jane-php/jane-php": "^4 <4.3",
"miloschuman/yii2-highcharts-widget": "^10.0",
"kartik-v/yii2-tabs-x": "@dev",
"stripe/stripe-php": "^10.2",
"stripe/stripe-php": "^12.0",
"sleifer/yii2-autocomplete-ajax": "dev-master",
"yiisoft/yii2-jui": "^2.0",
"cebe/markdown": "^1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Handles adding columns to table `{{%target_instance}}`.
*/
class m230826_200413_add_team_allowed_column_to_target_instance_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%target_instance}}', 'team_allowed', $this->boolean()->notNull()->defaultValue(false));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%target_instance}}', 'team_allowed');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Handles adding columns to table `{{%target_instance_audit}}`.
*/
class m230826_203504_add_team_allowed_column_to_target_instance_audit_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%target_instance_audit}}', 'team_allowed', $this->boolean()->notNull()->defaultValue(false));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%target_instance_audit}}', 'team_allowed');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use yii\db\Migration;

/**
* Handles adding columns to table `{{%server}}`.
*/
class m230826_212155_add_ssl_and_timeout_columns_to_server_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%server}}', 'ssl', $this->boolean()->notNull()->defaultValue(false));
$this->addColumn('{{%server}}', 'timeout', $this->integer()->notNull()->defaultValue(9000));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%server}}', 'ssl');
$this->dropColumn('{{%server}}', 'timeout');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use yii\db\Migration;

/**
* Class m230827_161057_update_tai_target_instance_trigger_add_team_allowed
*/
class m230827_161057_update_tai_target_instance_trigger_add_team_allowed extends Migration
{
public $DROP_SQL="DROP TRIGGER IF EXISTS {{%tai_target_instance}}";
public $CREATE_SQL="CREATE TRIGGER {{%tai_target_instance}} AFTER INSERT ON {{%target_instance}} FOR EACH ROW
thisBegin:BEGIN
IF (@TRIGGER_CHECKS = FALSE) THEN
LEAVE thisBegin;
END IF;
IF NEW.ip IS NOT NULL THEN
DO memc_set(CONCAT('target:',NEW.ip),NEW.target_id);
END IF;
INSERT DELAYED INTO {{%target_instance_audit}} (op,player_id,target_id,server_id,ip,reboot,team_allowed,ts) VALUES ('i',NEW.player_id,NEW.target_id,NEW.server_id,NEW.ip,NEW.reboot,NEW.team_allowed,NOW());
END";

public function up()
{
$this->db->createCommand($this->DROP_SQL)->execute();
$this->db->createCommand($this->CREATE_SQL)->execute();
}

public function down()
{
$this->db->createCommand($this->DROP_SQL)->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use yii\db\Migration;

/**
* Class m230827_161204_update_tau_target_instance_trigger_add_team_allowed
*/
class m230827_161204_update_tau_target_instance_trigger_add_team_allowed extends Migration
{
public $DROP_SQL="DROP TRIGGER IF EXISTS {{%tau_target_instance}}";
public $CREATE_SQL="CREATE TRIGGER {{%tau_target_instance}} AFTER UPDATE ON {{%target_instance}} FOR EACH ROW
thisBegin:BEGIN
IF (@TRIGGER_CHECKS = FALSE) THEN
LEAVE thisBegin;
END IF;
IF NEW.ip IS NOT NULL AND OLD.ip IS NULL THEN
DO memc_set(CONCAT('target:',NEW.ip),NEW.target_id);
INSERT DELAYED INTO {{%target_instance_audit}} (op,player_id,target_id,server_id,ip,reboot,team_allowed,ts) VALUES ('u',NEW.player_id,NEW.target_id,NEW.server_id,NEW.ip,NEW.reboot,NEW.team_allowed,NOW());
ELSEIF (NEW.ip IS NULL OR NEW.ip = '') and OLD.ip IS NOT NULL THEN
DO memc_delete(CONCAT('target:',OLD.ip));
INSERT DELAYED INTO {{%target_instance_audit}} (op,player_id,target_id,server_id,ip,reboot,team_allowed,ts) VALUES ('u',NEW.player_id,NEW.target_id,NEW.server_id,NEW.ip,NEW.reboot,NEW.team_allowed,NOW());
ELSEIF NEW.ip!=OLD.ip THEN
DO memc_delete(CONCAT('target:',OLD.ip));
DO memc_set(CONCAT('target:',NEW.ip),NEW.target_id);
INSERT DELAYED INTO {{%target_instance_audit}} (op,player_id,target_id,server_id,ip,reboot,team_allowed,ts) VALUES ('u',NEW.player_id,NEW.target_id,NEW.server_id,NEW.ip,NEW.reboot,NEW.team_allowed,NOW());
END IF;
END";

public function up()
{
$this->db->createCommand($this->DROP_SQL)->execute();
$this->db->createCommand($this->CREATE_SQL)->execute();
}

public function down()
{
$this->db->createCommand($this->DROP_SQL)->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use yii\db\Migration;

/**
* Class m230827_161324_update_tad_target_instance_trigger_add_team_allowed
*/
class m230827_161324_update_tad_target_instance_trigger_add_team_allowed extends Migration
{
public $DROP_SQL = "DROP TRIGGER IF EXISTS {{%tad_target_instance}}";
public $CREATE_SQL = "CREATE TRIGGER {{%tad_target_instance}} AFTER DELETE ON {{%target_instance}} FOR EACH ROW
thisBegin:BEGIN
IF (@TRIGGER_CHECKS = FALSE) THEN
LEAVE thisBegin;
END IF;
IF OLD.ip IS NOT NULL THEN
DO memc_delete(CONCAT('target:',OLD.ip));
END IF;
INSERT DELAYED INTO {{%target_instance_audit}} (op,player_id,target_id,server_id,ip,reboot,team_allowed,ts) VALUES ('d',OLD.player_id,OLD.target_id,OLD.server_id,OLD.ip,OLD.reboot,OLD.team_allowed,NOW());
END";

public function up()
{
$this->db->createCommand($this->DROP_SQL)->execute();
$this->db->createCommand($this->CREATE_SQL)->execute();
}

public function down()
{
$this->db->createCommand($this->DROP_SQL)->execute();
}
}
11 changes: 11 additions & 0 deletions backend/modules/infrastructure/models/DockerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public function __set($name, $value)
parent::__set($name,$value);
}

public function setTargetVariables($value)
{
if(is_array($value)) $this->targetVariables=$value;
$this->targetVariables=[];
}
public function setTargetVolumes($value)
{
if(is_array($value)) $this->targetVolumes=$value;
$this->targetVolumes=[];
}

public function connectAPI()
{
if($this->docker!==null) return;
Expand Down
24 changes: 24 additions & 0 deletions backend/modules/infrastructure/models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace app\modules\infrastructure\models;

use Yii;
use yii\behaviors\AttributeTypecastBehavior;

/**
* This is the model class for table "server".
Expand All @@ -13,10 +14,29 @@
* @property string|null $description
* @property string $service
* @property string $connstr
* @property boolean $ssl
* @property string $timeout
*/
class Server extends \yii\db\ActiveRecord
{
public $ipoctet;

public function behaviors()
{
return [
'typecast' => [
'class' => AttributeTypecastBehavior::class,
'attributeTypes' => [
'timeout' => AttributeTypecastBehavior::TYPE_INTEGER,
'ssl' => AttributeTypecastBehavior::TYPE_BOOLEAN,
],
'typecastAfterValidate' => false,
'typecastBeforeSave' => true,
'typecastAfterFind' => true,
],
];
}

/**
* {@inheritdoc}
*/
Expand All @@ -33,6 +53,8 @@ public function rules()
return [
[['name', 'ipoctet', 'connstr','network'], 'required'],
[['ipoctet'], 'ip'],
[['ssl'], 'boolean','defaultValue'=>false],
[['timeout'], 'integer','defaultValue'=>9000],
[['description', 'service','provider_id'], 'string'],
['service','default','value'=>'docker'],
[['name','network'], 'string', 'max' => 32],
Expand All @@ -54,6 +76,8 @@ public function attributeLabels()
'description' => Yii::t('app', 'Description'),
'service' => Yii::t('app', 'Service'),
'connstr' => Yii::t('app', 'Connstr'),
'ssl' => Yii::t('app', 'SSL'),
'timeout' => Yii::t('app', 'Timeout'),
];
}

Expand Down
5 changes: 4 additions & 1 deletion backend/modules/infrastructure/models/ServerSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ServerSearch extends Server
public function rules()
{
return [
[['id', 'ip'], 'integer'],
[['id', 'ip','timeout'], 'integer'],
[['ssl'], 'boolean'],
[['name', 'description', 'service', 'connstr','ipoctet','network','provider_id','ipoctet'], 'safe'],
];
}
Expand Down Expand Up @@ -59,6 +60,8 @@ public function search($params)
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'timeout'=>$this->timeout,
'ssl'=>$this->ssl,
]);

$query->andFilterWhere(['like', 'name', $this->name])
Expand Down
4 changes: 4 additions & 0 deletions backend/modules/infrastructure/models/TargetInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @property int|null $server_id
* @property int|null $ip
* @property int $reboot
* @property bool $team_allowed
* @property string|null $created_at
* @property string|null $updated_at
*
Expand Down Expand Up @@ -55,6 +56,7 @@ public function behaviors()
'class' => AttributeTypecastBehavior::class,
'attributeTypes' => [
'reboot' => AttributeTypecastBehavior::TYPE_INTEGER,
'team_allowed' => AttributeTypecastBehavior::TYPE_BOOLEAN,
],
'typecastAfterValidate' => false,
'typecastBeforeSave' => true,
Expand All @@ -78,6 +80,7 @@ public function rules()
[['ipoctet'], 'ip'],
['reboot','default','value'=>0],
['reboot','in','range'=>[0,1,2]],
[['team_allowed'], 'boolean',],
[['created_at', 'updated_at'], 'safe'],
[['player_id'], 'unique'],
[['player_id'], 'exist', 'skipOnError' => true, 'targetClass' => Player::class, 'targetAttribute' => ['player_id' => 'id']],
Expand All @@ -96,6 +99,7 @@ public function attributeLabels()
'server_id' => Yii::t('app', 'Server ID'),
'ip' => Yii::t('app', 'IP'),
'reboot' => Yii::t('app', 'Reboot'),
'team_allowed' => Yii::t('app', 'Team Allowed'),
'created_at' => Yii::t('app', 'Created At'),
'updated_at' => Yii::t('app', 'Updated At'),
];
Expand Down
2 changes: 2 additions & 0 deletions backend/modules/infrastructure/models/TargetInstanceAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function behaviors()
'class' => AttributeTypecastBehavior::class,
'attributeTypes' => [
'reboot' => AttributeTypecastBehavior::TYPE_INTEGER,
'team_allowed' => AttributeTypecastBehavior::TYPE_BOOLEAN,
],
'typecastAfterValidate' => false,
'typecastBeforeSave' => false,
Expand All @@ -54,6 +55,7 @@ public function rules()
return [
[['player_id', 'target_id'], 'required'],
[['player_id', 'target_id', 'server_id', 'ip', 'reboot'], 'integer'],
[['team_allowed'], 'boolean',],
[['ts'], 'safe'],
[['op'], 'string', 'max' => 1],
];
Expand Down
Loading