BCDRecords.vue 43.1 KB
Newer Older
1
<template>
gj4210's avatar
gj4210 committed
2
3
4
5
  <div id="bcd-records">
    <Loading :data="[range]">
      <template v-if="range"> <!-- TODO: Fix Loading.. this shouldn't be necessary -->
        <h1 class="my-4">
6
          {{ range.name }} <small class="text-muted">Broadcastdomain
7
8
9
          <b-badge variant="success" title="Der Broadcastdomain sind sowohl IPv4- als auch IPv6-Subnetze zugeteilt."
                   pill
                   v-if="has_v4 && has_v6">Dualstack
10
11
          </b-badge>
        </small>
janis.streib's avatar
janis.streib committed
12
13
        </h1>
        <div style="margin-bottom: 1.5rem">
14
          <b-button variant="outline-primary" @click="editBCD">
janis.streib's avatar
janis.streib committed
15
16
17
18
19
20
21
22
            BCD Bearbeiten
            <font-awesome-icon :icon="['far', 'edit']"></font-awesome-icon>
          </b-button>
          <b-button style="margin-left: 15px" variant="outline-secondary" @click="$bvModal.show('evlog_bcd')">
            Eventlog
            <font-awesome-icon icon="history"></font-awesome-icon>
          </b-button>
        </div>
gj4210's avatar
gj4210 committed
23
        <b-row>
janis.streib's avatar
janis.streib committed
24
          <b-col cols="2" order="1" class="d-none d-lg-block bottom-space">
25
26
            <Loading style="top:75px" class="shadow sticky-top" :data="[loaded]">
              <b-list-group v-if="record_types" v-b-scrollspy="{offset: 250}">
janis.streib's avatar
janis.streib committed
27
28
29
30
31
                <b-list-group-item href="#overview" @click="scrollIntoView($event,0, 'overview')" class="text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[0]" :icon="['fas','chevron-left']"/>
                    </transition>
janis.streib's avatar
janis.streib committed
32
                    Broadcastdomain
janis.streib's avatar
janis.streib committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
                  </div>
                </b-list-group-item>
                <b-list-group-item href="#reserved" @click="scrollIntoView($event,1, 'reserved')"
                                   class="d-flex justify-content-between align-items-center text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[1]" :icon="['fas','chevron-left']"/>
                    </transition>
                    Reservierte Adressen
                  </div>
                  <b-badge variant="primary" pill>{{ reservedAddrCount }}</b-badge>
                </b-list-group-item>
                <b-list-group-item v-for="(record_type, index) in record_types" :key="record_type"
                                   :href="'#' + record_type + '-records'"
                                   @click="scrollIntoView($event,2+index, record_type+'-records')"
                                   class="d-flex justify-content-between align-items-center text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[2+index]" :icon="['fas','chevron-left']"/>
                    </transition>
                    {{ record_type }} Records
                  </div>
                  <b-badge variant="primary" pill>{{ records[record_type].length }}</b-badge>
                </b-list-group-item>
57
58
              </b-list-group>
            </Loading>
gj4210's avatar
gj4210 committed
59
          </b-col>
janis.streib's avatar
janis.streib committed
60
          <b-col cols="10" cols-lg="12">
gj4210's avatar
gj4210 committed
61
62
            <b-card class="shadow mb-4" no-body :id="collapse_states[0] ? 'overview' : 'not-overview'">
              <b-card-header v-b-toggle:overview-collapse class="collapse-header">
janis.streib's avatar
janis.streib committed
63
                <h5>Broadcastdomain</h5>
gj4210's avatar
gj4210 committed
64
65
66
67
68
69
70
                <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
              </b-card-header>
              <b-card-body body-class="p-0">
                <b-collapse id="overview-collapse" v-model="collapse_states[0]">
                  <b-table-simple responsive class="m-0" striped>
                    <b-tr>
                      <b-th>
janis.streib's avatar
janis.streib committed
71
                        Broadcastdomain-Name
gj4210's avatar
gj4210 committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
                      </b-th>
                      <b-td>
                        {{ range.name }}
                      </b-td>
                    </b-tr>
                    <b-tr>
                      <b-th>
                        Beschreibung
                      </b-th>
                      <b-td>
                        {{ range.description }}
                      </b-td>
                    </b-tr>
                    <b-tr>
                      <b-th>
                        Organisationseinheit
                      </b-th>
                      <b-td>
90
                        {{ ou.name }} ({{ ou.short_name }})
gj4210's avatar
gj4210 committed
91
92
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
93
94
95
                    <b-tr>
                      <b-th>Betreuer/Administratoren</b-th>
                      <b-td>
janis.streib's avatar
janis.streib committed
96
                        <template v-if="parent_ous.length > 0">
janis.streib's avatar
janis.streib committed
97
                          Durch (übergeordnete) OEs:
janis.streib's avatar
janis.streib committed
98
99
100
101
102
103
104
105
106
                          <ul>
                            <li v-for="pou in parent_ous" v-bind:key="pou.short_name">
                              <b>{{ pou.name }} ({{ pou.short_name }})</b>
                              <ul>
                                <li v-for="mgr in parent_oe2mgr[pou.short_name]" v-bind:key="mgr.mgr_login_name">
                                  <b-link :href="'mailto:'+parent_oe_mgr[mgr.mgr_login_name].email">
                                    {{ parent_oe_mgr[mgr.mgr_login_name].first_name }}
                                    {{ parent_oe_mgr[mgr.mgr_login_name].last_name }}
                                  </b-link>
107
                                  ({{ mgr.mgr_login_name }})
janis.streib's avatar
janis.streib committed
108
109
110
111
112
                                </li>
                              </ul>
                            </li>
                          </ul>
                        </template>
