11

I have created some web app using Rook which listen to my network ip (192.168.xx.xx) at port 8000. Everyone inside my office can connect to them just typing http://192.168.xx.xx:8000/page_name in the browser. I need to monitor these pages usage and wonder how I can get the network ip address of those connected to them.

I'm not experienced in web development and from the research done so far it seems that using client side code like JavaScript it's very difficult (almost impossible) to achieve that, (correct me if I'm wrong). So, my question is: is there any way of getting the network client ip using server side code inside an Rook application? (If needed I'd be willing to change the web server, any solution appreciated).

Thanks and sorry in advance should my question seem confusing... in particular I'm unsure if other tags are needed.

EDIT: I would also accept answers using something different than Rook (but still in R)

EDIT 2: I have set Shiny Server following this link. I'm at step of configuring the Server in order to get the access_log that, according to @Thell, contains the information I need. In The shiny-server.conf I have added the relative statement and now is:

run_as shiny;

server {
  listen 3838;

  location / {
    site_dir /var/shiny-server/www;
    log_dir /var/shiny-server/log;
    directory_index on;
  }

}

access_log /home/michelec/log.txt;

the last line should tell shiny to write the access_log into my home folder. Nothing happens however, the log remains blank. according to here, in the Formats section, I should receive one of these logs:

default ':remote-addr - - [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"'
short ':remote-addr - :method :url HTTP/:http-version :status :res[content-length] - :response-time ms'
tiny ':method :url :status :res[content-length] - :response-time ms'
dev concise output colored by response status for development use

depending if you leave the default format or you change it.

Michele
  • 8,563
  • 6
  • 45
  • 72
  • 1
    Can you make your code available? There's not a lot out there on Rook other than the basic documentation, so answering your question will probably require a little experimentation, which will likely require a reproducible example. – SchaunW Jun 17 '13 at 02:09
  • @SchaunW thanks for replying. Sorry, I have no code yet for this task. I'm doing reasearch every day. As it is, the question would be answered even with just a (valid) input to start coding this. – Michele Jun 17 '13 at 09:51
  • 2
    I had a play with this today - it seemed that `ip()` should be what you're after, but I couldn't get any output from it – alexwhan Jun 17 '13 at 10:29
  • @alexwhan hi, thanks for that. In which package is `ip`? – Michele Jun 17 '13 at 10:47
  • 2
    In Rook - from the help (p12) "ip(): Returns the remote IP address as a character string." and (p13): `res$write(c(’ip: ’,req$ip(),’\n’))`. But I repeat - this did NOT work for me, otherwise I would post it as an answer. It only gave empty output. – alexwhan Jun 17 '13 at 10:51
  • @alexwhan Thanks a lot. I had a look at that. `req$ip` seems to be a call to `env[["REMOTE_ADDR"]]` which is `NULL`... – Michele Jun 17 '13 at 11:42
  • 4
    Deploy your Rook app with [rApache](http://rapache.net/manual.html#Rook) and you will end up with a nice `access.log` in standard format (with IP and time-stamp). – daroczig Jun 17 '13 at 20:59
  • @daroczig thanks for your input. I'll install and configure rApache asap, probably on Friday and update with the code. – Michele Jun 18 '13 at 06:20
  • @alexwhan The source of rook shows the addr is written when rApache is the backend, so that command should work after setup. – Thell Jun 18 '13 at 22:51
  • @Thell my apps currently run on windows but I've a got a virtual machine with ubuntu server to test `rApache`. Regarding `Shiny`, would retrieve the local ip be possible with it? – Michele Jun 18 '13 at 23:58
  • @Thell I've managed to setting up the server. It's amazing! Thanks, probably I'm on the right way. But I'm a bit stuck in the 2nd step, (setting the config log). would you tell me how to do that? it'd be great! – Michele Jun 22 '13 at 10:27
  • @Thell I've edited the question with my attempt of setting the `config_log` – Michele Jun 22 '13 at 16:32
  • @Thell everything done! I have now a detailed report with all accesses. Thanks a lot. I'd be happy to accept your answer if you post it (bounty is about to expire..) – Michele Jun 23 '13 at 11:51
  • Michele, it may be worth while to alter the Question title and the tags used. I'll clean up my comment steam and put it in an answer. Thanks. – Thell Jun 23 '13 at 16:55
  • @Thell I know (I personally mentioned my doubts about tags when posted). I'll make a change, feel free to edit again if necessary. thanks – Michele Jun 23 '13 at 17:23

1 Answers1

3

It seems that Rook will only provide remote add when backed by rApache.

Another option would be to setup shiny-server from the fine folks @ RStudio and then configure the access log such that you'd be able to parse that using the selected access log format that you choose.

I'd lean toward the Shiny solution as the author of rApache also helped on Shiny and Shiny (being that it is an official product of RStudio) seems poised for growth and long term availability which we can't really say about rApache (as fine as it is!).

Thell
  • 5,883
  • 31
  • 55
  • thanks for your patience during this week! By the way, in these days, while setting shiny up, I saw that it is build onto `Node.js`, which allows getting the ip very easily through the `connect` module. this module is the thing behind `access_log`, but unfortunately in shiny, differently then with Node, you can't access the retrieved ip into the server side code. According to this discussion [https://groups.google.com/forum/#!searchin/shiny-discuss/susan/shiny-discuss/EGQhEyoEk3E/lNQ5jLbPOBsJ] they are working on it – Michele Jun 23 '13 at 17:38
  • 1
    My pleasure. Interesting... I bet that could be inserted fairly easily into the api; and I'm guessing that those types of full control features will need to be in place for the enterprise edition, so be patient; or better yet, hack that shiny source! :) – Thell Jun 23 '13 at 22:35