forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload-root-ca.jsx
More file actions
161 lines (138 loc) · 4.9 KB
/
Copy pathdownload-root-ca.jsx
File metadata and controls
161 lines (138 loc) · 4.9 KB
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
/**
* The panel to edit the filter
*
*/
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import ClassBind from 'classnames/bind';
import { connect } from 'react-redux';
import { message, Button, Spin } from 'antd';
import ResizablePanel from 'component/resizable-panel';
import { hideRootCA, updateIsRootCAExists } from 'action/globalStatusAction';
import { MenuKeyMap } from 'common/Constant';
import { getJSON, ajaxGet, postJSON } from 'common/ApiUtil';
import Style from './download-root-ca.less';
import CommonStyle from '../style/common.less';
class DownloadRootCA extends React.Component {
constructor () {
super();
this.state = {
loadingCAQr: false,
generatingCA: false
};
this.onClose = this.onClose.bind(this);
this.getQrCodeContent = this.getQrCodeContent.bind(this);
}
static propTypes = {
dispatch: PropTypes.func,
globalStatus: PropTypes.object
}
fetchData () {
this.setState({
loadingCAQr: true
});
getJSON('/api/getQrCode')
.then((response) => {
this.setState({
loadingCAQr: false,
CAQrCodeImageDom: response.qrImgDom,
isRootCAFileExists: response.isRootCAFileExists,
url: response.url
});
})
.catch((error) => {
console.error(error);
message.error(error.errorMsg || 'Failed to get the QR code of RootCA path.');
});
}
onClose () {
this.props.dispatch(hideRootCA());
}
getQrCodeContent () {
const imgDomContent = { __html: this.state.CAQrCodeImageDom };
const content = (
<div className={Style.qrCodeWrapper} >
<div dangerouslySetInnerHTML={imgDomContent} />
<span>Scan to download rootCA.crt to your Phone</span>
</div>
);
const spin = <Spin />;
return this.state.loadingCAQr ? spin : content;
}
getGenerateRootCADiv () {
const doToggleRemoteIntercept = () => {
postJSON('/api/generateRootCA')
.then((result) => {
this.setState({
generateRootCA: false,
isRootCAFileExists: true
});
this.props.dispatch(updateIsRootCAExists(true));
})
.catch((error) => {
this.setState({
generatingCA: false
});
message.error('生成根证书失败,请重试');
});
};
return (
<div className={Style.wrapper}>
<div className={Style.title} >
RootCA
</div>
<div className={Style.generateRootCaTip} >
<span >Your RootCA has not been generated yet, please click the button to generate before you download it.</span>
<span className={Style.strongColor} >Please install and trust the generated RootCA.</span>
</div>
<div className={Style.generateCAButton} >
<Button
type="primary"
size="large"
onClick={doToggleRemoteIntercept}
loading={this.state.generateRootCA}
>
OK, GENERATE
</Button>
</div>
</div>
);
}
getDownloadDiv () {
return (
<div className={Style.wrapper} >
<div className={Style.fullHeightWrapper} >
<div className={Style.title} >
RootCA
</div>
<div className={Style.arCodeDivWrapper} >
{this.getQrCodeContent()}
</div>
</div>
<div className={Style.buttons} >
<a href="/fetchCrtFile" target="_blank">
<Button type="primary" size="large" > Download </Button>
</a>
<span className={Style.tipSpan} >Or click the button to download.</span>
</div>
</div>
);
}
componentDidMount () {
this.fetchData();
}
render() {
const panelVisible = this.props.globalStatus.activeMenuKey === MenuKeyMap.ROOT_CA;
return (
<ResizablePanel onClose={this.onClose} visible={panelVisible} >
{this.props.globalStatus.isRootCAFileExists ? this.getDownloadDiv() : this.getGenerateRootCADiv()}
</ResizablePanel>
);
}
}
function select (state) {
return {
globalStatus: state.globalStatus
};
}
export default connect(select)(DownloadRootCA);