<?vsp
--
--  $Id$
--
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--
--  Copyright (C) 1998-2024 OpenLink Software
--
--  This project 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; only version 2 of the License, dated June 1991.
--
--  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
--
--

  adm_pre_page(lines);

  declare _have integer;
  declare _ip1, _ip2, _ip3, _ip4 integer;
  declare _mode, _access integer;
  declare _gr_name varchar;
  declare _gr_s_id varchar;
  declare _ip varchar;
  declare _vec any;
  declare _vec_o any;

  _ip1 := get_keyword ('ip1', params, '%');
  _ip2 := get_keyword ('ip2', params, '%');
  _ip3 := get_keyword ('ip3', params, '%');
  _ip4 := get_keyword ('ip4', params, '%');

  _gr_s_id := get_keyword ('n_group', params, '0');
  _mode := get_keyword ('mode', params, '');
  _access := get_keyword ('access', params, '');

  if (_gr_s_id <> '0')
    {
       _gr_s_id := atoi (subseq (_gr_s_id, 5));
    }
  else
    _gr_s_id := NULL;

  if (_access = '_a')
    _access := 0;
  else
    _access := 1;

  if (_mode = '_r')
    _mode := 0;
  else
    _mode := 1;

  if (get_keyword ('_add', params, '') <> '' and not _gr_s_id is NULL)
    {
      _ip := concat (_ip1, '.', _ip2, '.', _ip3, '.', _ip4);

      DB.DBA.news_acl_insert (_gr_s_id, _ip, _access, _mode);
    }

  if (get_keyword ('_upd', params, '') <> '' and not _gr_s_id is NULL)
    {
      _ip := concat (_ip1, '.', _ip2, '.', _ip3, '.', _ip4);
       _vec_o :=  deserialize (decode_base64 (get_keyword ('vec_o', params, '')));

      update DB.DBA.NEWS_ACL set NA_GROUP = _gr_s_id, NA_IP = _ip, NA_A_D = _access, NA_RW = _mode
	 where NA_GROUP = _vec_o [0] and NA_IP = _vec_o [1] and NA_A_D = _vec_o [2] and NA_RW = _vec_o [3];
    }

  if (get_keyword ('DEL', params, '') <> '')
    {
       _vec :=  deserialize (decode_base64 (get_keyword ('DEL', params, '')));

       delete from DB.DBA.NEWS_ACL where NA_GROUP = _vec [0] and NA_IP = _vec [1] and
	   NA_A_D = _vec [2] and NA_RW = _vec [3];

    }

  if (get_keyword ('EDIT', params, '') <> '')
    {
       _vec_o := get_keyword ('EDIT', params, '');
       _vec :=  deserialize (decode_base64 (_vec_o));

       _gr_s_id := _vec[0];
       _ip := _vec[1];
       _access := _vec [2];
       _mode := _vec [3];

       _ip1 := "LEFT" (_ip, strstr (_ip, '.'));
       _ip := subseq (_ip,  strstr (_ip, '.') + 1);
       _ip2 := "LEFT" (_ip, strstr (_ip, '.'));
       _ip := subseq (_ip,  strstr (_ip, '.') + 1);
       _ip3 := "LEFT" (_ip, strstr (_ip, '.'));
       _ip4 := subseq (_ip,  strstr (_ip, '.') + 1);
    }

?>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="<?=adm_what_css()?>">
    <meta name="AUTHOR" content="OpenLink Software">
    <meta name="DESCRIPTION" content="Access Control List Page Virtuoso NNTP Server">
    <title>Internet News Search</title>
  </head>
<?vsp adm_page_header('NNTP Access Control List Manager', ''); ?>

    <TABLE CLASS="genlist" BORDER="0" CELLPADDING="0">
    <FORM name="main_form" method="POST" action="news_acl.vsp">
     <TR><TD COLSPAN="6" CLASS="genhead">Access Control List</TD></TR>
     <TR><TD CLASS="AdmBorders" COLSPAN="6"><IMG SRC="../admin/images/1x1.gif" WIDTH="1" HEIGHT="2" ALT=""></TD></TR>
	<TR>
	   <TD CLASS="genlistheadt">Group name</TD>
	   <TD CLASS="genlistheadt">Client IP</TD>
	   <TD CLASS="genlistheadt">Access</TD>
	   <TD CLASS="genlistheadt">Mode</TD>
	   <TD CLASS="genlistheadt" COLSPAN="2">Action</TD>
	</TR>
