{"id":299,"date":"2011-06-03T15:04:51","date_gmt":"2011-06-03T07:04:51","guid":{"rendered":"http:\/\/cowman-chiang.no-ip.org\/wordpress\/?p=299"},"modified":"2023-10-31T15:51:48","modified_gmt":"2023-10-31T07:51:48","slug":"radius-%e6%b8%ac%e8%a9%a6-radtest-php-%e6%af%8f%e5%8d%8a%e5%b0%8f%e6%99%82%e5%9f%b7%e8%a1%8c%e4%b8%80%e6%ac%a1","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=299","title":{"rendered":"Radius \u6e2c\u8a66 \u2013 radtest.php (\u6bcf\u534a\u5c0f\u6642\u57f7\u884c\u4e00\u6b21)"},"content":{"rendered":"<p>\u65e2\u7136\u90fd\u53ef\u4ee5\u5f9e\u8cc7\u6599\u5eab\u53d6\u5f97\u6e2c\u8a66\u8cc7\u6599\u4e86<br \/>\n\u90a3\u4f4d\u4ec0\u9ebc\u4e0d\u628a\u6e2c\u8a66\u7d50\u679c\u4e1f\u56de\u53bb\u5462?<br \/>\n\u6240\u4ee5\u5c31\u6709\u4e86\u9019\u4e00\u652f<\/p>\n<p><!--more--><\/p>\n<pre>\n\nphp\n  header(\"Content-Type:text\/html; charset=utf-8\");\n  $link = mysql_pconnect(\"\u8cc7\u6599\u5eab\", \"\u5e33\u865f\", \"\u5bc6\u78bc\") or die(\"\u7121\u6cd5\u8207MySQL\u5efa\u7acb\u9023\u7dda\");\n  mysql_select_db(\"\u8cc7\u6599\u5eab\") or die(\"\u7121\u6cd5\u9078\u64c7std\u8cc7\u6599\u5eab\");\n\n  $fp=fopen( '\/radtest\/temp1.log',\"w\");    #\u628a\u76f8\u95dc\u8cc7\u8a0a\u90fd\u6709\u5404log\u7d00\u9304\n\n  function radtest($un, $pw, $hn, $po, $sr){     #\u9032\u884cradtest\u6e2c\u8a66\n    return exec('radtest '.trim($un).' ''.trim($pw).'' '.trim($hn).':'.trim($po).' 0 '.trim($sr).'|grep Accept|grep -c Accept');\n  }\n\n  function insertintodb($name, $status, $note){      #\u5c07log\u8a18\u9304\u65b0\u589e\u81f3\u8cc7\u6599\u5eab\u4e2d\n    checkdb(strtolower($name));\n    $myquery1 = \"insert into `wordpress`.`\".strtolower($name).\"`(status, time, note) values ('\".$status.\"','\".date('Y-m-d G:i:s').\"','\".$note.\"')\";\n    $result1 = mysql_query($myquery1) or die(\"Insert \u932f\u8aa4\");\n    return $result1;\n  }\n\n  function checkdb($name){       #\u6aa2\u67e5\u8981\u65b0\u589e\u8cc7\u6599\u7684\u8cc7\u6599\u8868\u662f\u5426\u5b58\u5728\uff0c\u82e5\u4e0d\u5b58\u5728\u5247\u65b0\u589e\n    $sql ='SHOW TABLES in wordpress WHERE Tables_in_wordpress = '' . $name . ''';\n    $rs = mysql_query($sql);\n    if(!mysql_fetch_array($rs)){\n      \/\/echo \"createdb \".$name.\"n\";\n      createdb($name);\n      return FALSE;}\n    else\n      return TRUE;\n  }\n\n  function createdb($name){        #\u65b0\u589e\u8cc7\u6599\u8868\n    $myquery2 = \"CREATE TABLE `wordpress`.`\".$name.\"` (\n          `id` int(10) NOT NULL AUTO_INCREMENT,\n          `status` int(5) NOT NULL,\n          `time` datetime NOT NULL,\n          `note` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,\n          PRIMARY KEY (`id`)\n        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci\";\n    $result2 = mysql_query($myquery2) or die(\"Create \".$name.\" \u932f\u8aa4\");\n  }\n\n  mysql_query('SET NAMES utf8',$link);\n  mysql_query('SET CHARACTER_SET_CLIENT=utf8',$link);\n  mysql_query('SET CHARACTER_SET_RESULTS=utf8',$link);\n\n  $myquery   = \"select nasname, port, secret, schoolname, testaccounting, testpasswd, shortname from \u8cc7\u6599\u8868\";\n  $result = mysql_query($myquery) or die(\"\u67e5\u8a62 Query \u932f\u8aa4\");\n  fwrite($fp, \"\u4e0b\u5217\u55ae\u4f4d\u9032\u884cradtest\u6642\u767c\u751f\u932f\u8aa4!!n\");\n  $count=0;\n  while($row = mysql_fetch_array($result))\n  {\n    \/\/checkdb('LOG_'.$row[\"shortname\"]);\n    if(($row[\"testaccounting\"]<>\"\u6e2c\u8a66\u5e33\u865f\") and ($row[\"testaccounting\"]<>\"\u6e2c\u8a66\u5e33\u865f\")) # Have Testing username password\n    {\n      if( radtest($row[\"testaccounting\"], $row[\"testpasswd\"], '10.1.0.7', '1812', $row[\"secret\"])  =='1')\n      {\n        ########### Test Ok ##########\n        insertintodb('LOG_'.$row[\"shortname\"].'_'.$row[\"nasname\"],'1','\u4f7f\u7528\u9023\u7dda\u55ae\u4f4d\u63d0\u4f9b\u6e2c\u8a66\u5e33\u865f\u5bc6\u78bc\u6e2c\u8a66\u6210\u529f');\n      }\n      else\n      {\n        ########## Test Fault #########\n        if( radtest( '\u9810\u8a2d\u5e33\u865f', '\u9810\u8a2d\u5bc6\u78bc', $row[\"nasname\"], $row[\"port\"], $row[\"secret\"])  =='1')\n        {\n          insertintodb('LOG_'.$row[\"shortname\"].'_'.$row[\"nasname\"],'2','\u9023\u7dda\u55ae\u4f4d\u63d0\u4f9b\u6e2c\u8a66\u5e33\u865f\u5bc6\u78bc\u6e2c\u8a66\u5931\u6557\uff0c\u4f7f\u7528\u9810\u8a2d\u5e33\u5bc6\u6e2c\u8a66\u6210\u529f');\n        }\n        else\n        {\n          insertintodb('LOG_'.$row[\"shortname\"].'_'.$row[\"nasname\"],'3','\u9023\u7dda\u55ae\u4f4d\u63d0\u4f9b\u53ca\u9810\u8a2d\u6e2c\u5e33\u865f\u5bc6\u78bc\u6e2c\u8a66\u7686\u5931\u6557');\n          fwrite($fp, date('Y-m-d G:i:s').' : '.$row[\"schoolname\"].' '.$row[\"nasname\"].\"\u5931\u6557n\");\n          $count++;\n        }\n      }\n    }\n    else\n    {\n      if( radtest($row[\"testaccounting\"], $row[\"testpasswd\"], $row[\"nasname\"], $row[\"port\"], $row[\"secret\"])  =='1')\n      {\n        ########### Test Ok ##########\n        insertintodb('LOG_'.$row[\"shortname\"].'_'.$row[\"nasname\"],'4','\u9023\u7dda\u55ae\u4f4d\u672a\u63d0\u4f9b\u6e2c\u8a66\u5e33\u865f\u5bc6\u78bc\uff0c\u4f7f\u7528\u9810\u8a2d\u5e33\u5bc6\u6e2c\u8a66\u6210\u529f');\n      }\n      else\n      {\n        ########## Test Fault #########\n        insertintodb('LOG_'.$row[\"shortname\"].'_'.$row[\"nasname\"],'5','\u9023\u7dda\u55ae\u4f4d\u672a\u63d0\u4f9b\u6e2c\u8a66\u5e33\u865f\u5bc6\u78bc\uff0c\u4f7f\u7528\u9810\u8a2d\u5e33\u5bc6\u6e2c\u8a66\u5931\u6557');\n        fwrite($fp, date('Y-m-d G:i:s').' : '.$row[\"schoolname\"].' '.$row[\"nasname\"].\"\u5931\u6557n\");\n        $count++;\n      }\n    }\n  }\n  fwrite($fp, \"\u5171\u6709\".$count.\"\u9593\u55ae\u4f4d\u767c\u751f\u932f\u8aa4!!n\");\n  fclose($fp);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u65e2\u7136\u90fd\u53ef\u4ee5\u5f9e\u8cc7\u6599\u5eab\u53d6\u5f97\u6e2c\u8a66\u8cc7\u6599\u4e86 \u90a3\u4f4d\u4ec0\u9ebc\u4e0d\u628a\u6e2c\u8a66\u7d50\u679c\u4e1f\u56de\u53bb\u5462? \u6240\u4ee5\u5c31\u6709\u4e86\u9019\u4e00\u652f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-radius"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions"}],"predecessor-version":[{"id":2348,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions\/2348"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}