xref: /openbmc/webui-vue/src/views/SecurityAndAccess/Policies/Policies.vue (revision de23ea23d88451a2fa2774ec72053772603c23ae)
1<template>
2  <b-container fluid="xl">
3    <page-title />
4    <b-row>
5      <b-col md="8">
6        <b-row v-if="!modifySSHPolicyDisabled" class="setting-section">
7          <b-col class="d-flex align-items-center justify-content-between">
8            <dl class="mr-3 w-75">
9              <dt>{{ $t('pagePolicies.ssh') }}</dt>
10              <dd>
11                {{ $t('pagePolicies.sshDescription') }}
12              </dd>
13            </dl>
14            <b-form-checkbox
15              id="sshSwitch"
16              v-model="sshProtocolState"
17              data-test-id="policies-toggle-bmcShell"
18              switch
19              @change="changeSshProtocolState"
20            >
21              <span class="sr-only">
22                {{ $t('pagePolicies.ssh') }}
23              </span>
24              <span v-if="sshProtocolState">
25                {{ $t('global.status.enabled') }}
26              </span>
27              <span v-else>{{ $t('global.status.disabled') }}</span>
28            </b-form-checkbox>
29          </b-col>
30        </b-row>
31        <b-row class="setting-section">
32          <b-col class="d-flex align-items-center justify-content-between">
33            <dl class="mt-3 mr-3 w-75">
34              <dt>{{ $t('pagePolicies.ipmi') }}</dt>
35              <dd>
36                {{ $t('pagePolicies.ipmiDescription') }}
37              </dd>
38            </dl>
39            <b-form-checkbox
40              id="ipmiSwitch"
41              v-model="ipmiProtocolState"
42              data-test-id="polices-toggle-networkIpmi"
43              switch
44              @change="changeIpmiProtocolState"
45            >
46              <span class="sr-only">
47                {{ $t('pagePolicies.ipmi') }}
48              </span>
49              <span v-if="ipmiProtocolState">
50                {{ $t('global.status.enabled') }}
51              </span>
52              <span v-else>{{ $t('global.status.disabled') }}</span>
53            </b-form-checkbox>
54          </b-col>
55        </b-row>
56        <b-row class="setting-section">
57          <b-col class="d-flex align-items-center justify-content-between">
58            <dl class="mt-3 mr-3 w-75">
59              <dt>{{ $t('pagePolicies.vtpm') }}</dt>
60              <dd>
61                {{ $t('pagePolicies.vtpmDescription') }}
62              </dd>
63            </dl>
64            <b-form-checkbox
65              id="vtpmSwitch"
66              v-model="vtpmState"
67              data-test-id="policies-toggle-vtpm"
68              switch
69              @change="changeVtpmState"
70            >
71              <span class="sr-only">
72                {{ $t('pagePolicies.vtpm') }}
73              </span>
74              <span v-if="vtpmState">
75                {{ $t('global.status.enabled') }}
76              </span>
77              <span v-else>{{ $t('global.status.disabled') }}</span>
78            </b-form-checkbox>
79          </b-col>
80        </b-row>
81        <b-row class="setting-section">
82          <b-col class="d-flex align-items-center justify-content-between">
83            <dl class="mt-3 mr-3 w-75">
84              <dt>{{ $t('pagePolicies.rtad') }}</dt>
85              <dd>
86                {{ $t('pagePolicies.rtadDescription') }}
87              </dd>
88            </dl>
89            <b-form-checkbox
90              id="rtadSwitch"
91              v-model="rtadState"
92              data-test-id="policies-toggle-rtad"
93              switch
94              @change="changeRtadState"
95            >
96              <span class="sr-only">
97                {{ $t('pagePolicies.rtad') }}
98              </span>
99              <span v-if="rtadState">
100                {{ $t('global.status.enabled') }}
101              </span>
102              <span v-else>{{ $t('global.status.disabled') }}</span>
103            </b-form-checkbox>
104          </b-col>
105        </b-row>
106        <b-row class="setting-section">
107          <b-col class="d-flex align-items-center justify-content-between">
108            <dl class="mt-3 mr-3 w-75">
109              <dt>{{ $t('pagePolicies.webSessionTimeOut') }}</dt>
110              <dd>
111                {{ $t('pagePolicies.webSessionTimeOutDescription') }}
112              </dd>
113            </dl>
114          </b-col>
115          <b-col lg="3" class="session-timeout">
116            <b-form-select
117              id="session-timeout-options"
118              v-model="sessionTimeoutState"
119              :options="sessionTimeOutOptions"
120              @change="saveSessionTimeoutValue"
121            >
122              <template #first>
123                <b-form-select-option :value="null" disabled>
124                  {{ $t('global.form.selectAnOption') }}
125                </b-form-select-option>
126              </template>
127            </b-form-select>
128          </b-col>
129        </b-row>
130      </b-col>
131    </b-row>
132  </b-container>
133</template>
134
135<script>
136import PageTitle from '@/components/Global/PageTitle';
137
138import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
139import BVToastMixin from '@/components/Mixins/BVToastMixin';
140import { useI18n } from 'vue-i18n';
141import i18n from '@/i18n';
142
143export default {
144  name: 'Policies',
145  components: { PageTitle },
146  mixins: [LoadingBarMixin, BVToastMixin],
147  beforeRouteLeave(to, from, next) {
148    this.hideLoader();
149    next();
150  },
151  data() {
152    return {
153      $t: useI18n().t,
154      modifySSHPolicyDisabled:
155        process.env.VUE_APP_MODIFY_SSH_POLICY_DISABLED === 'true',
156      sessionTimeOutOptions: [
157        { value: 1800, text: i18n.global.t('pagePolicies.options.30minutes') },
158        { value: 3600, text: i18n.global.t('pagePolicies.options.1hour') },
159        { value: 7200, text: i18n.global.t('pagePolicies.options.2hours') },
160        { value: 14400, text: i18n.global.t('pagePolicies.options.4hours') },
161        { value: 28800, text: i18n.global.t('pagePolicies.options.8hours') },
162        { value: 86400, text: i18n.global.t('pagePolicies.options.1day') },
163      ],
164    };
165  },
166  computed: {
167    sshProtocolState: {
168      get() {
169        return this.$store.getters['policies/sshProtocolEnabled'];
170      },
171      set(newValue) {
172        return newValue;
173      },
174    },
175    ipmiProtocolState: {
176      get() {
177        return this.$store.getters['policies/ipmiProtocolEnabled'];
178      },
179      set(newValue) {
180        return newValue;
181      },
182    },
183    rtadState: {
184      get() {
185        if (this.$store.getters['policies/rtadEnabled'] === 'Enabled') {
186          return true;
187        } else {
188          return false;
189        }
190      },
191      set(newValue) {
192        return newValue;
193      },
194    },
195    vtpmState: {
196      get() {
197        if (this.$store.getters['policies/vtpmEnabled'] === 'Enabled') {
198          return true;
199        } else {
200          return false;
201        }
202      },
203      set(newValue) {
204        return newValue;
205      },
206    },
207    sessionTimeoutState: {
208      get() {
209        return this.$store.getters['policies/getSessionTimeoutValue'];
210      },
211      set(newValue) {
212        return newValue;
213      },
214    },
215  },
216  created() {
217    this.startLoader();
218    Promise.all([
219      this.$store.dispatch('policies/getBiosStatus'),
220      this.$store.dispatch('policies/getNetworkProtocolStatus'),
221      this.$store.dispatch('policies/getSessionTimeout'),
222    ]).finally(() => this.endLoader());
223  },
224  methods: {
225    changeIpmiProtocolState(state) {
226      this.$store
227        .dispatch('policies/saveIpmiProtocolState', state)
228        .then((message) => this.successToast(message))
229        .catch(({ message }) => this.errorToast(message));
230    },
231    changeSshProtocolState(state) {
232      this.$store
233        .dispatch('policies/saveSshProtocolState', state)
234        .then((message) => this.successToast(message))
235        .catch(({ message }) => this.errorToast(message));
236    },
237    changeRtadState(state) {
238      this.$store
239        .dispatch('policies/saveRtadState', state ? 'Enabled' : 'Disabled')
240        .then((message) => this.successToast(message))
241        .catch(({ message }) => this.errorToast(message));
242    },
243    changeVtpmState(state) {
244      this.$store
245        .dispatch('policies/saveVtpmState', state ? 'Enabled' : 'Disabled')
246        .then((message) => this.successToast(message))
247        .catch(({ message }) => this.errorToast(message));
248    },
249    saveSessionTimeoutValue(sessionTimeoutState) {
250      this.$store
251        .dispatch('policies/saveSessionTimeoutValue', sessionTimeoutState)
252        .then((message) => this.successToast(message))
253        .catch(({ message }) => this.errorToast(message));
254    },
255  },
256};
257</script>
258
259<style lang="scss" scoped>
260@import '@/assets/styles/bmc/helpers/_index.scss';
261@import '@/assets/styles/bootstrap/_helpers.scss';
262
263.setting-section {
264  border-bottom: 1px solid gray('300');
265}
266.session-timeout {
267  align-self: center;
268}
269</style>
270