[APP] Native Android web server 1.1 - updated! (folder browsing, basic AUTH)

Search This thread

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
Hello,

I've managed to compile a small native web server for Android (but for now only tested on Sony X10 with 2.3.3 version). You will need root.

The main advantage is that you can quickly share photos / documents from your phone as long as there's WiFi available. The other phone needs just to have WiFi and a browser.

It is an Android port of the webserver source code found here: http://www.jbox.dk/sanos/webserver.htm which comes under BSD License.

Download

webserver-1.1.zip

Archive contents

webserver – Android binary
LICENSE – initial BSD License
android_port.patch – BSD licensed patch for webserver.c
README.txt – description on how to install / compile.

Installing

Since most mobile carriers block incoming traffic, you won’t probably be able to access your phone via GSM/3G data connection, only over WiFi.

You need to unpack the archive, and extract the webserver binary to a directory of your choice. Then:

Code:
adb push webserver /sdcard/
adb shell
su
cd /system/bin
cp /sdcard/webserver .
chmod 755 webserver
./webserver -u <username> -p <password> -s <port>

To stop just kill its pid ...

If you run in Terminal Emulator, just send it a Ctrl-C and it will exit.

Screenshots

Starting up the webserver (runs by default on port 80) and navigating to /sdcard/DCIM folder in the browser:

webserver_terminal.png


webserver_browser.png


For more information about the porting process please check my website.

Change log

v1.0 - 21 Aug 2011
Initial port to Android
v1.1 23 - Aug 2011
Added command line options
Added listing of all local IPs (please check screenshot, it reports IPs and interfaces when starting up. Helps a lot to find out the WiFi IP, tun.ko is detected and works too)
Added Basic HTTP authentication for security

PS: if you have other rooted Android phones, I'm very interested in feedback if this works or not. I did not use anything specific to X10.

Thank you,
 
Last edited:

anantshri

Senior Member
Feb 22, 2011
687
320
Bangalore
anantshri.info
Hello,

I've managed to compile a small native web server for Android (but for now only tested on Sony X10 with 2.3.3 version). You will need root.

PS: if you have other rooted Android phones, I'm very interested in feedback if this works or not. I did not use anything specific to X10.

Thank you,

good to see someone working on not so generic stuff.... would like to help you with stuff althogh i am not that good at java.

Will be checking the webserver out....

i don't have any other phone however i am in a process of purchasing some tabs so might help you then....
 
  • Like
Reactions: viulian

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
Thank you for feedback :)

Don't know if it will work in tablets (I did not test it on 3.0, only 2.3.3) .. but yes, if you will root them, please give it a shot!
 

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
Did you install this on your own X10? I need some pics.

Yes :) and I've also tested it on X10. I've attached two screenshots to the first post of the thread. Please check them:

a) I have started webserver within Terminal Emulator
b) Then I navigated to the photos folder, in the browser (192.168.1.6 is phone's IP over WiFi).
 

anantshri

Senior Member
Feb 22, 2011
687
320
Bangalore
anantshri.info
Yes :) and I've also tested it on X10. I've attached two screenshots to the first post of the thread. Please check them:

a) I have started webserver within Terminal Emulator
b) Then I navigated to the photos folder, in the browser (192.168.1.6 is phone's IP over WiFi).

just a quick comment

when you copy it to system/bin

you don't need to cd or ./

you cna directly run webserver

EDIT : i would suggest you do one more change.

right now if i understand correctly this can pose a security risk....

as it can give you all folders any file effectively all data any location...

Make changes such that which ever folder you navigate and start webserver from only that folder and its subfolders are accessiblle on webserver.

webserver is already in bin so we can run from anywhere


so if i want to share /sdcard/share

cd /sdcard/share
webserver


hope that will help.
 
Last edited:
  • Like
Reactions: ethan_hines

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
just a quick comment

when you copy it to system/bin

you don't need to cd or ./

you cna directly run webserver

My bad! Yes, I was testing in /system/test when porting, and by reflex I typed it. I will leave it like that in descriptions, but you are right of course :)

right now if i understand correctly this can pose a security risk....

as it can give you all folders any file effectively all data any location...

It's a difficult decision to start adding security to folders ...
Because next question will be: but I want to access more folders! Or, yes, I want everything but I also want to exclude these and these ... And just like any software product, more time will be spent fool-proofing it. Because if you add configuration files, then you need a ton of error messages (and support for noobs) to explain what is wrong and how to fix it.

This is just a working proof of concept. It works, and it uses so little memory as compared to other Java apps that might do the same thing ...

I also thought of security (since I wouldn't want to start it on a public WiFi) but to add support for username and password - as even allowing some folders is still risky 'cos anybody than then browse all the photos.

On my todo list:
a) add file upload feature (fork()-ing is unstable on Android, so CGI support can't be done reliably - it will have to be built in)
b) add support for username and password.
c) sorting (alphabetically and folders first).
 
Last edited:
  • Like
Reactions: anantshri

anantshri