janis.streib's avatar
janis.streib committed
113
114
115
                        Durch Gruppenzuordnungen:
                        <ul>
                          <li v-for="grp in bcd_groups" v-bind:key="grp.group_name">
janis.streib's avatar
janis.streib committed
116
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
117
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
118
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
janis.streib's avatar
janis.streib committed
119
120
121
122
123
124
                            <ul>
                              <li v-for="mgr in group2mgrs[grp.group_name]" v-bind:key="mgr.mgr_login_name">
                                <b-link :href="'mailto:'+group_mgrs[mgr.mgr_login_name].email">
                                  {{ group_mgrs[mgr.mgr_login_name].first_name }}
                                  {{ group_mgrs[mgr.mgr_login_name].last_name }}
                                </b-link>
125
                                ({{ mgr.mgr_login_name }})
janis.streib's avatar
janis.streib committed
126
127
128
129
130
131
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
132
133
134
135
136
137
                    <b-tr>
                      <b-th>Domains</b-th>
                      <b-td>
                        Durch Gruppenzuordnungen:
                        <ul>
                          <li v-for="grp in bcd_groups" v-bind:key="grp.group_name">
janis.streib's avatar
janis.streib committed
138
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
139
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
140
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
janis.streib's avatar
janis.streib committed
141
142
                            <ul>
                              <li v-for="fqdn in fqdns2group[grp.group_name]" v-bind:key="fqdn.fqdn_value">
janis.streib's avatar
janis.streib committed
143
                                <b-link :to="'/dnsvs/fqdns/'+fqdn.fqdn_value">{{ fqdn.fqdn_value }}</b-link>
janis.streib's avatar
janis.streib committed
144
145
146
147
148
149
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
gj4210's avatar
gj4210 committed
150
151
152
153
154
155
156
157
                    <b-tr>
                      <b-th>
                        Subnetz{{ subnets.length > 1 ? 'e' : '' }}
                      </b-th>
                      <b-td>
                        <code v-for="subnet in subnets" :key="subnet.cidr">{{ subnet.cidr }}<br></code>
                      </b-td>
                    </b-tr>
158
159
160
161
162
163
164
165
166
167
168
169
                    <b-tr>
                      <b-th>
                        VLANs
                      </b-th>
                      <b-td>
                        <ul>
                          <li v-for="vlan in vlans" :key="vlan.id" :title="vlan.net_instnc">{{ vlan.name }}
                            ({{ vlan.id }})
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
170
171
172
173
                    <b-tr>
                      <b-th>NATVS-Bereich</b-th>
                      <b-td>
                        <b-link
janis.streib's avatar
janis.streib committed
174
175
                          target="_blank"
                          :href="$sysinfo.host_oper_mode.is_prod?`https://www-net.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/`:`https://www-net-${$sysinfo.host_oper_mode.mode}.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/`"
janis.streib's avatar
janis.streib committed
176
                        >{{ range.name }}
janis.streib's avatar
janis.streib committed
177
                        </b-link>
janis.streib's avatar
janis.streib committed
178
179
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
180
181
182
183
184
185
                    <b-tr>
                      <b-th>Gateways</b-th>
                      <b-td>
                        <code v-for="g in gateways" v-bind:key="g.ip_addr">{{ g.ip_addr }}<br/></code>
                      </b-td>
                    </b-tr>
gj4210's avatar
gj4210 committed
186
187
188
189
190
191
192
193
194
195
196
                  </b-table-simple>
                </b-collapse>
              </b-card-body>
            </b-card>
            <b-card class="shadow mb-4" no-body :id="collapse_states[1] ? 'reserved' : 'not-reserved'">
              <b-card-header v-b-toggle:reserved-collapse class="collapse-header">
                <h5>Reservierte Adressen</h5>
                <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
              </b-card-header>
              <b-card-body body-class="p-0">
                <b-collapse id="reserved-collapse" v-model="collapse_states[1]">
197
198
199
200
201
                  <b-pagination v-if="loaded && reserved_addrs.length > per_page" :per_page="per_page"
                                align="center" v-model="current_page['_reserved']"
                                :total-rows="reserved_addrs.length"></b-pagination>
                  <b-table :items="reserved_addrs" :fields="reserved_addrs_list_fields" :per-page="per_page"
                           :current-page="current_page['_reserved']">
janis.streib's avatar
janis.streib committed
202
                    <template v-slot:cell(value)="data">
203
204
                      <code>{{ data.item.value }}</code>
                      <b-badge v-if="data.item.is_dhcp">DHCP</b-badge>
janis.streib's avatar
janis.streib committed
205
206
                    </template>
                  </b-table>
207
208
209
                  <b-pagination v-if="loaded && reserved_addrs.length > per_page" :per_page="per_page"
                                align="center" v-model="current_page['_reserved']"
                                :total-rows="reserved_addrs.length"></b-pagination>
gj4210's avatar
gj4210 committed
210
211
212
                </b-collapse>
              </b-card-body>
            </b-card>
janis.streib's avatar
janis.streib committed
213
214
215
216
217
218
219
220
221
222
            <Loading :data="[record_types]">
              <b-card class="shadow mb-4" no-body
                      v-for="(record_type, index) in record_types" :key="record_type"
                      :id="collapse_states[2+index]?record_type+'-records':'not-'+record_type+'-records'">
                <b-card-header v-b-toggle="'records-'+record_type+'-collapse'" class="collapse-header">
                  <h5>{{ record_type }} Records</h5>
                  <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
                </b-card-header>
                <b-card-body body-class="p-0">
                  <b-collapse :id="'records-'+record_type+'-collapse'" v-model="collapse_states[2+index]">
223
                    <FilterInput v-model="filter[record_type]" class="mx-3" style="top: 0"/>
