前言
大佬们各种造轮子各种秀,秀的我头皮发麻,我也想和大佬们一样优秀,可是一直无法编程入门
考虑到只会 PHP ,并且也为了方便博客会员,因此另类加入造轮子队列中~
大佬请飞过,本文主要是分享给那些有博客的朋友们
成品样式
FOFA 高级搜索小工具之 WordPress 版开发
1.主题文件 function.php 末尾加入下面代码
/* fofa查询 */ function fofa_cx() { if ( !empty($_POST['fofa_yf']) ) { // 这里写入你的判断条件,我随便写的一个例子 $email = ''; //配置fofa账号 $key = ''; //配置fofa key $size = $_POST['fofa_ts']; $data = $_POST['fofa_yf']; $fields = 'host,ip,title,port'; $url = 'https://fofa.so/api/v1/search/all?email='.urlencode($email).'&key='.$key.'&size='.$size.'&fields='.$fields.'&qbase64='.base64_encode(stripslashes($data)).''; $ch = curl_init(); $timeout = 3; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); echo $file_contents; exit; } else { echo json_encode('null'); exit; } } function fofa_cx_no(){ echo json_encode('no_login'); // 登陆判断 可以去掉这个函数 exit; } add_action('wp_ajax_nopriv_fofa_cx', 'fofa_cx_no'); //登陆判断 可以去掉 add_action('wp_ajax_fofa_cx', 'fofa_cx');
2.主题 js 文件中加入下面代码
/** * fofa */ function run_form() { const fofa_yf = document.querySelector('#fofa_yf').value.replace(/&/g,"%26") //replace 不能去掉否则会无法解析 & const fofa_ts = document.querySelector('#fofa_ts').value $.ajax({ //几个参数需要注意一下 type: "POST",//方法类型 dataType: "json",//预期服务器返回的数据类型 url: "/wp-admin/admin-ajax.php" ,//url data: `action=fofa_cx&fofa_yf=${fofa_yf}&fofa_ts=${fofa_ts}`, beforeSend: function (data){ document.querySelector('.tsk').style.display='block' document.querySelector('.tsk').innerHTML='查询中.............' }, success: function (data) { if ( data['error'] == false ) { var json=data['results']; var str = ""; str += "
“;
document.getElementById(‘info’).innerHTML=str;
document.querySelector(‘#btn’).style.pointerEvents = ‘all’
document.querySelector(‘#btn’).style.opacity = ‘inherit’
document.querySelector(‘.tsk’).innerHTML=’查询完成’;
setTimeout(function () {
document.querySelector(‘.tsk’).style.display=’none’
}, 2000);
} else if( data[‘errmsg’] == ‘Query invalid!’ ) {
document.querySelector(‘.tsk’).style.display=’block’
document.querySelector(‘.tsk’).innerHTML=’查询语法不得为空,请输入!’
setTimeout(function () {
document.querySelector(‘.tsk’).style.display=’none’
}, 2000);
} else if( data[‘errmsg’] == ‘FOFA coin is not enough!’ ){
document.querySelector(‘.tsk’).style.display=’block’
document.querySelector(‘.tsk’).innerHTML=’API 接口可能出现问题,请留言告知管理员!’
setTimeout(function () {
document.querySelector(‘.tsk’).style.display=’none’
}, 2000);
} else if( data == ‘no_login’ ){
document.querySelector(‘.tsk’).innerHTML=’您还未登陆,请先登陆!’
setTimeout(function () {
window.location.href=`/wp-login.php`
}, 2000);
};
},
statusCode: {
500: function (){
document.querySelector(‘.tsk’).style.display=’block’
document.querySelector(‘.tsk’).innerHTML=’fofa 官网可能被攻击导致查询失败,请重试!’
setTimeout(function () {
document.querySelector(‘.tsk’).style.display=’none’
}, 2000);
},
},
});
}
3.主题的 page.php 页面文件 复制 粘贴命名为 page-fofa.php 并在文件的文章内容处加入下方代码
FOFA 搜索引擎高级会员搜索小工具,请遵守网络安全法规.
URL IP 标题 端口
4.主题样式 style.css 中加入下方代码
.mk-alert.danger{background-color:#fef0f0;color:#f56c6c} .mk-alert{padding:10px 15px;border-radius:3px;margin:1em auto;line-height:1.5em;display:block;background-color:#f0f9eb;color:#67c23a} .gbi{position:sticky;top:5px;right:10px;left:100%} .fofa_bq{background:#1f8076;color:#fff;padding:6px 12px} .btn{padding:6px 12px;margin-right:4px;margin-bottom:4px;display:inline-block;line-height:1.5} .btn,button{border:0;background:#eb5055;color:#fff;cursor:pointer;opacity:1;user-select:none} .fofa_input{margin-left:-5px;padding:5px 10px 5px 10px} input,textarea{width:100%;padding:5px;box-sizing:border-box;border:1px solid #e5e9ef;background-color:#f4f5f7;resize:vertical} .btn,button,input:not([type~=checkbox]):not([type~=radio]),textarea{-webkit-transition:.2s;-moz-transition:.2s;-ms-transition:.2s;-o-transition:.2s;transition:.2s;font-size:1em;border-radius:3px;-webkit-appearance:none} h2{font-weight:600;position:relative;margin:10px 0 10px;font-size:1.3em;color:#444;margin-left:2%} h2:before{font-weight:600;position:absolute;top:0;left:-15px;content:'#';color:#eb5055} .white_content{display:none;position:absolute;top:0;left:15%;width:60%;height:90%;padding:15px;box-shadow:2px 2px 10px 5px #b3b2b2;background-color:#fff;z-index:1002;overflow:auto} .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0} .mk-alert.info{background-color:#f4f4f5;color:#909399} table{border-collapse:collapse;border-spacing:0} table td,table th{border:1px solid #f2f2f2;padding:8px} .fancybox-close-small:focus,a:focus,button:focus,input:focus,select:focus,textarea:focus{outline:0} .btn:active,button:active{opacity:1} .btn:focus,.btn:hover,button:focus,button:hover{opacity:.9} a{text-decoration:none;color:#313131} .fofa_select{padding:6px 12px;border:1px solid #ccc;border-radius:4px} a:not([class]):not([data-fancybox]){color:#313131;border-bottom:1px solid #ccc;text-decoration:none;margin:0 5px}
5. 前往 WordPress 后台 页面管理处 创建 模板为 page-fofa.php 的页面,然后访问就完工了
FOFA 高级搜索小工具之独立 PHP 版
FOFA 搜索引擎高级会员搜索小工具,请遵守网络安全法规.
URL IP 标题 端口
然后在创建 js php 2个文件,代码用上面的 js php 代码 在适当修改下即可
结语
是否被我的另类方式弄的一脸懵逼?扯犊子半天,其实根本就是 fofa api PHP 配置拉~