elFinder as a Web File Manager or Web FTP for ISPConfig

Discussion in 'Tips/Tricks/Mods' started by ahrasis, Sep 9, 2023.

  1. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    While I was just checking some old code, I think I should write and share this script though I haven't perfected it yet, hopefully those who were looking for it for their ISPconfig server may use it. I wrote it with the intention to create a bash file that can run with a cron job, so it may be automatically updated to latest version thus less maintenance.
    Code:
    # Define elfinder directory
    elfinder=/usr/share/elfinder
    # Create it if does not exist
    if [ ! -d "$elfinder" ]; then
       mkdir -p $elfinder
    else
    # If it exists, go to it
       cd $elfinder
       currentversion=$(grep -i "version" package.json | cut -d : -f 2,3 | cut -d '"' -f2)
       lattestversion=$(curl -s https://api.github.com/repos/Studio-42/elFinder/releases/latest | grep "tag_name*" | cut -d : -f 2,3 | cut -d '"' -f2)
       # If older file exists, back it up
       if [[ -e "elfinder.html" ] && [ -e "package.json" ]]; then cp elfinder.html elfinder-html-$currentversion.bak
    fi
    # Check if package.json exists to proceed
    if [ ! -e "package.json" ] || [[ -e "package.json" ] && [ $currentversion != $lattestversion]]; then
       # Proceed if both versions are not the same
       wget https://github.com/Studio-42/elFinder/archive/$lattestversion.tar.gz
       # This will overwrite any existing files and folders, thus updating as well.
       tar -xvf $lattestversion.tar.gz --strip-components=1
       # This is necessary to make it full in browser
       sed -i '/defaultOpts/a \\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '99.7%',\n\t\t\t\t\tresizable: false,' elfinder.html
       # Symlink is preferred rather than rename
       ln -sf elfinder.html index.html
    fi
    # Define filemanager directory and symlink if doesn't exist
    filemanager=/usr/share/filemanager
    if [ ! -d "$filemanager" ]; then ln -sf $elfinder $filemanager; fi
    
    Now, to add to conf-custom/nginx_apps.vhost.master, may be before rspamd code, and do add it in conf-custom/install folder as well. Again, symbolically link the latter from the former is better since they should be identical in both of these locations.
    Code:
            ## FILEMANAGER ##
    
            location /filemanager {
                   root /usr/share/;
                   index index.php index.html index.htm;
                   location ~ ^/filemanager/(.+\.php)$ {
                           try_files $uri =404;
                           root /usr/share/;
                           include /etc/nginx/fastcgi_params;
    
                           # To access filemanager, create ftp users in ISPConfig UI
                           {use_tcp}fastcgi_pass 127.0.0.1:9000;
                           {use_socket}fastcgi_pass unix:{fpm_socket};
                           fastcgi_index index.php;
                           include /etc/nginx/fastcgi_buffer_temp;
                           fastcgi_read_timeout 1200;
                   }
                   location ~* ^/filemanager/(.+\.(ogg|ogv|svg|svgz|eot|ttf|otf|woff|woff2|mp4|mp3|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|html|xml|txt|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)(\?ver=[0-9.]+)?$) {
                           root /usr/share/;
                           access_log off;
                           log_not_found off;
                           expires max;
                   }
            }
            location /file {
                   rewrite ^/* /filemanager last;
            }
     
     
            {use_rspamd}location /rspamd/ {
    
    Note that the above is not perfected yet and may be developed from time to time. The above if done correctly, should be accessible via your ispconfig.domain.tld:8081/filemanager.

    Lastly, sorry but I do not use apache2, however, you can definitely follow the code phpMyAdmin (PMA) or Mailman (MM) or Roundcube (RC) in the ISPConfig vhost as they are about the same, so I think something like this code have to be added in your ISPConfig vhost for port 8080 (or apps vhost for port 8081):
    Code:
    <Directory /usr/share/filemanager>
            <tmpl_if name='apache_version' op='>' value='2.2' format='version'>
            Require all granted
            <tmpl_else>
            Order allow,deny
            Allow from all
            </tmpl_if>
    </Directory>
    I noted both ISPConfig and apps vhost because currently all I can see is PMA, Mailman and RC are in ISPConfig vhost and not in its apps vhost for apache2, thus I am not sure how this actually works in apache2. You have to figure out if I am right because this code though modified from apache2 ISPConfig vhost, it has not really been tested.

    All the best in your attempts with the above though.
     
    Last edited: Sep 11, 2023
    webguyz and till like this.

Share This Page