예제 #1
0
<?php

namespace controllers;

use Engine\X;
use Engine\Gvar;
use Engine\Route;
/**
* 添加脏词
*/
Route::get('add', function () {
    X::render('audit/dirtyword_add');
});
Route::post('add', function () {
    $post = X::request()->post(['dirtyword' => '']);
    //添加脏词
    X::module('dirtyword')->add(['words' => $post->dirtyword, 'company_id' => Gvar::audit('company_id')]);
    X::redirect("/audit/dirtyword/add");
});
Route::get('delete', function () {
    $get = X::request()->get(['id' => '']);
    //添加脏词
    X::module('dirtyword')->del($get->id);
    echo "success";
});
예제 #2
0
파일: api.php 프로젝트: sdgdsffdsfff/marvel
Route::post('testing', function () {
    $post = X::request()->post(['title' => '', 'content' => '', 'access_token' => '', 'client_ip' => '', 'if_spam' => 0, 'if_duplicate_deny' => 0, 'if_spate_deny' => 0, 'test' => 0]);
    if (!$post->access_token || !$post->content) {
        apiOutput(NO, "incomplete request");
    }
    if (!($company = X::module('company')->exists($post->access_token))) {
        apiOutput(NO, "company does not exist");
    }
    //临时关闭
    if ($company['closed']) {
        apiOutput(NO, "service temporarily unavailable");
    }
    //统计请求量
    X::module('company')->statisticsRequest($company['company_id']);
    $now = time();
    require 'function/post.php';
    list($tutu, $process_time) = searchEngine(['content' => $post->title . $post->content, 'if_spam' => $post->if_spam], true);
    if (!$tutu) {
        apiOutput(NO, "search service is not available");
    }
    $tutu = toArray($tutu);
    require "function/cook.php";
    $from_address = ipToAddress($post->client_ip);
    $tutu['title'] = $post->title;
    $tutu['content'] = $post->content;
    $tutu['posts_time'] = $now;
    $tutu['company_username'] = $company['company_name'];
    $tutu['company_id'] = $company['company_id'];
    $tutu['ip_city'] = $from_address;
    $tutu['process_time'] = $process_time;
    $tutu['ip'] = $post->client_ip;
    //请求日志
    X::module('post')->banLog($tutu);
    //IP是否被拦截
    $ipInfo = X::module('post')->whetherInBanip($post->client_ip);
    if ($ipInfo && $tutu['hit'] || $ipInfo && $ipInfo['valid_time'] > $now) {
        if ($tutu['hit']) {
            //看是否内容再次是非法,是就增加IP拦截时效
            if (!$ipInfo['valid_time'] || $ipInfo['valid_time'] < $now) {
                $valid_time = $now + 86400;
                //拦截一天
            } else {
                $valid_time = $ipInfo['valid_time'] + 43200;
            }
            X::db()->query("UPDATE banip \n\t\t\t\t\t\t\tSET valid_time = {$valid_time} ,\n\t\t\t\t\t\t\t\tattack_amount = attack_amount + 1\n\t\t\t\t\t\t\tWHERE ip_id = {$ipInfo['ip_id']}");
        }
        //统计命中率
        X::module('company')->statisticsHit($company['company_id']);
        apiOutput(YES, ['hit' => YES, 'dirty_works' => "ip({$post->client_ip})被拦截"]);
    }
    //命中脏词
    if ($tutu['hit']) {
        //统计命中率
        X::module('company')->statisticsHit($company['company_id']);
        //如果命中的词是公共库而且是要封ip的
        if ($tutu['depot'] === 2) {
            $dwRow = X::module('dirtyword')->byGlobal($tutu['dirty_id']);
            if ($dwRow['if_deny_id'] === 1) {
                X::module('post')->banIp($post->client_ip);
            }
        }
        apiOutput(YES, ['hit' => YES, 'dirty_works' => $tutu['dirty_works'], 'dirty_works_category_id' => $tutu['dwcategory_id'], 'category_name' => $tutu['category_name'], 'depot' => $tutu['depot']]);
    }
});
예제 #3
0
/**
* 查找
*/
Route::get('search', function () {
    $get = X::request()->get(['search' => '']);
    $dw = X::module('dirtyword')->search($get->search);
    X::render('audit/index', ['dirtyword' => $dw]);
});
/**
* 登录
*/
Route::get('signin', function () {
    X::render('audit/login');
});
Route::post('signin', function () {
    $post = X::request()->post(['account' => '', 'password' => '']);
    if (!$post->account || !$post->password) {
        X::redirect('/audit/signin');
    }
    if ($company = X::module('company')->signin($post->account, $post->password)) {
        X::redirect('/audit');
    } else {
        X::redirect('www.baidu.com');
    }
});
/**
* 脏词管理
*/
Route::get('dirtyword', function () {
    X::render('audit/dirtyword');
});