/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include const mstring default_tag=".default"; ///////////////////////////////////////////////////////////////// TOK_IMPL(remote_name) { out<tcp->node.name; } TOK_IMPL(remote_address) { out<tcp->node.ip; } TOK_IMPL(remote_port) { out<tcp->port; } ///////////////////////////////////////////////////////////////// inline int match(const sref& rem,const sref& longrem,const sref& dom) { if(rem==dom) return 1; if(*dom!='.') return 0; if(longrem.right_last(dom)==dom) return 1; return 0; } inline int allow(const sref& uname,const sref& list) { mstring remote=First(uname); mstring longrem=remote; if(longrem.find('.')<0) longrem+=default_tag; if(remote.empty()) return 0; if(First(list).empty()) return 1; sref first,rest=list; while(Split(first,rest)) if(match(remote,longrem,first)) return 1; return 0; } TOK_IMPL(remote_allow) { out<tcp->node.name,env[0]); } TOK_IMPL(bindroot) { Reqd(env)->htcd()->bindroot=env[0]; } ///////////////////////////////////////////////////////////////// TOK_IMPL(user_allow) { htcd_req* htcd=Reqd(env); mstring opt=env.parg(-1); int now=opt.empty()?time(0):atoi(opt); out<user.allow_list(env[0],now,htcd->RootAllowed()); } TOK_IMPL(on_clear) { htcd_req* htcd=Reqd(env); if(htcd->user.allow_list(env[0],time(0),htcd->RootAllowed())) env.parg(out,1); else env.parg(out,2); } ///////////////////////////////////////////////////////////////// TOK_IMPL(allowed) { int ok=0; if(!env.db) THROW("htc: no open database"); if(env.dbat>=0&&env.dbatsize()) { user_t user; env.db->Get(env.dbat,user.list); if(user.list.size()!=user_tabs) THROW("htc: cannot test - probably not a users database"); mstring opt=env.parg(-1); int now=opt.empty()?time(0):atoi(opt); ok=user.allow_list(env[0],now,Reqd(env)->RootAllowed()); } out<=0&&env.dbatsize()) { user_t user; env.db->Get(env.dbat,user.list); if(user.list.size()!=user_tabs) THROW("htc: cannot test - probably not a users database"); mstring opt=env.parg(-1); int now=opt.empty()?time(0):atoi(opt); ok=user.allow_list(env[0],now,-1); } out<\n" "%\n" "%In case of several groups, all must be allowed.\n" ); TOK_ADD(on_clear,"xr?",tok_t::SYSONLY, "%Do if user is allowed in all groups now\n" "%Syntax: \\on.clear{groups}{body}\n" ); ///////////////////////////////////////////////////////////// TOK_ADD(allowed,"x?",tok_t::SYSONLY, "%True if the current record is allowed in all groups now\n" "%Syntax: \\allowed{groups}