BCDRecords.vue 42.4 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
7
8
9
10
          {{ range.name }} <small class="text-muted">Broadcastdomain
          <b-badge variant="success" title="Der Broadcastdomain sind sowohl IPv4- alsauch IPv6-Subnetze zugeteilt." pill
                   v-if="bcd_is_dual_stack">Dualstack
          </b-badge>
        </small>
janis.streib's avatar
janis.streib committed
11
12
        </h1>
        <div style="margin-bottom: 1.5rem">
13
          <b-button variant="outline-primary" @click="editBCD">
janis.streib's avatar
janis.streib committed
14
15
16
17
18
19
20
21
            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
22
        <b-row>
janis.streib's avatar
janis.streib committed
23
          <b-col cols="2" order="1" class="d-none d-lg-block bottom-space">
24
25
            <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
26
27
28
29
30
                <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
31
                    Broadcastdomain
janis.streib's avatar
janis.streib committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
                  </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>
56
57
              </b-list-group>
            </Loading>
gj4210's avatar
gj4210 committed
58
          </b-col>
janis.streib's avatar
janis.streib committed
59
          <b-col cols="10" cols-lg="12">
gj4210's avatar
gj4210 committed
60
61
            <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
62
                <h5>Broadcastdomain</h5>
gj4210's avatar
gj4210 committed
63
64
65
66
67
68
69
                <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
70
                        Broadcastdomain-Name
gj4210's avatar
gj4210 committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
                      </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>
89
                        {{ ou.name }} ({{ ou.short_name }})
gj4210's avatar
gj4210 committed
90
91
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
92
93
94
                    <b-tr>
                      <b-th>Betreuer/Administratoren</b-th>
                      <b-td>
janis.streib's avatar
janis.streib committed
95
                        <template v-if="parent_ous.length > 0">
janis.streib's avatar
janis.streib committed
96
                          Durch (übergeordnete) OEs:
janis.streib's avatar
janis.streib committed
97
98
99
100
101
102
103
104
105
                          <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>
106
                                  ({{ mgr.mgr_login_name }})
janis.streib's avatar
janis.streib committed
107
108
109
110
111
                                </li>
                              </ul>
                            </li>
                          </ul>
                        </template>
janis.streib's avatar
janis.streib committed
112
113
114
                        Durch Gruppenzuordnungen:
                        <ul>
                          <li v-for="grp in bcd_groups" v-bind:key="grp.group_name">
janis.streib's avatar
janis.streib committed
115
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
116
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
117
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
janis.streib's avatar
janis.streib committed
118
119
120
121
122
123
                            <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>
124
                                ({{ mgr.mgr_login_name }})
janis.streib's avatar
janis.streib committed
125
126
127
128
129
130
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
131
132
133
134
135
136
                    <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
137
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
138
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
139
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
janis.streib's avatar
janis.streib committed
140
141
                            <ul>
                              <li v-for="fqdn in fqdns2group[grp.group_name]" v-bind:key="fqdn.fqdn_value">
janis.streib's avatar
janis.streib committed
142
                                <b-link :to="'/dnsvs/fqdns/'+fqdn.fqdn_value">{{ fqdn.fqdn_value }}</b-link>
janis.streib's avatar
janis.streib committed
143
144
145
146
147
148
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
gj4210's avatar
gj4210 committed
149
150
151
152
153
154
155
156
                    <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>
157
158
159
160
161
162
163
164
165
166
167
168
                    <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
169
170
171
172
                    <b-tr>
                      <b-th>NATVS-Bereich</b-th>
                      <b-td>
                        <b-link
janis.streib's avatar
janis.streib committed
173
174
                          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
175
                        >{{ range.name }}
janis.streib's avatar
janis.streib committed
176
                        </b-link>
janis.streib's avatar
janis.streib committed
177
178
                      </b-td>
                    </b-tr>
janis.streib's avatar
janis.streib committed
179
180
181
182
183
184
                    <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
185
186
187
188
189
190
191
192
193
194
195
                  </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]">
196
197
198
199
200
                  <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
201
                    <template v-slot:cell(value)="data">
202
203
                      <code>{{ data.item.value }}</code>
                      <b-badge v-if="data.item.is_dhcp">DHCP</b-badge>
janis.streib's avatar
janis.streib committed
204
205
                    </template>
                  </b-table>
206
207
208
                  <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
209
210
211
                </b-collapse>
              </b-card-body>
            </b-card>
janis.streib's avatar
janis.streib committed
212
213
214
215
216
217
218
219
220
221
            <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]">
222
                    <FilterInput v-model="filter[record_type]" class="mx-3" style="top: 0"/>
223
224
225
226
227
228
229
230
231
                    <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>
232
233
234
                          <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
235
                            <div class="text-center">