224
225
226
227
228
229
230
231
232
                    <b-pagination
                      v-if="(!(record_type in filter) || filter[record_type] === '')&& loaded && records[record_type].length > per_page"
                      :per-page="per_page"
                      align="center" v-model="current_page[record_type]"
                      :total-rows="records[record_type].length"></b-pagination>

                    <b-table-simple responsive class="table b-table" v-if="collapse_states[2+index]">
                      <b-thead>
                        <b-tr>
233
234
235
                          <b-th>
                            <!--b-checkbox :indeterminate="toggleAllIsUnkn(record_type)" v-model="toggle_all[record_type]" @input="toggleAll(record_type)"
                                        :unchecked-value="false"></b-checkbox!-->
janis.streib's avatar
janis.streib committed
236
                            <div class="text-center">
237
238
                              <span :id="record_type + '_bulk'">
                              <b-button :disabled="!canEnableBulkAction(record_type)"
janis.streib's avatar
janis.streib committed
239
240
241
                                        @click="bulkDelete(record_type)" variant="outline-danger">
                                <font-awesome-icon :icon="['far', 'trash-alt']"></font-awesome-icon>
                              </b-button>
242
                              </span>
janis.streib's avatar
janis.streib committed
243
                            </div>
244
245
                            <b-tooltip :target="record_type+'_bulk'" triggers="hover"
                                       variant="danger" placement="right">
246
                              Ausgewählte Records löschen
247
248
                            </b-tooltip>
                          </b-th>
249
250
251
252
253
254
255
256
                          <b-th style="vertical-align: middle;"
                                :aria-sort="(sort_by[record_type] == 'fqdn')?sort_dir[record_type]:'none'"
                                @click="changeSort(record_type, 'fqdn')">
                            <div>FQDN</div>
                          </b-th>
                          <b-th style="vertical-align: middle;">Weitere Info</b-th>
                          <b-th style="vertical-align: middle;"
                                :aria-sort="(sort_by[record_type] == 'fqdn_description')?sort_dir[record_type]:'none'"
dominik.rimpf's avatar
dominik.rimpf committed
257
                                @click="changeSort(record_type, 'fqdn_description')">FQDN-Beschreibung
258
259
260
261
262
                          </b-th>
                          <b-th style="vertical-align: middle;"
                                :aria-sort="(sort_by[record_type] == 'data')?sort_dir[record_type]:'none'"
                                @click="changeSort(record_type, 'data')">Record-Daten
                          </b-th>
janis.streib's avatar
janis.streib committed
263
264
265
                          <b-th style="vertical-align: middle;"
                                :aria-sort="(sort_by[record_type] == 'ttl')?sort_dir[record_type]:'none'"
                                @click="changeSort(record_type, 'ttl')">
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
                            TTL
                          </b-th>
                          <b-th>
                            <b-button block variant="outline-success"
                                      :id="'button-create-record-' +  record_type" @click="createItem(record_type)"
                                      v-if="user_possible_record_types.includes(record_type)">
                              <font-awesome-icon :icon="['fas', 'plus']"/>
                            </b-button>
                            <b-tooltip :target="'button-create-record-' +  record_type" triggers="hover"
                                       variant="success" placement="left">
                              Neuen Record anlegen
                            </b-tooltip>
                          </b-th>
                        </b-tr>
                      </b-thead>
                      <b-tbody>
                        <template
                          v-for="(item, i) in filterSortPerType(record_type)">
                          <template
                            v-if="record_type === 'A' && sort_by[record_type] == 'data'  && (!(record_type in filter) || filter[record_type] === '') && item.data in upperIfAsc(record_type) && (i-1 < 0 || filterSortPerType(record_type)[i-1].data !== item.data)">
286
287
288
289
                            <template
                              v-for="(blk,j) in reverseIfDesc(record_type, upperIfAsc(record_type)[item.data].containing_blocks)">
                              <BCDFreeAddressBlock :key="'block_upper_' + item.data + '_' + j"
                                                   :create_item_func="createItem" :block="blk"
janis.streib's avatar
janis.streib committed
290
                                                   :item="item" :index="j"></BCDFreeAddressBlock>
291
                            </template>
292
293
294
                          </template>
                          <b-tr
                            :key="item.fqdn + '_' + item.data">
295
296
297
298
                            <b-td>
                              <b-checkbox class="text-center"
                                          v-model="records_checked[record_type + '_' + item.fqdn + '_' + item.data]"></b-checkbox>
                            </b-td>
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
                            <b-td>
                              {{ item.fqdn }}
                              <b-badge variant="secondary" v-if="item.fqdn_type === 'domain'">Domain</b-badge>
                              <b-badge v-if="item.host_is_nws" variant="primary"
                                       :href="$sysinfo.host_oper_mode.is_prod?`https://www-net.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/nat_index.html`:`https://www-net-${$sysinfo.host_oper_mode.mode}.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/nat_index.html`"
                                       title="Host besitzt einen NATVS-Eintrag">NATVS
                              </b-badge>
                            </b-td>
                            <b-td>
                              <b-dropdown variant="light">
                                <template v-slot:button-content>
                                  <font-awesome-icon :icon="['fas', 'info-circle']"></font-awesome-icon>
                                </template>
                                <b-dropdown-item :to="'/dnsvs/fqdns/' + item.fqdn + '/records'">Records zu FQDN
                                </b-dropdown-item>
                                <b-dropdown-item :to="'/dnsvs/fqdns/' + item.fqdn + '/references'">Referenzen auf FQDN
                                </b-dropdown-item>
                              </b-dropdown>
                            </b-td>
                            <b-td>
                              {{ item.fqdn_description }}
                            </b-td>
                            <b-td>
322
                              <RRDataView :item="item"></RRDataView>
