import React from 'react'; import superagent from 'superagent'; import { Segment, Header, Icon, Button, Table, Label, Modal, Message, Form } from 'semantic-ui-react' import ApiButtonModal from '../../CloudApi/ApiButtonModal.jsx'; export default class AccountIPManager extends React.Component { constructor(props) { super(props); this.state = { loading: false, securityGroup: null, newIpAddress: "" }; } async componentDidMount() { return this.reload(); } async reload() { try { this.setState({securityGroup: null, loading: true}); const result = await superagent.get(`/api/admin/account/${this.props.accountId}/security_groups`).accept('json'); this.setState({ loading: false, securityGroup: result.body }); } catch (e) { console.log(e); this.setState({ loading: false, securityGroup: null }); } } async onChange(e, { name, value }) { this.setState({ [name]: value }) } stripCidrSuffix(cidrIp) { // Strip /32 for IPv4 or /128 for IPv6 if (cidrIp.endsWith('/32') || cidrIp.endsWith('/128')) { return cidrIp.substring(0, cidrIp.lastIndexOf('/')); } return cidrIp; } async onAddIP() { try { const ipAddress = this.stripCidrSuffix(this.state.newIpAddress); const result = await superagent.put(`/api/admin/account/${this.props.accountId}/security_groups/${ipAddress}`).accept('json').send(); console.log(result.body); this.setState({ newIpAddress: "" }); await this.reload(); } catch (e) { console.log(e); } } async onRemoveIP(ipRange) { try { const ipAddress = this.stripCidrSuffix(ipRange.CidrIp); const result = await superagent.delete(`/api/admin/account/${this.props.accountId}/security_groups/${ipAddress}`).accept('json').send(); console.log(result.body); await this.reload(); } catch (e) { console.log(e); } } getAccessType(ipPermission) { if (ipPermission.IpProtocol === 'tcp' && ipPermission.FromPort === 443 && ipPermission.ToPort === 443) { return 'Web Access'; } if (ipPermission.FromPort && ipPermission.ToPort) { return `${ipPermission.IpProtocol} ports ${ipPermission.FromPort}-${ipPermission.ToPort}`; } return ipPermission.IpProtocol; } render() { if (this.state.loading) { return ( Loading IP addresses... ) } if (!this.state.securityGroup) { return ( No security group information available for this account. ) } const securityGroup = this.state.securityGroup; // Collect all IP ranges from all permissions const ipRanges = []; if (securityGroup.IpPermissions && securityGroup.IpPermissions.length > 0) { securityGroup.IpPermissions.forEach(permission => { if (permission.IpRanges && permission.IpRanges.length > 0) { permission.IpRanges.forEach(ipRange => { ipRanges.push({ ...ipRange, permission: permission }); }); } }); } return (
IP Addresses Allows HTTPS Access to Arda and Admin APIs
IP Address Access Type Actions {ipRanges.length > 0 ? ( ipRanges.map((ipRange, index) => { const accessType = this.getAccessType(ipRange.permission); const displayIp = this.stripCidrSuffix(ipRange.CidrIp); return ( {ipRange.Description && ( {ipRange.Description} )} this.onRemoveIP(ipRange)}> Are you sure you want to remove {displayIp} from this account's allowed IP addresses?

Warning This will immediately revoke access from this IP address.
) }) ) : ( No IP addresses configured for this account. )}

Add a new IP address to this account's security group.

); } }