Project

General

Profile

« Previous | Next » 

Revision 36f6ed35

Added by Cyrill B about 13 years ago

Use Certificate Manager in Captive Portal settings

View differences:

usr/local/www/services_captiveportal.php
76 76
	exit;
77 77
}
78 78

  
79
if (!is_array($config['ca']))
80
	$config['ca'] = array();
81

  
82
$a_ca =& $config['ca'];
83

  
84
if (!is_array($config['cert']))
85
	$config['cert'] = array();
86

  
87
$a_cert =& $config['cert'];
88

  
79 89
if ($a_cp[$cpzone]) {
80 90
	$pconfig['zoneid'] = $a_cp[$cpzone]['zoneid'];
81 91
	$pconfig['cinterface'] = $a_cp[$cpzone]['interface'];
......
97 107
	$pconfig['httpslogin_enable'] = isset($a_cp[$cpzone]['httpslogin']);
98 108
	$pconfig['httpsname'] = $a_cp[$cpzone]['httpsname'];
99 109
	$pconfig['preauthurl'] = strtolower($a_cp[$cpzone]['preauthurl']);
100
	$pconfig['cert'] = base64_decode($a_cp[$cpzone]['certificate']);
101
	$pconfig['cacert'] = base64_decode($a_cp[$cpzone]['cacertificate']);
102
	$pconfig['key'] = base64_decode($a_cp[$cpzone]['private-key']);
110
	$pconfig['certref'] = $a_cp[$cpzone]['certref'];
111
	$pconfig['caref'] = $a_cp[$cpzone]['caref'];
103 112
	$pconfig['logoutwin_enable'] = isset($a_cp[$cpzone]['logoutwin_enable']);
104 113
	$pconfig['peruserbw'] = isset($a_cp[$cpzone]['peruserbw']);
105 114
	$pconfig['bwdefaultdn'] = $a_cp[$cpzone]['bwdefaultdn'];
......
163 172
		}