323
324
325
                              <b-badge href="#" @click="createItem('AAAA', '', item.fqdn)"
                                       v-if="has_v4 && has_v6 && record_type == 'A' && !(item.target_ipaddr in dhcp_ip_addrs) && !fqdnHasAAAA(item.fqdn)"
                                       variant="danger">Kein
326
327
                                AAAA-Record!
                              </b-badge>
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
                            </b-td>
                            <b-td>
                              <template v-if="item.ttl != null">{{ item.ttl }}s</template>
                              <span v-else title="Geerbt von Zone"
                                    class="text-muted">{{ item.ttl_zone_default }}s</span>
                              <span v-if="item.ttl_reset_days"
                                    class="text-danger"><br/>Reset in {{ item.ttl_reset_days }} Tagen</span>
                            </b-td>
                            <b-td>
                              <b-button-group>
                                <b-dropdown
                                  :id="'button-edit-record-' +  item.fqdn + '_' + record_type + '_' + item.data"
                                  @click="editItem(item)" split variant="outline-primary">
                                  <template #button-content>
                                    <font-awesome-icon :icon="['far', 'edit']"></font-awesome-icon>
                                  </template>
                                  <b-dropdown-item :disabled="!(item.fqdn in fqdns)"
                                                   @click="editFQDN(fqdns[item.fqdn])">FQDN Bearbeiten
                                  </b-dropdown-item>
                                </b-dropdown>
                                <b-dropdown @click="deleteItem(item, false)" split variant="outline-danger">
                                  <template #button-content>
                                    <font-awesome-icon :icon="['far', 'trash-alt']"></font-awesome-icon>
                                  </template>
                                  <b-dropdown-item @click="deleteItem(item, true)">Falls FQDN gelöscht wird: Alle den
                                    FQDN referenzierende Records
                                    mitlöschen
                                  </b-dropdown-item>
                                </b-dropdown>
                              </b-button-group>
                              <b-tooltip
                                :target="'button-edit-record-' +  item.fqdn + '_' + record_type + '_' + item.data"
                                triggers="hover"
                                variant="primary" placement="left">
                                Record bearbeiten
                              </b-tooltip>
                            </b-td>
                          </b-tr>
                          <template
                            v-if="record_type === 'A' && (!(record_type in filter) || filter[record_type] === '') && sort_by[record_type] == 'data' && (records[record_type].slice(per_page*(current_page[record_type]-1), per_page*current_page[record_type]).length - 1) == i && item.data in lowerIfAsc(record_type)">
368
369
370
371
                            <template
                              v-for="(blk,j) in reverseIfDesc(record_type, lowerIfAsc(record_type)[item.data].containing_blocks)">
                              <BCDFreeAddressBlock :key="'block_lower_' + item.data + '_' + j"
                                                   :create_item_func="createItem" :block="blk"
janis.streib's avatar
janis.streib committed
372
                                                   :item="item" :index="j"></BCDFreeAddressBlock>
373
                            </template>
374
375
376
377
378
379
                          </template>
                        </template>
                      </b-tbody>
                    </b-table-simple>
                    <b-pagination
                      v-if="(!(record_type in filter) || filter[record_type] === '')&& loaded && records[record_type].length > per_page"
janis.streib's avatar
fixup    
janis.streib committed
380
381
382
                      :per-page="per_page"
                      align="center" v-model="current_page[record_type]"
                      :total-rows="records[record_type].length"></b-pagination>
janis.streib's avatar
janis.streib committed
383
384
385
386
                  </b-collapse>
                </b-card-body>
              </b-card>
            </Loading>
gj4210's avatar
gj4210 committed
387
388
389
          </b-col>
        </b-row>
      </template>
janis.streib's avatar
janis.streib committed
390
391
392
      <DBEditor :presets="db_editor_presets" :input_reducer="create_record_reducer" modal_id="create_record"
                :object_title="object_title"
                :object_function="db_editor_function" object_fq_name="dns.record" :old_data="db_editor_old_data"
janis.streib's avatar
janis.streib committed
393
394
395
396
397
                :non_optionals_order="['fqdn', 'type', 'data', 'fqdn_description', 'target_is_singleton', 'target_is_reverse_unique']">
      </DBEditor>
      <DBEditor :presets="range" modal_id="edit_bcd"
                :object_title="object_title"
                object_function="update" object_fq_name="nd.bcd" :old_data="db_editor_old_data"
janis.streib's avatar
janis.streib committed
398
                :non_optionals_order="['description']">
janis.streib's avatar
janis.streib committed
399
      </DBEditor>
400
401
402
403
404
      <DBEditor :presets="db_editor_presets" modal_id="edit_fqdn"
                :object_title="object_title" :input_reducer="full_edit_fqdn_reducer"
                object_function="update" object_fq_name="dns.fqdn" :old_data="db_editor_old_data"
                :non_optionals_order="['value', 'description']">
      </DBEditor>
405
      <EVLogViewer v-if="range" modal_id="evlog_bcd" :title="'BCD \''+ range.name + '\''"
janis.streib's avatar
janis.streib committed
406
                   ref_obj_fq="nd.bcd" refobj_id_field="name_list" :refobj_id_value="[range.name]"></EVLogViewer>
gj4210's avatar
gj4210 committed
407
408
    </Loading>
  </div>
409
410
411
</template>

<script>
janis.streib's avatar
janis.streib committed
412
413
import RangeService from '@/api-services/dns_bcd.service'
import RecordService from '@/api-services.gen/dns.record'
gj4210's avatar
gj4210 committed
414
import Loading from '../../components/Loading'
janis.streib's avatar
janis.streib committed
415
import DBEditor from '../../components/DBEditor'
416
import BCDFreeAddressBlock from '../../components/BCDFreeAddressBlock'
417
import RRDataView from '../../components/RRDataView'
janis.streib's avatar
janis.streib committed
418
import transactionutil from '@/util/transactionutil'
419
import apiutil from '@/util/apiutil'
janis.streib's avatar
janis.streib committed
420
import EVLogViewer from '@/components/EVLogViewer'
421
import FilterInput from '@/components/FilterInput'
422
import ipaddress from '@/util/ipaddress'
423

