Changeset 292
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r290 r292 1732 1732 # Add a group 1733 1733 # Takes a database handle, group name, parent group, hashref for permissions, 1734 # and optional template-vs-cloneme flag 1734 # and optional template-vs-cloneme flag for the default records 1735 1735 # Returns a status code and message 1736 1736 sub addGroup { … … 1751 1751 local $dbh->{RaiseError} = 1; 1752 1752 1753 my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?"); 1754 my $group_id; 1755 1756 # quick check to start to see if we've already got one 1757 $sth->execute($groupname); 1758 ($group_id) = $sth->fetchrow_array; 1753 my ($group_id) = $dbh->selectrow_array("SELECT group_id FROM groups WHERE group_name=?", undef, ($groupname)); 1759 1754 1760 1755 return ('FAIL', "Group already exists") if $group_id; … … 1762 1757 # Wrap all the SQL in a transaction 1763 1758 eval { 1764 $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)"); 1765 $sth->execute($pargroup,$groupname); 1766 1767 my ($groupid) = $dbh->selectrow_array("SELECT group_id FROM groups WHERE group_name=?", undef, ($groupname)); 1768 1769 # Permissions 1770 if ($inherit) { 1771 } else { 1772 my @permvals; 1773 foreach (@permtypes) { 1774 if (!defined ($permissions->{$_})) { 1775 push @permvals, 0; 1776 } else { 1777 push @permvals, $permissions->{$_}; 1778 } 1759 $dbh->do("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)", undef, ($pargroup, $groupname) ); 1760 1761 my ($groupid) = $dbh->selectrow_array("SELECT currval('groups_group_id_seq')"); 1762 1763 # We work through the whole set of permissions instead of specifying them so 1764 # that when we add a new permission, we don't have to change the code anywhere 1765 # that doesn't explicitly deal with that specific permission. 1766 my @permvals; 1767 foreach (@permtypes) { 1768 if (!defined ($permissions->{$_})) { 1769 push @permvals, 0; 1770 } else { 1771 push @permvals, $permissions->{$_}; 1779 1772 } 1780 1781 $sth = $dbh->prepare("INSERT INTO permissions (group_id,$permlist) values (?".',?'x($#permtypes+1).")"); 1782 $sth->execute($groupid,@permvals); 1783 1784 $sth = $dbh->prepare("SELECT permission_id FROM permissions WHERE group_id=?"); 1785 $sth->execute($groupid); 1786 my ($permid) = $sth->fetchrow_array(); 1787 1788 $dbh->do("UPDATE groups SET permission_id=$permid WHERE group_id=$groupid"); 1789 } # done permission fiddling 1790 1791 # Default records 1773 } 1774 $dbh->do("INSERT INTO permissions (group_id,$permlist) values (?".',?'x($#permtypes+1).")", 1775 undef, ($groupid, @permvals) ); 1776 my ($permid) = $dbh->selectrow_array("SELECT currval('permissions_permission_id_seq')"); 1777 $dbh->do("UPDATE groups SET permission_id=$permid WHERE group_id=$groupid"); 1778 1779 # Default records 1792 1780 my $sthf = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ". 1793 1781 "VALUES ($groupid,?,?,?,?,?,?,?)"); … … 1803 1791 } 1804 1792 # And now the reverse records 1805 $sth2 = $dbh->prepare("SELECT group_id,host,type,val,ttl FROM default_rev_records WHERE group_id=?");1793 $sth2 = $dbh->prepare("SELECT host,type,val,ttl FROM default_rev_records WHERE group_id=?"); 1806 1794 $sth2->execute($pargroup); 1807 1795 while (my @clonedata = $sth2->fetchrow_array) { … … 1823 1811 } 1824 1812 1813 _log($dbh, (group_id => $pargroup, entry => "Added group $groupname") ); 1814 1825 1815 # once we get here, we should have suceeded. 1826 1816 $dbh->commit; … … 1830 1820 my $msg = $@; 1831 1821 eval { $dbh->rollback; }; 1822 if ($config{log_failures}) { 1823 _log($dbh, (group_id => $pargroup, entry => "Failed to add group $groupname: $msg") ); 1824 $dbh->commit; 1825 } 1832 1826 return ('FAIL',$msg); 1833 } else { 1834 return ('OK','OK'); 1835 } 1836 1827 } 1828 1829 return ('OK','OK'); 1837 1830 } # end addGroup() 1838 1831 -
trunk/dns.cgi
r291 r292 933 933 my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup}, \%newperms); 934 934 if ($code eq 'OK') { 935 logaction(0, $session->param("username"), $webvar{pargroup}, "Added group $webvar{newgroup}");936 935 if ($alterperms) { 937 936 changepage(page => "grpman", warnmsg => … … 941 940 } 942 941 } # fallthrough else 943 logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg")944 if $config{log_failures};945 942 # no point in doing extra work 946 943 fill_permissions($page, \%newperms);
Note:
See TracChangeset
for help on using the changeset viewer.