xiaoz 6 år sedan
förälder
incheckning
5159822567
8 ändrade filer med 87 tillägg och 43 borttagningar
  1. 2 2
      config.php
  2. BIN
      data/nssl.db3
  3. 2 4
      data/temp.conf
  4. 35 14
      editsite.php
  5. 41 14
      functions/method.php
  6. 2 2
      index.php
  7. 3 5
      test.php
  8. 2 2
      website.php

+ 2 - 2
config.php

@@ -1,8 +1,8 @@
 <?php
 	//生产环境建议填写绝对路径,且目录可写,如D:/ssl/
 	//设置证书路径
-    $ssldir = "../ssl/";
+    $ssldir = "D:/ssl/";
     //设置配置文件路径
     //$confdir = "D:/wwwroot/nssl/conf/";
-    $confdir = "../vhost/";
+    $confdir = "D:/nginx/conf/vhost/";
 ?>

BIN
data/nssl.db3


+ 2 - 4
data/temp.conf

@@ -1,5 +1,5 @@
 server {
-	listen         192.168.1.1:443 ssl http2;
+	listen 443 ssl http2;
 	
 	ssl_certificate mycer.crt;
     ssl_certificate_key mycer.key;
@@ -10,8 +10,6 @@ server {
     ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
     ssl_prefer_server_ciphers on;
     add_header Strict-Transport-Security max-age=15768000;
-    ssl_stapling on;
-    ssl_stapling_verify on;
 
 	server_name    domain.com;
 	
@@ -27,7 +25,7 @@ server {
 }
 server
 {
-    listen 192.168.1.1:80;
+    listen 80;
     server_name test301.com;
     rewrite ^(.*) https://test301.com$1 permanent;
 }

+ 35 - 14
editsite.php

@@ -3,17 +3,21 @@
 	include_once('functions/medoo.php');
 	include_once("config.php");
 
-	$host = $_SERVER['HTTP_HOST'].$_SERVER["PHP_SELF"];
-	$host = "http://".str_replace("editsite.php","",$host)."functions/method.php?type=select_ssl";
-	
-	$selectssl = file_get_contents($host);
-
 	$database = new medoo([
     'database_type' => 'sqlite',
     'database_file' => 'data/nssl.db3']);
 
 	$siteid = $_GET['siteid'];
 	$siteinfo = $database->get("s_site",["domain","sslid","https"],["id" => $siteid]);
+
+	//开关按钮状态
+	if($siteinfo['https'] == 1) {
+		$isswitch = "checked";
+	}
+	if($siteinfo['https'] == 0) {
+		$isswitch = "";
+	}
+	
 ?>
 <div class="layui-container" style = "margin-top:40px;">
 	<div class="layui-row">
@@ -33,17 +37,9 @@
 			    </div>
 			  </div>
 			  <div class="layui-form-item">
-			    <label class="layui-form-label">选择证书</label>
-			    <div class="layui-input-block">
-			      <select id = "cert" lay-verify="required">
-				      <?php echo $selectssl; ?>
-			      </select>
-			    </div>
-			  </div>
-			  <div class="layui-form-item">
 			    <label class="layui-form-label">强制HTTPS</label>
 			    <div class="layui-input-block">
-			      <input type="checkbox" name="switch" lay-skin="switch" id = "https">
+			      <input type="checkbox" name="switch" lay-skin="switch" id = "https" <?php echo $isswitch; ?>>
 			    </div>
 			  </div>
 			</form>
@@ -66,4 +62,29 @@
 	  var form = layui.form;
 	  //监听提交
 	});
+	$(document).ready(function(){
+		$("title").empty();
+		$("title").append("是否强制HTTPS?");
+		$("#btn").click(function(){
+			//alert('dsds');
+			var domain = $("#domain").val();
+			var siteid = <?php echo $siteid; ?>
+			
+			//是否强制SSL
+			if ($("#https").get(0).checked) {
+			    var https = 1;
+			}
+			else {
+				var https = 0;
+			}
+			
+			$.post("./functions/method.php?type=update_site",{domain:domain,siteid:siteid,https:https},function(data,status){
+				layer.open({
+					title:'温馨提示',
+					content:data,
+					time:2000
+				});
+			});
+		});
+	});
 </script>

+ 41 - 14
functions/method.php

@@ -2,7 +2,7 @@
 	error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
 	$myhost = $_SERVER['HTTP_HOST'];
 	//判断主机,不允许公网访问
-	if(($myhost != 'localhost') && ($myhost != '127.0.0.1')) {
+	if(($myhost != 'localhost') && ($myhost != '127.0.0.1:88')) {
 		echo "不允许公网访问!";
 		exit;
 	}
@@ -14,12 +14,6 @@
     'database_type' => 'sqlite',
     'database_file' => '../data/nssl.db3']);
 
-    //设置证书路径
-    //$ssldir = "../ssl/";
-    //设置配置文件路径
-    //$confdir = "D:/wwwroot/nssl/conf/";
-    //$confdir = "../vhost/";
-	
 	//获取域名
 	$domain = $_POST['domain'];
 	//替换http and https
@@ -29,9 +23,13 @@
 	$key = $_POST['key'];			//获取证书私钥
 	$note = $_POST['note'];		//获取证书备注
 	$id = $_POST['id'];			//获取ID