janis.streib's avatar
janis.streib committed
424
425
export default {
  name: 'BCDRecords',
426
  components: {FilterInput, EVLogViewer, Loading, DBEditor, BCDFreeAddressBlock, RRDataView},
427
  data() {
janis.streib's avatar
janis.streib committed
428
    return {
429
430
      toggle_all: {},
      records_checked: {},
431
432
433
434
435
      sort_by: {},
      sort_dir: {},
      asc_v4_blocklist: [],
      asc_v4_blocklist_by_lower: {},
      asc_v4_blocklist_by_upper: {},
436
      filter: {},
437
      vlans: null,
438
      fqdns: null,
439
      groups: null,
janis.streib's avatar
janis.streib committed
440
      gateways: null,
janis.streib's avatar
janis.streib committed
441
442
      parent_oe2mgr: null,
      parent_oe_mgr: null,
janis.streib's avatar
janis.streib committed
443
444
      bcd_groups: null,
      group2mgrs: null,
janis.streib's avatar
janis.streib committed
445
      fqdns2group: null,
janis.streib's avatar
janis.streib committed
446
      group_mgrs: null,
447
      user_possible_record_types: [],
janis.streib's avatar
janis.streib committed
448
449
450
      loaded: null,
      per_page: 50,
      current_page: {},
451
      full_create_record_reducer: undefined,
452
      full_edit_fqdn_reducer: undefined,
janis.streib's avatar
janis.streib committed
453
454
455
      create_record_reducer: undefined,
      object_title: null,
      db_editor_function: 'create',
456
      db_editor_presets: {},
janis.streib's avatar
janis.streib committed
457
      db_editor_old_data: {},
janis.streib's avatar
janis.streib committed
458
      range: null,
gj4210's avatar
gj4210 committed
459
460
      subnets: null,
      ou: null,
janis.streib's avatar
janis.streib committed
461
      parent_ous: null,
janis.streib's avatar
janis.streib committed
462
      reserved_addrs: null,
janis.streib's avatar
janis.streib committed
463
      records: null,
464
      records_by_fqdn: {},
gj4210's avatar
gj4210 committed
465
      record_types: null,
466
      record_types_by_name: null,
janis.streib's avatar
janis.streib committed
467
      collapse_states: [true],
468
      dhcp_ip_addrs: {},
469
470
      has_v4: false,
      has_v6: false,
janis.streib's avatar
janis.streib committed
471
472
473
474
475
476
477
      reserved_addrs_list_fields: [
        {
          label: 'Adresse',
          key: 'value',
          sortable: false // TODO: Sort function
        }

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
      ],
      record_list_fields: [
        {
          label: 'FQDN',
          key: 'fqdn',
          sortable: true
        },
        {
          label: 'Weitere Info',
          key: 'info',
          sortable: false
        },
        {
          label: 'FQDN-Beschreibung',
          key: 'fqdn_description',
          sortable: true
        },
        {
          label: 'Record-Data',
          key: 'data',
          sortable: false
        },
        {
          label: 'TTL',
          key: 'ttl',
          sortable: true
        },
        {
          label: 'Aktionen',
          key: 'actions',
          sortable: false
        }
janis.streib's avatar
janis.streib committed
510
      ]
janis.streib's avatar
janis.streib committed
511
512
    }
  },
gj4210's avatar
gj4210 committed
513
  computed: {
514
    reservedAddrCount() {
gj4210's avatar
gj4210 committed
515
516
517
      let count = 0
      for (let i = 0; i < this.subnets.length; i++) {
        count += this.subnets[i].dns_addr_rsv_count
janis.streib's avatar
janis.streib committed
518
      }
gj4210's avatar
gj4210 committed
519
520
521
      return count
    }
  },
522
  created() {
gj4210's avatar
gj4210 committed
523
524
    this.fetchData()
  },
525
526
527
528
529
530
  watch: {
    $route() {
      this.range = null
      this.fetchData()
    }
  },
gj4210's avatar
gj4210 committed
531
  methods: {
532
533
534
535
536
537
538
539
    fqdnHasAAAA(fqdn) {
      for (const r of this.records_by_fqdn[fqdn]) {
        if (r.type === 'AAAA') {
          return true
        }
      }
      return false
    },
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
    bulkDelete(rec_type) {
      for (const b of this.records[rec_type]) {
        if (this.records_checked[rec_type + '_' + b.fqdn + '_' + b.data]) {
          this.deleteItem(b, false)
          this.$root.$set(this.records_checked, rec_type + '_' + b.fqdn + '_' + b.data, false)
        }
      }
    },
    canEnableBulkAction(rec_type) {
      let check_count = 0
      for (const b of this.records[rec_type]) {
        if (this.records_checked[rec_type + '_' + b.fqdn + '_' + b.data]) {
          check_count++
        }
      }
      return check_count > 0
    },
    toggleAllIsUnkn(rec_type) {
      let uncheck_count = 0
      for (const b of this.records[rec_type]) {
        if (!this.records_checked[rec_type + '_' + b.fqdn + '_' + b.data]) {
          uncheck_count++
        }
      }
      return uncheck_count > 0 && uncheck_count < (this.records[rec_type].length - 1)
    },
    toggleAll(rec_type) {
      for (const b of this.filterSortPerType(rec_type)) {
        this.$root.$set(this.records_checked, rec_type + '_' + b.fqdn + '_' + b.data, this.toggle_all[rec_type])
      }
    },
571
572
573
    reverseIfDesc(rec_type, arr) {
      return (this.sort_dir[rec_type] === 'ascending') ? arr : [...arr].reverse()
    },
574
575
576
    reverseIfAsc(rec_type, arr) {
      return (this.sort_dir[rec_type] === 'descending') ? arr : [...arr].reverse()
    },
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
    upperIfAsc(rec_type) {
      return (this.sort_dir[rec_type] === 'ascending') ? this.asc_v4_blocklist_by_upper : this.asc_v4_blocklist_by_lower
    },
    lowerIfAsc(rec_type) {
      return (this.sort_dir[rec_type] === 'ascending') ? this.asc_v4_blocklist_by_lower : this.asc_v4_blocklist_by_upper
    },
    filterFunc(item, term) {
      if (typeof term === 'string') {
        term = term.toLowerCase()
      }
      for (const v of Object.values(item)) {
        if (typeof v === 'string') {
          if (v.toLowerCase().includes(term)) {
            return true
          }
        }
      }
      return false
    },
    filterSortPerType(record_type) {
      let recs = null
      if (!(record_type in this.filter) || this.filter[record_type] === '') {
        recs = this.records[record_type].slice(this.per_page * (this.current_page[record_type] - 1), this.per_page * this.current_page[record_type])
      } else {
        recs = this.records[record_type].filter(x => this.filterFunc(x, this.filter[record_type]))
      }
      recs = recs.sort((a, b) => {
        if (record_type === 'A' && this.sort_by[record_type] === 'data') {
          return ipaddress.ip_to_int(a.data) - ipaddress.ip_to_int(b.data)
janis.streib's avatar
janis.streib committed
606
607
        } else if (this.sort_by[record_type] === 'ttl') {
          return (a.ttl || a.ttl_zone_default) - (b.ttl || b.ttl_zone_default)
608
        } else {
609
          return (a[this.sort_by[record_type]] || '').localeCompare((b[this.sort_by[record_type]] || ''))
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
        }
      })
      if (this.sort_dir[record_type] === 'descending') {
        return recs.reverse()
      }
      return recs
    },
    changeSort: function (rec_type, col) {
      if (this.sort_by[rec_type] === col) {
        if (this.sort_dir[rec_type] === 'ascending') {
          this.$root.$set(this.sort_dir, rec_type, 'descending')
        } else {
          this.$root.$set(this.sort_dir, rec_type, 'ascending')
        }
      } else {
        this.$root.$set(this.sort_by, rec_type, col)
        this.$root.$set(this.sort_dir, rec_type, 'ascending')
      }
    },
629
630
631
632
633
634
635
    deleteItem: function (item, force_del_ref_records) {
      const itc = {}
      Object.assign(itc, item)
      itc.force_del_ref_records = force_del_ref_records
      const ta = transactionutil.generateDeleteElement('dns.record', RecordService.deleteParamsList(), itc,
        item.type + '-Record auf FQDN ' + item.fqdn +
        (force_del_ref_records ? ' Falls der FQDN gelöscht wird, werden auch alle ihn referenzierenden DNS-Resource-Records automatisch gelöscht.' : ''))
janis.streib's avatar
janis.streib committed
636
637
638
639
640
641
      this.$store.commit('addTransactionElement', ta)
      this.$emit('commited', ta)
      if (!this.isMobile() && !this.$store.state.show_sidebar) {
        this.$store.state.show_sidebar = true
      }
    },
janis.streib's avatar
janis.streib committed
642
643
644
645
646
647
    editBCD: function () {
      this.db_editor_old_data = this.range
      this.db_editor_presets = this.range
      this.object_title = this.range.name
      this.$root.$emit('bv::show::modal', 'edit_bcd')
    },
janis.streib's avatar
janis.streib committed
648
649
650
651
652
    editItem: function (item) {
      this.db_editor_function = 'update'
      this.db_editor_old_data = item
      this.db_editor_presets = item
      this.object_title = item.type + '-Record auf FQDN ' + item.fqdn
653
      this.create_record_reducer = {fqdn: false}
janis.streib's avatar
janis.streib committed
654
655
      this.$root.$emit('bv::show::modal', 'create_record')
    },
656
657
658
659
660
661
662
    editFQDN: function (item) {
      this.db_editor_function = 'update'
      this.db_editor_old_data = item
      this.db_editor_presets = item
      this.object_title = 'FQDN ' + item.value
      this.$root.$emit('bv::show::modal', 'edit_fqdn')
    },
663
    createItem: function (record_type, data, fqdn) {
janis.streib's avatar
janis.streib committed
664
665
      this.db_editor_function = 'create'
      this.db_editor_old_data = {}
666
      const recobj = this.record_types_by_name[record_type] || null
667
668
      this.db_editor_presets = {
        type: record_type,
669
        data: data,
670
        fqdn: fqdn,
671
672
        target_is_singleton: recobj === null ? false : recobj.target_is_singleton_dflt,
        target_is_reverse_unique: recobj === null ? false : recobj.target_is_reverse_unique_dflt
673
      }
674
      if (record_type === 'AAAA') {
675
676
677
678
679
680
681
682
683
684
685
686
687
688
        let sub = null
        let multi = false
        this.subnets.forEach((item) => {
          if (item.type === '6') {
            if (sub !== null) {
              multi = true
            }
            sub = item
          }
        })
        if (sub !== null && !multi) {
          this.db_editor_presets.data = sub.cidr.split('/')[0]
        }
      }
janis.streib's avatar
janis.streib committed
689
      if (record_type === 'A' && (!data)) {
690
691
692
        for (const bl of this.reverseIfAsc('A', this.asc_v4_blocklist)) {
          for (const b of bl.containing_blocks) {
            if (b.type === 'free') {
janis.streib's avatar
janis.streib committed
693
              this.db_editor_presets.data = b.first
694
695
696
697
698
              break
            }
          }
        }
      }
699
      this.create_record_reducer = {type: false}
janis.streib's avatar
janis.streib committed
700
701
      this.$root.$emit('bv::show::modal', 'create_record')
    },
702
    async fetchData() {
janis.streib's avatar
janis.streib committed
703
      this.loaded = null
704
705
706
707
      const rangeResponse = await RangeService.getDetail(this.$store.state.netdb_axios_config, this.$route.params.name)
      this.range = rangeResponse.data[0][0]
      this.ou = rangeResponse.data[1][0]
      this.subnets = rangeResponse.data[2]
janis.streib's avatar
janis.streib committed
708
      this.reserved_addrs = rangeResponse.data[3]
709
      this.reserved_addrs_by_ip = apiutil.dict_by_value_of_array(this.reserved_addrs, 'value')
janis.streib's avatar
janis.streib committed
710
711
712
713
714
715
716
717
718
719
      this.bcd_groups = rangeResponse.data[4]
      this.group2mgrs = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[6], 'group_name')
      this.group_mgrs = apiutil.dict_by_value_of_array(rangeResponse.data[7], 'login_name')
      this.gateways = apiutil.dict_by_value_of_array(rangeResponse.data[11], 'ip_addr')
      this.fqdns2group = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[12], 'group_name')
      this.groups = apiutil.dict_by_value_of_array(rangeResponse.data[5], 'name')
      this.parent_ous = rangeResponse.data[13]
      this.parent_oe2mgr = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[14], 'ou_short_name')
      this.parent_oe_mgr = apiutil.dict_by_value_of_array(rangeResponse.data[15], 'login_name')
      this.vlans = rangeResponse.data[16]
