aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--imagecache_auto.admin.inc9
-rw-r--r--imagecache_auto.inc21
2 files changed, 30 insertions, 0 deletions
diff --git a/imagecache_auto.admin.inc b/imagecache_auto.admin.inc
index 4d31bc5..9b8efcb 100644
--- a/imagecache_auto.admin.inc
+++ b/imagecache_auto.admin.inc
@@ -32,5 +32,14 @@ function imagecache_auto_admin_settings() {
'#description' => t('The maximum height an automatically created ImageCache preset can have.'),
);
+ $form['imagecache_auto_max_presets'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Maximum number of presets'),
+ '#default_value' => variable_get('imagecache_auto_max_presets', '250'),
+ '#size' => 10,
+ '#maxlength' => 64,
+ '#description' => t('The maximum number of total imagecache presets before ImageCache auto refuses to create additional presets. This might prevent abuses from malicious clients.'),
+ );
+
return system_settings_form($form);
}
diff --git a/imagecache_auto.inc b/imagecache_auto.inc
index 3541ba3..1b0fe7d 100644
--- a/imagecache_auto.inc
+++ b/imagecache_auto.inc
@@ -39,6 +39,14 @@ function imagecache_auto_create_preset($options) {
return;
}
+ // Check if maximum number of presets was reached.
+ $max_presets = (int) variable_get('imagecache_auto_max_presets', '250');
+ if (imagecache_auto_count_presets() > $max_presets + 1) {
+ $message = 'Maximum number of imagecache presets reached. Please consider increasing the max number of presets.';
+ watchdog('imagecache_auto', $message, array(), WATCHDOG_ERROR);
+ return;
+ }
+
// Create a preset.
$preset = imagecache_preset_save(array('presetname' => $name));
@@ -120,3 +128,16 @@ function imagecache_auto_presets() {
return $presets;
}
+
+/**
+ * Count number of existing imagecache presets.
+ *
+ * @return
+ * Number of existing presets.
+ */
+function imagecache_auto_count_presets() {
+ $query = 'SELECT COUNT(presetid) AS count FROM imagecache_preset';
+ $result = db_query($query);
+ $count = db_fetch_object($result);
+ return $count->count;
+}