source: portal_2019/php/sign.php @ 9eb89a1

dev
Last change on this file since 9eb89a1 was 9eb89a1, checked in by Argenis Osorio <argenisosorio580@…>, 7 months ago

Agregada consulta del valor upload_max_filesize para restringir el tamaño máximo del archivo desde el formulario

  • Property mode set to 100755
File size: 5.4 KB
Line 
1<!DOCTYPE html>
2<html lang="es">
3<head>
4  <?php require_once "./url.php" ?>
5
6  <!-- Metadata & Essential styles and scripts -->
7  <?php require_once "./headEssential.php" ?>
8  <?php require_once "./gen_keys.php"; ?>
9
10</head>
11<body>
12
13  <?php
14    // Consultar el valor de upload_max_filesize o el tamaño máximo permitido
15    // para un archivo que se envía al servidor.
16    $maxFileSize = ini_get('upload_max_filesize');
17  ?>
18
19  <!-- Header -->
20  <?php require_once "./header.php" ?>
21
22  <!-- Navbar -->
23  <?php require_once "./navbar.php" ?>
24
25  <!-- Main -->
26  <main class="container">
27    <div id="operation">
28      <ul id="tabs-operation" class="nav nav-tabs mt-6" data-tabs="tabs">
29        <li class="nav-item d-none">
30          <a class="nav-link" href="<?php returnURL(); ?>">Firmar con token</a>
31        </li>
32        <li>
33          <a class="nav-link active" href="<?php returnURL(); ?>/php/sign.php">Firmar con .p12</a>
34        </li>
35        <li>
36          <a class="nav-link" href="<?php returnURL(); ?>/">Verificar</a>
37        </li>
38      </ul>
39
40      <div id="operation-tab-content" class="tab-content py-4">
41        <input id="pubkey" type="hidden" value=" <?php echo $_SESSION['public_key_pem'] ?>">
42        <section class="container-fluid">
43          <div class="row">
44            <div class="col-12 px-0">
45              <h2 class="text-center py-3 font-weight-bold text-dark">
46                Firmar Electrónicamente <span class="text-primary">PKCS12</span>
47              </h2>
48            </div>
49          </div>
50
51          <div class="row">
52            <div class="col-10 offset-1 col-md-8 offset-md-2 pt-4">
53              <form
54                id="form-sign"
55                action="./run_script.php"
56                method="POST"
57                enctype="multipart/form-data"
58              >
59
60                <div class="input-group pb-3">
61                  <div class="custom-file">
62                    <input
63                      id="pdf"
64                      class="custom-file-input"
65                      type="file"
66                      name="pdf"
67                      accept=".pdf"
68                      required
69                      tabindex="1"
70                      onchange="checkFileSize(this)"
71                    />
72                    <label class="custom-file-label" for="pdf">
73                      Seleccionar PDF (Tamaño máximo <?php echo $maxFileSize ?>)
74                    </label>
75                  </div>
76                </div>
77
78                <div class="input-group pb-3">
79                  <div class="custom-file">
80                    <input
81                      id="pkcs12"
82                      class="custom-file-input"
83                      type="file"
84                      name="pkcs12"
85                      accept=".p12"
86                      required
87                      tabindex="2"
88                    />
89                    <label class="custom-file-label" for="pkcs12">
90                      Seleccionar certificado PKCS12
91                    </label>
92                  </div>
93                </div>
94
95                <div class="form-group">
96                  <input
97                    id="phasepass"
98                    class="form-control"
99                    type="password"
100                    aria-describedby="passHelp"
101                    required tabindex="3"
102                    placeholder="Contraseña del certificado"
103                  />
104                  <small id="passHelp" class="form-text text-muted">
105                    Esta contraseña no será guardada en el servidor.
106                  </small>
107                  <input id="password" name="password" type="hidden" />
108                </div>
109
110                <div class="form-group text-center">
111                  <input
112                    id="sign-button"
113                    class="btn btn-primary btn-block"
114                    name="submit"
115                    type="submit"
116                    value="Firmar"
117                    tabindex="4"
118                  />
119                </div>
120
121              </form>
122            </div>
123          </div>
124
125        </section>
126      </div>
127    </div>
128  </main>
129
130  <!-- Footer -->
131  <?php require_once "./footer.php" ?>
132
133  <script src="../js/jsencrypt.min.js"></script>
134  <script src="../js/validate.js"></script>
135  <script>
136    (function() {
137    /**
138     * Función para encriptar la frase de paso
139     */
140      document.getElementById('phasepass').addEventListener('change', function() {
141        var encrypt = new JSEncrypt();
142        encrypt.setPublicKey(document.getElementById("pubkey").value);
143        document.getElementById("password").value = encrypt.encrypt(this.value);
144      });
145    })();
146
147    /**
148     * Función para verificar el tamaño del archivo seleccionado y mostrar una
149     * alerta si es demasiado grande en comparación con el valor máximo permitido.
150     * @param {HTMLInputElement} input - El elemento de entrada de archivo.
151     */
152    function checkFileSize(input) {
153      if (input.files.length > 0) {
154        // Tamaño máximo en bytes
155        const maxSize = parseInt('<?php echo $maxFileSize; ?>') * 1024 * 1024;
156
157        const fileSize = input.files[0].size;
158
159        if (fileSize > maxSize) {
160          alert(
161            "El archivo seleccionado es demasiado grande, el " +
162            "tamaño máximo permitido es <?php echo $maxFileSize; ?>."
163          );
164          /* Limpiar el valor del input para que el usuario seleccione otro archivo. */
165          input.value = "";
166        }
167      }
168    }
169  </script>
170</body>
171</html>
Note: See TracBrowser for help on using the repository browser.