rafaelgzuz
(usa Ubuntu)
Enviado em 26/06/2024 - 20:46h
Pessoal, estou me aventurando em criar um formulário com HTML que a partir do JS cria um json para ser aplicado na api do mikrotik router. Estou com dificuldades em formatar oos resultados da maneira que o roteador interpreta.
CODIGO JS:
document.addEventListener('DOMContentLoaded', () => {
const userForm = document.getElementById('userForm');
const jsonOutput = document.getElementById('jsonOutput');
const users = [];
userForm.addEventListener('submit', function (event) {
event.preventDefault();
const teste = document.getElementById('teste');
const name = document.getElementById('name').value;
const country = document.getElementById('country').value;
const state = document.getElementById('state').value;
const locality = document.getElementById('locality').value;
const organization = document.getElementById('organization').value;
const unit = document.getElementById('unit').value;
const commonName = document.getElementById('common-name').value;
const subjectAltNameDNS = document.getElementById('subject-alt-name-DNS').value;
const subjectAltNameIP = document.getElementById('subject-alt-name-IP').value;
const subjectAltNameEmail = document.getElementById('subject-alt-name-email').value;
const digestAlgorithm = document.querySelector('input[name=digest-algorithm]:checked').value;
const keySize = document.querySelector('input[name=key-size]:checked').value;
let KeyUsageQ = document.querySelectorAll('input[name=key-usage]:checked');
let keyUsage = [];
KeyUsageQ.forEach((checkbox) => {
keyUsage.push(checkbox.value)
});
const daysValid = document.getElementById('days-valid').value;
const user = { name, country, state, locality, organization, unit, commonName, subjectAltNameDNS, subjectAltNameIP, subjectAltNameEmail, digestAlgorithm, keySize, keyUsage, daysValid };
users.push(user);
jsonOutput.textContent = JSON.stringify(users, null, 2);
userForm.reset();
var "days-Valid"
});
});
RESULTADO OBTIDO:
[
{
"name": "Your full name",
"country": "BR",
"state": "SP",
"locality": "SaoPaulo",
"organization": "Sousa",
"unit": "515",
"commonName": "youruser",
"subjectAltNameDNS": "",
"subjectAltNameIP": "",
"subjectAltNameEmail": "Your@email",
"digestAlgorithm": "sha256",
"keySize": "2048",
"keyUsage": [
"data-encipherment",
"10tls-server24",
"key-cert-sign",
"encipher-only"
],
"daysValid": "365"
}
]
RESULTADO ESPERADO:
[
{
"name": "Your full name",
"country": "BR",
"state": "SP",
"locality": "SaoPaulo",
"organization": "Sousa",
"unit": "515",
"common-name": "youruser",
"subject-alt-name:DNS": "",
"subject-alt-name:IP": "",
"subject-alt-name:email": "Your@email",
"digest-algorithm": "sha256",
"key-size": "2048",
"key-usage": [ "data-encipherment,10tls-server24, key-cert-sign, encipher-only" ],
"days-valid": "365"
}
]
Não sou um desenvolvedor/programador, sou um profissional da area de redes e estou me aventurando em programar.