Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http_server = context.CreateTcpServer();
- http_server.onaccept = 'http_server_accept';
- http_server.listen(5000, "0.0.0.0");
- function http_server_accept()
- {
- peer.onreadline = 'peer_readline';
- }
- function peer_readline()
- {
- var args = text.split(' ');
- if (args[0] == 'GET' || args[0] == 'POST')
- {
- peer.hand = args[1] + ' ' + args[2];
- }
- if (text.length == 0)
- {
- processRequest(peer.hand.split(' ')[0]);
- }
- }
- function sendResponse(response)
- {
- peer.sendline(peer.hand.split(' ')[1] + ' 200 OK');
- peer.sendline('Server: cubix 6.2');
- peer.sendline('Date: ' + new Date());
- peer.sendline('Content-Type: text/html');
- peer.sendline('Content-Length: ' + (response.length + 2));
- peer.sendline('');
- peer.sendline(response);
- }
- function processRequest(document)
- {
- switch (document)
- {
- case '/':
- sendResponse("<h1>You are at the root directory</h1>");
- break;
- default:
- sendResponse(dumpChannel('#' + document.substring(1)));
- break;
- }
- }
- function dumpChannel(chan)
- {
- var chan = irc.channel(chan);
- var result = '<html>' + '\r\n';
- result += '<head>' + '\r\n';
- result += '<meta http-equiv="refresh" content="5">' + '\r\n';
- result += '<style type="text/css">' + '\r\n';
- result += '<!--' + '\r\n';
- result += 'td{font-family:"Fixedsys Excelsior 2.00"; src: url("http://prog.ma/fixedsys.ttf"); font-size: 11pt;}' + '\r\n';
- result += '--->' + '\r\n';
- result += '</style>' + '\r\n';
- result += '</head>' + '\r\n';
- result += '<body>' + '\r\n';
- result += '<h1>' + chan + '</h1>' + '\r\n';
- result += '<h2>Topic: ' + chan.topic + '</h2>' + '\r\n';
- result += '<h2>Users: ' + chan.users.count + '</h2>' + '\r\n';
- result += '<table border="1" width="700" style="table-layout:fixed">' + '\r\n';
- result += '<col width="130">' + '\r\n';
- result += '<col width="570">' + '\r\n';
- result += '<tr>' + '\r\n';
- result += '<th>User</td>' + '\r\n';
- result += '<th>Full address</td>' + '\r\n';
- result += '</tr>' + '\r\n';
- for (var i = 0; i < chan.users.count; i++)
- {
- result += '<tr>' + '\r\n';
- result += '<td>' + chan.users(i).nickname + '</td>' + '\r\n';
- result += '<td>' + chan.users(i).fulladdress + '</td>' + '\r\n';
- result += '</tr>' + '\r\n';
- }
- result += '</table>' + '\r\n';
- result += '</body>' + '\r\n';
- result += '</html>' + '\r\n';
- return result;
- }
Add Comment
Please, Sign In to add comment