walkor %!s(int64=11) %!d(string=hai) anos
pai
achega
acb0dcc408

+ 54 - 5
applications/Statistics/Modules/admin.php

@@ -1,11 +1,11 @@
 <?php
 namespace Statistics\Modules;
-use Statistics\Lib\Cache;
 
 function admin()
 {
     $act = isset($_GET['act'])? $_GET['act'] : 'home';
-    $ip_list_str = '';
+    $err_msg = $notice_msg = $suc_msg = $ip_list_str = '';
+    $action = 'save_server_list';
     switch($act)
     {
         case 'detect_server':
@@ -31,19 +31,68 @@ function admin()
                     $ip_list[$host] = $host;
                 }
             }
+            
             // 过滤掉已经保存的ip
             foreach($ip_list as $ip)
             {
-                if(!isset(Cache::$ServerIpList[$ip]))
+                if(!isset(\Statistics\Lib\Cache::$ServerIpList[$ip]))
                 {
                     $ip_list_str .= $ip."\r\n";
                 }
             }
-            
+            $action = 'add_to_server_list';
+            break;
+        case 'add_to_server_list':
+            if(empty($_POST['ip_list']))
+            {
+                $err_msg = "保存的ip列表为空";
+                break;
+            }
+            $ip_list = explode("\n", $ip_list);
+            if($ip_list)
+            {
+                foreach($ip_list as $ip)
+                {
+                    $ip = trim($ip);
+                    if(false !== ip2long($ip))
+                    {
+                        \Statistics\Lib\Cache::$ServerIpList[$ip] = $ip;
+                    }
+                }
+            }
+            $suc_msg = "添加成功";
+            foreach(\Statistics\Lib\Cache::$ServerIpList as $ip)
+            {
+                $ip_list_str .= $ip."\r\n";
+            }
+            break;
+        case 'save_server_list':
+            if(empty($_POST['ip_list']))
+            {
+                $err_msg = "保存的ip列表为空";
+                break;
+            }
+            \Statistics\Lib\Cache::$ServerIpList = array();
+            $ip_list = explode("\n", $ip_list);
+            if($ip_list)
+            {
+                foreach($ip_list as $ip)
+                {
+                    $ip = trim($ip);
+                    if(false !== ip2long($ip))
+                    {
+                        \Statistics\Lib\Cache::$ServerIpList[$ip] = $ip;
+                    }
+                }
+            }
+            $suc_msg = "添加成功";
+            foreach(\Statistics\Lib\Cache::$ServerIpList as $ip)
+            {
+                $ip_list_str .= $ip."\r\n";
+            }
             break;
     }
     
-    
     include ST_ROOT . '/Views/header.tpl.php';
     include ST_ROOT . '/Views/admin.tpl.php';
     include ST_ROOT . '/Views/footer.tpl.php';

+ 18 - 5
applications/Statistics/Views/admin.tpl.php

@@ -27,13 +27,26 @@
 	</div>
 	<div class="row clearfix">
 		<div class="col-md-12 column">
-			<form action="/?fn=admin&act=save_server_list" method="post">
-			<textarea rows="100" cols="30"><?php echo $ip_list_str;?></textarea>
-			<div class="form-group">
-				<div class="col-sm-offset-2 col-sm-10">
-					 <button type="submit" class="btn btn-default">保存</button>
+		<?php if($suc_msg){?>
+				<div class="alert alert-dismissable alert-success">
+				 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+				 <strong><?php echo $suc_msg;?></strong> 
 				</div>
+		<?php }elseif($err_msg){?>
+			<div class="alert alert-dismissable alert-danger">
+				 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+				<strong><?php echo $err_msg;?></strong> 
 			</div>
+		<?php }elseif($notie_msg){?>
+			<div class="alert alert-dismissable alert-info">
+				 <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+				<strong><?php echo $notie_msg;?></strong>
+			</div>
+		<?php }?>
+		
+			<form action="/?fn=admin&act=<?php echo $action;?>" method="post">
+			<textarea rows="22" cols="30" name="ip_list"><?php echo $ip_list_str;?></textarea>
+			<button type="submit" class="btn btn-default">保存</button>
 			</form>
 		</div>
 	</div>