236
237
                              <span :id="record_type + '_bulk'">
                              <b-button :disabled="!canEnableBulkAction(record_type)"
janis.streib's avatar
janis.streib committed
238
239
240
                                        @click="bulkDelete(record_type)" variant="outline-danger">
                                <font-awesome-icon :icon="['far', 'trash-alt']"></font-awesome-icon>
                              </b-button>
241
                              </span>
janis.streib's avatar
janis.streib committed
242
                            </div>
243
244
                            <b-tooltip :target="record_type+'_bulk'" triggers="hover"
                                       variant="danger" placement="right">
245
                              Ausgewählte Records löschen
246
247
                            </b-tooltip>
                          </b-th>
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                          <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'"
                                @click="changeSort(record_type, 'fqdn_description')">FQDN-Beschriebung
                          </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
262
263
264
                          <b-th style="vertical-align: middle;"
                                :aria-sort="(sort_by[record_type] == 'ttl')?sort_dir[record_type]:'none'"
                                @click="changeSort(record_type, 'ttl')">
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
                            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)">
285
286
287
288
                            <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
289
                                                   :item="item" :index="j"></BCDFreeAddressBlock>
290
                            </template>
291
292
293
                          </template>
                          <b-tr
                            :key="item.fqdn + '_' + item.data">
294
295
296
297
                            <b-td>
                              <b-checkbox class="text-center"
                                          v-model="records_checked[record_type + '_' + item.fqdn + '_' + item.data]"></b-checkbox>
                            </b-td>
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
                            <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>
321
                              <RRDataView :item="item"></RRDataView>
322
323
324
                              <b-badge href="#" @click="createItem('AAAA', '', item.fqdn)" v-if="bcd_is_dual_stack && record_type == 'A' && !fqdnHasAAAA(item.fqdn)" variant="danger">Kein
                                AAAA-Record!
                              </b-badge>
325
326
327
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
                            </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)">
365
366
367
368
                            <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
369
                                                   :item="item" :index="j"></BCDFreeAddressBlock>
370
                            </template>
371
372
373
374
375
376
                          </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
377
378
379
                      :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
380
381
382
383
                  </b-collapse>
                </b-card-body>
              </b-card>
            </Loading>
gj4210's avatar
gj4210 committed
384
385
386
          </b-col>
        </b-row>
      </template>
janis.streib's avatar
janis.streib committed
387
388
389
      <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
390
391
392
393
394
                :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
395
                :non_optionals_order="['description']">
janis.streib's avatar
janis.streib committed
396
      </DBEditor>
397
398
399
400
401
      <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>
402
      <EVLogViewer v-if="range" modal_id="evlog_bcd" :title="'BCD \''+ range.name + '\''"
janis.streib's avatar
janis.streib committed
403
                   ref_obj_fq="nd.bcd" refobj_id_field="name_list" :refobj_id_value="[range.name]"></EVLogViewer>
gj4210's avatar
gj4210 committed
404
405
    </Loading>
  </div>
406
407
408
</template>

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

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

473
474
475
476
477
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
      ],
      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
505
      ]
janis.streib's avatar
janis.streib committed
506
507
    }
  },
gj4210's avatar
gj4210 committed
508
  computed: {
509
    reservedAddrCount() {
gj4210's avatar
gj4210 committed
510
511
512
      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
513
      }
gj4210's avatar
gj4210 committed
514
515
516
      return count
    }
  },
517
  created() {
gj4210's avatar
gj4210 committed
518
519
    this.fetchData()
  },
520
521
522
523
524
525
  watch: {
    $route() {
      this.range = null
      this.fetchData()
    }
  },
gj4210's avatar
gj4210 committed
526
  methods: {
527
528
529
530
531
532
533
534
    fqdnHasAAAA(fqdn) {
      for (const r of this.records_by_fqdn[fqdn]) {
        if (r.type === 'AAAA') {
          return true
        }
      }
      return false
    },
535
536
537
538
539
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
    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])
      }
    },
566
567
568
    reverseIfDesc(rec_type, arr) {
      return (this.sort_dir[rec_type] === 'ascending') ? arr : [...arr].reverse()
    },
569
570
571
    reverseIfAsc(rec_type, arr) {
      return (this.sort_dir[rec_type] === 'descending') ? arr : [...arr].reverse()
    },
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
    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
601
602
        } else if (this.sort_by[record_type] === 'ttl') {
          return (a.ttl || a.ttl_zone_default) - (b.ttl || b.ttl_zone_default)
603
        } else {
604
          return (a[this.sort_by[record_type]] || '').localeCompare((b[this.sort_by[record_type]] || ''))
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
        }
      })
      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')
      }
    },
624
625
626
627
628
629
630
    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
631
632
633
634
635
636
      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
637
638
639
640
641
642
    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
643
644
645
646
647
    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
