Jump to content
MaximiliumM

Web Server ( Easily start a web server and add files to it )

Recommended Posts

Web Server

Easily start a web server and add files to it (v 1.3.6)

 

------------------------------------------

 


Update 1.3.6:

 

- Port number wasn't copying to clipboard when checking the IP Address.


 


Update 1.3.5:

 

- New and Better IP addresses checker. My Thanks and Credits to Shawn Rice.

- Now php.ini and index.php files are hidden as well.

- Fixed some other bugs. I hope the initial setup works properly now.


 


Update 1.3.4:

 

- Uploads won't overwrite existing file with same name anymore.

- Moved user defined port file to Workflow data storage.


 


Update 1.3.3:

 

- Auto-refresh page after upload is completed!

- New notification banner saying "Upload Completed". Yay.

 


 


Update 1.3.2:

 

- Upload feature revamped. Now you can Drag and Drop files and then upload :D You can even rename them before uploading.

- It seems PHP has upload and memory limit. So uploading big files wasn't working. Hopefully everything works now. Or at least 2GB files.

 


 


Update 1.3.1:

 

- HUGE mistake. Sorry. The last update wasn't copying the new files to the Server folder.

 


 


Update 1.3:

 

- Added ability to Upload files

- Now you can check your Local and External IP addresses

- Set the Server Port number to any Port you want

 


 


Update 1.2.1:

 

- ***CRITICAL*** Fixed huge typo bug. The server wouldn't stop if your local IP address didn't start with "10" :(

 


 


Update 1.2:

 

- Fixed an issue with the File Action "Add Files to Web Server".

 


 

Update 1.1:

 

- Changed Server folder location to Workflow Data storage. (Thanks, Shawn)

- Added Readme content.

 

------------------------------------------

 


Requirements:

 

- Mavericks or any prior OS X with PHP 5.4 


 

Description:

 


The default server's port is set to 21025. To access the web server folder, open your browser and go to your local IP address at the mentioned port. Example: "10.0.1.5:21025"

 

You can access your Web Server folder from any computer in the same network. If you want people from outside your local network to be able to access your Web Server folder, you have to clear the port in your router's settings (Google "port forwarding"). After clearing the port, use your external IP address instead of your local IP address. Example: "179.233.196.211:21025"

 

Also, the Web Server allows you or people who are accessing it to upload files, as long as the file is an allowed extension. This limitation is for security purpose.

 

Instructions:

 

+ Keywords:

- "server": Lets you start the server (if it's not running) or stop the server (if it's running).

 

- "server open": Open the Web Server folder. This is where you put the files you want to share.

 

- "add": Copy files selected in Finder to the Web Server folder.

 

- "server ip": Check what's your Local and External IP address.

 

- "set port": Set the Web Server port number to any port within the valid range of 0 and 65535, so long as it doesn't conflict with an already assigned port.

 

+ File Action:

- "Add Files to Web Server": Copy selected files to the Web Server folder.


 

 

Screenshots:

 

pQO6WPw.png

 

uezbmcE.png

 

Yz5nSPL.png

 

 


Download link:


 


 

Contact:

@MaximiliumM

 

Any feedback is welcome.

Edited by MaximiliumM

Share this post


Link to post

This is pretty clever. Kudos.

 

Two things:

 

1) This will work only on Mavericks. Reason: Mavericks finally upgraded its php to 5.4, which includes the built-in webserver. All versions before that have php 5.3, which doesn't have this feature. If you're running something pre-Mavericks, then you can make this work by upgrading PHP, and the easiest way to do that is to upgrade to Mavericks. After all, it's free.

 

2) Max, you might consider moving the server folder. Right now, it places all information inside the workflow folder itself, which potentially causes problems with upgrading / exporting. Instead, consider putting the server path at the recommended storage place:

~/Library/Application Support/Alfred 2/Workflow Data/fmanoeli.webserver

Just add in a line into the Applescript to check for the folder's existence, and, if not, to create it.

 

Looking forward to using it.

 

Cheers.

Share this post


Link to post

Shawn,

 

Thanks for clearing that PHP 5.4 thing out. I didn't know that.

 

And about your second point, yeah, I knew that... Today while using it I thought it could cause problems when exporting the Workflow and so on, but unfortunately I haven't got time to fix it yet.

 

I'll have everything fixed by tomorrow.

 

Thanks :)

Share this post


Link to post

Here's the quick fix. I think this should cover it:

 

Change the serverPath variable everywhere to this line:

set serverPath to POSIX path of ((path to "cusr" as text) & "Library/Application Support/Alfred 2/Workflow Data/fmanoeli.webserver/ServerFolder" as text

And, at the beginning of the scripts that initialize anything, add the line

do shell script "bash run.sh"

And, lastly, add this into a file called "run.sh" in the workflow folder

#!/bin/bash

# set the folder
nv="/Users/$USER/Library/Application Support/Alfred 2/Workflow Data/fmanoeli.webserver"

# first run not completed. Start.
if [ ! -d "$nv" ]
then
  # make the directory
  mkdir "$nv"
fi
if [ ! -d "$nv/ServerFolder" ]
then
  # copy the template directory from the workflow folder
  cp -R ServerFolder "$nv"
  # can't remember if you'll need this... if the hidden files don't copy, then uncomment it
  # cp -R ServerFolder/.images "$nv/ServerFolder"
  # cp ServerFolder/.images/.index.php "$nv/ServerFolder/.images"
  # cp ServerFolder/.htaccess "$nv/ServerFolder"
  # cp ServerFolder/.error.php "$nv/ServerFolder"
  # cp ServerFolder/.sorttable.js "$nv/ServerFolder"
  # cp ServerFolder/.style.css "$nv/ServerFolder"
fi

That should do it.

 

The bash script will make sure that the folder exists, and if it doesn't, then it'll make it and copy the "template" directory to the directory.

Share this post


Link to post

Haha. Thanks for the code. But I've already fixed it. I'll check your code anyway, maybe it's better than mine :P

 

About the PHP 5.4 requirement. I've added the information to the main post.

 

Also, I had another really simple Workflow that would run the command "python -m SimpleHTTPServer 21025", but there was no CSS style file, so its appearance was just a list of files and really ugly ;( 

 

Thanks again. If you find more bugs or any improvement that can be made, please tell me :) And check my other Workflows, if you want. I'd love to have more feedbacks like yours :)

Share this post


Link to post

@ctwise,

 

does the python simplehttpserver process php files like that? I know that it's possible to make it do so, but I'm not quite sure how much more work is needed to get that done. It's actually something that I'm fairly curious about.

Share this post


Link to post

It doesn't, I guess.

 

My new "upload function" is not really working, it seems :( 

 

I'm fully testing it now with a friend. I didn't get the chance yesterday. Sorry for uploading a broken thing.

 

Can someone tell me if you tested it?

Share this post


Link to post

Seems like it has to do with file upload size. My research keeps turning up the same thing "change php.ini", but not sure what to do here. I tried putting a php.ini inside the ServerFolder and changed it file upload limit size, but it didn't work.

 

Anyone with more experience?

 

Thanks

Share this post


Link to post

Either use the ini_set() function in the php files themselves, or initialize the server with...

php -S localhost:8000 -c php.ini

Obviously, change the localhost:8000 to what it is in your script.

Share this post


Link to post

Thanks, Shawn. Hopefully I got it working.

 

Update bump again.

 

Update 1.3.2:
- Upload feature revamped. Now you can Drag and Drop files and then upload  :D You can even rename them before uploading.
- It seems PHP has upload and memory limit. So uploading big files wasn't working. Hopefully everything works now. Or at least 2GB files.

Share this post


Link to post

I just uploaded another workflow that might help out with this one. It finds your external and internal IP addresses. This can help out if you want to do any of the port forwarding options to make your webserver available to the external world. Find it on Packal.

Share this post


Link to post

Update 1.3 added this feature, Shawn. Isn't it the same thing? I'm going to check yours anyway ;) 

 

ALSO, Update bump.

 

 

Update 1.3.4:
- Uploads won't overwrite existing file with same name anymore.
- Moved user defined port file to Workflow data storage.

Share this post


Link to post

I've just found some bugs here. Trying to address them all to release 1.3.5. I'll check your implementation, because the current one only checks ipconfig en0, so local ip is in en1 it doesn't work properly. I'll check if yours solves this :P 

 

Thanks :) 

Share this post


Link to post

Shawn,

 

Thanks for your implementation. It's better than the one I was using.

 

---------

 

Update bump.

 

Update 1.3.5:
 
- New and Better IP addresses checker. My Thanks and Credits to Shawn Rice.
- Now php.ini and index.php files are hidden as well.
- Fixed some other bugs. I hope the initial setup works properly now.

Share this post


Link to post

On macOS Sierra 10.12.3

Safri says "Cannot open the page" for both {local, public} IP:21025

After "Start/Stop web server" -> "Start server" appears in Alfred

There is no "Stop server" command (as shown on screenshots here).

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...