164 173

  
165 174
		if ($_POST['httpslogin_enable']) {
166
		 	if (!$_POST['cert'] || !$_POST['key']) {
167
				$input_errors[] = gettext("Certificate and key must be specified for HTTPS login.");
168
			} else {
169
				if (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE"))
170
					$input_errors[] = gettext("This certificate does not appear to be valid.");
171
				if (!strstr($_POST['cacert'], "BEGIN CERTIFICATE") || !strstr($_POST['cacert'], "END CERTIFICATE"))
172
					$input_errors[] = gettext("This intermmediate certificate does not appear to be valid.");
173
				if (!strstr($_POST['key'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['key'], "END RSA PRIVATE KEY"))
174
					$input_errors[] = gettext("This key does not appear to be valid.");
175
		 	if (!$_POST['certref']) {
176
				$input_errors[] = gettext("Certificate must be specified for HTTPS login.");
175 177
			}
176

  
177 178
			if (!$_POST['httpsname'] || !is_domain($_POST['httpsname'])) {
178 179
				$input_errors[] = gettext("The HTTPS server name must be specified for HTTPS login.");
179 180
			}
......
263 264
		$newcp['peruserbw'] = $_POST['peruserbw'] ? true : false;
264 265
		$newcp['bwdefaultdn'] = $_POST['bwdefaultdn'];
265 266
		$newcp['bwdefaultup'] = $_POST['bwdefaultup'];
266
		$newcp['certificate'] = base64_encode($_POST['cert']);
267
		$newcp['cacertificate'] = base64_encode($_POST['cacert']);
268
		$newcp['private-key'] = base64_encode($_POST['key']);
267
		$newcp['certref'] = $_POST['certref'];
268
		$newcp['caref'] = $_POST['caref'];
269 269
		$newcp['logoutwin_enable'] = $_POST['logoutwin_enable'] ? true : false;
270 270
		$newcp['nomacfilter'] = $_POST['nomacfilter'] ? true : false;
271 271
		$newcp['noconcurrentlogins'] = $_POST['noconcurrentlogins'] ? true : false;
......
350 350
	var endis, radius_endis;
351 351
	endis = !(document.iform.enable.checked || enable_change);
352 352
	radius_endis = !((!endis && document.iform.auth_method[2].checked) || enable_change);
353
	https_endis = !((!endis && document.iform.httpslogin_enable.checked) || enable_change);
353 354

  
354 355
	document.iform.cinterface.disabled = endis;
355 356
	//document.iform.maxproc.disabled = endis;
......
388 389
	document.iform.radmac_enable.disabled = radius_endis;
389 390
	document.iform.httpslogin_enable.disabled = endis;
390 391
	document.iform.radmac_format.disabled = radius_endis;
391
	document.iform.httpsname.disabled = endis;
392
	document.iform.cert.disabled = endis;
393
	document.iform.cacert.disabled = endis;
394
	document.iform.key.disabled = endis;
392
	document.iform.httpsname.disabled = https_endis;
393
	document.iform.certref.disabled = https_endis;
394
	document.iform.caref.disabled = https_endis;
395 395
	document.iform.logoutwin_enable.disabled = endis;
396 396
	document.iform.nomacfilter.disabled = endis;
397 397
	document.iform.noconcurrentlogins.disabled = endis;
......
860 860
	<tr>
861 861
      <td valign="top" class="vncell"><?=gettext("HTTPS login"); ?></td>
862 862
      <td class="vtable">
863
        <input name="httpslogin_enable" type="checkbox" class="formfld" id="httpslogin_enable" value="yes" <?php if($pconfig['httpslogin_enable']) echo "checked"; ?>>
863
        <input name="httpslogin_enable" type="checkbox" class="formfld" id="httpslogin_enable" value="yes" onClick="enable_change(false)" <?php if($pconfig['httpslogin_enable']) echo "checked"; ?>>
864 864
        <strong><?=gettext("Enable HTTPS login"); ?></strong><br>
865
    <?=gettext("If enabled, the username and password will be transmitted over an HTTPS connection to protect against eavesdroppers. A server name, certificate and matching private key must also be specified below."); ?></td>
866
	  </tr>
865
    <?=gettext("If enabled, the username and password will be transmitted over an HTTPS connection to protect against eavesdroppers. A server name and certificate must also be specified below."); ?></td>
866
	</tr>
867 867
	<tr>
868 868
      <td valign="top" class="vncell"><?=gettext("HTTPS server name"); ?> </td>
869 869
      <td class="vtable">
870 870
        <input name="httpsname" type="text" class="formfld unknown" id="httpsname" size="30" value="<?=htmlspecialchars($pconfig['httpsname']);?>"><br>
871 871
	<?php printf(gettext("This name will be used in the form action for the HTTPS POST and should match the Common Name (CN) in your certificate (otherwise, the client browser will most likely display a security warning). Make sure captive portal clients can resolve this name in DNS and verify on the client that the IP resolves to the correct interface IP on %s."), $g['product_name']);?> </td>
872
	  </tr>
873
	<tr>
874
      <td valign="top" class="vncell"><?=gettext("HTTPS certificate"); ?></td>
875
      <td class="vtable">
876
        <textarea name="cert" cols="65" rows="7" id="cert" class="formpre"><?=htmlspecialchars($pconfig['cert']);?></textarea>
877
        <br>
878
    <?=gettext("Paste a signed certificate in X.509 PEM format here."); ?></td>
879
	  </tr>
880
	<tr>
881
      <td valign="top" class="vncell"><?=gettext("HTTPS private key"); ?></td>
882
      <td class="vtable">
883
        <textarea name="key" cols="65" rows="7" id="key" class="formpre"><?=htmlspecialchars($pconfig['key']);?></textarea>
884
        <br>
885
    <?=gettext("Paste an RSA private key in PEM format here."); ?></td>
886
	  </tr>
887
        <tr>
888
      <td valign="top" class="vncell"><?=gettext("HTTPS intermediate certificate"); ?></td>
889
      <td class="vtable">
890
        <textarea name="cacert" cols="65" rows="7" id="cacert" class="formpre"><?=htmlspecialchars($pconfig['cacert']);?></textarea>
891
        <br>
892
    <?=gettext("Paste a certificate in X.509 PEM format here."); ?></td>
893
          </tr>
872
	</tr>
873
  <tr id="tls_ca">
874
    <td width="22%" valign="top" class="vncell"><?=gettext("Certificate Authority"); ?></td>
875
      <td width="78%" class="vtable">
876
      <?php if (count($a_ca)): ?>
877
      <select name='caref' class="formselect">
878
        <option value=""><?=gettext("None"); ?></option>
879
      <?php
880
        foreach ($a_ca as $ca):
881
          $selected = "";
882
          if ($pconfig['caref'] == $ca['refid'])
883
            $selected = "selected";
884
      ?>
885
        <option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
886
      <?php endforeach; ?>
887
      </select>
888
      <?php else: ?>
889
        <b><?=gettext("No Certificate Authorities defined."); ?></b> <br/>Create one under <a href="system_camanager.php">System &gt; Cert Manager</a>.
890
      <?php endif; ?>
891
      </td>
892
  </tr>
893
  <tr id="tls_cert">
894
    <td width="22%" valign="top" class="vncell"><?=gettext("Server Certificate"); ?></td>
895
      <td width="78%" class="vtable">
896
      <?php if (count($a_cert)): ?>
897
      <select name='certref' class="formselect">
898
        <option value=""><?=gettext("None"); ?></option>
899
      <?php
900
      foreach ($a_cert as $cert):
901
        $selected = "";
902
        $caname = "";
903
        $inuse = "";
904
        $revoked = "";
905
        $ca = lookup_ca($cert['caref']);
906
        if ($ca)
907
          $caname = " (CA: {$ca['descr']})";
908
        if ($pconfig['certref'] == $cert['refid'])
909
          $selected = "selected";
910
        if (cert_in_use($cert['refid']))
911
          $inuse = " *In Use";
912
        if (is_cert_revoked($cert))
913
        $revoked = " *Revoked";
914
      ?>
915
        <option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
916
      <?php endforeach; ?>
917
      </select>
918
      <?php else: ?>
919
        <b><?=gettext("No Certificates defined."); ?></b> <br/>Create one under <a href="system_certmanager.php">System &gt; Cert Manager</a>.
920
      <?php endif; ?>
921
    </td>
922
  </tr>
894 923
	<tr>
895 924
	  <td width="22%" valign="top" class="vncell"><?=gettext("Portal page contents"); ?></td>
896 925
	  <td width="78%" class="vtable">
......
898 927
		<?php
899 928
			list($host) = explode(":", $_SERVER['HTTP_HOST']);
900 929
			$zoneid = $pconfig['zoneid'] ? $pconfig['zoneid'] : 8000;
901
			if (isset($pconfig['httpslogin'])) {
930
			if ($pconfig['httpslogin_enable']) {
902 931
				$port = $pconfig['listenporthttps'] ? $pconfig['listenporthttps'] : ($zoneid + 1);
903 932
				$href = "https://{$host}:{$port}";
904 933
			} else {

Also available in: Unified diff