-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1131 from proditis/master
Multiple improvements and fixes from dev environment
- Loading branch information
Showing
24 changed files
with
509 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* Validate email with Verifymail.io | ||
*/ | ||
namespace app\components\validators; | ||
|
||
use yii\validators\Validator; | ||
use yii\helpers\ArrayHelper; | ||
|
||
class VerifymailValidator extends Validator | ||
{ | ||
public $url = 'https://verifymail.io/api/'; | ||
public $message="Verifymail.io: Disposable email detected! Please use a different email address."; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
} | ||
|
||
public function validateValue($value) | ||
{ | ||
if(\Yii::$app->sys->signup_ValidatemailValidator===false) | ||
return; | ||
|
||
$data = http_build_query(['key'=>\Yii::$app->sys->verifymail_key]); | ||
|
||
$domain=$value; | ||
|
||
if(str_contains($value,'@')) | ||
{ | ||
$parts=explode("@",$value); | ||
if(count($parts)<2) | ||
{ | ||
return ['Verifymail.io: Failed to parse email!', [ | ||
'email' => $value, | ||
]]; | ||
} | ||
$domain=end($parts); | ||
} | ||
|
||
$req=$this->url.$domain.'?'.$data; | ||
$ch = curl_init($req); | ||
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 40); | ||
|
||
try | ||
{ | ||
$result = curl_exec($ch); | ||
curl_close($ch); | ||
$retData=json_decode($result); | ||
if($retData != null && $retData->disposable===true) | ||
{ | ||
return [$this->message, [ | ||
'email' => $value, | ||
]]; | ||
} | ||
} | ||
catch(\Exception $e) | ||
{ | ||
if(curl_errno($ch)===0) | ||
return [$this->message, ['email' => $value]]; | ||
} | ||
} | ||
|
||
public function validateAttribute($model, $attribute) | ||
{ | ||
if(\Yii::$app->sys->signup_ValidatemailValidator===false) | ||
return; | ||
$value = $model->$attribute; | ||
|
||
$data = http_build_query(['key'=>\Yii::$app->sys->verifymail_key]); | ||
|
||
if(str_contains($value,'@')) | ||
{ | ||
$parts=explode("@",$value); | ||
if(count($parts)<2) | ||
{ | ||
return ['Verifymail.io: Failed to parse email!', [ | ||
'email' => $value, | ||
]]; | ||
} | ||
$domain=end($parts); | ||
} | ||
|
||
$req=$this->url.$domain.'?'.$data; | ||
$ch = curl_init($req); | ||
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 40); | ||
|
||
try | ||
{ | ||
$result = curl_exec($ch); | ||
curl_close($ch); | ||
$retData=json_decode($result); | ||
if($retData && $retData->message) | ||
{ | ||
\Yii::error("Verifymail.io return message: ".$retData->message); | ||
} | ||
if($retData != null && $retData->disposable===true) | ||
{ | ||
return [$this->message, ['email' => $value]]; | ||
} | ||
} | ||
catch(\Exception $e) | ||
{ | ||
if(curl_errno($ch)===0) | ||
return [$this->message, ['email' => $value]]; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/migrations/m240320_235210_add_server_column_to_openvpn_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles adding columns to table `{{%openvpn}}`. | ||
*/ | ||
class m240320_235210_add_server_column_to_openvpn_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->addColumn('{{%openvpn}}', 'server', $this->string()->after('id')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropColumn('{{%openvpn}}', 'server'); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/migrations/m240320_235211_alter_openvpn_table_unique_keys.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m240320_235211_alter_openvpn_table_unique_keys | ||
*/ | ||
class m240320_235211_alter_openvpn_table_unique_keys extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->dropIndex('name', 'openvpn'); | ||
$this->dropIndex('net', 'openvpn'); | ||
$this->createIndex('server_name_net', 'openvpn', ['server','name','net'], true ); | ||
|
||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropIndex('server_name_net', 'openvpn'); | ||
$this->createIndex('name', 'openvpn', ['name'], true ); | ||
$this->createIndex('net', 'openvpn', ['name'], true ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.