Changeset 74

Show
Ignore:
Timestamp:
07/01/09 16:22:13 (4 years ago)
Author:
cyrus
Message:

Export REMOTE_ADDR and SERVER_ADDR through LuCIttpd

Location:
trunk/luci/libs/lucittpd
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/luci/libs/lucittpd/hostfiles/usr/lib/lucittpd/plugins/httpd.lua

    r4 r74  
    3030                        local chunk, err = webuci_sendfile(...) 
    3131                        return chunk or (err and error(err, 0)) 
    32                 end 
     32                end, 
     33 
     34                _REMOTE_ADDR = webuci_REMOTE_ADDR, 
     35                _SERVER_ADDR = webuci_SERVER_ADDR 
    3336        }) 
    3437end 
  • trunk/luci/libs/lucittpd/luasrc/ttpd/server.lua

    r4 r74  
    323323                end 
    324324 
     325                -- set remote_addr and server_addr 
     326                message.env.REMOTE_ADDR = self._REMOTE_ADDR 
     327                message.env.SERVER_ADDR = self._SERVER_ADDR 
     328 
    325329                -- keep-alive 
    326330                if message.http_version == 1.1 then 
  • trunk/luci/libs/lucittpd/root/usr/lib/lucittpd/plugins/httpd.lua

    r4 r74  
    3131                        local chunk, err = webuci_sendfile(...) 
    3232                        return chunk or (err and error(err, 0)) 
    33                 end 
     33                end, 
     34 
     35                _REMOTE_ADDR = webuci_REMOTE_ADDR, 
     36                _SERVER_ADDR = webuci_SERVER_ADDR 
    3437        }) 
    3538end 
  • trunk/luci/libs/lucittpd/src/main.c

    r4 r74  
    212212} 
    213213 
    214 static void run_luci(int sockfd) 
    215 { 
     214static void run_luci(int sockfd, char *remote_addr, char *server_addr) 
     215{ 
     216        lua_pushstring(ctx.L, remote_addr); 
     217        lua_setfield(ctx.L, LUA_GLOBALSINDEX, "webuci_REMOTE_ADDR"); 
     218 
     219        lua_pushstring(ctx.L, server_addr); 
     220        lua_setfield(ctx.L, LUA_GLOBALSINDEX, "webuci_SERVER_ADDR"); 
     221 
    216222        lua_pushinteger(ctx.L, sockfd); 
    217223        lua_pushcclosure(ctx.L, webuci_read, 1); 
     
    245251{ 
    246252        int sockfd, new_fd; 
    247         struct sockaddr_storage their_addr; 
    248253        socklen_t sin_size; 
    249254        int yes = 1; 
    250         struct sockaddr_in myaddr; 
     255        struct sockaddr_in myaddr, local_addr, their_addr; 
     256        char local_ip[INET6_ADDRSTRLEN+1], remote_ip[INET6_ADDRSTRLEN+1]; 
    251257 
    252258        log_start(1); 
     
    308314                        continue; 
    309315                } 
     316                memset(remote_ip, 0, sizeof remote_ip); 
     317                inet_ntop(their_addr.sin_family, (void*)&their_addr.sin_addr, 
     318                                remote_ip, sizeof remote_ip); 
     319 
     320                /* local address */ 
     321                memset(local_ip, 0, sizeof local_ip); 
     322                sin_size = sizeof local_addr; 
     323                getsockname(new_fd, (struct sockaddr*)&local_addr, &sin_size); 
     324                inet_ntop(local_addr.sin_family, (void*)&local_addr.sin_addr, 
     325                                local_ip, sizeof local_ip); 
     326 
    310327 
    311328                /*inet_ntop(their_addr.ss_family, 
     
    321338                        setsockopt(new_fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); 
    322339 
    323                         run_luci(new_fd); 
     340                        run_luci(new_fd, remote_ip, local_ip); 
    324341                        cleanup_luci(); 
    325342                        close(new_fd);