720
      this.has_v4 = this.has_v6 = false
721
      for (const sub of this.subnets) {
janis.streib's avatar
janis.streib committed
722
723
        this.has_v4 = this.has_v4 || sub.type === '4'
        this.has_v6 = this.has_v6 || sub.type === '6'
724
      }
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
      const recordQuery = await RangeService.getRecords(this.$store.state.netdb_axios_config, this.$route.params.name)
      this.fqdns = apiutil.dict_by_value_of_array(recordQuery.data[1], 'value')
      this.record_types_by_name = apiutil.dict_by_value_of_array(recordQuery.data[3], 'name')
      const types = recordQuery.data[2]
      const selections = {}
      const fqdnSelections = {}
      for (const t of types) {
        selections[t.record_type] = {display_name: t.record_type}
      }
      for (const t of recordQuery.data[4]) {
        let disp_name = t.description
        disp_name += ' ['
        disp_name += t.is_nonterminal ? 'nicht-terminal' : 'terminal'
        disp_name += ']'
        fqdnSelections[t.name] = {display_name: disp_name}
      }
      this.full_edit_fqdn_reducer = {
        type: fqdnSelections
      }
      this.full_create_record_reducer = {
        type: selections
      }
      this.records = apiutil.dict_of_lists_by_value_of_array(recordQuery.data[0], 'type')
