diff --git a/includes/permissions.inc.php b/includes/permissions.inc.php index 3869863..c007e98 100644 --- a/includes/permissions.inc.php +++ b/includes/permissions.inc.php @@ -90,6 +90,22 @@ function set_permissions($userid,$groupid,$zone,$permissions) { } } +// Interface function - Copy permissions from one zone to another - used for cloning, so assumes no existing permissions on the domain + +function copy_permissions($srczone,$dstzone) { + $db = get_db(); + + $q = $db->prepare('SELECT p.user,p."group",p.permissions FROM permissions p, zones z WHERE p.zone=z.id AND z.zone=?'); + $q->bindValue(1, $srczone, SQLITE3_TEXT); + $result = $q->execute(); + + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + set_permissions($row['user'],$row['group'],$dstzone,$row['permissions']); + } + + return null; +} + // Interface function - Update permissions for a zone function update_permissions($id,$permissions) { global $permissionmap; diff --git a/index.php b/index.php index e380145..0b4d5df 100644 --- a/index.php +++ b/index.php @@ -1055,6 +1055,13 @@ $(document).ready(function () { title: 'Domain', inputClass: 'destname' }, + copypermissions: { + title: 'Copy Permissions', + type: 'checkbox', + values: {'0': 'No', '1': 'Yes'}, + defaultValue: 1, + inputClass: 'copypermissions' + }, account: { title: 'Owner', options: function(data) { diff --git a/zones.php b/zones.php index 44ef601..74cad32 100644 --- a/zones.php +++ b/zones.php @@ -522,6 +522,7 @@ case "export": case "clone": $name = $_POST['destname']; $src = $_POST['sourcename']; + $copypermissions = $_POST['copypermissions']; if (!is_adminuser() and $allowzoneadd !== true) { jtable_respond(null, 'error', "You are not allowed to add zones"); @@ -566,6 +567,10 @@ case "clone": $zone = $api->savezone($srczone->export()); + if($copypermissions==1) { + copy_permissions($src,$name); + } + writelog("Cloned zone $src into $name"); jtable_respond($zone, 'single'); break;