Make hourly limit settable per-user too
authorJamie Cameron <jcameron@webmin.com>
Mon, 28 Apr 2008 02:11:14 +0000 (02:11 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 28 Apr 2008 02:11:14 +0000 (02:11 +0000)
cron/CHANGELOG
cron/acl_security.pl
cron/cron-lib.pl
cron/defaultacl
cron/lang/en

index b91623d..bb13a23 100644 (file)
@@ -28,3 +28,5 @@ Handle the daily / monthly / weekly Cron specification used on Ubuntu 7.
 ---- Changes since 1.400 ----
 Fixed a bug that prevented new cron jobs from being created unless the 'Date range to execute' setting was changed.
 Added a check for a valid module configuration, especially the cron jobs directory, to prevent accidental deletion of jobs.
+---- Changes since 1.410 ----
+Added an access control option to prevent individual Webmin users from creating cron jobs that run more often than hourly.
index 4ddaa7d..acfb8d8 100644 (file)
@@ -6,63 +6,56 @@ do '../ui-lib.pl';
 # Output HTML for editing security options for the cron module
 sub acl_security_form
 {
-print "<tr> <td valign=top><b>$text{'acl_users'}</b></td> <td colspan=3>\n";
-printf "<input type=radio name=mode value=0 %s> $text{'acl_all'}<br>\n",
-       $_[0]->{'mode'} == 0 ? "checked" : "";
-
-printf "<input type=radio name=mode value=3 %s> $text{'acl_this'}<br>\n",
-       $_[0]->{'mode'} == 3 ? "checked" : "";
-
-printf "<input type=radio name=mode value=1 %s> $text{'acl_only'}\n",
-       $_[0]->{'mode'} == 1 ? "checked" : "";
-printf "<input name=userscan size=40 value='%s'> %s<br>\n",
-       $_[0]->{'mode'} == 1 ? $_[0]->{'users'} : "",
-       &user_chooser_button("userscan", 1);
-
-printf "<input type=radio name=mode value=2 %s> $text{'acl_except'}\n",
-       $_[0]->{'mode'} == 2 ? "checked" : "";
-printf "<input name=userscannot size=40 value='%s'> %s<br>\n",
-       $_[0]->{'mode'} == 2 ? $_[0]->{'users'} : "",
-       &user_chooser_button("userscannot", 1);
-
-printf "<input type=radio name=mode value=5 %s> $text{'acl_gid'}\n",
-       $_[0]->{'mode'} == 5 ? "checked" : "";
-printf "<input name=gid size=8 value='%s'> %s<br>\n",
-       $_[0]->{'mode'} == 5 ? scalar(getgrgid($_[0]->{'users'})) : "",
-       &group_chooser_button("gid", 0);
-
-printf "<input type=radio name=mode value=4 %s> $text{'acl_uid'}\n",
-       $_[0]->{'mode'} == 4 ? "checked" : "";
-printf "<input name=uidmin size=6 value='%s'> -\n",
-       $_[0]->{'mode'} == 4 ? $_[0]->{'uidmin'} : "";
-printf "<input name=uidmax size=6 value='%s'></td> </tr>\n",
-       $_[0]->{'mode'} == 4 ? $_[0]->{'uidmax'} : "";
-
-print "<tr> <td><b>$text{'acl_control'}</b></td>\n";
-print "<td>",&ui_radio("allow", $_[0]->{'allow'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td>\n";
-
-print "<td><b>$text{'acl_command'}</b></td>\n";
-print "<td>",&ui_radio("command", $_[0]->{'command'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td> </tr>\n";
-
-print "<tr> <td><b>$text{'acl_create'}</b></td>\n";
-print "<td>",&ui_radio("create", $_[0]->{'create'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td>\n";
-
-print "<td><b>$text{'acl_delete'}</b></td>\n";
-print "<td>",&ui_radio("delete", $_[0]->{'delete'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td> </tr>\n";
-
-print "<tr> <td><b>$text{'acl_move'}</b></td>\n";
-print "<td>",&ui_radio("move", $_[0]->{'move'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td>\n";
-
-print "<td><b>$text{'acl_kill'}</b></td>\n";
-print "<td>",&ui_radio("kill", $_[0]->{'kill'},
-       [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]),"</td> </tr>\n";
-
-print "</tr>\n";
+local $m = $_[0]->{'mode'};
+print &ui_table_row($text{'acl_users'},
+       &ui_radio("mode", $m,
+        [ [ 0, "$text{'acl_all'}<br>" ],
+          [ 3, "$text{'acl_this'}<br>" ],
+          [ 1, $text{'acl_only'}." ".
+               &ui_textbox("userscan",
+                       $m == 1 ? $_[0]->{'users'} : "", 40)." ".
+               &user_chooser_button("userscan", 1)."<br>" ],
+          [ 2, $text{'acl_except'}." ".
+               &ui_textbox("userscannot",
+                       $m == 2 ? $_[0]->{'users'} : "", 40)." ".
+               &user_chooser_button("userscannot", 1)."<br>" ],
+          [ 5, $text{'acl_gid'}." ".
+               &ui_textbox("gid",
+                   $m == 5 ? scalar(getgrgid($_[0]->{'users'})) : "", 13)." ".
+               &group_chooser_button("gid", 0)."<br>" ],
+          [ 4, $text{'acl_uid'}." ".
+               &ui_textbox("uidmin", $_[0]->{'uidmin'}, 6)." - ".
+               &ui_textbox("uidmax", $_[0]->{'uidmax'}, 6)."<br>" ],
+        ]), 3);
+
+print &ui_table_row($text{'acl_control'},
+       &ui_radio("allow", $_[0]->{'allow'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_command'},
+       &ui_radio("command", $_[0]->{'command'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_create'},
+       &ui_radio("create", $_[0]->{'create'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_delete'},
+       &ui_radio("delete", $_[0]->{'delete'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_move'},
+       &ui_radio("move", $_[0]->{'move'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_kill'},
+       &ui_radio("kill", $_[0]->{'kill'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
+
+print &ui_table_row($text{'acl_hourly'},
+       &ui_radio("hourly", $_[0]->{'hourly'},
+               [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ],
+                 [ 2, $text{'acl_hourlydef'} ] ]), 3);
 }
 
 # acl_security_save(&options)
@@ -83,5 +76,6 @@ $_[0]->{'create'} = $in{'create'};
 $_[0]->{'delete'} = $in{'delete'};
 $_[0]->{'move'} = $in{'move'};
 $_[0]->{'kill'} = $in{'kill'};
+$_[0]->{'hourly'} = $in{'hourly'};
 }
 
index a5b73b4..d394b30 100644 (file)
@@ -12,9 +12,13 @@ if ($module_info{'usermin'}) {
        &switch_to_remote_user();
        &create_user_config_dirs();
        $range_cmd = "$user_module_config_directory/range.pl";
+       $hourly_only = 0;
        }
 else {
        $range_cmd = "$module_config_directory/range.pl";
+       $hourly_only = $access{'hourly'} == 0 ? 0 :
+                      $access{'hourly'} == 1 ? 1 :
+                       $config{'hourly_only'};
        }
 $temp_delete_cmd = "$module_config_directory/tempdelete.pl";
 $cron_temp_file = &transname();
@@ -691,18 +695,18 @@ foreach $arr ("mins", "hours", "days", "months", "weekdays") {
        # Output selection list
        print "<td valign=top>\n";
         printf "<input type=radio name=all_$arr value=1 %s %s> $text{'edit_all'}<br>\n",
-                $arr eq "mins" && $config{'hourly_only'} ? "disabled" : "",
+                $arr eq "mins" && $hourly_only ? "disabled" : "",
                $job->{$arr} eq "*" ? "checked" : "";
        printf "<input type=radio name=all_$arr value=0 %s> $text{'edit_selected'}<br>\n",
                $job->{$arr} ne "*" ? "checked" : "";
        print "<table> <tr>\n";
-        for($j=0; $j<@$arr; $j+=($arr eq "mins" && $config{'hourly_only'} ? 60 : 12)) {
-                $jj = $j+($arr eq "mins" && $config{'hourly_only'} ? 59 : 11);
+        for($j=0; $j<@$arr; $j+=($arr eq "mins" && $hourly_only ? 60 : 12)) {
+                $jj = $j+($arr eq "mins" && $hourly_only ? 59 : 11);
                if ($jj >= @$arr) { $jj = @$arr - 1; }
                @sec = @$arr[$j .. $jj];
                 printf "<td valign=top><select %s size=%d name=$arr>\n",
-                        $arr eq "mins" && $config{'hourly_only'} ? "" : "multiple",
-                        @sec > 12 ? ($arr eq "mins" && $config{'hourly_only'} ? 1 : 12) : scalar(@sec);
+                        $arr eq "mins" && $hourly_only ? "" : "multiple",
+                        @sec > 12 ? ($arr eq "mins" && $hourly_only ? 1 : 12) : scalar(@sec);
                foreach $v (@sec) {
                        if ($v =~ /^(.*)=(.*)$/) { $disp = $1; $code = $2; }
                        else { $disp = $code = $v; }
index fcabff6..2104b66 100644 (file)
@@ -7,3 +7,4 @@ create=1
 delete=1
 move=1
 kill=1
+hourly=2
index 2f76e3f..5ef27f0 100644 (file)
@@ -118,6 +118,8 @@ acl_create=Can create Cron jobs?
 acl_delete=Can delete Cron jobs?
 acl_move=Can move Cron jobs?
 acl_kill=Can terminate Cron jobs?
+acl_hourly=Limit jobs to at most hourly?
+acl_hourlydef=As set in Module Config
 
 log_modify=Modified Cron job for $1
 log_modify_l=Modified Cron job "$2" for $1