Senior Member
Feb 22, 2011
687
320
Bangalore
anantshri.info
My bad! Yes, I was testing in /system/test when porting, and by reflex I typed it. I will leave it like that in descriptions, but you are right of course :)


I was adding more while you replied :D

EDIT : i would suggest you do one more change.

right now if i understand correctly this can pose a security risk....

as it can give you all folders any file effectively all data any location...

Make changes such that which ever folder you navigate and start webserver from only that folder and its subfolders are accessiblle on webserver.

webserver is already in bin so we can run from anywhere


so if i want to share /sdcard/share

cd /sdcard/share
webserver


hope that will help.
 

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
why not just swiftp ?

Well, this is a completely different approach. Native (.c) compile, very fast and extremely low memory footprint.

It is not ment for the masses. Google wants people to use Java / DalvikVM. What I (as a developer) want is to get closer to hardware instead of being abstracted away. While it is true that interface with good implementation wins (Apple proves it), it is very good that we can still go low level.

Second, FTP is limited. You can only connect to download.

In future, if people like webserver and keep providing feedback, HTTP is more powerful:
a) interact with phone - contacts, call logs, send sms from browser, etc
b) have cached previews when browsing the photos - this you cannot over FTP.
c) compression
d) no data/command channels to slow down interaction.

:)

As said, this is a proof of concept, and not offered as an alternative to "SwiFTP" and the rest.
 

pheel

Senior Member
Mar 7, 2011
491
95
Sydney
hmmm i see your point :)
but swiftp has proxy servers and you can upload :S

will test out tho. and will hit thanks when near comp

Sent from my X10i using XDA Premium App
 
It's a difficult decision to start adding security to folders ...
Because next question will be: but I want to access more folders! Or, yes, I want everything but I also want to exclude these and these ... And just like any software product, more time will be spent fool-proofing it. Because if you add configuration files, then you need a ton of error messages (and support for noobs) to explain what is wrong and how to fix it.

This is just a working proof of concept. It works, and it uses so little memory as compared to other Java apps that might do the same thing ...

I also thought of security (since I wouldn't want to start it on a public WiFi) but to add support for username and password - as even allowing some folders is still risky 'cos anybody than then browse all the photos.

On my todo list:
a) add file upload feature (fork()-ing is unstable on Android, so CGI support can't be done reliably - it will have to be built in)
b) add support for username and password.
c) sorting (alphabetically and folders first).
Why not just virtually create a .htaccess inside of each folder? :)

Do that, and you can get user accounts, directory blocking, etc.
 

Haldi4803

Senior Member
Oct 14, 2010
3,865
1,568
Amazon Fire HD 8 and HD 10
Xperia XZ2
SwiFTP works with FTP right? Some1 know Wifi FileExplorer?

What i miss with those 2 apps is Add Hoc support! I want to Acces one phone with another over Wifi! Would be perfect over http because it also works to an Iphone. Sadly most apps like that wont work while Barnacle theters WiFi.

P.S. Dont have a PC here, you can compile a APK? Or that wont Work because its not java?
 

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
It will work, and APK can launch a native file :) but I wanted as close to bare minimum as possible.

However, I will only have time to investigate tonight when I get back home ..
 

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
New version released !

v1.1
Added command line options
Added listing of all local IPs (please check screenshot, it reports IPs and interfaces when starting up. Helps a lot to find out the WiFi IP, tun.ko is detected and works too)
Added Basic HTTP authentication for security

Download

webserver-1.1.zip

I've also updated the first post of the thread with new screenshots (Hit Ctrl-R to reload the screenshots in case you have the old ones in the cache).
 
Last edited:
  • Like
Reactions: anantshri
F

Frans Parnel

Guest
Whilst some will disagree with me this would be awesome to bundle with MySQL and PHP servers...

Apache, MySQL, and PHP running on mobile...not so much for hosting a website but for developement...our devices are getting more and more powerful and would be cool to develop websites on the phone using a mobile version of lamp and an HTML/PHP ide like a mobile dreamweaver/expressions web...that and we already have photoediting software...

Not saying it'd be practical but would be nice...and I think it would come in handy from time to time...

Sent from my PC36100 using Tapatalk
 

viulian

Inactive Recognized Developer
Apr 6, 2011
419
411
hex.ro
Whilst some will disagree with me this would be awesome to bundle with MySQL and PHP servers...

Actually :D

I downloaded the php-for-android bundle and which comes with php 5.3.3 compiled native.

The native php executable lies hidden, since it is intended for SL4A to detect and invoke it; I want to do the same thing, but only from this web server. Initially GET only - and later POST too.

The following issues are make it difficult to have full featured Linux alongside Android:

a) Google's poor implementation of fork / pthread. It is so poor, they insist people should not use it.
Here are some insights: http://groups.google.com/group/android-ndk/browse_thread/thread/1dfa066e20175c5a/e4c79372d365f5e3.

Dianne Hackborn, Android framework engineer, was hinting to actually limit even the basic one that exists, if people "abuse" it. http://comments.gmane.org/gmane.comp.handhelds.android.ndk/2132

b) Google implementation of bionic (many things lack) makes it difficult to port from Linux. Standard libraries are missing (libcrypt / base64 / ... ) and so on.

We'll see :) but with the avoidance attitude towards low level access (Google need people to use all the location services and ads based apps) I am a bit skeptical that they will ease transition to glibc.

At least to leave it as is ...
 

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    Hello,

    I've managed to compile a small native web server for Android (but for now only tested on Sony X10 with 2.3.3 version). You will need root.

    The main advantage is that you can quickly share photos / documents from your phone as long as there's WiFi available. The other phone needs just to have WiFi and a browser.

    It is an Android port of the webserver source code found here: http://www.jbox.dk/sanos/webserver.htm which comes under BSD License.

    Download

    webserver-1.1.zip

    Archive contents

    webserver – Android binary
    LICENSE – initial BSD License
    android_port.patch – BSD licensed patch for webserver.c
    README.txt – description on how to install / compile.

    Installing

    Since most mobile carriers block incoming traffic, you won’t probably be able to access your phone via GSM/3G data connection, only over WiFi.

    You need to unpack the archive, and extract the webserver binary to a directory of your choice. Then:

    Code:
    adb push webserver /sdcard/
    adb shell
    su
    cd /system/bin
    cp /sdcard/webserver .
    chmod 755 webserver
    ./webserver -u <username> -p <password> -s <port>

    To stop just kill its pid ...

    If you run in Terminal Emulator, just send it a Ctrl-C and it will exit.

    Screenshots

    Starting up the webserver (runs by default on port 80) and navigating to /sdcard/DCIM folder in the browser:

    webserver_terminal.png


    webserver_browser.png


    For more information about the porting process please check my website.

    Change log

    v1.0 - 21 Aug 2011
    Initial port to Android
    v1.1 23 - Aug 2011
    Added command line options
    Added listing of all local IPs (please check screenshot, it reports IPs and interfaces when starting up. Helps a lot to find out the WiFi IP, tun.ko is detected and works too)
    Added Basic HTTP authentication for security

    PS: if you have other rooted Android phones, I'm very interested in feedback if this works or not. I did not use anything specific to X10.

    Thank you,
    1
    Hello,

    I've managed to compile a small native web server for Android (but for now only tested on Sony X10 with 2.3.3 version). You will need root.

    PS: if you have other rooted Android phones, I'm very interested in feedback if this works or not. I did not use anything specific to X10.

    Thank you,

    good to see someone working on not so generic stuff.... would like to help you with stuff althogh i am not that good at java.

    Will be checking the webserver out....

    i don't have any other phone however i am in a process of purchasing some tabs so might help you then....
    1
    Yes :) and I've also tested it on X10. I've attached two screenshots to the first post of the thread. Please check them:

    a) I have started webserver within Terminal Emulator
    b) Then I navigated to the photos folder, in the browser (192.168.1.6 is phone's IP over WiFi).

    just a quick comment

    when you copy it to system/bin

    you don't need to cd or ./

    you cna directly run webserver

    EDIT : i would suggest you do one more change.

    right now if i understand correctly this can pose a security risk....

    as it can give you all folders any file effectively all data any location...

    Make changes such that which ever folder you navigate and start webserver from only that folder and its subfolders are accessiblle on webserver.

    webserver is already in bin so we can run from anywhere


    so if i want to share /sdcard/share

    cd /sdcard/share
    webserver


    hope that will help.
    1
    just a quick comment

    when you copy it to system/bin

    you don't need to cd or ./

    you cna directly run webserver

    My bad! Yes, I was testing in /system/test when porting, and by reflex I typed it. I will leave it like that in descriptions, but you are right of course :)

    right now if i understand correctly this can pose a security risk....

    as it can give you all folders any file effectively all data any location...

    It's a difficult decision to start adding security to folders ...
    Because next question will be: but I want to access more folders! Or, yes, I want everything but I also want to exclude these and these ... And just like any software product, more time will be spent fool-proofing it. Because if you add configuration files, then you need a ton of error messages (and support for noobs) to explain what is wrong and how to fix it.

    This is just a working proof of concept. It works, and it uses so little memory as compared to other Java apps that might do the same thing ...

    I also thought of security (since I wouldn't want to start it on a public WiFi) but to add support for username and password - as even allowing some folders is still risky 'cos anybody than then browse all the photos.

    On my todo list:
    a) add file upload feature (fork()-ing is unstable on Android, so CGI support can't be done reliably - it will have to be built in)
    b) add support for username and password.
    c) sorting (alphabetically and folders first).
    1
    New version released !

    v1.1
    Added command line options
    Added listing of all local IPs (please check screenshot, it reports IPs and interfaces when starting up. Helps a lot to find out the WiFi IP, tun.ko is detected and works too)
    Added Basic HTTP authentication for security

    Download

    webserver-1.1.zip

    I've also updated the first post of the thread with new screenshots (Hit Ctrl-R to reload the screenshots in case you have the old ones in the cache).