diff --git a/app/mobile/src/api/addAccount.js b/app/mobile/src/api/addAccount.js index 1252a1a8..35a84257 100644 --- a/app/mobile/src/api/addAccount.js +++ b/app/mobile/src/api/addAccount.js @@ -2,13 +2,15 @@ import { checkResponse, fetchWithCustomTimeout } from './fetchUtil'; import base64 from 'react-native-base64' export async function addAccount(server, username, password, token) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let access = ""; if (token) { access = `?token=${token}` } let headers = new Headers() headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password)); - let profile = await fetchWithCustomTimeout(`https://${server}/account/profile${access}`, { method: 'POST', headers: headers }, 60000) + let profile = await fetchWithCustomTimeout(`${protocol}://${server}/account/profile${access}`, { method: 'POST', headers: headers }, 60000) checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/api/addAccountAccess.js b/app/mobile/src/api/addAccountAccess.js index 90584a1b..8765c979 100644 --- a/app/mobile/src/api/addAccountAccess.js +++ b/app/mobile/src/api/addAccountAccess.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addAccountAccess(server, token, accountId) { - let access = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}/auth?token=${token}`, { method: 'POST' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let access = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}/auth?token=${token}`, { method: 'POST' }) checkResponse(access); return await access.json() } diff --git a/app/mobile/src/api/addAccountCreate.js b/app/mobile/src/api/addAccountCreate.js index 1642a0ab..0888299a 100644 --- a/app/mobile/src/api/addAccountCreate.js +++ b/app/mobile/src/api/addAccountCreate.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addAccountCreate(server, token) { - let access = await fetchWithTimeout(`https://${server}/admin/accounts?token=${token}`, { method: 'POST' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let access = await fetchWithTimeout(`${protocol}://${server}/admin/accounts?token=${token}`, { method: 'POST' }) checkResponse(access); return await access.json() } diff --git a/app/mobile/src/api/addCall.js b/app/mobile/src/api/addCall.js index caa11954..157dd2d0 100644 --- a/app/mobile/src/api/addCall.js +++ b/app/mobile/src/api/addCall.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addCall(server, token, cardId) { - let call = await fetchWithTimeout(`https://${server}/talk/calls?agent=${token}`, { method: 'POST', body: JSON.stringify(cardId)} ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls?agent=${token}`, { method: 'POST', body: JSON.stringify(cardId)} ); checkResponse(call); return await call.json(); } diff --git a/app/mobile/src/api/addCard.js b/app/mobile/src/api/addCard.js index 684a8238..ce65181a 100644 --- a/app/mobile/src/api/addCard.js +++ b/app/mobile/src/api/addCard.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addCard(server, token, message) { - let card = await fetchWithTimeout(`https://${server}/contact/cards?agent=${token}`, { method: 'POST', body: JSON.stringify(message)} ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards?agent=${token}`, { method: 'POST', body: JSON.stringify(message)} ); checkResponse(card); return await card.json(); } diff --git a/app/mobile/src/api/addChannel.js b/app/mobile/src/api/addChannel.js index 2bfebea9..1d69a3e5 100644 --- a/app/mobile/src/api/addChannel.js +++ b/app/mobile/src/api/addChannel.js @@ -1,8 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addChannel(server, token, type, data, cards ) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let params = { dataType: type, data: JSON.stringify(data), groups: [], cards }; - let channel = await fetchWithTimeout(`https://${server}/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} ); + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} ); checkResponse(channel); return await channel.json(); } diff --git a/app/mobile/src/api/addChannelTopic.js b/app/mobile/src/api/addChannelTopic.js index be37692c..fd340a9e 100644 --- a/app/mobile/src/api/addChannelTopic.js +++ b/app/mobile/src/api/addChannelTopic.js @@ -1,9 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addChannelTopic(server, token, channelId, messageType, message, assets ): string { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; if (message == null && (assets == null || assets.length === 0)) { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${token}`, { method: 'POST', body: JSON.stringify({}) }); checkResponse(topic); let slot = await topic.json(); @@ -14,7 +16,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes if (value !== null) return value }), datatype: messageType }; - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}&confirm=true`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${token}&confirm=true`, { method: 'POST', body: JSON.stringify(subject) }); checkResponse(topic); let slot = await topic.json(); @@ -22,7 +24,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes } else { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${token}`, { method: 'POST', body: JSON.stringify({}) }); checkResponse(topic); let slot = await topic.json(); @@ -34,7 +36,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes const formData = new FormData(); formData.append('asset', asset.image); let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -49,7 +51,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes formData.append('asset', asset.video); let thumb = 'vthumb;video;' + asset.position; let transform = encodeURIComponent(JSON.stringify(["vlq;video", "vhd;video", thumb])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -64,7 +66,7 @@ export async function addChannelTopic(server, token, channelId, messageType, mes const formData = new FormData(); formData.append('asset', asset.audio); let transform = encodeURIComponent(JSON.stringify(["acopy;audio"])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -80,11 +82,11 @@ export async function addChannelTopic(server, token, channelId, messageType, mes if (value !== null) return value }), datatype: messageType }; - let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`, + let unconfirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(subject) }); checkResponse(unconfirmed); - let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`, + let confirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') }); checkResponse(confirmed); return slot.id; diff --git a/app/mobile/src/api/addContactChannelTopic.js b/app/mobile/src/api/addContactChannelTopic.js index acd85357..b1f9c112 100644 --- a/app/mobile/src/api/addContactChannelTopic.js +++ b/app/mobile/src/api/addContactChannelTopic.js @@ -1,8 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addContactChannelTopic(server, token, channelId, messageType, message, assets ) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + if (message == null && (assets == null || assets.length === 0)) { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}`, { method: 'POST', body: JSON.stringify({}) }); checkResponse(topic); let slot = await topic.json(); @@ -13,14 +16,14 @@ export async function addContactChannelTopic(server, token, channelId, messageTy if (value !== null) return value }), datatype: messageType }; - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`, { method: 'POST', body: JSON.stringify(subject) }); checkResponse(topic); let slot = await topic.json(); return slot.id; } else { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`, + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}`, { method: 'POST', body: JSON.stringify({}) }); checkResponse(topic); let slot = await topic.json(); @@ -32,7 +35,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy const formData = new FormData(); formData.append('asset', asset.image); let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -47,7 +50,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy formData.append('asset', asset.video); let thumb = "vthumb;video;" + asset.position let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -62,7 +65,7 @@ export async function addContactChannelTopic(server, token, channelId, messageTy const formData = new FormData(); formData.append('asset', asset.audio); let transform = encodeURIComponent(JSON.stringify(["acopy;audio"])); - let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); + let topicAsset = await fetch(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData }); checkResponse(topicAsset); let assetEntry = await topicAsset.json(); message.assets.push({ @@ -78,11 +81,11 @@ export async function addContactChannelTopic(server, token, channelId, messageTy if (value !== null) return value }), datatype: messageType }; - let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`, + let unconfirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`, { method: 'PUT', body: JSON.stringify(subject) }); checkResponse(unconfirmed); - let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`, + let confirmed = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') }); checkResponse(confirmed); return slot.id; diff --git a/app/mobile/src/api/addContactRing.js b/app/mobile/src/api/addContactRing.js index 6754ea00..e667377d 100644 --- a/app/mobile/src/api/addContactRing.js +++ b/app/mobile/src/api/addContactRing.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addContactRing(server, token, call) { - let ring = await fetchWithTimeout(`https://${server}/talk/rings?contact=${token}`, { method: 'POST', body: JSON.stringify(call) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let ring = await fetchWithTimeout(`${protocol}://${server}/talk/rings?contact=${token}`, { method: 'POST', body: JSON.stringify(call) }); checkResponse(ring); } diff --git a/app/mobile/src/api/addFlag.js b/app/mobile/src/api/addFlag.js index 14141ec2..791a6538 100644 --- a/app/mobile/src/api/addFlag.js +++ b/app/mobile/src/api/addFlag.js @@ -1,13 +1,15 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function addFlag(server, guid, channel, topic) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; if (channel) { const param = topic ? `&topic=${topic}` : ''; - const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}?channel=${channel}${param}`, { method: 'POST' } ); + const flag = await fetchWithTimeout(`${protocol}://${server}/account/flag/${guid}?channel=${channel}${param}`, { method: 'POST' } ); checkResponse(flag); } else { - const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}`, { method: 'POST' } ); + const flag = await fetchWithTimeout(`${protocol}://${server}/account/flag/${guid}`, { method: 'POST' } ); checkResponse(flag); } } diff --git a/app/mobile/src/api/clearChannelCard.js b/app/mobile/src/api/clearChannelCard.js index c67d042f..35d88694 100644 --- a/app/mobile/src/api/clearChannelCard.js +++ b/app/mobile/src/api/clearChannelCard.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function clearChannelCard(server, token, channelId, cardId ) { - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'}); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'}); checkResponse(channel); return await channel.json(); } diff --git a/app/mobile/src/api/clearLogin.js b/app/mobile/src/api/clearLogin.js index 69b6a321..9ea9c67a 100644 --- a/app/mobile/src/api/clearLogin.js +++ b/app/mobile/src/api/clearLogin.js @@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; import base64 from 'react-native-base64' export async function clearLogin(server, token) { - let logout = await fetchWithTimeout(`https://${server}/account/apps?agent=${token}`, { method: 'DELETE' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let logout = await fetchWithTimeout(`${protocol}://${server}/account/apps?agent=${token}`, { method: 'DELETE' }) checkResponse(logout) } diff --git a/app/mobile/src/api/createAccount.js b/app/mobile/src/api/createAccount.js index d12feb39..9bc8e1ca 100644 --- a/app/mobile/src/api/createAccount.js +++ b/app/mobile/src/api/createAccount.js @@ -2,6 +2,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; import base64 from 'react-native-base64' export async function createAccount(username, password) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let headers = new Headers() headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password)); let profile = await fetchWithTimeout("/account/profile", { method: 'POST', headers: headers }) diff --git a/app/mobile/src/api/getAccountImageUrl.js b/app/mobile/src/api/getAccountImageUrl.js index 5ba95bf9..368d0b03 100644 --- a/app/mobile/src/api/getAccountImageUrl.js +++ b/app/mobile/src/api/getAccountImageUrl.js @@ -1,4 +1,6 @@ export function getAccountImageUrl(server, token, accountId) { - return `https://${server}/admin/accounts/${accountId}/image?token=${token}` + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + return `${protocol}://${server}/admin/accounts/${accountId}/image?token=${token}` } diff --git a/app/mobile/src/api/getAccountStatus.js b/app/mobile/src/api/getAccountStatus.js index 4c7a7f4b..04b4bb66 100644 --- a/app/mobile/src/api/getAccountStatus.js +++ b/app/mobile/src/api/getAccountStatus.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getAccountStatus(server, token) { - let status = await fetchWithTimeout(`https://${server}/account/status?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let status = await fetchWithTimeout(`${protocol}://${server}/account/status?agent=${token}`, { method: 'GET' }); checkResponse(status); return await status.json() } diff --git a/app/mobile/src/api/getAvailable.js b/app/mobile/src/api/getAvailable.js index 1fd16519..d278c799 100644 --- a/app/mobile/src/api/getAvailable.js +++ b/app/mobile/src/api/getAvailable.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getAvailable(server) { - let available = await fetchWithTimeout(`https://${server}/account/available`, { method: 'GET' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let available = await fetchWithTimeout(`${protocol}://${server}/account/available`, { method: 'GET' }) checkResponse(available) return await available.json() } diff --git a/app/mobile/src/api/getCard.js b/app/mobile/src/api/getCard.js index 33bc59e0..6534daa2 100644 --- a/app/mobile/src/api/getCard.js +++ b/app/mobile/src/api/getCard.js @@ -1,8 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCard(server, token, cardId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let param = "?agent=" + token - let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}${param}`, { method: 'GET' }); + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}${param}`, { method: 'GET' }); checkResponse(card); return await card.json() } diff --git a/app/mobile/src/api/getCardCloseMessage.js b/app/mobile/src/api/getCardCloseMessage.js index 0363f027..b8769c5b 100644 --- a/app/mobile/src/api/getCardCloseMessage.js +++ b/app/mobile/src/api/getCardCloseMessage.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCardCloseMessage(server, token, cardId) { - let message = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/closeMessage?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let message = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/closeMessage?agent=${token}`, { method: 'GET' }); checkResponse(message); return await message.json(); } diff --git a/app/mobile/src/api/getCardDetail.js b/app/mobile/src/api/getCardDetail.js index 207b3bf3..0afd46cc 100644 --- a/app/mobile/src/api/getCardDetail.js +++ b/app/mobile/src/api/getCardDetail.js @@ -1,8 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCardDetail(server, token, cardId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let param = "?agent=" + token - let detail = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/detail${param}`, { method: 'GET' }); + let detail = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/detail${param}`, { method: 'GET' }); checkResponse(detail); return await detail.json() } diff --git a/app/mobile/src/api/getCardImageUrl.js b/app/mobile/src/api/getCardImageUrl.js index c91a58c2..95a1f830 100644 --- a/app/mobile/src/api/getCardImageUrl.js +++ b/app/mobile/src/api/getCardImageUrl.js @@ -1,4 +1,6 @@ export function getCardImageUrl(server, token, cardId, revision) { - return `https://${server}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}` + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + return `${protocol}://${server}/contact/cards/${cardId}/profile/image?agent=${token}&revision=${revision}` } diff --git a/app/mobile/src/api/getCardOpenMessage.js b/app/mobile/src/api/getCardOpenMessage.js index 24705605..0824303c 100644 --- a/app/mobile/src/api/getCardOpenMessage.js +++ b/app/mobile/src/api/getCardOpenMessage.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCardOpenMessage(server, token, cardId) { - let message = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/openMessage?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let message = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/openMessage?agent=${token}`, { method: 'GET' }); checkResponse(message); return await message.json(); } diff --git a/app/mobile/src/api/getCardProfile.js b/app/mobile/src/api/getCardProfile.js index 5154c527..13b37e6b 100644 --- a/app/mobile/src/api/getCardProfile.js +++ b/app/mobile/src/api/getCardProfile.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCardProfile(server, token, cardId) { - let profile = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let profile = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'GET' }); checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/api/getCards.js b/app/mobile/src/api/getCards.js index 9c2cde59..c06945ea 100644 --- a/app/mobile/src/api/getCards.js +++ b/app/mobile/src/api/getCards.js @@ -1,11 +1,13 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getCards(server, token, revision) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let param = "agent=" + token if (revision != null) { param += '&revision=' + revision } - let cards = await fetchWithTimeout(`https://${server}/contact/cards?${param}`, { method: 'GET' }); + let cards = await fetchWithTimeout(`${protocol}://${server}/contact/cards?${param}`, { method: 'GET' }); checkResponse(cards) return await cards.json() } diff --git a/app/mobile/src/api/getChannelDetail.js b/app/mobile/src/api/getChannelDetail.js index 3b873a86..dd474a5e 100644 --- a/app/mobile/src/api/getChannelDetail.js +++ b/app/mobile/src/api/getChannelDetail.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannelDetail(server, token, channelId) { - let detail = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/detail?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let detail = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/detail?agent=${token}`, { method: 'GET' }); checkResponse(detail) return await detail.json() } diff --git a/app/mobile/src/api/getChannelNotifications.js b/app/mobile/src/api/getChannelNotifications.js index 8011a543..e9763de0 100644 --- a/app/mobile/src/api/getChannelNotifications.js +++ b/app/mobile/src/api/getChannelNotifications.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannelNotifications(server, token, channelId) { - const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'GET' }); checkResponse(notify) return await notify.json() } diff --git a/app/mobile/src/api/getChannelSummary.js b/app/mobile/src/api/getChannelSummary.js index 062528bc..7be806bd 100644 --- a/app/mobile/src/api/getChannelSummary.js +++ b/app/mobile/src/api/getChannelSummary.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannelSummary(server, token, channelId) { - let summary = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/summary?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let summary = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/summary?agent=${token}`, { method: 'GET' }); checkResponse(summary) return await summary.json() } diff --git a/app/mobile/src/api/getChannelTopic.js b/app/mobile/src/api/getChannelTopic.js index 73492778..c96a8439 100644 --- a/app/mobile/src/api/getChannelTopic.js +++ b/app/mobile/src/api/getChannelTopic.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannelTopic(server, token, channelId, topicId) { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`, + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`, { method: 'GET' }); checkResponse(topic) return await topic.json() diff --git a/app/mobile/src/api/getChannelTopicAssetUrl.js b/app/mobile/src/api/getChannelTopicAssetUrl.js index 8cb7185a..fdc533ac 100644 --- a/app/mobile/src/api/getChannelTopicAssetUrl.js +++ b/app/mobile/src/api/getChannelTopicAssetUrl.js @@ -1,4 +1,6 @@ export function getChannelTopicAssetUrl(server, token, channelId, topicId, assetId) { - return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}` + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + return `${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}` } diff --git a/app/mobile/src/api/getChannelTopics.js b/app/mobile/src/api/getChannelTopics.js index f5f2e0b4..3ddf52c0 100644 --- a/app/mobile/src/api/getChannelTopics.js +++ b/app/mobile/src/api/getChannelTopics.js @@ -1,6 +1,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannelTopics(server, token, channelId, revision, count, begin, end) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let rev = '' if (revision != null) { @@ -18,7 +20,7 @@ export async function getChannelTopics(server, token, channelId, revision, count if (end != null) { edn = `&end=${end}` } - let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`, + let topics = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`, { method: 'GET' }); checkResponse(topics) return { diff --git a/app/mobile/src/api/getChannels.js b/app/mobile/src/api/getChannels.js index 9ea79300..976b907c 100644 --- a/app/mobile/src/api/getChannels.js +++ b/app/mobile/src/api/getChannels.js @@ -1,12 +1,14 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getChannels(server, token, revision) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let param = "?agent=" + token if (revision != null) { param += `&channelRevision=${revision}` } param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`; - let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' }); + let channels = await fetchWithTimeout(`${protocol}://${server}/content/channels${param}`, { method: 'GET' }); checkResponse(channels) let ret = await channels.json() return ret; diff --git a/app/mobile/src/api/getContactChannelDetail.js b/app/mobile/src/api/getContactChannelDetail.js index ef8e5499..3146fb54 100644 --- a/app/mobile/src/api/getContactChannelDetail.js +++ b/app/mobile/src/api/getContactChannelDetail.js @@ -1,9 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannelDetail(server, token, channelId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let host = ""; if (server) { - host = `https://${server}`; + host = `${protocol}://${server}`; } let detail = await fetchWithTimeout(`${host}/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' }); checkResponse(detail) diff --git a/app/mobile/src/api/getContactChannelNotifications.js b/app/mobile/src/api/getContactChannelNotifications.js index f30fed89..e2c77c49 100644 --- a/app/mobile/src/api/getContactChannelNotifications.js +++ b/app/mobile/src/api/getContactChannelNotifications.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannelNotifications(server, token, channelId) { - const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'GET' }); checkResponse(notify) return await notify.json() } diff --git a/app/mobile/src/api/getContactChannelSummary.js b/app/mobile/src/api/getContactChannelSummary.js index 278cbfa6..ad6c9b09 100644 --- a/app/mobile/src/api/getContactChannelSummary.js +++ b/app/mobile/src/api/getContactChannelSummary.js @@ -1,9 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannelSummary(server, token, channelId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let host = ""; if (server) { - host = `https://${server}`; + host = `${protocol}://${server}`; } let summary = await fetchWithTimeout(`${host}/content/channels/${channelId}/summary?contact=${token}`, { method: 'GET' }); checkResponse(summary) diff --git a/app/mobile/src/api/getContactChannelTopic.js b/app/mobile/src/api/getContactChannelTopic.js index 9b921ee0..4e780cd7 100644 --- a/app/mobile/src/api/getContactChannelTopic.js +++ b/app/mobile/src/api/getContactChannelTopic.js @@ -1,7 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannelTopic(server, token, channelId, topicId) { - let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`, + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let topic = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`, { method: 'GET' }); checkResponse(topic) return await topic.json() diff --git a/app/mobile/src/api/getContactChannelTopicAssetUrl.js b/app/mobile/src/api/getContactChannelTopicAssetUrl.js index 6051f74b..a6c13ba2 100644 --- a/app/mobile/src/api/getContactChannelTopicAssetUrl.js +++ b/app/mobile/src/api/getContactChannelTopicAssetUrl.js @@ -1,4 +1,6 @@ export function getContactChannelTopicAssetUrl(server, token, channelId, topicId, assetId) { - return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}` + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + return `${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}` } diff --git a/app/mobile/src/api/getContactChannelTopics.js b/app/mobile/src/api/getContactChannelTopics.js index cef507d2..a50b6d55 100644 --- a/app/mobile/src/api/getContactChannelTopics.js +++ b/app/mobile/src/api/getContactChannelTopics.js @@ -1,6 +1,8 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; let rev = '' if (revision != null) { @@ -18,7 +20,7 @@ export async function getContactChannelTopics(server, token, channelId, revision if (end != null) { edn = `&end=${end}` } - let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`, + let topics = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`, { method: 'GET' }); checkResponse(topics) diff --git a/app/mobile/src/api/getContactChannels.js b/app/mobile/src/api/getContactChannels.js index 5247b843..9dece1b2 100644 --- a/app/mobile/src/api/getContactChannels.js +++ b/app/mobile/src/api/getContactChannels.js @@ -1,6 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannels(server, token, viewRevision, channelRevision) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let param = "?contact=" + token if (viewRevision != null) { param += `&viewRevision=${viewRevision}`; @@ -9,7 +12,7 @@ export async function getContactChannels(server, token, viewRevision, channelRev param += `&channelRevision=${channelRevision}`; } param += `&types=${encodeURIComponent(JSON.stringify(['sealed','superbasic']))}`; - let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' }); + let channels = await fetchWithTimeout(`${protocol}://${server}/content/channels${param}`, { method: 'GET' }); checkResponse(channels) return await channels.json() } diff --git a/app/mobile/src/api/getContactProfile.js b/app/mobile/src/api/getContactProfile.js index b1badc62..1c31b247 100644 --- a/app/mobile/src/api/getContactProfile.js +++ b/app/mobile/src/api/getContactProfile.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactProfile(server, token) { - let profile = await fetchWithTimeout(`https://${server}/profile/message?contact=${token}`, { method: 'GET', }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let profile = await fetchWithTimeout(`${protocol}://${server}/profile/message?contact=${token}`, { method: 'GET', }); checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/api/getGroups.js b/app/mobile/src/api/getGroups.js index a6a64a96..bc85ec52 100644 --- a/app/mobile/src/api/getGroups.js +++ b/app/mobile/src/api/getGroups.js @@ -1,11 +1,14 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; -export async function getGroups(token, revision) { +export async function getGroups(server, token, revision) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let param = "agent=" + token if (revision != null) { param += '&revision=' + revision } - let groups = await fetchWithTimeout(`/alias/groups?${param}`, { method: 'GET' }); + let groups = await fetchWithTimeout(`${protocol}://server/alias/groups?${param}`, { method: 'GET' }); checkResponse(groups) return await groups.json() } diff --git a/app/mobile/src/api/getHandle.js b/app/mobile/src/api/getHandle.js index 4006df55..7d2b8734 100644 --- a/app/mobile/src/api/getHandle.js +++ b/app/mobile/src/api/getHandle.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getHandle(server, token, name) { - let available = await fetchWithTimeout(`https://${server}/account/username?agent=${token}&name=${encodeURIComponent(name)}`, { method: 'GET' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let available = await fetchWithTimeout(`${protocol}://${server}/account/username?agent=${token}&name=${encodeURIComponent(name)}`, { method: 'GET' }) checkResponse(available) return await available.json() } diff --git a/app/mobile/src/api/getListing.js b/app/mobile/src/api/getListing.js index 753c610f..983311e2 100644 --- a/app/mobile/src/api/getListing.js +++ b/app/mobile/src/api/getListing.js @@ -1,8 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getListing(server, filter) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + const param = filter ? `?filter=${filter}` : ''; - let listing = await fetchWithTimeout(`https://${server}/account/listing${param}`, { method: 'GET' }); + let listing = await fetchWithTimeout(`${protocol}://${server}/account/listing${param}`, { method: 'GET' }); checkResponse(listing); return await listing.json(); } diff --git a/app/mobile/src/api/getListingImageUrl.js b/app/mobile/src/api/getListingImageUrl.js index 9399b0db..6307f7ae 100644 --- a/app/mobile/src/api/getListingImageUrl.js +++ b/app/mobile/src/api/getListingImageUrl.js @@ -1,7 +1,10 @@ export function getListingImageUrl(server, guid) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let host = ""; if (server) { - host = `https://${server}`; + host = `${protocol}://${server}`; } return `${host}/account/listing/${guid}/image` diff --git a/app/mobile/src/api/getListingMessage.js b/app/mobile/src/api/getListingMessage.js index aebad94b..14f1a289 100644 --- a/app/mobile/src/api/getListingMessage.js +++ b/app/mobile/src/api/getListingMessage.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getListingMessage(server, guid) { - let listing = await fetchWithTimeout(`https://${server}/account/listing/${guid}/message`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let listing = await fetchWithTimeout(`${protocol}://${server}/account/listing/${guid}/message`, { method: 'GET' }); checkResponse(listing); return await listing.json(); } diff --git a/app/mobile/src/api/getNodeAccounts.js b/app/mobile/src/api/getNodeAccounts.js index a86fa530..0c712db5 100644 --- a/app/mobile/src/api/getNodeAccounts.js +++ b/app/mobile/src/api/getNodeAccounts.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getNodeAccounts(server, token) { - let accounts = await fetchWithTimeout(`https://${server}/admin/accounts?token=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let accounts = await fetchWithTimeout(`${protocol}://${server}/admin/accounts?token=${token}`, { method: 'GET' }); checkResponse(accounts); return await accounts.json(); } diff --git a/app/mobile/src/api/getNodeConfig.js b/app/mobile/src/api/getNodeConfig.js index e4e65f47..2cda2ab9 100644 --- a/app/mobile/src/api/getNodeConfig.js +++ b/app/mobile/src/api/getNodeConfig.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getNodeConfig(server, token) { - let config = await fetchWithTimeout(`https://${server}/admin/config?token=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let config = await fetchWithTimeout(`${protocol}://${server}/admin/config?token=${token}`, { method: 'GET' }); checkResponse(config); return await config.json(); } diff --git a/app/mobile/src/api/getNodeStatus.js b/app/mobile/src/api/getNodeStatus.js index 9770fc8e..bbdb29de 100644 --- a/app/mobile/src/api/getNodeStatus.js +++ b/app/mobile/src/api/getNodeStatus.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getNodeStatus(server) { - let status = await fetchWithTimeout(`https://${server}/admin/status`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let status = await fetchWithTimeout(`${protocol}://${server}/admin/status`, { method: 'GET' }); checkResponse(status); return await status.json(); } diff --git a/app/mobile/src/api/getProfile.js b/app/mobile/src/api/getProfile.js index 7789e053..9481ddf3 100644 --- a/app/mobile/src/api/getProfile.js +++ b/app/mobile/src/api/getProfile.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getProfile(server, token) { - let profile = await fetchWithTimeout(`https://${server}/profile?agent=${token}`, { method: 'GET' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let profile = await fetchWithTimeout(`${protocol}://${server}/profile?agent=${token}`, { method: 'GET' }); checkResponse(profile) return await profile.json() } diff --git a/app/mobile/src/api/getProfileImageUrl.js b/app/mobile/src/api/getProfileImageUrl.js index 46d96a05..fbd66a78 100644 --- a/app/mobile/src/api/getProfileImageUrl.js +++ b/app/mobile/src/api/getProfileImageUrl.js @@ -1,4 +1,7 @@ export function getProfileImageUrl(server, token, revision) { - return `https://${server}/profile/image?agent=${token}&revision=${revision}`; + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + return `${protocol}://${server}/profile/image?agent=${token}&revision=${revision}`; } diff --git a/app/mobile/src/api/getUsername.js b/app/mobile/src/api/getUsername.js index 5fb322dd..b31412b0 100644 --- a/app/mobile/src/api/getUsername.js +++ b/app/mobile/src/api/getUsername.js @@ -1,6 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getUsername(name, server, token) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let query = ""; if (token && name) { query = `?name=${encodeURIComponent(name)}&token=${token}`; @@ -12,7 +15,7 @@ export async function getUsername(name, server, token) { query = `?token=${token}`; } - let available = await fetchWithTimeout(`https://${server}/account/username${query}`, { method: 'GET' }) + let available = await fetchWithTimeout(`${protocol}://${server}/account/username${query}`, { method: 'GET' }) checkResponse(available) return await available.json() } diff --git a/app/mobile/src/api/keepCall.js b/app/mobile/src/api/keepCall.js index 1219de40..4a1cf030 100644 --- a/app/mobile/src/api/keepCall.js +++ b/app/mobile/src/api/keepCall.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function keepCall(server, token, callId) { - let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}`, { method: 'PUT' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?agent=${token}`, { method: 'PUT' }); checkResponse(call); } diff --git a/app/mobile/src/api/removeAccount.js b/app/mobile/src/api/removeAccount.js index a98dfd85..55558167 100644 --- a/app/mobile/src/api/removeAccount.js +++ b/app/mobile/src/api/removeAccount.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeAccount(server, token, accountId) { - let res = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}?token=${token}`, { method: 'DELETE' }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let res = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}?token=${token}`, { method: 'DELETE' }) checkResponse(res); } diff --git a/app/mobile/src/api/removeCall.js b/app/mobile/src/api/removeCall.js index 78bbe14d..b49e7aeb 100644 --- a/app/mobile/src/api/removeCall.js +++ b/app/mobile/src/api/removeCall.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeCall(server, token, callId) { - let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}`, { method: 'DELETE' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?agent=${token}`, { method: 'DELETE' }); checkResponse(call) } diff --git a/app/mobile/src/api/removeCard.js b/app/mobile/src/api/removeCard.js index 2ba2d513..6a2801e7 100644 --- a/app/mobile/src/api/removeCard.js +++ b/app/mobile/src/api/removeCard.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeCard(server, token, cardId) { - let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}?agent=${token}`, { method: 'DELETE' } ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}?agent=${token}`, { method: 'DELETE' } ); checkResponse(card); return await card.json(); } diff --git a/app/mobile/src/api/removeChannel.js b/app/mobile/src/api/removeChannel.js index 836031be..205c7f58 100644 --- a/app/mobile/src/api/removeChannel.js +++ b/app/mobile/src/api/removeChannel.js @@ -1,8 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeChannel(server, token, channelId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?agent=${token}`, + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}?agent=${token}`, { method: 'DELETE' }); checkResponse(channel); } diff --git a/app/mobile/src/api/removeChannelTopic.js b/app/mobile/src/api/removeChannelTopic.js index 63504f5e..60c1bfc0 100644 --- a/app/mobile/src/api/removeChannelTopic.js +++ b/app/mobile/src/api/removeChannelTopic.js @@ -1,8 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeChannelTopic(server, token, channelId, topicId) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?agent=${token}`, + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}?agent=${token}`, { method: 'DELETE' }); checkResponse(channel); } diff --git a/app/mobile/src/api/removeContactCall.js b/app/mobile/src/api/removeContactCall.js index 8e2a553f..6d32a84c 100644 --- a/app/mobile/src/api/removeContactCall.js +++ b/app/mobile/src/api/removeContactCall.js @@ -1,6 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeContactCall(server, token, callId) { - const call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?contact=${token}`, { method: 'DELETE' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + const call = await fetchWithTimeout(`${protocol}://${server}/talk/calls/${callId}?contact=${token}`, { method: 'DELETE' }); checkResponse(call); } diff --git a/app/mobile/src/api/removeContactChannel.js b/app/mobile/src/api/removeContactChannel.js index 43b41e38..8b3d1e61 100644 --- a/app/mobile/src/api/removeContactChannel.js +++ b/app/mobile/src/api/removeContactChannel.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeContactChannel(server, token, channelId) { - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?contact=${token}`, + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}?contact=${token}`, { method: 'DELETE' }); checkResponse(channel); } diff --git a/app/mobile/src/api/removeContactChannelTopic.js b/app/mobile/src/api/removeContactChannelTopic.js index 1178c330..932e9340 100644 --- a/app/mobile/src/api/removeContactChannelTopic.js +++ b/app/mobile/src/api/removeContactChannelTopic.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeContactChannelTopic(server, token, channelId, topicId) { - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?contact=${token}`, + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}?contact=${token}`, { method: 'DELETE' }); checkResponse(channel); } diff --git a/app/mobile/src/api/removeProfile.js b/app/mobile/src/api/removeProfile.js index ad906598..aea80cf8 100644 --- a/app/mobile/src/api/removeProfile.js +++ b/app/mobile/src/api/removeProfile.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeProfile(server, token) { - let profile = await fetchWithTimeout(`https://${server}/profile?agent=${token}`, { method: 'DELETE' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let profile = await fetchWithTimeout(`${protocol}://${server}/profile?agent=${token}`, { method: 'DELETE' }); checkResponse(profile) } diff --git a/app/mobile/src/api/setAccountAccess.js b/app/mobile/src/api/setAccountAccess.js index 233968a3..ddd9b2fa 100644 --- a/app/mobile/src/api/setAccountAccess.js +++ b/app/mobile/src/api/setAccountAccess.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountAccess(server, token, appName, appVersion, platform, deviceToken, pushType, notifications) { - let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'PUT', body: JSON.stringify(notifications) }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let access = await fetchWithTimeout(`${protocol}://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'PUT', body: JSON.stringify(notifications) }) checkResponse(access) return await access.json() } diff --git a/app/mobile/src/api/setAccountLogin.js b/app/mobile/src/api/setAccountLogin.js index 9365469c..ad49d656 100644 --- a/app/mobile/src/api/setAccountLogin.js +++ b/app/mobile/src/api/setAccountLogin.js @@ -2,9 +2,12 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; import base64 from 'react-native-base64' export async function setAccountLogin(server, token, username, password) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let headers = new Headers() headers.append('Credentials', 'Basic ' + base64.encode(username + ":" + password)); - let res = await fetchWithTimeout(`https://${server}/account/login?agent=${token}`, { method: 'PUT', headers }) + let res = await fetchWithTimeout(`${protocol}://${server}/account/login?agent=${token}`, { method: 'PUT', headers }) checkResponse(res); } diff --git a/app/mobile/src/api/setAccountNotifications.js b/app/mobile/src/api/setAccountNotifications.js index c3410846..76ce5747 100644 --- a/app/mobile/src/api/setAccountNotifications.js +++ b/app/mobile/src/api/setAccountNotifications.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountNotifications(server, token, flag) { - let res = await fetchWithTimeout(`https://${server}/account/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let res = await fetchWithTimeout(`${protocol}://${server}/account/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) checkResponse(res); } diff --git a/app/mobile/src/api/setAccountSeal.js b/app/mobile/src/api/setAccountSeal.js index 33326245..60476a80 100644 --- a/app/mobile/src/api/setAccountSeal.js +++ b/app/mobile/src/api/setAccountSeal.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountSeal(server, token, seal) { - let res = await fetchWithTimeout(`https://${server}/account/seal?agent=${token}`, { method: 'PUT', body: JSON.stringify(seal) }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let res = await fetchWithTimeout(`${protocol}://${server}/account/seal?agent=${token}`, { method: 'PUT', body: JSON.stringify(seal) }) checkResponse(res); } diff --git a/app/mobile/src/api/setAccountSearchable.js b/app/mobile/src/api/setAccountSearchable.js index 57990d1a..a9d80e50 100644 --- a/app/mobile/src/api/setAccountSearchable.js +++ b/app/mobile/src/api/setAccountSearchable.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountSearchable(server, token, flag) { - let res = await fetchWithTimeout(`https://${server}/account/searchable?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let res = await fetchWithTimeout(`${protocol}://${server}/account/searchable?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }) checkResponse(res); } diff --git a/app/mobile/src/api/setAccountStatus.js b/app/mobile/src/api/setAccountStatus.js index 450726d1..c4a3abd8 100644 --- a/app/mobile/src/api/setAccountStatus.js +++ b/app/mobile/src/api/setAccountStatus.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountStatus(server, token, accountId, disabled) { - let res = await fetchWithTimeout(`https://${server}/admin/accounts/${accountId}/status?token=${token}`, { method: 'PUT', body: JSON.stringify(disabled) }) + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let res = await fetchWithTimeout(`${protocol}://${server}/admin/accounts/${accountId}/status?token=${token}`, { method: 'PUT', body: JSON.stringify(disabled) }) checkResponse(res); } diff --git a/app/mobile/src/api/setCardCloseMessage.js b/app/mobile/src/api/setCardCloseMessage.js index 4e0a64b2..9e17b203 100644 --- a/app/mobile/src/api/setCardCloseMessage.js +++ b/app/mobile/src/api/setCardCloseMessage.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setCardCloseMessage(server, message) { - let status = await fetchWithTimeout(`https://${server}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let status = await fetchWithTimeout(`${protocol}://${server}/contact/closeMessage`, { method: 'PUT', body: JSON.stringify(message) }); checkResponse(status); return await status.json(); } diff --git a/app/mobile/src/api/setCardOpenMessage.js b/app/mobile/src/api/setCardOpenMessage.js index b9e39884..aa46907e 100644 --- a/app/mobile/src/api/setCardOpenMessage.js +++ b/app/mobile/src/api/setCardOpenMessage.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setCardOpenMessage(server, message) { - let status = await fetchWithTimeout(`https://${server}/contact/openMessage`, { method: 'PUT', body: JSON.stringify(message) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let status = await fetchWithTimeout(`${protocol}://${server}/contact/openMessage`, { method: 'PUT', body: JSON.stringify(message) }); checkResponse(status); return await status.json(); } diff --git a/app/mobile/src/api/setCardProfile.js b/app/mobile/src/api/setCardProfile.js index 17f5e303..e5d78562 100644 --- a/app/mobile/src/api/setCardProfile.js +++ b/app/mobile/src/api/setCardProfile.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setCardProfile(server, token, cardId, message) { - let profile = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let profile = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) }); checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/api/setCardStatus.js b/app/mobile/src/api/setCardStatus.js index fde6cac4..975b8a4d 100644 --- a/app/mobile/src/api/setCardStatus.js +++ b/app/mobile/src/api/setCardStatus.js @@ -1,19 +1,22 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setCardConnecting(server, token, cardId) { - let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('connecting') } ); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('connecting') } ); checkResponse(card); return await card.json(); } export async function setCardConnected(server, token, cardId, access, view, article, channel, profile) { - let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=${view}&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`, { method: 'PUT', body: JSON.stringify('connected') } ); + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}&token=${access}&viewRevision=${view}&articleRevision=${article}&channelRevision=${channel}&profileRevision=${profile}`, { method: 'PUT', body: JSON.stringify('connected') } ); checkResponse(card); return await card.json(); } export async function setCardConfirmed(server, token, cardId) { - let card = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') } ); + let card = await fetchWithTimeout(`${protocol}://${server}/contact/cards/${cardId}/status?agent=${token}`, { method: 'PUT', body: JSON.stringify('confirmed') } ); checkResponse(card); return await card.json(); } diff --git a/app/mobile/src/api/setChannelCard.js b/app/mobile/src/api/setChannelCard.js index 87acb271..333ce8cd 100644 --- a/app/mobile/src/api/setChannelCard.js +++ b/app/mobile/src/api/setChannelCard.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setChannelCard(server, token, channelId, cardId ) { - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'PUT'}); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'PUT'}); checkResponse(channel); return await channel.json(); } diff --git a/app/mobile/src/api/setChannelNotifications.js b/app/mobile/src/api/setChannelNotifications.js index 97845bff..3a7e9eef 100644 --- a/app/mobile/src/api/setChannelNotifications.js +++ b/app/mobile/src/api/setChannelNotifications.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setChannelNotifications(server, token, channelId, flag) { - const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?agent=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); checkResponse(notify) } diff --git a/app/mobile/src/api/setChannelSubject.js b/app/mobile/src/api/setChannelSubject.js index 1f24670f..1e8be3f1 100644 --- a/app/mobile/src/api/setChannelSubject.js +++ b/app/mobile/src/api/setChannelSubject.js @@ -1,8 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setChannelSubject(server, token, channelId, dataType, data ) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let params = { dataType, data: JSON.stringify(data) }; - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} ); + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} ); checkResponse(channel); return await channel.json(); } diff --git a/app/mobile/src/api/setChannelTopicAsset.js b/app/mobile/src/api/setChannelTopicAsset.js index 116b4801..e93db8c6 100644 --- a/app/mobile/src/api/setChannelTopicAsset.js +++ b/app/mobile/src/api/setChannelTopicAsset.js @@ -1,6 +1,9 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setChannelTopicSubject(token, channelId, topicId, asset) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + if (asset.image) { const formData = new FormData(); formData.append('asset', asset.image); diff --git a/app/mobile/src/api/setChannelTopicSubject.js b/app/mobile/src/api/setChannelTopicSubject.js index 9052858a..971ad35f 100644 --- a/app/mobile/src/api/setChannelTopicSubject.js +++ b/app/mobile/src/api/setChannelTopicSubject.js @@ -1,11 +1,14 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setChannelTopicSubject(server, token, channelId, topicId, dataType, data) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let subject = { data: JSON.stringify(data, (key, value) => { if (value !== null) return value }), datatype: dataType }; - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`, + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`, { method: 'PUT', body: JSON.stringify(subject) }); checkResponse(channel); } diff --git a/app/mobile/src/api/setContactChannelNotifications.js b/app/mobile/src/api/setContactChannelNotifications.js index 5b239742..f5fa322d 100644 --- a/app/mobile/src/api/setContactChannelNotifications.js +++ b/app/mobile/src/api/setContactChannelNotifications.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setContactChannelNotifications(server, token, channelId, flag) { - const notify = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + const notify = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/notification?contact=${token}`, { method: 'PUT', body: JSON.stringify(flag) }); checkResponse(notify) } diff --git a/app/mobile/src/api/setContactChannelTopicAsset.js b/app/mobile/src/api/setContactChannelTopicAsset.js index eda4244a..987d55c8 100644 --- a/app/mobile/src/api/setContactChannelTopicAsset.js +++ b/app/mobile/src/api/setContactChannelTopicAsset.js @@ -1,9 +1,12 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setContactChannelTopicSubject(server, token, channelId, topicId, asset) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let host = ""; if (server) { - host = `https://${server}`; + host = `${protocol}://${server}`; } if (asset.image) { diff --git a/app/mobile/src/api/setContactChannelTopicSubject.js b/app/mobile/src/api/setContactChannelTopicSubject.js index a7bbf9a9..89fece1a 100644 --- a/app/mobile/src/api/setContactChannelTopicSubject.js +++ b/app/mobile/src/api/setContactChannelTopicSubject.js @@ -1,11 +1,14 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setContactChannelTopicSubject(server, token, channelId, topicId, dataType, data) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let subject = { data: JSON.stringify(data, (key, value) => { if (value !== null) return value }), datatype: dataType }; - let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`, + let channel = await fetchWithTimeout(`${protocol}://${server}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`, { method: 'PUT', body: JSON.stringify(subject) }); checkResponse(channel); } diff --git a/app/mobile/src/api/setLogin.js b/app/mobile/src/api/setLogin.js index 0d1c49c7..dc2cf15c 100644 --- a/app/mobile/src/api/setLogin.js +++ b/app/mobile/src/api/setLogin.js @@ -2,9 +2,12 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; import base64 from 'react-native-base64' export async function setLogin(username, server, password, appName, appVersion, platform, deviceToken, pushType, notifications) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let headers = new Headers() headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password)); - let login = await fetchWithTimeout(`https://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'POST', body: JSON.stringify(notifications), headers: headers }) + let login = await fetchWithTimeout(`${protocol}://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=${pushType}`, { method: 'POST', body: JSON.stringify(notifications), headers: headers }) checkResponse(login) return await login.json() } diff --git a/app/mobile/src/api/setNodeConfig.js b/app/mobile/src/api/setNodeConfig.js index 65eb10aa..b9813a26 100644 --- a/app/mobile/src/api/setNodeConfig.js +++ b/app/mobile/src/api/setNodeConfig.js @@ -1,8 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setNodeConfig(server, token, config) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let body = JSON.stringify(config); - let settings = await fetchWithTimeout(`https://${server}/admin/config?token=${token}`, { method: 'PUT', body }); + let settings = await fetchWithTimeout(`${protocol}://${server}/admin/config?token=${token}`, { method: 'PUT', body }); checkResponse(settings); } diff --git a/app/mobile/src/api/setNodeStatus.js b/app/mobile/src/api/setNodeStatus.js index a34e653d..123c5a87 100644 --- a/app/mobile/src/api/setNodeStatus.js +++ b/app/mobile/src/api/setNodeStatus.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setNodeStatus(server, token) { - let status = await fetchWithTimeout(`https://${server}/admin/status?token=${token}`, { method: 'PUT' }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let status = await fetchWithTimeout(`${protocol}://${server}/admin/status?token=${token}`, { method: 'PUT' }); checkResponse(status); } diff --git a/app/mobile/src/api/setProfileData.js b/app/mobile/src/api/setProfileData.js index e973b035..ecd78b25 100644 --- a/app/mobile/src/api/setProfileData.js +++ b/app/mobile/src/api/setProfileData.js @@ -1,8 +1,11 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setProfileData(server, token, name, location, description) { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + let data = { name: name, location: location, description: description }; - let profile = await fetchWithTimeout(`https://${server}/profile/data?agent=${token}`, { method: 'PUT', body: JSON.stringify(data) }); + let profile = await fetchWithTimeout(`${protocol}://${server}/profile/data?agent=${token}`, { method: 'PUT', body: JSON.stringify(data) }); checkResponse(profile) return await profile.json() } diff --git a/app/mobile/src/api/setProfileImage.js b/app/mobile/src/api/setProfileImage.js index a40cafe9..73abe1c5 100644 --- a/app/mobile/src/api/setProfileImage.js +++ b/app/mobile/src/api/setProfileImage.js @@ -1,7 +1,10 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setProfileImage(server, token, image) { - let profile = await fetchWithTimeout(`https://${server}/profile/image?agent=${token}`, { method: 'PUT', body: JSON.stringify(image) }); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server); + const protocol = insecure ? 'http' : 'https'; + + let profile = await fetchWithTimeout(`${protocol}://${server}/profile/image?agent=${token}`, { method: 'PUT', body: JSON.stringify(image) }); checkResponse(profile) return await profile.json() } diff --git a/app/mobile/src/session/channels/addMember/useAddMember.hook.js b/app/mobile/src/session/channels/addMember/useAddMember.hook.js index 571d76f4..b4c0e123 100644 --- a/app/mobile/src/session/channels/addMember/useAddMember.hook.js +++ b/app/mobile/src/session/channels/addMember/useAddMember.hook.js @@ -25,7 +25,7 @@ export function useAddMember(item, members) { useEffect(() => { const { cardId, revision, profile } = item; const { name, handle, node } = profile; - updateState({ cardId, name, handle: `${handle}@${node}`, + updateState({ cardId, name, handle: `${handle}/${node}`, logo: profile.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar' }); }, [card.state]);