|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* App\Models\Port |
|
9
|
|
|
* |
|
10
|
|
|
* @property integer $port_id |
|
11
|
|
|
* @property integer $device_id |
|
12
|
|
|
* @property string $port_descr_type |
|
13
|
|
|
* @property string $port_descr_descr |
|
14
|
|
|
* @property string $port_descr_circuit |
|
15
|
|
|
* @property string $port_descr_speed |
|
16
|
|
|
* @property string $port_descr_notes |
|
17
|
|
|
* @property string $ifDescr |
|
18
|
|
|
* @property string $ifName |
|
19
|
|
|
* @property string $portName |
|
20
|
|
|
* @property integer $ifIndex |
|
21
|
|
|
* @property integer $ifSpeed |
|
22
|
|
|
* @property string $ifConnectorPresent |
|
23
|
|
|
* @property string $ifPromiscuousMode |
|
24
|
|
|
* @property integer $ifHighSpeed |
|
25
|
|
|
* @property string $ifOperStatus |
|
26
|
|
|
* @property string $ifAdminStatus |
|
27
|
|
|
* @property string $ifDuplex |
|
28
|
|
|
* @property integer $ifMtu |
|
29
|
|
|
* @property string $ifType |
|
30
|
|
|
* @property string $ifAlias |
|
31
|
|
|
* @property string $ifPhysAddress |
|
32
|
|
|
* @property string $ifHardType |
|
33
|
|
|
* @property string $ifLastChange |
|
34
|
|
|
* @property string $ifVlan |
|
35
|
|
|
* @property string $ifTrunk |
|
36
|
|
|
* @property integer $ifVrf |
|
37
|
|
|
* @property integer $counter_in |
|
38
|
|
|
* @property integer $counter_out |
|
39
|
|
|
* @property boolean $ignore |
|
40
|
|
|
* @property boolean $disabled |
|
41
|
|
|
* @property boolean $detailed |
|
42
|
|
|
* @property boolean $deleted |
|
43
|
|
|
* @property string $pagpOperationMode |
|
44
|
|
|
* @property string $pagpPortState |
|
45
|
|
|
* @property string $pagpPartnerDeviceId |
|
46
|
|
|
* @property string $pagpPartnerLearnMethod |
|
47
|
|
|
* @property integer $pagpPartnerIfIndex |
|
48
|
|
|
* @property integer $pagpPartnerGroupIfIndex |
|
49
|
|
|
* @property string $pagpPartnerDeviceName |
|
50
|
|
|
* @property string $pagpEthcOperationMode |
|
51
|
|
|
* @property string $pagpDeviceId |
|
52
|
|
|
* @property integer $pagpGroupIfIndex |
|
53
|
|
|
* @property integer $ifInUcastPkts |
|
54
|
|
|
* @property integer $ifInUcastPkts_prev |
|
55
|
|
|
* @property integer $ifInUcastPkts_delta |
|
56
|
|
|
* @property integer $ifInUcastPkts_rate |
|
57
|
|
|
* @property integer $ifOutUcastPkts |
|
58
|
|
|
* @property integer $ifOutUcastPkts_prev |
|
59
|
|
|
* @property integer $ifOutUcastPkts_delta |
|
60
|
|
|
* @property integer $ifOutUcastPkts_rate |
|
61
|
|
|
* @property integer $ifInErrors |
|
62
|
|
|
* @property integer $ifInErrors_prev |
|
63
|
|
|
* @property integer $ifInErrors_delta |
|
64
|
|
|
* @property integer $ifInErrors_rate |
|
65
|
|
|
* @property integer $ifOutErrors |
|
66
|
|
|
* @property integer $ifOutErrors_prev |
|
67
|
|
|
* @property integer $ifOutErrors_delta |
|
68
|
|
|
* @property integer $ifOutErrors_rate |
|
69
|
|
|
* @property integer $ifInOctets |
|
70
|
|
|
* @property integer $ifInOctets_prev |
|
71
|
|
|
* @property integer $ifInOctets_delta |
|
72
|
|
|
* @property integer $ifInOctets_rate |
|
73
|
|
|
* @property integer $ifOutOctets |
|
74
|
|
|
* @property integer $ifOutOctets_prev |
|
75
|
|
|
* @property integer $ifOutOctets_delta |
|
76
|
|
|
* @property integer $ifOutOctets_rate |
|
77
|
|
|
* @property integer $poll_time |
|
78
|
|
|
* @property integer $poll_prev |
|
79
|
|
|
* @property integer $poll_period |
|
80
|
|
|
* @property-read \App\Models\Device $device |
|
81
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $users |
|
82
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortId($value) |
|
83
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereDeviceId($value) |
|
84
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortDescrType($value) |
|
85
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortDescrDescr($value) |
|
86
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortDescrCircuit($value) |
|
87
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortDescrSpeed($value) |
|
88
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortDescrNotes($value) |
|
89
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfDescr($value) |
|
90
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfName($value) |
|
91
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePortName($value) |
|
92
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfIndex($value) |
|
93
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfSpeed($value) |
|
94
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfConnectorPresent($value) |
|
95
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfPromiscuousMode($value) |
|
96
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfHighSpeed($value) |
|
97
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOperStatus($value) |
|
98
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfAdminStatus($value) |
|
99
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfDuplex($value) |
|
100
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfMtu($value) |
|
101
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfType($value) |
|
102
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfAlias($value) |
|
103
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfPhysAddress($value) |
|
104
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfHardType($value) |
|
105
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfLastChange($value) |
|
106
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfVlan($value) |
|
107
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfTrunk($value) |
|
108
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfVrf($value) |
|
109
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereCounterIn($value) |
|
110
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereCounterOut($value) |
|
111
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIgnore($value) |
|
112
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereDisabled($value) |
|
113
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereDetailed($value) |
|
114
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereDeleted($value) |
|
115
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpOperationMode($value) |
|
116
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPortState($value) |
|
117
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPartnerDeviceId($value) |
|
118
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPartnerLearnMethod($value) |
|
119
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPartnerIfIndex($value) |
|
120
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPartnerGroupIfIndex($value) |
|
121
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpPartnerDeviceName($value) |
|
122
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpEthcOperationMode($value) |
|
123
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpDeviceId($value) |
|
124
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePagpGroupIfIndex($value) |
|
125
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInUcastPkts($value) |
|
126
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInUcastPktsPrev($value) |
|
127
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInUcastPktsDelta($value) |
|
128
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInUcastPktsRate($value) |
|
129
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutUcastPkts($value) |
|
130
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutUcastPktsPrev($value) |
|
131
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutUcastPktsDelta($value) |
|
132
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutUcastPktsRate($value) |
|
133
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInErrors($value) |
|
134
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInErrorsPrev($value) |
|
135
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInErrorsDelta($value) |
|
136
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInErrorsRate($value) |
|
137
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutErrors($value) |
|
138
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutErrorsPrev($value) |
|
139
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutErrorsDelta($value) |
|
140
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutErrorsRate($value) |
|
141
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInOctets($value) |
|
142
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInOctetsPrev($value) |
|
143
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInOctetsDelta($value) |
|
144
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfInOctetsRate($value) |
|
145
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutOctets($value) |
|
146
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutOctetsPrev($value) |
|
147
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutOctetsDelta($value) |
|
148
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port whereIfOutOctetsRate($value) |
|
149
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePollTime($value) |
|
150
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePollPrev($value) |
|
151
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Port wherePollPeriod($value) |
|
152
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Notification NotDeleted() |
|
153
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Notification IsUp() |
|
154
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Notification IsDown() |
|
155
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Notification IsIgnored() |
|
156
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Notification IsDisabled() |
|
157
|
|
|
* @mixin \Eloquent |
|
158
|
|
|
*/ |
|
159
|
|
|
class Port extends Model |
|
160
|
|
|
{ |
|
161
|
|
|
/** |
|
162
|
|
|
* Indicates if the model should be timestamped. |
|
163
|
|
|
* |
|
164
|
|
|
* @var bool |
|
165
|
|
|
*/ |
|
166
|
|
|
public $timestamps = false; |
|
167
|
|
|
/** |
|
168
|
|
|
* The table associated with the model. |
|
169
|
|
|
* |
|
170
|
|
|
* @var string |
|
171
|
|
|
*/ |
|
172
|
|
|
protected $table = 'ports'; |
|
173
|
|
|
/** |
|
174
|
|
|
* The primary key column name. |
|
175
|
|
|
* |
|
176
|
|
|
* @var string |
|
177
|
|
|
*/ |
|
178
|
|
|
protected $primaryKey = 'port_id'; |
|
179
|
|
|
|
|
180
|
|
|
// ---- Define Reletionships ---- |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Get the device this port belongs to. |
|
184
|
|
|
* |
|
185
|
|
|
*/ |
|
186
|
|
|
public function device() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->belongsTo('App\Models\Device', 'device_id', 'device_id'); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Returns a list of users that can access this port. |
|
193
|
|
|
*/ |
|
194
|
|
|
public function users() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->belongsToMany('App\Models\User', 'ports_perms', 'port_id', 'user_id'); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\hasMany |
|
201
|
|
|
*/ |
|
202
|
|
|
public function ipv4() |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->hasMany('App\Models\General\IPv4', 'port_id'); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\hasMany |
|
209
|
|
|
*/ |
|
210
|
|
|
public function ipv6() |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->hasMany('App\Models\General\IPv6', 'port_id'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
// ---- Accessors/Mutators ---- |
|
216
|
|
|
|
|
217
|
|
|
public function getIfPhysAddressAttribute($mac) |
|
218
|
|
|
{ |
|
219
|
|
|
if (!empty($mac)) { |
|
220
|
|
|
return preg_replace('/(..)(..)(..)(..)(..)(..)/', '\\1:\\2:\\3:\\4:\\5:\\6', $mac); |
|
221
|
|
|
} |
|
222
|
|
|
return null; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
// ---- Query scopes ---- |
|
226
|
|
|
|
|
227
|
|
|
public function scopeNotDeleted($query) |
|
228
|
|
|
{ |
|
229
|
|
|
return $query->where([ |
|
230
|
|
|
['deleted', '=', 0] |
|
231
|
|
|
]); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
View Code Duplication |
public function scopeIsUp($query) |
|
|
|
|
|
|
235
|
|
|
{ |
|
236
|
|
|
return $query->where([ |
|
237
|
|
|
['deleted', '=', 0], |
|
238
|
|
|
['ignore', '=', 0], |
|
239
|
|
|
['ifOperStatus', '=', 'up'] |
|
240
|
|
|
]); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function scopeIsDown($query) |
|
244
|
|
|
{ |
|
245
|
|
|
return $query->where([ |
|
246
|
|
|
['deleted', '=', 0], |
|
247
|
|
|
['ignore', '=', 0], |
|
248
|
|
|
['ifOperStatus', '=', 'down'], |
|
249
|
|
|
['ifAdminStatus', '=', 'up'] |
|
250
|
|
|
]); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
public function scopeIsIgnored($query) |
|
254
|
|
|
{ |
|
255
|
|
|
return $query->where([ |
|
256
|
|
|
['deleted', '=', 0], |
|
257
|
|
|
['ignore', '=', 1] |
|
258
|
|
|
]); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
View Code Duplication |
public function scopeIsDisabled($query) |
|
|
|
|
|
|
262
|
|
|
{ |
|
263
|
|
|
return $query->where([ |
|
264
|
|
|
['deleted', '=', 0], |
|
265
|
|
|
['ignore', '=', 0], |
|
266
|
|
|
['ifAdminStatus', '=', 'down'] |
|
267
|
|
|
]); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
// ---- Define Helper Functions ---- |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Returns a human readable label for this port |
|
274
|
|
|
* @return string |
|
275
|
|
|
*/ |
|
276
|
|
|
public function getLabel() { |
|
277
|
|
|
return $this->ifName ?: $this->ifDescr; |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.