+	$siteid = $_POST['siteid'];		//获取站点ID
 	$cerid = $_GET['cerid'];	//获取证书ID,更新证书时使用
 	$sslid = $_POST['sslid'];	//获取证书id,更新站点时使用
 	$https = $_POST['https'];	//是否强制https
+
+	//当前时间
+	$time = date('Y-m-d',time());
 	//获取类型
 	$type = $_GET['type'];
 
@@ -51,7 +49,7 @@
 				echo "添加失败,域名已存在!";
 				exit;
 			}
-			$time = date('Y-m-d',time());
+			
 			$last_user_id = $database->insert("s_cert", [
 		    "domain" => $domain,
 		    "crt" => $crt,
@@ -76,7 +74,6 @@
 			check($key,"key");
 			check($note,"note");
 			
-			$time = date('Y-m-d',time());
 			$last_user_id = $database->update("s_cert", [
 		    "crt" => $crt,
 		    "key" => $key,
@@ -159,7 +156,7 @@
 				echo "添加失败,域名已存在!";
 				exit;
 			}
-			$time = date('Y-m-d',time());
+			
 			$last_user_id = $database->insert("s_site", [
 		    "domain" => $domain,
 		    "sslid" => $sslid,
@@ -171,10 +168,10 @@
 				$cert = $database->get("s_cert",["id","domain","note"],["id" => $sslid]);
 				$certdir = $ssldir.$cert['domain'];					//设置证书路径
 				$content = file_get_contents("../data/temp.conf");
-				$ip = file_get_contents("https://api-ipv4.ip.sb/ip");
-				$ip = str_replace("\n","",$ip);
+				//$ip = file_get_contents("https://api-ipv4.ip.sb/ip");
+				//$ip = str_replace("\n","",$ip);
 				//替换监听地址
-				$content = str_replace("192.168.1.1",$ip,$content);
+				//$content = str_replace("192.168.1.1",$ip,$content);
 				//替换域名
 				$content = str_replace("domain.com",$domain,$content);
 				//替换证书路径
@@ -189,6 +186,7 @@
 				fwrite($myconf, $content);
 				fclose($myconf);
 				echo '添加成功!';
+				//reload();
 			}
 			break;
 		//显示站点
@@ -221,7 +219,7 @@
 				echo "<td>".$ressl."</td>";
 				echo "<td>".$https."</td>";
 				echo "<td>".$data['time']."</td>";
-				echo "<td><a href = 'javascript:;' class='layui-btn layui-btn-danger layui-btn-xs' onclick = 'delsite(\"$id\")'>"."删除</a></td>";
+				echo "<td><a class='layui-btn layui-btn-normal layui-btn-xs' href = 'editsite.php?siteid=$id' title = '301设置'>设置</a> <a href = 'javascript:;' class='layui-btn layui-btn-danger layui-btn-xs' onclick = 'delsite(\"$id\")'>"."删除</a></td>";
 			   	echo "</tr>";
 			}
 			break;
@@ -238,6 +236,30 @@
 				echo 'ok';
 			}
 			break;
+		//更新站点
+		case 'update_site':
+			$upsite = $database->update("s_site",["https" => $https,"time" => $time],["id" => $siteid]);
+			
+			//如果更新成功
+			if($upsite) {
+				$sitecontent = file_get_contents("$confdir".$domain.".conf");
+				
+				if($https == 1) {
+					$sitecontent = str_replace("test301.com",$domain,$sitecontent);
+				}
+				if($https == 0) {
+					$sitecontent = str_replace($domain,"test301.com",$sitecontent);
+				}
+				$mysite = fopen($confdir.$domain.".conf", "w") or die("Unable to open file!");
+				fwrite($mysite, $sitecontent);
+				fclose($mysite);
+				echo '更新成功!';
+				//reload();
+			}
+			else {
+				echo '未知错误!';
+			}
+			break;
 		default:
 			;
 			break;
@@ -245,6 +267,11 @@
 
 ?>
 <?php
+	//重载nginx
+	function reload(){
+		$re = system("D:\SOFT_PHP_PACKAGE\nssl\reload.bat");
+		var_dump($re);
+	}
 	function check($parameter,$category){
 		switch ( $category )
 		{

+ 2 - 2
index.php

@@ -10,11 +10,11 @@
 			<div id="listsite">
 				<table class="layui-table">
 				  <colgroup>
-				    <col width="35%">
+				    <col width="30%">
 				    <col width="25%">
 				    <col width="15%">
 					<col width="15%">
-					<col width="10%">
+					<col width="15%">
 				  </colgroup>
 				  <thead>
 				    <tr>

+ 3 - 5
test.php

@@ -1,7 +1,5 @@
 <?php
-	$content = file_get_contents("data/temp.conf");
-	$content = str_replace("192.168.1.1","211.149.123.45",$content);
-	$content = str_replace("domain.com","xiaoz.me",$content);
-
-	echo $content;
+	//$re = system("c:\windows\system32\cmd.exe D:\SOFT_PHP_PACKAGE\nssl\reload.bat");
+	$re = system("c:\windows\system32\ping.exe www.baidu.com");
+	print_r($re);
 ?>

+ 2 - 2
website.php

@@ -8,11 +8,11 @@
 			<div id="listsite">
 				<table class="layui-table">
 				  <colgroup>
-				    <col width="35%">
+				    <col width="30%">
 				    <col width="25%">
 				    <col width="15%">
 					<col width="15%">
-					<col width="10%">
+					<col width="15%">
 				  </colgroup>
 				  <thead>
 				    <tr>