1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Dialog, DialogActions, Button, StyleRulesCallback, WithStyles, withStyles, CardHeader, Tab, Tabs } from '@material-ui/core';
7 import { withDialog } from "store/dialog/with-dialog";
8 import { COLLECTION_WEBDAV_S3_DIALOG_NAME, WebDavS3InfoDialogData } from 'store/collections/collection-info-actions';
9 import { WithDialogProps } from 'store/dialog/with-dialog';
10 import { compose } from 'redux';
11 import { DetailsAttribute } from "components/details-attribute/details-attribute";
12 import { DownloadIcon } from "components/icon/icon";
13 import { DefaultCodeSnippet } from "components/default-code-snippet/default-code-snippet";
15 export type CssRules = 'details' | 'downloadButton' | 'detailsAttrValWithCode';
17 const styles: StyleRulesCallback<CssRules> = theme => ({
19 marginLeft: theme.spacing.unit * 3,
20 marginRight: theme.spacing.unit * 3,
23 marginTop: theme.spacing.unit * 2,
25 detailsAttrValWithCode: {
31 interface TabPanelData {
32 children: React.ReactElement<any>[];
37 function TabPanel(props: TabPanelData) {
38 const { children, value, index } = props;
43 hidden={value !== index}
44 id={`simple-tabpanel-${index}`}
45 aria-labelledby={`simple-tab-${index}`}
47 {value === index && children}
52 const isValidIpAddress = (ipAddress: string): Boolean => {
53 if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress)) {
60 const mountainduckTemplate = ({
67 return `<?xml version="1.0" encoding="UTF-8"?>
68 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
74 <string>iterate GmbH</string>
76 <string>${uuid}</string>
78 <string>${collectionsUrl.replace('https://', ``).replace('*', uuid).split(':')[0]}</string>
80 <string>${(cyberDavStr.split(':')[2] || '443').split('/')[0]}</string>
82 <string>${username}</string>${isValidIpAddress(collectionsUrl.replace('https://', ``).split(':')[0])?
85 <string>/c=${uuid}</string>` : ''}
90 </plist>`.split(/\r?\n/).join('\n');
93 const downloadMountainduckFileHandler = (filename: string, text: string) => {
94 const element = document.createElement('a');
95 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
96 element.setAttribute('download', filename);
98 element.style.display = 'none';
99 document.body.appendChild(element);
103 document.body.removeChild(element);
106 export const WebDavS3InfoDialog = compose(
107 withDialog(COLLECTION_WEBDAV_S3_DIALOG_NAME),
110 (props: WithDialogProps<WebDavS3InfoDialogData> & WithStyles<CssRules>) => {
111 if (!props.data.downloadUrl) { return null; }
116 if (props.data.collectionsUrl.indexOf("*") > -1) {
117 const withuuid = props.data.collectionsUrl.replace("*", props.data.uuid);
118 winDav = new URL(withuuid);
119 cyberDav = new URL(withuuid);
121 winDav = new URL(props.data.downloadUrl);
122 cyberDav = new URL(props.data.downloadUrl);
123 winDav.pathname = `/by_id/${props.data.uuid}`;
124 cyberDav.pathname = `/by_id/${props.data.uuid}`;
127 cyberDav.username = props.data.username;
128 const cyberDavStr = "dav" + cyberDav.toString().slice(4);
130 const s3endpoint = new URL(props.data.collectionsUrl.replace(/\/\*(--[^.]+)?\./, "/"));
132 const sp = props.data.token.split("/");
135 if (sp.length === 3 && sp[0] === "v2" && sp[1].slice(0, 5) === props.data.localCluster) {
139 tokenUuid = props.data.token.replace(/\//g, "_");
140 tokenSecret = tokenUuid;
143 const isCollection = (props.data.uuid.indexOf("-4zz18-") === 5);
145 let activeTab = props.data.activeTab;
150 const wgetCommand = `wget --http-user=${props.data.username} --http-passwd=${props.data.token} --mirror --no-parent --no-host --cut-dirs=0 ${winDav.toString()}`;
151 const curlCommand = `curl -O -u ${props.data.username}:${props.data.token} ${winDav.toString()}`;
156 onClose={props.closeDialog}
157 style={{ alignSelf: 'stretch' }}>
159 title={`Open with 3rd party client`} />
160 <div className={props.classes.details} >
161 <Tabs value={activeTab} onChange={props.data.setActiveTab}>
162 {isCollection && <Tab value={0} key="cyberduck" label="WebDAV" />}
163 {isCollection && <Tab value={1} key="windows" label="Windows or MacOS" />}
164 <Tab value={2} key="s3" label="S3 bucket" />
165 {isCollection && <Tab value={3} key="cli" label="wget / curl" />}
168 <TabPanel index={1} value={activeTab}>
172 label='Internet address'
173 value={<a href={winDav.toString()} target="_blank" rel="noopener noreferrer">{winDav.toString()}</a>}
174 copyValue={winDav.toString()} />
178 value={props.data.username}
179 copyValue={props.data.username} />
183 value={props.data.token}
184 copyValue={props.data.token} />
188 <li>Open File Explorer</li>
189 <li>Click on "This PC", then go to Computer → Add a Network Location</li>
190 <li>Click Next, then choose "Add a custom network location", then click Next</li>
191 <li>Use the "internet address" and credentials listed under Settings, above</li>
197 <li>Click Go → Connect to server</li>
198 <li>Use the "internet address" and credentials listed under Settings, above</li>
202 <TabPanel index={0} value={activeTab}>
205 value={<a href={cyberDavStr} target="_blank" rel="noopener noreferrer">{cyberDavStr}</a>}
206 copyValue={cyberDavStr} />
210 value={props.data.username}
211 copyValue={props.data.username} />
215 value={props.data.token}
216 copyValue={props.data.token} />
218 <h3>Cyberduck/Mountain Duck</h3>
221 data-cy='download-button'
222 className={props.classes.downloadButton}
223 onClick={() => downloadMountainduckFileHandler(`${props.data.collectionName || props.data.uuid}.duck`, mountainduckTemplate({ ...props.data, cyberDavStr }))}
228 Download Cyber/Mountain Duck bookmark
234 <li>Select +Other Locations</li>
235 <li>Connect to Server → Enter server address</li>
240 <TabPanel index={2} value={activeTab}>
243 value={s3endpoint.host}
244 copyValue={s3endpoint.host} />
248 value={props.data.uuid}
249 copyValue={props.data.uuid} />
254 copyValue={tokenUuid} />
259 copyValue={tokenSecret} />
263 <TabPanel index={3} value={activeTab}>
267 copyValue={wgetCommand}
268 classValue={props.classes.detailsAttrValWithCode}>
270 lines={[wgetCommand]} />
275 copyValue={curlCommand}
276 classValue={props.classes.detailsAttrValWithCode}>
278 lines={[curlCommand]} />
282 Note: This curl command downloads single files.
283 Append the desired filename to the end of the URL.
293 onClick={props.closeDialog}>