How to allow http
-
How can I allow http for accessing my immich server. I have a self-hosted server and don’t want (or need) a ssl certificate.
Looking forward to using this plugin.
Thanks!
-
A single prompt in Google Antigravity enabled it for me. Here is a summary:
Developer Guide: Enabling HTTP and SSL Support
This guide explains how to modify the Gallery for Immich WordPress plugin to allow HTTP connections (for local network setups) and add an SSL verification toggle (for self-signed certificates). 1. Loosen URL Validation
In the original plugin, the Immich server URL is restricted to HTTPS unless it is
localhostor127.0.0.1. To allow any HTTP URL (likehttp://192.168.1.50:2283), follow these steps: Updatesanitize_settings()Find the
sanitize_settingsfunction ingallery-for-immich.phpand modify the URL check:- // Original: Ensure it's HTTPS in production (or localhost for dev) - if (strpos($url, 'https://') === 0 || strpos($url, 'http://localhost') === 0 || strpos($url, 'http://127.0.0.1') === 0) { + // Modified: Ensure it's HTTPS or HTTP (allows local network URLs) + if (strpos($url, 'https://') === 0 || strpos($url, 'http://') === 0) { $sanitized['server_url'] = rtrim($url, '/'); } else { add_settings_error( $this->option_name, 'invalid_url', - __('Server URL must use HTTPS (or localhost for development).', 'gallery-for-immich') + __('Server URL must use HTTPS (preferred) or HTTP.', 'gallery-for-immich') ); }2. Add SSL Verification Setting
To help users with self-signed certificates on their local network, you can add an “SSL Verification” toggle. Update
settings_init()Register the new field in the
settings_initfunction:add_settings_field('ssl_verify', __('SSL Verification', 'gallery-for-immich'), [$this, 'field_ssl_verify'], 'gallery_for_immich', 'gallery_for_immich_section');Add the
field_ssl_verify()MethodAdd this method to render the checkbox in the settings page:
public function field_ssl_verify() { $options = get_option($this->option_name); $checked = isset($options['ssl_verify']) ? (bool)$options['ssl_verify'] : true; ?> <label> <input type="checkbox" name="<?php echo esc_attr($this->option_name); ?>[ssl_verify]" value="1" <?php checked($checked); ?>> <?php echo esc_html__('Verify SSL certificates (uncheck for self-signed certificates on local networks)', 'gallery-for-immich'); ?> </label> <?php }Update
sanitize_settings()againEnsure the new field is saved:
// Add this line at the end of sanitize_settings() before the return $sanitized['ssl_verify'] = !empty($input['ssl_verify']);3. Respect the SSL Setting in API Requests
Finally, update all WordPress remote request calls (
wp_remote_get,wp_remote_post,wp_remote_request) to use the new setting. Example forapi_request()Find where
wp_remote_getis called and update thesslverifyparameter:$response = wp_remote_get($url, [ 'headers' => [ ... ], 'timeout' => 15, - 'sslverify' => true + 'sslverify' => isset($options['ssl_verify']) ? (bool)$options['ssl_verify'] : true ]);[!NOTE]
You must also apply this change tohandle_image_proxy(),get_video_url_with_shared_link(), andcleanup_shared_link().Summary Checklist
- [ ] Change
strposcheck to allow anyhttp://prefix. - [ ] Update the localized error message string.
- [ ] Register the
ssl_verifysetting field. - [ ] Add the
field_ssl_verifyUI method. - [ ] Ensure
sanitize_settingssaves the checkbox value (boolean). - [ ] Pass the dynamic boolean to the
sslverifykey in all remote requests.
I chose forcing HTTPS because it enforces safety, localhost and 127.0.0.1 are the only exceptions because that _really_ is local.
I still think this is the way to go, you can try to convince me otherwise.
Sietse
Thanks for the tip about editing the plugin code. I’ve commented out a bit of the code and it works now.
I can understand having the option to secure the plugin via ssl but I think it should be up to us users if we want (or need) to implement it. Not to mention, it’s cumbersome to set up ssl with immich without added work or expense.
Thanks for all your work!
-
This reply was modified 1 month, 3 weeks ago by
johnd126.
I just released v0.7.0 – it allows http:// but you will get a warning whether this is really what you want.
Thanks for using this plugin!
Sietse
I updated. The warning is a great compromise. Thanks!
- [ ] Change
You must be logged in to reply to this topic.