aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/components/flowdetail.jsx.js
blob: 7c984193049b18f4df26b04e6cc377deeded4bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/** @jsx React.DOM */

var FlowDetailNav = React.createClass({
    render: function(){

        var items = this.props.tabs.map(function(e){
            var str = e.charAt(0).toUpperCase() + e.slice(1);
            var className = this.props.active === e ? "active" : "";
            var onClick = function(){
                this.props.selectTab(e);
                return false;
            }.bind(this);
            return <a key={e}
                      href="#" 
                      className={className}
                      onClick={onClick}>{str}</a>;
        }.bind(this));
        return (
            <nav ref="head" className="nav-tabs nav-tabs-sm">
                {items}
            </nav>
        );
    } 
});

var Headers = React.createClass({
    render: function(){
        var rows = this.props.message.headers.map(function(header){
            return (
                <tr>
                    <td className="header-name">{header[0]+":"}</td>
                    <td className="header-value">{header[1]}</td>
                </tr>
            );
        });
        return (
            <table className="header-table">
                <tbody>
                    {rows}
                </tbody>
            </table>
        );
    }
});

var FlowDetailRequest = React.createClass({
    render: function(){
        var flow = this.props.flow;
        var first_line = [
                flow.request.method,
                RequestUtils.pretty_url(flow.request),
                "HTTP/"+ flow.response.httpversion.join(".")
            ].join(" ");
        var content = null;
        if(flow.request.contentLength > 0){
            content = "Request Content Size: "+ formatSize(flow.request.contentLength);
        } else {
            content = <div className="alert alert-info">No Content</div>;
        }

        //TODO: Styling

        return (
            <section>
                <code>{ first_line }</code>
                <Headers message={flow.request}/>
                <hr/>
                {content}
            </section>
        );
    }
});

var FlowDetailResponse = React.createClass({
    render: function(){
        var flow = this.props.flow;
        var first_line = [
                "HTTP/"+ flow.response.httpversion.join("."),
                flow.response.code,
                flow.response.msg
            ].join(" ");
        var content = null;
        if(flow.response.contentLength > 0){
            content = "Response Content Size: "+ formatSize(flow.response.contentLength);
        } else {
            content = <div className="alert alert-info">No Content</div>;
        }

        //TODO: Styling

        return (
            <section>
                <code>{ first_line }</code>
                <Headers message={flow.response}/>
                <hr/>
                {content}
            </section>
        );
    }
});

var TimeStamp = React.createClass({
    render: function() {
        var ts, delta;

        if(!this.props.t && this.props.optional){
            //should be return null, but that triggers a React bug.
            return <tr></tr>;
        } else if (!this.props.t){
            ts = "active";
        } else {
            ts = (new Date(this.props.t * 1000)).toISOString();
            ts = ts.replace("T", " ").replace("Z","");

            if(this.props.deltaTo){
                delta = Math.round((this.props.t-this.props.deltaTo)*1000) + "ms";
                delta = <span className="text-muted">{"(" + delta + ")"}</span>;
            } else {
                delta = null;
            }
        }

        return <tr><td>{this.props.title + ":"}</td><td>{ts} {delta}</td></tr>;
    }
});

var ConnectionInfo = React.createClass({

    render: function() {
        var conn = this.props.conn;
        var address = conn.address.address.join(":");

        var sni = <tr key="sni"></tr>; //should be null, but that triggers a React bug.
        if(conn.sni){
            sni = <tr key="sni"><td><abbr title="TLS Server Name Indication">TLS SNI:</abbr></td><td>{conn.sni}</td></tr>;
        }
        return (
            <table className="connection-table">
                <tbody>
                    <tr key="address"><td>Address:</td><td>{address}</td></tr>
                    {sni}
                    <TimeStamp title="Start time"
                               key="start"
                               t={conn.timestamp_start} />
                    <TimeStamp title="TCP Setup"
                               key="tcpsetup"
                               t={conn.timestamp_tcp_setup}
                               deltaTo={conn.timestamp_start}
                               optional={true} />
                    <TimeStamp title="SSL handshake"
                               key="sslsetup"
                               t={conn.timestamp_ssl_setup}
                               deltaTo={conn.timestamp_start}
                               optional={true} />
                    <TimeStamp title="End time"
                               key="end"
                               t={conn.timestamp_end}
                               deltaTo={conn.timestamp_start} />
                </tbody>
            </table>
        );
    }
});

var CertificateInfo = React.createClass({
    render: function(){
        //TODO: We should fetch human-readable certificate representation
        // from the server
        var flow = this.props.flow;
        var client_conn = flow.client_conn;
        var server_conn = flow.server_conn;
        return (
            <div>
            {client_conn.cert ? <h4>Client Certificate</h4> : null}
            {client_conn.cert ? <pre>{client_conn.cert}</pre> : null}

            {server_conn.cert ? <h4>Server Certificate</h4> : null}
            {server_conn.cert ? <pre>{server_conn.cert}</pre> : null}
            </div>
        );
    }
});

var FlowDetailConnectionInfo = React.createClass({
    render: function(){
        var flow = this.props.flow;
        var client_conn = flow.client_conn;
        var server_conn = flow.server_conn;
        return (
            <section>

            <h4>Client Connection</h4>
            <ConnectionInfo conn={client_conn}/>

            <h4>Server Connection</h4>
            <ConnectionInfo conn={server_conn}/>

            <CertificateInfo flow={flow}/>

            </section>
        );
    }
});

var tabs = {
    request: FlowDetailRequest,
    response: FlowDetailResponse,
    details: FlowDetailConnectionInfo
};

var FlowDetail = React.createClass({
    getDefaultProps: function(){
        return {
            tabs: ["request","response", "details"]
        };
    },
    mixins: [StickyHeadMixin],
    nextTab: function(i) {
        var currentIndex = this.props.tabs.indexOf(this.props.active);
        // JS modulo operator doesn't correct negative numbers, make sure that we are positive.
        var nextIndex = (currentIndex + i + this.props.tabs.length) % this.props.tabs.length;
        this.props.selectTab(this.props.tabs[nextIndex]);
    },
    render: function(){
        var flow = JSON.stringify(this.props.flow, null, 2);
        var Tab = tabs[this.props.active];
        return (
            <div className="flow-detail" onScroll={this.adjustHead}>
                <FlowDetailNav ref="head"
                               tabs={this.props.tabs}
                               active={this.props.active}
                               selectTab={this.props.selectTab}/>
                <Tab flow={this.props.flow}/>
            </div>
            );
    } 
});