Skip to content

Feature form rights #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- charset is now utf8 by Michal Švamberg
- add import CAA records into Custom zone file entries by Michal Švamberg
- fix import of multiple TXT zone records by Michal Švamberg
- forms can be limited by restrict.yaml file by Michal Švamberg

0.7.4
[project moved to sourceforge and switched to use git instead of cvs]
Expand Down
3 changes: 3 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ install: make_dirs
$(INSTALL_ROOT)/$(etcdir)/config-browser; \
$(PERL) -p -i -e 's@^\$$PROG_DIR = "/usr/local/sauron/";@\$$PROG_DIR = "$(bindir)/";@;' $(INSTALL_ROOT)/$(etcdir)/config-browser; \
fi
if [ ! -f $(INSTALL_ROOT)/$(etcdir)/restrict.yaml ]; then \
$(INSTALL) -m 644 restrict.yaml $(INSTALL_ROOT)/$(etcdir)/restrict.yaml; \
fi
@for f in $(PROGS); do \
$(INSTALL) -m 755 $$f $(INSTALL_ROOT)/$(bindir); \
done
Expand Down
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ REQUIREMENTS
- MIME::Base64
- Crypt::Cipher::RC5
- Text::Table
- YAML::XS module
- PostgresSQL [7.4 or newer (may work fine with earlier 7.x versions)]
(or add support to your favorite db yourself :)
- www-server (Apache or any other www-server with CGI support)
Expand Down
56 changes: 56 additions & 0 deletions Sauron/CGIutil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use Sauron::DB;
use Sauron::Util;
use Sauron::BackEnd;
use Net::IP qw(:PROC);
use YAML::XS 'LoadFile';
use Data::Dumper;

use strict;
use vars qw(@ISA @EXPORT);
Expand Down Expand Up @@ -46,6 +48,58 @@ our $inetFamily6 = 0;
our $inetNet = undef;
our $formduid = undef;

my $restrict_cache = undef;

sub is_restricted($) {
my ($tag) = @_;
return 0 if $tag =~/^$/;
return 0 if (%main::state{superuser} eq 'yes'); # superuser is always permitted
my (@q, $group, $rtag);
my $module=(split /::/, (caller(1))[0])[-1];
my $restrict_file = $main::CONFIG_FILE;
$restrict_file =~ s/[^\/]+$/restrict.yaml/;

if (!$restrict_cache) {
if (-e $restrict_file) {
$restrict_cache = LoadFile($restrict_file);
}
else {
return 0; # not restricted (false), config file is not exists
}
}

db_query("SELECT g.name FROM user_groups g, user_rights r " .
"WHERE g.id=r.rref AND r.rtype=0 AND r.type=2 AND r.ref=$main::state{uid} " .
" ORDER BY g.id;",\@q);

#print "<pre>" . Dumper (@{$q[0]}) . "</pre>\n";
return 0 if (scalar(@{$q[0]}) == 0); # user is not listed in any group

foreach $group (@{$q[0]}) {
# pro kazdou skupinu precti seznam tagu, pokud tento tag v nejake chybi, dej false
#print "<pre>" . Dumper($restrict_cache) . "</pre>\n";
#print "<pre>group: $group\nmodule: $module\n</pre>";

if (exists $restrict_cache->{$group}->{$module}) {
my @list = @{$restrict_cache->{$group}->{$module}};

# Ověřit, zda $test je v seznamu
if (grep { $_ eq $tag } @list) {
#print "Prvek '$tag' je v seznamu pro skupinu $group v $module.\n";
} else {
#print "Prvek '$tag' NENI v seznamu pro skupinu $group v $module.\n";
return 0;
}
}
else {
#print "Restrict $group->$module neexistuje <br>\n";
return 0;
}
}
# je ve vsech skupinach, vracim true (je restricted)
return 1;
}

sub cgi_util_set_zone($$) {
my ($id,$name) = @_;
$CGI_UTIL_zoneid = $id;
Expand Down Expand Up @@ -599,6 +653,8 @@ sub form_magic($$$) {
next unless ($val =~ /^($e)$/);
}
next if ($rec->{no_edit});
# TODO
next if is_restricted($rec->{tag});

print "<TR ".($form->{bgcolor}?" bgcolor=\"$form->{bgcolor}\" ":'').">";

Expand Down
18 changes: 18 additions & 0 deletions restrict.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# List of group/package/tag from forms that will be restricted (not showed).
# Sauron used same path as 'config' file location (typicaly /usr/local/etc/sauron/)

# structure and commands for listing items
#
# <group_name>: # ./modgroup --list
# <perl_package_name>: # grep ^package /usr/local/sauron/Sauron/CGI/*.pm
# - <tag_name> # grep 'tag=>' /usr/local/sauron/Sauron/CGI/*.pm
# - <tag_name>

sample:
Hosts:
- mx
- expiration

Zones:
- mx