[APP] WebHosting for firmware V4+ (10/2015)

Nazar78 excellent job, because you have installed Transmission and works wonders.
Now try installing WebHosting but errors thrown me every you see that I try, this is the log:

##################################################

64K Page Size Memory Installer v1.0 by Nazar78

##################################################

 Package: webhosting-mods_1.0.0
 Description: WebHosting Mods for WDMyCloud V4 Firmware,
 Nginx, MySQL, ESMTP, UNRAR, INOTIFY-TOOLS, PERL-FCGI+LIBS,
 PHP5-FPM/CLI/GD/IMAGICK/CURL/MYSQL/SQLITE/MCRYPT/APCU/JSON

Note:
If you’re behind web proxy, try my alternate port ‘8245’:

  curl teanazar.com:8245/installer.fcgi?webhosting-mods_1.0.0|sh;

To preserve my internet bandwidth, I’m limiting your download
speed to 1MB/s and maximum of ‘3’ download attempts per/hour.

*** You’re currently left with ‘3’ download attempt(s). ***
*** Unauthorized attempts is not tolerated and warrants permanent ban! ***

Disclaimer:
By you using this free service, you hereby agree taking full
responsibilities of any fault/damages resulted by/from your
actions and/or the developer’s contributions. No personal
information or individual usage tracking has been used or
transmitted. All trademarks/copyrights/licenses/credits
remain property of their respective holders.

Do you agree? (<[N]o/[Y]es>) Y

Checking available rootfs space…

        Partition : 1922.20MBytes
        Available : 1054.86MBytes
        Required  : 21.14MBytes

Estimated 1033.72MBytes left after installing. Proceed? (<[N]o/[Y]es>) Y

Checking resources…
Downloading → webhosting-mods_1.0.0 (22,161,907Bytes)…
Error-8: Unable to retrieve required files! Server issued an error response.
WDMyCloud:~#

@Ganthet

I just checked it’s working. May be a hiccup. Just try again.

Checking resources…
Downloading → webhosting-mods_1.0.0 (22,161,907Bytes)…
32% [===========>                          ] 7,277,180   1.00M/s  eta 15s

Hi Nazar,

i have a WD MyCloud Mirror and i get a error.

When i send

curl teanazar.com/installer.fcgi?webhosting-mods_1.0.0|sh;

I get this error

root@WDMyCloudMirror root # curl http://teanazar.com/installer.fcgi?webhosting-m
ods_1.0.0|sh;
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 22009 0 22009 0 0 23999 0 --:–:-- --:–:-- --:–:-- 36620
sh: syntax error: unexpected redirection

Have you any idear ?

Thx Peter

@do2fn

It only supports WDMyCloud single drive, not Mirror/EX2/EX4 etc as I don’t have those devices to test.

Ok Thx Nazar.

NAZAR> So I installed the NGINX package as per your instructions,  it works excellent thank you very much.

Quick question,  is it possible to give a remote user access to a single folder / sub folders in order for them to maintain a website without giving them access to the request of the public shares on the drive?  If so how would you recommend setting it up.

thanks

Ian

@chickenzown

Yes, I’m doing it too. But do take note that WDMyCloud is underpowered, if you have a power user using too much heavy CGIs it will slow down everyone.

There’s two way, one is chroot but this requires lots of changes and you’ll need to mount the user’s home path accordingly in the chroot environment. I shall not elaborate this as you’ll of course need to setup chroot prior.

The other is to sync with the existing layout:-

You’ll need to declare each user’s home dir, eg. in the /etc/passwd (avoid editing directly using vi/nano, see next):

username:x:999:1000:Full Name,,,:/home/Username:/bin/bash

I believe the default home path is /shares. Mine’s changed to /home is a symlink to /shares but you can change them as /shares/Username too. Note the home path is case sensitive.

To add or edit use (don’t use -m switch (move existing path to new) for below):

usermod -d /shares/Username username;

Or (vi basics: [INSERT] to edit, [ESC]+[:]+[wq] to write & quit):

vipw;

For access, depending what kind you wanna give, ie. SFTP, forward port 22 on your router to WDMyCloud, edit /etc/ssh/sshd_config then reload “service ssh reload”:

# Authentication:
LoginGraceTime 120
PermitRootLogin yes# To avoid internet attacks, I advise to set above to "PermitRootLogin without-password" then setup RSA/DSA passwordless logins for root.
StrictModes no
#AllowUsers root

Next is to create and activate the new nginx for each user. Similar to my OwnCloud guide: 

nano /etc/nginx/sites-available/Username;# Copy from my OwnCloud guide.# Main point is to change "root" to the user's www or html path, below assuming there's a www sub-dir to place all the cgi/htmls eg.:# root /shares/Username/www
# Get the user a dynamic DNS, set it to "server_name".
cd /etc/nginx/sites-enabled;
 
ln -s ../sites-available/Username Username;
service nginx reload;

  

With the above pointers, users can now SSH or FTP into the WDMyCloud, place CGI/HTML files like /shares/Username/www/index.html and access them via http://username.freedns.com/. If you have a personal domain which supports wildcard, this is even better. With this you can just setup one nginx dynamic config, set the “server_name” as “_” default to catch all request, then do an internal rewrite based on the hostname request to the user’s www path. There’s several ways to achieve this depending on how you want it. You can separate each users config or all-in-one config as described above for wildcard domains. You can also have several “server_name” directive in one config for each user.

Note that when some user runs a CGI, any created files will be owned by “www-data” since php-fpm/perl-fcgi is running as “www-data” group which could cause those users not able to access their own created files as users belong to “share” group. You can create different set of php-fpm/perl-fcgi pools running as the user/group but this will consume lots of memory which is bad for our NAS. My workaround is to set the umask as 0006 for the CGIs and set a sticky “www-data” gid for the www sub-dir. This ensure files created by CGIs like php-fpm or perl-fcgi will always be accessible to the user.

Umask 0006 (default is 0022):-

File=rw-rw---- (660)

Dir=rwxrwx–x (770)

Add the umask where php-fpm starts:

nano /etc/init/php5-fpm.conf;...# Add umask before daemon startsumask 0006pre-start exec /usr/lib/php5/php5-fpm-checkconf...

Add the umask where perl-fcgi starts:

nano /etc/init.d/perl-fcgi;
...
# Add umask before daemon startsumask 0006PATH=/sbin:/usr/sbin:/bin:/usr/bin...

Then for each user’s “www” sub-dir, make sure it’s a “www-data” group and set it to sticky gid:

chown -R :share /shares/Username/www;chmod g+s /shares/Username/www;

Then for each user, add them to the “www-data” group:

useradd -G www-data username;

To prevent users accessing the Public shares, there’s a known hack how to do this. Not sure if it still works for newer firmwares, look for it. My way is to edit them manually:

sqlite3 /usr/local/nas/orion/orion.db;update UserShares set public_access='false' where share_name='Public';.quit

Then login to the WDMyCloud Dashboard and set the permissions manually for those who can access the Public shares.

Guide added to the first post: Securing WDMyCloud SSH & FTP Remote Access.

This guide is useful for those who expose their WDMyCloud SSH/FTP ports to the internet. I’m placing the guide here in this thread because it involves webserver and CGI. Hope it helps…

Guide added to the first post: Setting Up Remote WOL (Wake On LAN).

This guide is useful for those who likes putting computers to sleep to save energy then wake them up remotely to access when needed. I’m placing the guide here in this thread because it involves webserver and CGI. Hope it helps…

hi again teanazar.

today i will buy a new domain adress.

can i use it with my cloud (host) same your website ?

and i want to make asp.net websites.is it possible ?

aksneo wrote:

hi again teanazar.

 

today i will buy a new domain adress.

can i use it with my cloud (host) same your website ?

 

and i want to make asp.net websites.is it possible ?

 

Yes you can even use your personal domain to host a website on WDMyCloud. It looks better. If you have a dynamic IP, depending on your domain provider, you’ll need to ensure the DNS is always pointing to your ISP IP.

ASP.Net is not possible without further modifications. I only do ASP on IIS.

Hi,

I installed this mod today and now the WD panel wont load.

I am seeing this error in the apache logs:

[Tue Oct 06 18:02:54.980288 2015] [:error] [pid 18198:tid 1156838464] [client 127.0.0.1:35267] FastCGI: server “/usr/lib/cgi-bin/php5-fcgi” stderr: Primary script unknown
[Tue Oct 06 18:02:56.092210 2015] [:error] [pid 18198:tid 1148449856] [client 127.0.0.1:35268] FastCGI: server “/usr/lib/cgi-bin/php5-fcgi” stderr: Primary script unknown
[Tue Oct 06 18:05:19.573754 2015] [:error] [pid 18198:tid 1182004288] [client 127.0.0.1:35353] FastCGI: server “/usr/lib/cgi-bin/php5-fcgi” stderr: Primary script unknown
[Tue Oct 06 18:05:20.663378 2015] [:error] [pid 18198:tid 1198781504] [client 127.0.0.1:35354] FastCGI: server “/usr/lib/cgi-bin/php5-fcgi” stderr: Primary script unknown

Any thoughts?

2015-10-06T18:05:20+0100 { mi:“web”, rm:“GET”, rurl:“/php5-fcgi/api/1.0/rest/”, rp:“18198”, rsrc:“Darwin/11.4.0, UPnP/1.0, M”, t:3865, s:404, I:222, O:242 

@TalkTech,

There’s seems issues with Apache’s mod_fastcgi in the latest .308 firmware. I’ve just placed a warning notice on the first post.

I found the issue but I can’t do any quick fix on this (see quick fix below). Will update soon. Nginx, MySQL and PHP5-FPM should be working fine. If you can’t wait to restore the DashBoard, look for a thread on how to downgrade earlier than .307/.308. I can’t confirm the downgrade will work with this .308 firmware, worst getting bricked while downgrading, so I suggest you wait…

Quick fix (but Apache2 will be back using high resources, this is as per-stock firmware):

a2dismod mpm_event fastcgi;

a2enmod mpm_prefork php5;

service apache2 restart;
1 Like

@TalkTech

I’ve updated my previous post…

Thank you for an excellent response!

I have already restored back to a previous version of the OS using TFTP method to keep my shares and all is now fine!

I will take another look at your stuff tomorrow as it is late here now.

I will let you know how I get on.

Does anyone have this issue?  After succesful installation of this webhosting package, I lost the access to the dashboard, I was redirect to wdmycloud/UI with “file not found” error.  Any advice or help will be greatly appreciated.  Ngnix site works fine at port 5080.

Tony

mistan wrote:

Does anyone have this issue?  After succesful installation of this webhosting package, I lost the access to the dashboard, I was redirect to wdmycloud/UI with “file not found” error.  Any advice or help will be greatly appreciated.  Ngnix site works fine at port 5080.

 

Tony

See my first post.

Fixed mod_fastcgi issues on firmware v04.04.00-308 which caused WD DashBoard not loading .

For those who already installed my WebHosting Mods prior this fix, _ do not reinstall _, just fix it as below:

# Revert any quick fix done, switching back to MPM_EVENT/FASTCGI, ignore any errors if any.
a2dismod mpm_prefork php5;

a2enmod mpm_event fastcgi;

# Replace the previous fastcgi config (include the #Nazar78 tags, I use it to track changes).
nano /etc/apache2/conf.d/fastcgi.conf;

# __Copy & Paste below__
#Nazar78 - 20151007
<IfModule mod_fastcgi.c>
  AddType application/x-httpd-fastphp5 .php
  Action application/x-httpd-fastphp5 /var/www/htdocs
  FastCgiExternalServer /var/www/htdocs -socket /var/run/php5-fpm.sock -idle-timeout 300 -pass-header Authorization
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !(\.php|\/)$
  RewriteRule (.*) - [H=text/html,L]
</IfModule>
#Nazar78 - 20151007# __Copy & Paste above__ # CTRL+[x] to exit, [y] to confirm save.

# Restart Apache2 daemon.
service apache2 restart;

The latest update does indeed work well with the latest OS.

Thank you very much Nazar78

TalkTech wrote:

The latest update does indeed work well with the latest OS.

 

Thank you very much Nazar78

No problem, please help to test thoroughly and let me know if there’s any other DashBoard issue as I’m still using a quite old firmware v04.01.02-417 (no time to upgrade and port over the many changes).