748
      this.records_by_fqdn = apiutil.dict_of_lists_by_value_of_array(recordQuery.data[0], 'fqdn')
749
      this.dhcp_ip_addrs = apiutil.dict_by_value_of_array(recordQuery.data[0], 'value')
750
751
752
753
754
755
756
757
758
759
760
761
762
      for (const t of Object.keys(this.records)) {
        this.$root.$set(this.sort_by, t, 'data')
        this.$root.$set(this.sort_dir, t, 'ascending')
      }

      // Precalculate blocklists
      if ('A' in this.records) {
        const working_arecs = this.records.A.slice()
        for (const subnet of this.subnets) {
          if (subnet.type !== '4') {
            continue
          }
          let last = ipaddress.ip_to_int(subnet.cidr.split('/')[0])
763
          const min = last
764
          const hard_maximum = ipaddress.ip_to_int(ipaddress.ip_net_get_last(subnet.cidr)) - 1
765
766
767
768
769
770
771
772
773
774
          let cur = null
          while (working_arecs.length > 0) {
            const r = working_arecs.shift()
            const cur_pre = ipaddress.ip_to_int(r.data)
            if (cur_pre > hard_maximum) {
              break
            }
            cur = cur_pre
            if (cur - last > 1) {
              const blk = {
janis.streib's avatar
janis.streib committed
775
                orphan: false,
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
                lower: ipaddress.int_to_ip(last),
                upper: ipaddress.int_to_ip(cur),
                subnet: subnet
              }
              const containing_blocks = []
              let last_chg_ip = last + 1
              let last_was_reserved = ipaddress.int_to_ip(last_chg_ip) in this.reserved_addrs_by_ip
              for (var i = 1; i < cur - last; i++) {
                if (ipaddress.int_to_ip(last + i) in this.reserved_addrs_by_ip) {
                  if (!last_was_reserved) {
                    containing_blocks.push({
                      first: ipaddress.int_to_ip(last_chg_ip),
                      type: 'free',
                      space: (last + i) - last_chg_ip
                    })
                    last_was_reserved = true
                    last_chg_ip = (last + i)
                  }
                } else {
                  if (last_was_reserved) {
                    containing_blocks.push({
                      first: ipaddress.int_to_ip(last_chg_ip),
                      type: 'reserved',
                      space: (last + i) - last_chg_ip
                    })
                    last_was_reserved = false
                    last_chg_ip = last + i
                  }
                }
              }
              if (last_was_reserved) {
                containing_blocks.push({
                  first: ipaddress.int_to_ip(last_chg_ip),
                  type: 'reserved',
                  space: cur - last_chg_ip
                })
              } else {
                containing_blocks.push({
                  first: ipaddress.int_to_ip(last_chg_ip),
                  type: 'free',
                  space: cur - last_chg_ip
                })
              }

              blk.containing_blocks = containing_blocks
              this.asc_v4_blocklist.push(blk)
            }
            last = cur
          }
          if (cur !== hard_maximum) {
janis.streib's avatar
janis.streib committed
826
827
            const orphan = cur === null
            if (orphan) {
828
829
              cur = min
            }
830
831
            // The last fucking block
            const blk = {
janis.streib's avatar
janis.streib committed
832
              orphan: orphan,
833
              lower: ipaddress.int_to_ip(cur),
janis.streib's avatar
janis.streib committed
834
835
              upper: ipaddress.int_to_ip(hard_maximum),
              subnet: subnet
836
837
838
839
            }
            const containing_blocks = []
            let last_chg_ip = cur + 1
            let last_was_reserved = ipaddress.int_to_ip(last_chg_ip) in this.reserved_addrs_by_ip
840
            for (var k = 1; k < hard_maximum - cur; k++) {
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
              if (ipaddress.int_to_ip(cur + k) in this.reserved_addrs_by_ip) {
                if (!last_was_reserved) {
                  containing_blocks.push({
                    first: ipaddress.int_to_ip(last_chg_ip),
                    type: 'free',
                    space: (cur + k) - last_chg_ip
                  })
                  last_was_reserved = true
                  last_chg_ip = (cur + k)
                }
              } else {
                if (last_was_reserved) {
                  containing_blocks.push({
                    first: ipaddress.int_to_ip(last_chg_ip),
                    type: 'reserved',
                    space: (cur + k) - last_chg_ip
                  })
                  last_was_reserved = false
                  last_chg_ip = cur + k
                }
              }
            }
            if (last_was_reserved) {
              containing_blocks.push({
                first: ipaddress.int_to_ip(last_chg_ip),
                type: 'reserved',
867
                space: hard_maximum + 1 - (last_chg_ip)
868
869
870
871
872
              })
            } else {
              containing_blocks.push({
                first: ipaddress.int_to_ip(last_chg_ip),
                type: 'free',
873
                space: hard_maximum + 1 - (last_chg_ip)
874
875
876
877
878
879
880
881
882
883
              })
            }
            blk.containing_blocks = containing_blocks
            this.asc_v4_blocklist.push(blk)
          }
        }
      }
      this.asc_v4_blocklist_by_lower = apiutil.dict_by_value_of_array(this.asc_v4_blocklist, 'lower')
      this.asc_v4_blocklist_by_upper = apiutil.dict_by_value_of_array(this.asc_v4_blocklist, 'upper')

