commit 983c786222201e52e2802a61563fe5b45f93bb68 Author: PaolaSilvestre21 Date: Thu Dec 21 12:45:01 2023 -0300 ñ diff --git a/Codes/user.py b/Codes/user.py new file mode 100644 index 0000000..8685fec --- /dev/null +++ b/Codes/user.py @@ -0,0 +1,34 @@ +#import urllib3 +#from urllib3 import request +import requests +proxmox_host = "IP" +username = "user" +password = "passw" +realm = 'pam' + + +auth_url = f'{proxmox_host}/api2/json/access/ticket' +auth_data = {'username': username, 'password': password, 'realm': realm} +auth_response = requests.post(auth_url, data=auth_data, verify=False) + +try: + auth_response.raise_for_status() + auth_ticket = auth_response.json().get('data', {}).get('ticket') + if auth_ticket: + print(f'Autenticación exitosa. Ticket: {auth_ticket}') + else: + print('No se pudo obtener el ticket de autenticación.') +except requests.exceptions.HTTPError as err: + print(f'Error en la solicitud de autenticación. Código de estado: {auth_response.status_code}, Mensaje: {auth_response.text}') + raise err + +user_url = f'{proxmox_host}/api2/json/access/users' +#r = http.request('GET',user_url) +headers = {'CSRFPreventionToken': auth_ticket} +user_data = {'userid': 'test', 'password': '12345', 'comment': 'soft-pro'} + +response = request.post(user_url, headers=headers, data=user_data, verify=False) +if response.status_code == 200: + print(f'Usuario creado exitosamente: {response.json()}') +else: + print(f'Error al crear usuario. COdigo de estado: {response.status_code}, Mensaje: {response.text}') diff --git a/Codes/usuarios.sh b/Codes/usuarios.sh new file mode 100644 index 0000000..225ffaa --- /dev/null +++ b/Codes/usuarios.sh @@ -0,0 +1,54 @@ +#!/bin/bash + + +PROXMOX_HOST="host" +PROXMOX_USER="user" +PROXMOX_PASSWORD="password" +REALM="pam" + + +NEW_USERNAME="terraforms-$(hostname)@pve" +NEW_PASSWORD=$(openssl rand -base64 14) +NEW_ROLE="soft" + + +API_URL="https://${PROXMOX_HOST}/api2/json/access/users" + + +create_user() { + local response + response=$(curl -s -k -b "PVEAuthCookie=${PROXMOX_TICKET}" -H "CSRFPreventionToken: ${CSRF_TOKEN}" -d "username=${NEW_USERNAME}" -d "password=${NEW_PASSWORD}" -d "roleid=${NEW_ROLE}" -d "realm=${REALM}" "${API_URL}") + + if [[ "${response}" == *"create failed"* ]]; then + echo "Error: User creation failed." + echo "${response}" + exit 1 + fi +} + + +authenticate() { + local response + response=$(curl -s -k -d "username=${PROXMOX_USER}" -d "password=${PROXMOX_PASSWORD}" -d "realm=${REALM}" -X POST "https://${PROXMOX_HOST}/api2/json/access/ticket") + + if [[ "${response}" == *"authentication failed"* ]]; then + echo "Error: Authentication failed." + echo "${response}" + exit 1 + fi + + PROXMOX_TICKET=$(echo "${response}" | jq -r '.data.ticket') + CSRF_TOKEN=$(echo "${response}" | jq -r '.data.CSRFPreventionToken') +} + + +authenticate +create_user + + +echo "Usuario creado correctamente:" +echo "Username: ${NEW_USERNAME}" +echo "Password: ${NEW_PASSWORD}" + + + diff --git a/Codes/vm.sh b/Codes/vm.sh new file mode 100644 index 0000000..1808186 --- /dev/null +++ b/Codes/vm.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +PROXMOX_NODE_IP="IP" +PROXMOX_NODE_NAME=what +PROXMOX_STORAGE="local-lvm" + +API_USER="user" +API_USER_PASSWORD="password" + +CRED="username=$API_USER@pve&password=$API_USER_PASSWORD" + +curl --silent --insecure --data $CRED https://$PROXMOX_NODE_IP:8006/api2/json/access/ticket | jq --raw-output '.data.ticket' | sed 's/^/PVEAuthCookie=/' > cookie +curl --silent --insecure --data $CRED https://$PROXMOX_NODE_IP:8006/api2/json/access/ticket | jq --raw-output '.data.CSRFPreventionToken' | sed 's/^/CSRFPreventionToken:/' > token + +# container config + +CPU=1 +CPUUNITS=512 +MEMORY=512 +DISK=4G +SWAP=0 +OS_TEMPLATE="local:vztmpl/debian-12-standard_!2.2-1_amd64.tar.zst" + + +# script options + +case $1 in + + start|stop) curl --silent --insecure --cookie "$( ";echo ""; ;; + +esac + +# remove cookie and token + +rm cookie token diff --git a/Documentos/API.pdf b/Documentos/API.pdf new file mode 100644 index 0000000..0e818f7 Binary files /dev/null and b/Documentos/API.pdf differ diff --git a/Documentos/InstalacionLXC.pdf b/Documentos/InstalacionLXC.pdf new file mode 100644 index 0000000..5ee71b5 Binary files /dev/null and b/Documentos/InstalacionLXC.pdf differ diff --git a/Documentos/InstalacionVM-1.pdf b/Documentos/InstalacionVM-1.pdf new file mode 100644 index 0000000..8e56d7b Binary files /dev/null and b/Documentos/InstalacionVM-1.pdf differ diff --git a/Documentos/InterfazWeb.pdf b/Documentos/InterfazWeb.pdf new file mode 100644 index 0000000..5f80bdc Binary files /dev/null and b/Documentos/InterfazWeb.pdf differ