|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Server module for HiPanel |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
|
7
|
|
|
* @package hipanel-module-server |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hipanel\modules\server\controllers; |
|
13
|
|
|
|
|
14
|
|
|
use hipanel\actions\Action; |
|
15
|
|
|
use hipanel\actions\IndexAction; |
|
16
|
|
|
use hipanel\actions\OrientationAction; |
|
17
|
|
|
use hipanel\actions\PrepareBulkAction; |
|
18
|
|
|
use hipanel\actions\ProxyAction; |
|
19
|
|
|
use hipanel\actions\RedirectAction; |
|
20
|
|
|
use hipanel\actions\RenderAction; |
|
21
|
|
|
use hipanel\actions\RenderJsonAction; |
|
22
|
|
|
use hipanel\actions\RequestStateAction; |
|
23
|
|
|
use hipanel\actions\SearchAction; |
|
24
|
|
|
use hipanel\actions\SmartDeleteAction; |
|
25
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
26
|
|
|
use hipanel\actions\ValidateFormAction; |
|
27
|
|
|
use hipanel\actions\ViewAction; |
|
28
|
|
|
use hipanel\base\CrudController; |
|
29
|
|
|
use hipanel\models\Ref; |
|
30
|
|
|
use hipanel\modules\finance\models\Tariff; |
|
31
|
|
|
use hipanel\modules\server\cart\ServerRenewProduct; |
|
32
|
|
|
use hipanel\modules\server\helpers\ServerHelper; |
|
33
|
|
|
use hipanel\modules\server\models\Osimage; |
|
34
|
|
|
use hipanel\modules\server\models\Server; |
|
35
|
|
|
use hipanel\modules\server\models\ServerUseSearch; |
|
36
|
|
|
use hiqdev\hiart\ErrorResponseException; |
|
37
|
|
|
use hiqdev\yii2\cart\actions\AddToCartAction; |
|
38
|
|
|
use Yii; |
|
39
|
|
|
use yii\base\Event; |
|
40
|
|
|
use yii\helpers\ArrayHelper; |
|
41
|
|
|
use yii\web\NotFoundHttpException; |
|
42
|
|
|
use yii\web\Response; |
|
43
|
|
|
|
|
44
|
|
|
class ServerController extends CrudController |
|
45
|
|
|
{ |
|
46
|
1 |
|
public function actions() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'index' => [ |
|
50
|
1 |
|
'class' => IndexAction::class, |
|
51
|
1 |
|
'findOptions' => ['with_requests' => true, 'with_discounts' => true], |
|
52
|
|
|
'on beforePerform' => function (Event $event) { |
|
53
|
|
|
/** @var \hipanel\actions\SearchAction $action */ |
|
54
|
|
|
$action = $event->sender; |
|
55
|
|
|
$dataProvider = $action->getDataProvider(); |
|
56
|
|
|
$dataProvider->query->joinWith('ips'); |
|
57
|
|
|
|
|
58
|
|
|
$dataProvider->query |
|
59
|
|
|
->andWhere(['with_ips' => 1]) |
|
60
|
|
|
->andWhere(['with_tariffs' => 1]) |
|
61
|
|
|
->andWhere(['with_switches' => 1]) |
|
62
|
|
|
->andWhere(['with_requests' => 1]) |
|
63
|
|
|
->andWhere(['with_discounts' => 1]) |
|
64
|
|
|
->select(['*']); |
|
65
|
1 |
|
}, |
|
66
|
|
|
'filterStorageMap' => [ |
|
67
|
1 |
|
'name_like' => 'server.server.name', |
|
68
|
1 |
|
'ips' => 'hosting.ip.ip_in', |
|
69
|
1 |
|
'state' => 'server.server.state', |
|
70
|
1 |
|
'client_id' => 'client.client.id', |
|
71
|
1 |
|
'seller_id' => 'client.client.seller_id', |
|
72
|
1 |
|
], |
|
73
|
1 |
|
], |
|
74
|
|
|
'search' => [ |
|
75
|
1 |
|
'class' => SearchAction::class, |
|
76
|
1 |
|
], |
|
77
|
|
|
'view' => [ |
|
78
|
1 |
|
'class' => ViewAction::class, |
|
79
|
|
|
'on beforePerform' => function (Event $event) { |
|
80
|
|
|
/** @var \hipanel\actions\SearchAction $action */ |
|
81
|
|
|
$action = $event->sender; |
|
82
|
|
|
$dataProvider = $action->getDataProvider(); |
|
83
|
|
|
$dataProvider->query->joinWith('uses'); |
|
84
|
|
|
$dataProvider->query->joinWith('ips'); |
|
85
|
|
|
|
|
86
|
|
|
// TODO: ipModule is not wise yet. Redo |
|
87
|
|
|
$dataProvider->query |
|
88
|
|
|
->andWhere(['with_requests' => 1]) |
|
89
|
|
|
->andWhere(['show_deleted' => 1]) |
|
90
|
|
|
->andWhere(['with_discounts' => 1]) |
|
91
|
|
|
->andWhere(['with_uses' => 1]) |
|
92
|
|
|
->andWhere(['with_ips' => 1]) |
|
93
|
|
|
->select(['*']); |
|
94
|
1 |
|
}, |
|
95
|
|
|
'data' => function ($action) { |
|
96
|
|
|
/** |
|
97
|
|
|
* @var Action $action |
|
98
|
|
|
* @var self $controller |
|
99
|
|
|
* @var Server $model |
|
100
|
|
|
*/ |
|
101
|
|
|
$controller = $action->controller; |
|
102
|
|
|
$model = $action->getModel(); |
|
103
|
|
|
$model->vnc = $controller->getVNCInfo($model); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$panels = $controller->getPanelTypes(); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$tariff = Yii::$app->cache->getAuthTimeCached(3600, [$model->tariff_id], function ($tariff_id) { |
|
108
|
|
|
return Tariff::find()->where([ |
|
109
|
|
|
'id' => $tariff_id, |
|
110
|
|
|
'show_final' => true, |
|
111
|
|
|
'show_deleted' => true, |
|
112
|
|
|
'with_resources' => true, |
|
113
|
|
|
])->joinWith('resources')->one(); |
|
114
|
|
|
}); |
|
115
|
|
|
|
|
116
|
|
|
$ispSupported = false; |
|
117
|
|
|
if ($tariff !== null) { |
|
118
|
|
|
foreach ($tariff->getResources() as $resource) { |
|
119
|
|
|
if ($resource->type === 'isp' && $resource->quantity > 0) { |
|
120
|
|
|
$ispSupported = true; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$osimages = $controller->getOsimages($model); |
|
|
|
|
|
|
126
|
|
|
$groupedOsimages = ServerHelper::groupOsimages($osimages, $ispSupported); |
|
127
|
|
|
|
|
128
|
|
|
if ($model->isLiveCDSupported()) { |
|
129
|
|
|
$osimageslivecd = $controller->getOsimagesLiveCd(); |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$blockReasons = $controller->getBlockReasons(); |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
return compact([ |
|
135
|
|
|
'model', |
|
136
|
|
|
'osimages', |
|
137
|
|
|
'osimageslivecd', |
|
138
|
|
|
'groupedOsimages', |
|
139
|
|
|
'panels', |
|
140
|
|
|
'blockReasons', |
|
141
|
|
|
]); |
|
142
|
1 |
|
}, |
|
143
|
1 |
|
], |
|
144
|
|
|
'requests-state' => [ |
|
145
|
1 |
|
'class' => RequestStateAction::class, |
|
146
|
1 |
|
'model' => Server::class, |
|
147
|
1 |
|
], |
|
148
|
|
|
'set-note' => [ |
|
149
|
1 |
|
'class' => SmartUpdateAction::class, |
|
150
|
1 |
|
'success' => Yii::t('hipanel:server', 'Note changed'), |
|
151
|
1 |
|
'error' => Yii::t('hipanel:server', 'Failed to change note'), |
|
152
|
1 |
|
], |
|
153
|
|
|
'set-label' => [ |
|
154
|
1 |
|
'class' => SmartUpdateAction::class, |
|
155
|
1 |
|
'success' => Yii::t('hipanel:server', 'Internal note changed'), |
|
156
|
1 |
|
'error' => Yii::t('hipanel:server', 'Failed to change internal note'), |
|
157
|
1 |
|
], |
|
158
|
|
|
'set-lock' => [ |
|
159
|
1 |
|
'class' => RenderAction::class, |
|
160
|
1 |
|
'success' => Yii::t('hipanel:server', 'Record was changed'), |
|
161
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error occurred'), |
|
162
|
|
|
'POST pjax' => [ |
|
163
|
1 |
|
'save' => true, |
|
164
|
|
|
'success' => [ |
|
165
|
1 |
|
'class' => ProxyAction::class, |
|
166
|
1 |
|
'action' => 'index', |
|
167
|
1 |
|
], |
|
168
|
1 |
|
], |
|
169
|
|
|
'POST' => [ |
|
170
|
1 |
|
'save' => true, |
|
171
|
|
|
'success' => [ |
|
172
|
1 |
|
'class' => RenderJsonAction::class, |
|
173
|
|
|
'return' => function ($action) { |
|
174
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
175
|
|
|
return $action->collection->models; |
|
176
|
1 |
|
}, |
|
177
|
1 |
|
], |
|
178
|
1 |
|
], |
|
179
|
1 |
|
], |
|
180
|
|
|
'sale' => [ |
|
181
|
1 |
|
'class' => SmartUpdateAction::class, |
|
182
|
1 |
|
'view' => '_saleModal', |
|
183
|
|
|
'POST' => [ |
|
184
|
1 |
|
'save' => true, |
|
185
|
|
|
'success' => [ |
|
186
|
1 |
|
'class' => RenderJsonAction::class, |
|
187
|
|
|
'return' => function ($action) { |
|
188
|
|
|
return ['success' => !$action->collection->hasErrors()]; |
|
189
|
1 |
|
}, |
|
190
|
1 |
|
], |
|
191
|
1 |
|
], |
|
192
|
1 |
|
], |
|
193
|
|
|
'enable-vnc' => [ |
|
194
|
1 |
|
'class' => ViewAction::class, |
|
195
|
1 |
|
'view' => '_vnc', |
|
196
|
|
|
'data' => function ($action) { |
|
197
|
|
|
$model = $action->getModel(); |
|
198
|
|
|
if ($model->canEnableVNC()) { |
|
199
|
|
|
$model->vnc = $this->getVNCInfo($model, true); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
return []; |
|
203
|
1 |
|
}, |
|
204
|
1 |
|
], |
|
205
|
|
|
'reboot' => [ |
|
206
|
1 |
|
'class' => SmartUpdateAction::class, |
|
207
|
1 |
|
'success' => Yii::t('hipanel:server', 'Reboot task has been successfully added to queue'), |
|
208
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the rebooting'), |
|
209
|
1 |
|
], |
|
210
|
|
|
'reset' => [ |
|
211
|
1 |
|
'class' => SmartUpdateAction::class, |
|
212
|
1 |
|
'success' => Yii::t('hipanel:server', 'Reset task has been successfully added to queue'), |
|
213
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the resetting'), |
|
214
|
1 |
|
], |
|
215
|
|
|
'shutdown' => [ |
|
216
|
1 |
|
'class' => SmartUpdateAction::class, |
|
217
|
1 |
|
'success' => Yii::t('hipanel:server', 'Shutdown task has been successfully added to queue'), |
|
218
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the shutting down'), |
|
219
|
1 |
|
], |
|
220
|
|
|
'power-off' => [ |
|
221
|
1 |
|
'class' => SmartUpdateAction::class, |
|
222
|
1 |
|
'success' => Yii::t('hipanel:server', 'Power off task has been successfully added to queue'), |
|
223
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the turning power off'), |
|
224
|
1 |
|
], |
|
225
|
|
|
'power-on' => [ |
|
226
|
1 |
|
'class' => SmartUpdateAction::class, |
|
227
|
1 |
|
'success' => Yii::t('hipanel:server', 'Power on task has been successfully added to queue'), |
|
228
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the turning power on'), |
|
229
|
1 |
|
], |
|
230
|
|
|
'reset-password' => [ |
|
231
|
1 |
|
'class' => SmartUpdateAction::class, |
|
232
|
1 |
|
'success' => Yii::t('hipanel:server', 'Root password reset task has been successfully added to queue'), |
|
233
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the resetting root password'), |
|
234
|
1 |
|
], |
|
235
|
|
|
'enable-block' => [ |
|
236
|
1 |
|
'class' => SmartUpdateAction::class, |
|
237
|
1 |
|
'success' => Yii::t('hipanel:server', 'Server was blocked successfully'), |
|
238
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the server blocking'), |
|
239
|
1 |
|
], |
|
240
|
|
|
'disable-block' => [ |
|
241
|
1 |
|
'class' => SmartUpdateAction::class, |
|
242
|
1 |
|
'success' => Yii::t('hipanel:server', 'Server was unblocked successfully'), |
|
243
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the server unblocking'), |
|
244
|
1 |
|
], |
|
245
|
|
|
'refuse' => [ |
|
246
|
1 |
|
'class' => SmartUpdateAction::class, |
|
247
|
1 |
|
'success' => Yii::t('hipanel:server', 'You have refused the service'), |
|
248
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the refusing the service'), |
|
249
|
1 |
|
], |
|
250
|
|
|
'enable-autorenewal' => [ |
|
251
|
1 |
|
'class' => SmartUpdateAction::class, |
|
252
|
1 |
|
'success' => Yii::t('hipanel:server', 'Server renewal enabled successfully'), |
|
253
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the renewing the service'), |
|
254
|
1 |
|
], |
|
255
|
|
|
'reinstall' => [ |
|
256
|
1 |
|
'class' => SmartUpdateAction::class, |
|
257
|
|
|
'on beforeSave' => function (Event $event) { |
|
258
|
|
|
/** @var Action $action */ |
|
259
|
|
|
$action = $event->sender; |
|
260
|
|
|
foreach ($action->collection->models as $model) { |
|
261
|
|
|
$model->osimage = Yii::$app->request->post('osimage'); |
|
262
|
|
|
$model->panel = Yii::$app->request->post('panel'); |
|
263
|
|
|
} |
|
264
|
1 |
|
}, |
|
265
|
1 |
|
'success' => Yii::t('hipanel:server', 'Server reinstalling task has been successfully added to queue'), |
|
266
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the server reinstalling'), |
|
267
|
1 |
|
], |
|
268
|
|
|
'boot-live' => [ |
|
269
|
1 |
|
'class' => SmartUpdateAction::class, |
|
270
|
|
|
'on beforeSave' => function (Event $event) { |
|
271
|
|
|
/** @var Action $action */ |
|
272
|
|
|
$action = $event->sender; |
|
273
|
|
|
foreach ($action->collection->models as $model) { |
|
274
|
|
|
$model->osimage = Yii::$app->request->post('osimage'); |
|
275
|
|
|
} |
|
276
|
1 |
|
}, |
|
277
|
1 |
|
'success' => Yii::t('hipanel:server', 'Live CD booting task has been successfully added to queue'), |
|
278
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the booting live CD'), |
|
279
|
1 |
|
], |
|
280
|
|
|
'validate-form' => [ |
|
281
|
1 |
|
'class' => ValidateFormAction::class, |
|
282
|
1 |
|
], |
|
283
|
|
|
'buy' => [ |
|
284
|
1 |
|
'class' => RedirectAction::class, |
|
285
|
1 |
|
'url' => Yii::$app->params['orgUrl'], |
|
286
|
1 |
|
], |
|
287
|
|
|
'add-to-cart-renewal' => [ |
|
288
|
1 |
|
'class' => AddToCartAction::class, |
|
289
|
1 |
|
'productClass' => ServerRenewProduct::class, |
|
290
|
1 |
|
], |
|
291
|
|
|
'delete' => [ |
|
292
|
1 |
|
'class' => SmartDeleteAction::class, |
|
293
|
1 |
|
'success' => Yii::t('hipanel:server', 'Server was deleted successfully'), |
|
294
|
1 |
|
'error' => Yii::t('hipanel:server', 'Failed to delete server'), |
|
295
|
1 |
|
], |
|
296
|
|
|
'bulk-delete-modal' => [ |
|
297
|
1 |
|
'class' => PrepareBulkAction::class, |
|
298
|
1 |
|
'scenario' => 'delete', |
|
299
|
1 |
|
'view' => '_bulkDelete', |
|
300
|
1 |
|
], |
|
301
|
|
|
'bulk-enable-block' => [ |
|
302
|
1 |
|
'class' => SmartUpdateAction::class, |
|
303
|
1 |
|
'scenario' => 'enable-block', |
|
304
|
1 |
|
'success' => Yii::t('hipanel:server', 'Servers were blocked successfully'), |
|
305
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the servers blocking'), |
|
306
|
|
|
'POST html' => [ |
|
307
|
1 |
|
'save' => true, |
|
308
|
|
|
'success' => [ |
|
309
|
1 |
|
'class' => RedirectAction::class, |
|
310
|
1 |
|
], |
|
311
|
1 |
|
], |
|
312
|
|
|
'on beforeSave' => function (Event $event) { |
|
313
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
314
|
|
|
$action = $event->sender; |
|
315
|
|
|
$type = Yii::$app->request->post('type'); |
|
316
|
|
|
$comment = Yii::$app->request->post('comment'); |
|
317
|
|
|
if (!empty($type)) { |
|
318
|
|
|
foreach ($action->collection->models as $model) { |
|
319
|
|
|
$model->setAttributes([ |
|
320
|
|
|
'type' => $type, |
|
321
|
|
|
'comment' => $comment, |
|
322
|
|
|
]); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
1 |
|
}, |
|
326
|
1 |
|
], |
|
327
|
|
|
'bulk-enable-block-modal' => [ |
|
328
|
1 |
|
'class' => PrepareBulkAction::class, |
|
329
|
1 |
|
'scenario' => 'enable-block', |
|
330
|
1 |
|
'view' => '_bulkEnableBlock', |
|
331
|
|
|
'data' => function ($action, $data) { |
|
332
|
|
|
return array_merge($data, [ |
|
333
|
|
|
'blockReasons' => $this->getBlockReasons(), |
|
334
|
|
|
]); |
|
335
|
1 |
|
}, |
|
336
|
1 |
|
], |
|
337
|
|
|
'bulk-disable-block' => [ |
|
338
|
1 |
|
'class' => SmartUpdateAction::class, |
|
339
|
1 |
|
'scenario' => 'disable-block', |
|
340
|
1 |
|
'success' => Yii::t('hipanel:server', 'Servers were unblocked successfully'), |
|
341
|
1 |
|
'error' => Yii::t('hipanel:server', 'Error during the servers unblocking'), |
|
342
|
|
|
'POST html' => [ |
|
343
|
1 |
|
'save' => true, |
|
344
|
|
|
'success' => [ |
|
345
|
1 |
|
'class' => RedirectAction::class, |
|
346
|
1 |
|
], |
|
347
|
1 |
|
], |
|
348
|
|
|
'on beforeSave' => function (Event $event) { |
|
349
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
350
|
|
|
$action = $event->sender; |
|
351
|
|
|
$comment = Yii::$app->request->post('comment'); |
|
352
|
|
|
if (!empty($type)) { |
|
|
|
|
|
|
353
|
|
|
foreach ($action->collection->models as $model) { |
|
354
|
|
|
$model->setAttribute('comment', $comment); |
|
355
|
|
|
} |
|
356
|
|
|
} |
|
357
|
1 |
|
}, |
|
358
|
1 |
|
], |
|
359
|
|
|
'bulk-disable-block-modal' => [ |
|
360
|
1 |
|
'class' => PrepareBulkAction::class, |
|
361
|
1 |
|
'scenario' => 'disable-block', |
|
362
|
1 |
|
'view' => '_bulkDisableBlock', |
|
363
|
1 |
|
], |
|
364
|
|
|
'set-orientation' => [ |
|
365
|
1 |
|
'class' => OrientationAction::class, |
|
366
|
|
|
'allowedRoutes' => [ |
|
367
|
|
|
'@server/index' |
|
368
|
1 |
|
] |
|
369
|
1 |
|
] |
|
370
|
|
|
|
|
371
|
1 |
|
]; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Gets info of VNC on the server. |
|
376
|
|
|
* |
|
377
|
|
|
* @param Server $model |
|
378
|
|
|
* @param bool $enable |
|
379
|
|
|
* @return array |
|
380
|
|
|
* @throws ErrorResponseException |
|
381
|
|
|
*/ |
|
382
|
|
|
public function getVNCInfo($model, $enable = false) |
|
383
|
|
|
{ |
|
384
|
|
|
$vnc = ['endTime' => strtotime('+8 hours', strtotime($model->statuses['serverEnableVNC']))]; |
|
|
|
|
|
|
385
|
|
|
if ($model->canEnableVnc() && $vnc['endTime'] > time() || $enable) { |
|
386
|
|
|
try { |
|
387
|
|
|
$vnc = ArrayHelper::merge($vnc, Server::perform('EnableVNC', ['id' => $model->id])); |
|
|
|
|
|
|
388
|
|
|
$vnc['enabled'] = true; |
|
389
|
|
|
} catch (ErrorResponseException $e) { |
|
390
|
|
|
if ($e->getMessage() !== 'vds_has_tasks') { // expected error, that could be skipped |
|
391
|
|
|
throw $e; |
|
392
|
|
|
} |
|
393
|
|
|
$vnc['enabled'] = false; |
|
394
|
|
|
} |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
return $vnc; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
public function actionDrawChart() |
|
401
|
|
|
{ |
|
402
|
|
|
$post = Yii::$app->request->post(); |
|
403
|
|
|
if (!in_array($post['type'], ['traffic', 'bandwidth'], true)) { |
|
404
|
|
|
throw new NotFoundHttpException(); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
$searchModel = new ServerUseSearch(); |
|
408
|
|
|
$dataProvider = $searchModel->search([]); |
|
409
|
|
|
$dataProvider->pagination = false; |
|
410
|
|
|
$dataProvider->query->options = ['scenario' => 'get-uses']; |
|
|
|
|
|
|
411
|
|
|
$dataProvider->query->andWhere($post); |
|
412
|
|
|
$models = $dataProvider->getModels(); |
|
413
|
|
|
|
|
414
|
|
|
list($labels, $data) = ServerHelper::groupUsesForChart($models); |
|
|
|
|
|
|
415
|
|
|
|
|
416
|
|
|
return $this->renderAjax('_' . $post['type'] . '_consumption', [ |
|
417
|
|
|
'labels' => $labels, |
|
418
|
|
|
'data' => $data, |
|
419
|
|
|
]); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* Gets OS images. |
|
424
|
|
|
* |
|
425
|
|
|
* @param Server $model |
|
426
|
|
|
* @throws NotFoundHttpException |
|
427
|
|
|
* @return array |
|
428
|
|
|
*/ |
|
429
|
|
|
protected function getOsimages(Server $model = null) |
|
430
|
|
|
{ |
|
431
|
|
|
if ($model !== null) { |
|
432
|
|
|
$type = $model->type; |
|
|
|
|
|
|
433
|
|
|
} else { |
|
434
|
|
|
$type = null; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
$models = ServerHelper::getOsimages($type); |
|
438
|
|
|
|
|
439
|
|
|
if ($models === null) { |
|
440
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
return $models; |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
protected function getOsimagesLiveCd() |
|
447
|
|
|
{ |
|
448
|
|
|
$models = Yii::$app->cache->getTimeCached(3600, [true], function ($livecd) { |
|
449
|
|
|
return Osimage::findAll(['livecd' => $livecd]); |
|
450
|
|
|
}); |
|
451
|
|
|
|
|
452
|
|
|
if ($models !== null) { |
|
453
|
|
|
return $models; |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
protected function getPanelTypes() |
|
460
|
|
|
{ |
|
461
|
|
|
return ServerHelper::getPanels(); |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
public function actionIsOperable($id) |
|
465
|
|
|
{ |
|
466
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
467
|
|
|
|
|
468
|
|
|
$result = ['id' => $id, 'result' => false]; |
|
469
|
|
|
|
|
470
|
|
|
if ($server = Server::find()->where(['id' => $id])->one()) { |
|
471
|
|
|
$result['result'] = $server->isOperable(); |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
return $result; |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: