-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
140 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,152 @@ | ||
// Generate a unique UUID for the configuration profile and its payloads | ||
function uuidv4() { | ||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => | ||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | ||
); | ||
} | ||
const configForm = document.getElementById('config-form'); | ||
|
||
// Determine the APN to use based on the form data | ||
function getApn(formData) { | ||
const apn = formData.get('apn'); | ||
if (apn === '') { | ||
// Automatically select APN based on carrier | ||
const carrier = formData.get('carrier'); | ||
if (carrier === 'mcinet') { | ||
return 'mcinet'; | ||
} else if (carrier === 'irancell') { | ||
return 'irancelmci'; | ||
} else if (carrier === 'rightel') { | ||
return 'right'; | ||
} else { | ||
return ''; | ||
} | ||
} else { | ||
// Use selected APN | ||
return apn; | ||
configForm.addEventListener('submit', (event) => { | ||
event.preventDefault(); | ||
|
||
// Collect form data | ||
const formData = new FormData(configForm); | ||
const configProfile = generateConfigProfile(formData); | ||
|
||
// Create a download link and click it to download the file | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(new Blob([configProfile], { type: 'text/plain' })); | ||
downloadLink.download = 'config.cfg'; | ||
downloadLink.click(); | ||
}); | ||
|
||
function generateConfigProfile(formData) { | ||
// Determine the APN to use based on the apn_option parameter | ||
let apn = formData.get('apn') || ''; | ||
if (formData.get('apn_option') === 'hamrahaval') { | ||
apn = 'mcinet'; | ||
} else if (formData.get('apn_option') === 'irancell') { | ||
apn = 'irancelmci'; | ||
} else if (formData.get('apn_option') === 'rightel') { | ||
apn = 'right'; | ||
} | ||
} | ||
|
||
// Generate the cellular payload for the configuration profile | ||
function generateCellularPayload(formData) { | ||
const apn = getApn(formData); | ||
const carrier = apn === '' ? formData.get('carrier') : apn; | ||
return { | ||
PayloadDisplayName: "Cellular", | ||
PayloadIdentifier: uuidv4(), | ||
PayloadType: "com.apple.cellular", | ||
PayloadUUID: uuidv4(), | ||
PayloadVersion: 1, | ||
APNs: [{ | ||
AuthenticationType: (carrier === 'mcinet') ? 'CHAP' : 'PAP', | ||
Enabled: true, | ||
Name: apn | ||
}], | ||
SignalBoostEnabled: true, | ||
APNSelectionMode: "Automatic" | ||
// Create the configuration profile dictionary | ||
const configDict = { | ||
"PayloadContent": [], | ||
"PayloadDisplayName": "Cellular and Network Settings", | ||
"PayloadIdentifier": "com.example.cellular.config", | ||
"PayloadOrganization": "Example Inc.", | ||
"PayloadRemovalDisallowed": false, | ||
"PayloadType": "Configuration", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1 | ||
}; | ||
} | ||
|
||
// Generate the VPN payload for the configuration profile, if VPN is enabled | ||
function generateVpnPayload(formData) { | ||
if (!formData.get('vpn-toggle')) { | ||
return null; | ||
} | ||
const vpnServer = formData.get('vpn_server'); | ||
if (vpnServer === '') { | ||
return null; | ||
} | ||
const vpnUsername = formData.get('vpn_username') || "YourUsername"; | ||
const vpnPassword = formData.get('vpn_password') || "YourPassword"; | ||
return { | ||
PayloadDisplayName: "VPN", | ||
PayloadIdentifier: uuidv4(), | ||
PayloadType: "com.apple.vpn.managed", | ||
PayloadUUID: uuidv4(), | ||
PayloadVersion: 1, | ||
AuthenticationMethod: "Certificate", | ||
DisconnectOnLogout: true, | ||
DisconnectOnSleep: true, | ||
SendAllTraffic: true, | ||
ServerAddress: vpnServer, | ||
ServerPort: 1723, | ||
Protocol: "L2TP", | ||
SharedSecret: "YourSharedSecret", | ||
Username: vpnUsername, | ||
Password: vpnPassword | ||
// Create the cellular payload dictionary | ||
const cellularDict = { | ||
"PayloadDisplayName": "Cellular", | ||
"PayloadIdentifier": uuidv4(), | ||
"PayloadType": "com.apple.cellular", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1, | ||
"APNs": [ | ||
{ | ||
"AuthenticationType": formData.get('carrier') === 'mcinet' ? "CHAP" : "PAP", | ||
"Enabled": true, | ||
"Name": apn | ||
} | ||
], | ||
"SignalBoostEnabled": true, | ||
"APNSelectionMode": "Automatic" // Set the APN to automatic | ||
}; | ||
} | ||
|
||
// Generate the on-demand VPN payload for the configuration profile, if Cloudflare is enabled | ||
function generateOnDemandVpnPayload(formData, vpnPayload) { | ||
if (!formData.get('cloudflare-toggle')) { | ||
return null; | ||
// Add the cellular payload to the configuration profile | ||
configDict["PayloadContent"].push(cellularDict); | ||
|
||
// Create the VPN payload dictionary if VPN server is provided | ||
const vpnServer = formData.get('vpn_server') || ''; | ||
if (vpnServer) { | ||
const vpnDict = { | ||
"PayloadDisplayName": "VPN", | ||
"PayloadIdentifier": uuidv4(), | ||
"PayloadType": "com.apple.vpn.managed", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1, | ||
"AuthenticationMethod": "Certificate", | ||
"DisconnectOnLogout": true, | ||
"DisconnectOnSleep": true, | ||
"SendAllTraffic": true, | ||
"ServerAddress": vpnServer, | ||
"ServerPort": 1723, | ||
"Protocol": "L2TP", | ||
"SharedSecret": "YourSharedSecret", | ||
"Username": formData.get('vpn_username') || "YourUsername", | ||
"Password": formData.get('vpn_password') || "YourPassword" | ||
}; | ||
|
||
// Add the VPN payload to the configuration profile | ||
configDict["PayloadContent"].push(vpnDict); | ||
} | ||
const cloudflareDomain = formData.get('cloudflare_domain'); | ||
if (cloudflareDomain === '') { | ||
return null; | ||
|
||
// Create the proxy payload dictionary if proxy server and port are provided | ||
const proxyServer = formData.get('proxy_server') || ''; | ||
const proxyPort = formData.get('proxy_port') || ''; | ||
if (proxyServer && proxyPort) { | ||
const proxyDict = { | ||
"PayloadDisplayName": "Proxy", | ||
"PayloadIdentifier": uuidv4(), | ||
"PayloadType": "com.apple.proxy", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1, | ||
"HTTPEnable": true, | ||
"HTTPPort": parseInt(proxyPort), | ||
"HTTPServer": proxyServer, | ||
"HTTPSEnable": true, | ||
"HTTPSPort": parseInt(proxyPort), | ||
"HTTPSServer": proxyServer | ||
}; | ||
|
||
// Add the proxy payload to the configuration profile | ||
configDict["PayloadContent"].push(proxyDict); | ||
} | ||
return { | ||
PayloadDisplayName: "On-Demand VPN", | ||
PayloadIdentifier: uuidv4(), | ||
PayloadType: "com.apple.vpn.on-demand", | ||
PayloadUUID: uuidv4(), | ||
PayloadVersion: 1, | ||
VPNPayloadIdentifier: vpnPayload.PayloadIdentifier, | ||
DomainAction: "Connect", | ||
Domains: [cloudflareDomain] | ||
}; | ||
} | ||
|
||
// Generate the proxy payload for the configuration profile, if proxy is enabled | ||
function generateProxyPayload(formData) { | ||
if (!formData.get('proxy-toggle')) { | ||
return null; | ||
// Create the DNS payload dictionary if DNS server is provided | ||
const dnsServer = formData.get('dns_server') || ''; | ||
if (dnsServer) { | ||
const dnsDict = { | ||
"PayloadDisplayName": "DNS", | ||
"PayloadIdentifier": uuidv4(), | ||
"PayloadType": "com.apple.dns", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1, | ||
"Servers": [dnsServer] | ||
}; | ||
|
||
// Add the DNS payload to the configuration profile | ||
configDict["PayloadContent"].push(dnsDict); | ||
} | ||
const proxyServer = formData.get('proxy_server'); | ||
if (proxyServer === '') { | ||
return null; | ||
|
||
// Create the Cloudflare payload dictionary if Cloudflare domain is provided | ||
const cloudflareDomain = formData.get('cloudflare_domain') || ''; | ||
if (cloudflareDomain) { | ||
const cloudflareDict = { | ||
"PayloadDisplayName": "Cloudflare", | ||
"PayloadIdentifier": uuidv4(), | ||
"PayloadType": "com.apple.dns", | ||
"PayloadUUID": uuidv4(), | ||
"PayloadVersion": 1, | ||
"Domains": [cloudflareDomain], | ||
"ServerAddresses": ["1.1.1.1", "1.0.0.1"] | ||
}; | ||
|
||
// Add the Cloudflare payload to the configuration profile | ||
configDict["PayloadContent"].push(cloudflareDict); | ||
} | ||
const proxyPort = parseInt(formData.get('proxy_port')) || | ||
|
||
// Convert the configuration dictionary to a string | ||
const configProfile = JSON.stringify(configDict, null, 2); | ||
|
||
return configProfile; | ||
} | ||
|
||
// Generate a random UUID (universally unique identifier) | ||
function uuidv4() { | ||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => | ||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | ||
); | ||
} |