1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
14
|
|
|
* copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Pterodactyl\Models; |
26
|
|
|
|
27
|
|
|
use Crypt; |
28
|
|
|
use Config; |
29
|
|
|
use Illuminate\Database\Eloquent\Model; |
30
|
|
|
|
31
|
|
|
class DatabaseHost extends Model |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* The table associated with the model. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $table = 'database_hosts'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The attributes excluded from the model's JSON form. |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $hidden = ['password']; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Fields that are mass assignable. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $fillable = [ |
53
|
|
|
'name', 'host', 'port', 'username', 'max_databases', 'node_id', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Cast values to correct type. |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
protected $casts = [ |
62
|
|
|
'id' => 'integer', |
63
|
|
|
'max_databases' => 'integer', |
64
|
|
|
'node_id' => 'integer', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sets the database connection name with the details of the host. |
69
|
|
|
* |
70
|
|
|
* @param string $connection |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function setDynamicConnection($connection = 'dynamic') |
74
|
|
|
{ |
75
|
|
|
Config::set('database.connections.' . $connection, [ |
76
|
|
|
'driver' => 'mysql', |
77
|
|
|
'host' => $this->host, |
78
|
|
|
'port' => $this->port, |
79
|
|
|
'database' => 'mysql', |
80
|
|
|
'username' => $this->username, |
81
|
|
|
'password' => Crypt::decrypt($this->password), |
82
|
|
|
'charset' => 'utf8', |
83
|
|
|
'collation' => 'utf8_unicode_ci', |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Gets the node associated with a database host. |
89
|
|
|
* |
90
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
91
|
|
|
*/ |
92
|
|
|
public function node() |
93
|
|
|
{ |
94
|
|
|
return $this->belongsTo(Node::class); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Gets the databases assocaited with this host. |
99
|
|
|
* |
100
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
101
|
|
|
*/ |
102
|
|
|
public function databases() |
103
|
|
|
{ |
104
|
|
|
return $this->hasMany(Database::class); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|