884
885
      this.record_types = Object.keys(this.records)
      for (let i = 0; i < this.record_types.length; i++) {
janis.streib's avatar
janis.streib committed
886
        if (!(this.record_types[i] in this.current_page)) {
887
          this.$root.$set(this.current_page, this.record_types[i], 1)
janis.streib's avatar
janis.streib committed
888
        }
889
890
891
892
893
        if (this.record_types[i] in this.records) {
          continue
        }
        this.records[this.record_types[i]] = []
      }
894
      for (const inttype of types) {
895
896
897
        if (!this.user_possible_record_types.includes(inttype.record_type)) {
          this.user_possible_record_types.push(inttype.record_type)
        }
898
899
900
901
902
903
904
        if (inttype.record_type in this.records) {
          continue
        }
        this.record_types.push(inttype.record_type)
        this.records[inttype.record_type] = []
      }
      this.record_types.sort()
905
906
907
908
909
910
911
912
913
914
      const self = this
      this.record_types = this.record_types.filter(t => (function (t) {
        if (t === 'A' && !self.has_v4) {
          return false
        }
        if (t === 'AAAA' && !self.has_v6) {
          return false
        }
        return true
      })(t))
janis.streib's avatar
janis.streib committed
915
      this.loaded = true
janis.streib's avatar
janis.streib committed
916
    },
gj4210's avatar
gj4210 committed
917

918
    scrollIntoView(e, index, id) {
gj4210's avatar
gj4210 committed
919
920
921
922
923
924
925
926
927
928
929
930
      e.preventDefault()
      let target = document.getElementById(id)
      if (e.target.classList.contains('active') || e.target.parentElement.classList.contains('active')) {
        this.$set(this.collapse_states, index, false)
      } else {
        if (target) {
          const offset = window.innerWidth > 1200 ? 140 : 410
          window.scrollTo({left: window.scrollX, top: target.offsetTop + offset, behavior: 'smooth'})
        } else {
          target = document.getElementById('not-' + id)
          this.$set(this.collapse_states, index, true)
          const offset = window.innerWidth > 1200 ? 140 : 410
931
932
933
934
935
          setTimeout(() => window.scrollTo({
            left: window.scrollX,
            top: target.offsetTop + offset,
            behavior: 'smooth'
          }), 350)
janis.streib's avatar
janis.streib committed
936
937
938
        }
      }
    }
gj4210's avatar
gj4210 committed
939
  }
janis.streib's avatar
janis.streib committed
940
}
941
</script>
gj4210's avatar
gj4210 committed
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967

<style scoped>
.list-group-item.active {
  color: white !important;
}

.collapse-icon {
  position: absolute;
  top: 20px;
  right: 20px;

  transition: transform;
  transition-duration: 250ms;
}

.not-collapsed > .collapse-icon {
  transform: rotate(-180deg);
}

.bottom-space {
  padding-bottom: 200px;
}

.squish-enter-active, .squish-leave-active {
  transition: width 250ms, padding-left 250ms, padding-right 250ms;
}
968

gj4210's avatar
gj4210 committed
969
970
971
972
973
974
.squish-enter, .squish-leave-to {
  width: 0;
  padding-right: 0;
  padding-left: 0;
}

975
976
977
978
.collapse-header {
  z-index: 69;
}

gj4210's avatar
gj4210 committed
979
</style>