text: const bodyParser = require('koa-bodyparser');
  const list = require('./cgi/list');
  const proxyNetwork = require('./cgi/proxyNetwork');
  const selectEnv = require('./cgi/selectEnv');
  const checkAdminLogin = require('./cgi/admin/login');
  const getAllAccounts = require('./cgi/admin/allAccounts');
  const addAccount = require('./cgi/admin/addAccount');
  const moveAccount = require('./cgi/admin/move');
  const activeAccount = require('./cgi/admin/activeAccount');
  const removeAccount = require('./cgi/admin/removeAccount');
  const getSettings = require('./cgi/admin/getSettings');
  const setJsonData = require('./cgi/admin/setJsonData');
  const setRulesTpl = require('./cgi/admin/setRulesTpl');
  const setEntryPatterns = require('./cgi/admin/setEntryPatterns');
  const setTestRules = require('./cgi/admin/setTestRules');
  const setDefaultRules = require('./cgi/admin/setDefaultRules');
  const getAuthKey = require('./cgi/admin/getAuthKey');
  const setAuthKey = require('./cgi/admin/setAuthKey');
  const enableGuest = require('./cgi/admin/enableGuest');
  const proxy = require('./cgi/proxy');
  const getEntryRules = require('./cgi/entryRules');
  const getPluginRules = require('./cgi/pluginRules');
  const changePassword = require('./cgi/account/changePassword');
  const exportSessions = require('./cgi/sessions/export');
  const importSessions = require('./cgi/sessions/import');
  const patterns = require('./cgi/patterns');
  const openAPI = require('./openAPI');
  const follow = require('./cgi/follow');
  const unfollow = require('./cgi/unfollow');
  const redirect = require('./cgi/redirect');
  const changeAdminPassword = require('./cgi/admin/changePassword');
  
  const forwardCapture = async (ctx, next) => {
    ctx.url = '/capture.html';
    await next();
  };
  
  module.exports = (router) => {
    router.get('/admin.html', checkAdminLogin);
    router.all('/cgi-bin/admin/**', checkAdminLogin);
    router.all('/cgi-bin/**', bodyParser({ formLimit: '6mb' }));
    router.all('/public-api/**', bodyParser({ formLimit: '1mb' }));
    router.get('/cgi-bin/list', list);
    router.get('/public-api/list', list);
    router.get('/cgi-bin/rules', getEntryRules);
    router.get('/cgi-bin/entry-rules', getEntryRules);
    router.get('/cgi-bin/remote-rules', getPluginRules);
    router.get('/cgi-bin/plugin-rules', getPluginRules);
    router.all('/network/**', proxyNetwork);
    router.post('/cgi-bin/sessions/export', exportSessions);
    router.get('/cgi-bin/sessions/import', importSessions);
    router.get('/data.html', forwardCapture);
    router.get('/cgi-bin/select', selectEnv);
    router.get('/public-api/select', selectEnv);
    router.get('/cgi-bin/admin/all-accounts', getAllAccounts);
    router.post('/cgi-bin/admin/add-account', addAccount);
    router.post('/cgi-bin/admin/move', moveAccount);
    router.post('/cgi-bin/admin/active-account', activeAccount);
    router.post('/cgi-bin/admin/remove-account', removeAccount);
    router.post('/cgi-bin/admin/change-password', changeAdminPassword);
    router.post('/cgi-bin/admin/enable-guest', enableGuest);
    router.post('/cgi-bin/admin/set-entry-patterns', setEntryPatterns);
    router.get('/cgi-bin/admin/get-settings', getSettings);
    router.post('/cgi-bin/admin/set-json-data', setJsonData);
    router.post('/cgi-bin/admin/set-rules-tpl', setRulesTpl);
    router.post('/cgi-bin/admin/set-test-rules', setTestRules);
    router.post('/cgi-bin/admin/set-default-rules', setDefaultRules);
    router.get('/cgi-bin/admin/get-auth-key', getAuthKey);
    router.post('/cgi-bin/admin/set-auth-key', setAuthKey);
    router.get('/cgi-bin/patterns', patterns);
    router.all('/account/:name/**', proxy);
    router.all('/user/:name', (ctx) => {
      const name = ctx.params.name.replace(/\..*$/, '');
      ctx.redirect(`../data.html?name=${name}`);
    });
    router.post('/cgi-bin/account/change-password', changePassword);
    router.all('/open-api/:cgiName', openAPI);
    router.get('/follow', follow);
    router.get('/unfollow', unfollow);
    router.get('/redirect', redirect);
  };
  