648
      this.create_record_reducer = {fqdn: false}
janis.streib's avatar
janis.streib committed
649
650
      this.$root.$emit('bv::show::modal', 'create_record')
    },
651
652
653
654
655
656
657
    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')
    },
658
    createItem: function (record_type, data, fqdn) {
janis.streib's avatar
janis.streib committed
659
660
      this.db_editor_function = 'create'
      this.db_editor_old_data = {}
661
      const recobj = this.record_types_by_name[record_type] || null
662
663
      this.db_editor_presets = {
        type: record_type,
664
        data: data,
665
        fqdn: fqdn,
666
667
        target_is_singleton: recobj === null ? false : recobj.target_is_singleton_dflt,
        target_is_reverse_unique: recobj === null ? false : recobj.target_is_reverse_unique_dflt
668
      }
669
      if (record_type === 'AAAA') {
670
671
672
673
674
675
676
677
678
679
680
681
682
683
        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
684
      if (record_type === 'A' && (!data)) {
685
686
687
        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
688
              this.db_editor_presets.data = b.first
689
690
691
692
693
              break
            }
          }
        }
      }
694
      this.create_record_reducer = {type: false}
janis.streib's avatar
janis.streib committed
695
696
      this.$root.$emit('bv::show::modal', 'create_record')
    },
697
    async fetchData() {
janis.streib's avatar
janis.streib committed
698
      this.loaded = null
699
700
701
702
      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
703
      this.reserved_addrs = rangeResponse.data[3]
704
      this.reserved_addrs_by_ip = apiutil.dict_by_value_of_array(this.reserved_addrs, 'value')
janis.streib's avatar
janis.streib committed
705
706
707
708
709
710
711
712
713
714
      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]
715
716
717
718
719
720
721
722
723
724
      let had_v4 = false
      let had_v6 = false
      for (const sub of this.subnets) {
        if (sub.type === '4') {
          had_v4 = true
        } else {
          had_v6 = true
        }
      }
      this.bcd_is_dual_stack = had_v4 && had_v6
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
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
826
827
828
829
830
      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])
          const hard_maximum = ipaddress.ip_to_int(ipaddress.ip_net_get_last(subnet.cidr))
          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 = {
                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) {
            // The last fucking block
            const blk = {
              lower: ipaddress.int_to_ip(cur),
              upper: ipaddress.int_to_ip(hard_maximum)
            }
            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
831
            for (var k = 1; k < hard_maximum - cur; k++) {
832
833
834
835
836
837
838
839
840
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
867
868
869
870
871
872
873
874
              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',
                space: hard_maximum + 1 - last_chg_ip
              })
            } else {
              containing_blocks.push({
                first: ipaddress.int_to_ip(last_chg_ip),
                type: 'free',
                space: hard_maximum + 1 - last_chg_ip
              })
            }
            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')

875
876
      this.record_types = Object.keys(this.records)
      for (let i = 0; i < this.record_types.length; i++) {
janis.streib's avatar
janis.streib committed
877
        if (!(this.record_types[i] in this.current_page)) {
878
          this.$root.$set(this.current_page, this.record_types[i], 1)
janis.streib's avatar
janis.streib committed
879
        }
880
881
882
883
884
        if (this.record_types[i] in this.records) {
          continue
        }
        this.records[this.record_types[i]] = []
      }
885
      for (const inttype of types) {
886
887
888
        if (!this.user_possible_record_types.includes(inttype.record_type)) {
          this.user_possible_record_types.push(inttype.record_type)
        }
889
890
891
892
893
894
895
        if (inttype.record_type in this.records) {
          continue
        }
        this.record_types.push(inttype.record_type)
        this.records[inttype.record_type] = []
      }
      this.record_types.sort()
janis.streib's avatar
janis.streib committed
896
      this.loaded = true
janis.streib's avatar
janis.streib committed
897
    },
gj4210's avatar
gj4210 committed
898

899
    scrollIntoView(e, index, id) {
gj4210's avatar
gj4210 committed
900
901
902
903
904
905
906
907
908
909
910
911
      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
912
913
914
915
916
          setTimeout(() => window.scrollTo({
            left: window.scrollX,
            top: target.offsetTop + offset,
            behavior: 'smooth'
          }), 350)
janis.streib's avatar
janis.streib committed
917
918
919
        }
      }
    }
gj4210's avatar
gj4210 committed
920
  }
janis.streib's avatar
janis.streib committed
921
}
922
</script>
gj4210's avatar
gj4210 committed
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948

<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;
}
949

gj4210's avatar
gj4210 committed
950
951
952
953
954
955
.squish-enter, .squish-leave-to {
  width: 0;
  padding-right: 0;
  padding-left: 0;
}

956
957
958
959
.collapse-header {
  z-index: 69;
}

gj4210's avatar
gj4210 committed
960
</style>