<?vsp
	_have := 0;

	for (select * from DB.DBA.NEWS_ACL) do
	  {
	     _vec := encode_base64 (serialize (vector (NA_GROUP, NA_IP, NA_A_D, NA_RW)));

	     select NG_NAME into _gr_name from DB.DBA.NEWS_GROUPS where NG_GROUP = NA_GROUP;
	     _have := _have + 1;

	     http (sprintf ('<TR><TD class="statdata">%s</TD><TD class="statdata">%s</TD><TD>', _gr_name, NA_IP));

	     if (NA_A_D)
	       http ('<font color=ff0020>deny</font>');
	     else
	       http ('allow');

	     http ('</TD><TD>');

	     if (NA_RW)
	       http ('post');
	     else
	       http ('<font color=ff0020>read</font>');

	     http ('</TD>');
?>
          <TD CLASS="statdata"><a CLASS="tablelistaction" href="news_acl.vsp?DEL=<?=_vec?>">remove</a></TD>
          <TD CLASS="statdata"><a CLASS="tablelistaction" href="news_acl.vsp?EDIT=<?=_vec?>">edit</a></TD>
 	</TR>
<?vsp
	  }

	if (_have = 0)
    	   http ('<TR><TD  CLASS="gendata" COLSPAN="6"><sTRong>Empty access list</sTRong><br /> click \'Add\' to new restriction</TD></TR>');

	if (get_keyword ('_add', params, '') <> '' or
	    get_keyword ('EDIT', params, '') <> '')
	  {
?>
	<TR><TD COLSPAN="6">
	<TABLE BORDER="0" WIDTH="100%">
	   <TR><TD COLSPAN="2"><IMG SRC="../admin/images/1x1.gif" WIDTH="1" HEIGHT="15" ALT=""></TD></TR>
           <TR>
             <TD CLASS="genlisthead">Group name:</TD><TD>
	       <SELECT NAME="n_group">
<?vsp
		for (select NG_NAME, NG_GROUP from NEWS_GROUPS) do
		  {
		    if (_gr_s_id = NG_GROUP)
		      http (sprintf ('<OPTION VALUE="__gr_%i" SELECTED>%s</OPTION>', NG_GROUP, NG_NAME));
		    else
		      http (sprintf ('<OPTION VALUE="__gr_%i">%s</OPTION>', NG_GROUP, NG_NAME));
		  }
?>
	       </SELECT>
	     </TD></TR>
	     <TR><TD CLASS="genlisthead">Client IP</TD>
	     <TD>
	       <INPUT type="text" name="ip1" value="<?=_ip1?>" size="3">.
	       <INPUT type="text" name="ip2" value="<?=_ip2?>" size="3">.
	       <INPUT type="text" name="ip3" value="<?=_ip3?>" size="3">.
	       <INPUT type="text" name="ip4" value="<?=_ip4?>" size="3">
	     </TD></TR>
	     <TR><TD CLASS="genlisthead">Access</TD>
	     <TD>
	       <SELECT NAME="access">
	         <OPTION VALUE="_d" <?vsp if (_access) http ('SELECTED'); ?>>Deny</OPTION>
	         <OPTION VALUE="_a" <?vsp if (not _access) http ('SELECTED'); ?>>Allow</OPTION>
	       </SELECT>
	     </TD></TR>
	     <TR><TD CLASS="genlisthead">Mode</TD>
	     <TD>
	       <SELECT NAME="mode">
	         <OPTION VALUE="_p" <?vsp if (_mode) http ('SELECTED'); ?>>Post</OPTION>
	         <OPTION VALUE="_r" <?vsp if (not _mode) http ('SELECTED'); ?>>Read</OPTION>
	       </SELECT>
	     </TD></TR>
       </TABLE>
<?vsp
	  }
?>
	<TR><TD ALIGN="right" COLSPAN="6">
<?vsp
	 if (get_keyword ('EDIT', params, '') <> '')
	   {
	     http ('<INPUT TYPE="submit" NAME="_upd" VALUE="Update">');
	     http (sprintf ('<INPUT TYPE="hidden" NAME="vec_o" VALUE="%s">', _vec_o));
	   }
	 else
	   http ('<INPUT TYPE="submit" NAME="_add" VALUE="Add">');
?>
	</TD></TR>
    </TABLE>

<?vsp adm_page_footer(); ?>
</html>

