2023-04-12 19:13:41 +03:00
import QtQuick
import QtQuick . Controls
import QtQuick . Layouts
import PageEnum 1.0
2024-08-20 16:54:05 +07:00
import Style 1.0
2023-04-12 19:13:41 +03:00
import "./"
import "../Controls2"
import "../Config"
2023-06-21 20:56:00 +09:00
import "../Controls2/TextTypes"
2023-04-12 19:13:41 +03:00
2023-05-25 15:40:17 +08:00
PageType {
2023-04-12 19:13:41 +03:00
id: root
2023-06-05 15:49:10 +08:00
BackButtonType {
id: backButton
anchors.top: parent . top
anchors.left: parent . left
anchors.right: parent . right
2026-04-30 14:53:03 +08:00
anchors.topMargin: 20 + PageController . safeAreaTopMargin
2024-04-18 17:54:55 +04:00
2024-12-31 04:16:52 +01:00
onFocusChanged: {
if ( this . activeFocus ) {
listView . positionViewAtBeginning ( )
}
}
2023-06-05 15:49:10 +08:00
}
2025-08-06 04:35:51 +02:00
ListViewType {
2024-12-31 04:16:52 +01:00
id: listView
2025-08-06 04:35:51 +02:00
2023-06-05 15:49:10 +08:00
anchors.top: backButton . bottom
2023-06-20 10:25:24 +09:00
anchors.bottom: parent . bottom
2024-12-31 04:16:52 +01:00
anchors.right: parent . right
anchors.left: parent . left
header: ColumnLayout {
width: listView . width
2023-04-12 19:13:41 +03:00
2025-05-02 23:54:36 -07:00
BaseHeaderType {
2023-04-12 19:13:41 +03:00
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
2023-04-12 19:13:41 +03:00
2023-10-14 15:55:07 +01:00
headerText: qsTr ( "Configure your server" )
2023-04-12 19:13:41 +03:00
}
2024-12-31 04:16:52 +01:00
}
2023-04-12 19:13:41 +03:00
2024-12-31 04:16:52 +01:00
model: inputFields
spacing: 16
2023-05-17 23:28:27 +08:00
2024-12-31 04:16:52 +01:00
delegate: ColumnLayout {
width: listView . width
2023-04-12 19:13:41 +03:00
TextFieldWithHeaderType {
2025-01-24 23:27:01 +07:00
id: delegate
2023-05-17 23:28:27 +08:00
2023-04-12 19:13:41 +03:00
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2024-03-14 15:59:16 +05:00
2024-12-31 04:16:52 +01:00
headerText: title
2025-01-24 23:27:01 +07:00
textField.echoMode: hideContent ? TextInput.Password : TextInput . Normal
textField.placeholderText: placeholderContent
textField.text: textField . text
2023-07-31 14:29:49 +09:00
2024-12-31 04:16:52 +01:00
rightButtonClickedOnEnter: true
2023-07-31 14:29:49 +09:00
2024-12-31 04:16:52 +01:00
clickedFunc: function ( ) {
clickedHandler ( )
2025-11-28 05:00:53 +02:00
buttonImageSource = textField . text !== "" ? imageSource : ""
2023-07-31 14:29:49 +09:00
}
2023-10-30 14:20:21 +05:00
2024-03-14 15:59:16 +05:00
textField.onFocusChanged: {
2025-01-24 23:27:01 +07:00
textField . text = textField . text . replace ( /^\s+|\s+$/g , '' )
2023-10-30 14:20:21 +05:00
}
2024-02-17 23:09:05 +02:00
2024-12-31 04:16:52 +01:00
textField.onTextChanged: {
2026-03-24 12:06:40 +04:00
if ( headerText === qsTr ( "Password or SSH private key" ) ) {
2025-11-28 05:00:53 +02:00
buttonImageSource = textField . text !== "" ? imageSource : ""
2024-12-31 04:16:52 +01:00
}
}
2023-04-12 19:13:41 +03:00
}
2026-03-24 12:06:40 +04:00
WarningType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 8
visible: title === qsTr ( "Password or SSH private key" )
backGroundColor: AmneziaStyle . color . translucentWhite
iconPath: "qrc:/images/controls/alert-circle.svg"
2026-04-10 21:24:00 +07:00
textString: qsTr ( "SSH key requirements: supported key types are ED25519 and RSA in PEM format. Paste the private key, including the BEGIN/END lines. If your key doesn’ t work, generate a compatible one" )
2026-03-24 12:06:40 +04:00
}
2024-12-31 04:16:52 +01:00
}
footer: ColumnLayout {
width: listView . width
2023-04-12 19:13:41 +03:00
BasicButtonType {
2024-02-17 23:09:05 +02:00
id: continueButton
2023-04-12 19:13:41 +03:00
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.topMargin: 32
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-04-12 19:13:41 +03:00
2023-07-31 20:38:13 +09:00
text: qsTr ( "Continue" )
2023-04-14 19:31:10 +03:00
2024-02-17 23:09:05 +02:00
clickedFunc: function ( ) {
2024-12-31 04:16:52 +01:00
if ( ! root . isCredentialsFilled ( ) ) {
2023-06-23 15:24:40 +09:00
return
}
2025-01-24 23:27:01 +07:00
var _hostname = listView . itemAtIndex ( vars . hostnameIndex ) . children [ 0 ] . textField . text
var _username = listView . itemAtIndex ( vars . usernameIndex ) . children [ 0 ] . textField . text
var _secretData = listView . itemAtIndex ( vars . secretDataIndex ) . children [ 0 ] . textField . text
2024-12-31 04:16:52 +01:00
InstallController . setProcessedServerCredentials ( _hostname , _username , _secretData )
2026-05-28 10:57:08 +08:00
ServersUiController . setProcessedServerId ( "" )
2023-05-22 00:10:51 +08:00
2023-07-31 20:38:13 +09:00
PageController . showBusyIndicator ( true )
var isConnectionOpened = InstallController . checkSshConnection ( )
PageController . showBusyIndicator ( false )
if ( ! isConnectionOpened ) {
return
}
2023-09-06 13:37:37 +05:00
PageController . goToPage ( PageEnum . PageSetupWizardEasy )
2023-04-14 19:31:10 +03:00
}
2023-04-12 19:13:41 +03:00
}
2023-10-14 15:55:07 +01:00
LabelTextType {
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.topMargin: 24
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
2023-10-14 15:55:07 +01:00
2023-10-30 14:20:21 +05:00
text: qsTr ( "All data you enter will remain strictly confidential and will not be shared or disclosed to the Amnezia or any third parties" )
2023-10-14 15:55:07 +01:00
}
2024-08-20 16:54:05 +07:00
CardWithIconsType {
id: siteLink
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2024-08-20 16:54:05 +07:00
Layout.bottomMargin: 16
headerText: qsTr ( "How to run your VPN server" )
bodyText: qsTr ( "Where to get connection data, step-by-step instructions for buying a VPS" )
rightImageSource: "qrc:/images/controls/chevron-right.svg"
leftImageSource: "qrc:/images/controls/help-circle.svg"
onClicked: {
2026-04-30 14:53:03 +08:00
Qt . openUrlExternally ( LanguageUiController . getCurrentSiteUrl ( "starter-guide" ) )
2024-08-20 16:54:05 +07:00
}
2025-08-01 05:56:02 +02:00
Keys.onEnterPressed: this . clicked ( )
Keys.onReturnPressed: this . clicked ( )
2024-08-20 16:54:05 +07:00
}
2023-04-12 19:13:41 +03:00
}
}
2023-06-23 15:24:40 +09:00
function isCredentialsFilled ( ) {
var hasEmptyField = false
2025-01-24 23:27:01 +07:00
var hostnameItem = listView . itemAtIndex ( vars . hostnameIndex ) . children [ 0 ]
if ( hostnameItem . textField . text === "" ) {
hostnameItem . errorText = qsTr ( "Ip address cannot be empty" )
2023-06-23 15:24:40 +09:00
hasEmptyField = true
2025-01-24 23:27:01 +07:00
} else if ( ! hostnameItem . textField . acceptableInput ) {
hostnameItem . errorText = qsTr ( "Enter the address in the format 255.255.255.255:88" )
2023-06-23 15:24:40 +09:00
}
2025-01-24 23:27:01 +07:00
var usernameItem = listView . itemAtIndex ( vars . usernameIndex ) . children [ 0 ]
if ( usernameItem . textField . text === "" ) {
usernameItem . errorText = qsTr ( "Login cannot be empty" )
2023-06-23 15:24:40 +09:00
hasEmptyField = true
}
2024-12-31 04:16:52 +01:00
2025-01-24 23:27:01 +07:00
var secretDataItem = listView . itemAtIndex ( vars . secretDataIndex ) . children [ 0 ]
if ( secretDataItem . textField . text === "" ) {
secretDataItem . errorText = qsTr ( "Password/private key cannot be empty" )
2023-06-23 15:24:40 +09:00
hasEmptyField = true
}
2024-12-31 04:16:52 +01:00
2023-06-23 15:24:40 +09:00
return ! hasEmptyField
}
2024-12-31 04:16:52 +01:00
property list < QtObject > inputFields: [
2025-01-24 23:27:01 +07:00
hostnameObject ,
usernameObject ,
secretDataObject
2024-12-31 04:16:52 +01:00
]
QtObject {
2025-01-24 23:27:01 +07:00
id: hostnameObject
2024-12-31 04:16:52 +01:00
property string title: qsTr ( "Server IP address [:port]" )
2025-01-24 23:27:01 +07:00
readonly property string placeholderContent: qsTr ( "255.255.255.255:22" )
property bool hideContent: false
readonly property var clickedHandler: undefined
2024-12-31 04:16:52 +01:00
}
QtObject {
2025-01-24 23:27:01 +07:00
id: usernameObject
2024-12-31 04:16:52 +01:00
property string title: qsTr ( "SSH Username" )
2025-01-24 23:27:01 +07:00
readonly property string placeholderContent: "root"
property bool hideContent: false
2024-12-31 04:16:52 +01:00
readonly property var clickedHandler: undefined
}
QtObject {
2025-01-24 23:27:01 +07:00
id: secretDataObject
2024-12-31 04:16:52 +01:00
property string title: qsTr ( "Password or SSH private key" )
2025-01-24 23:27:01 +07:00
readonly property string placeholderContent: ""
property bool hideContent: true
2025-11-28 05:00:53 +02:00
property string imageSource: "qrc:/images/controls/eye.svg"
2024-12-31 04:16:52 +01:00
readonly property var clickedHandler: function ( ) {
2025-01-24 23:27:01 +07:00
hideContent = ! hideContent
2025-11-28 05:00:53 +02:00
imageSource = hideContent ? "qrc:/images/controls/eye.svg" : "qrc:/images/controls/eye-off.svg"
2024-12-31 04:16:52 +01:00
}
}
QtObject {
id: vars
readonly property int hostnameIndex: 0
readonly property int usernameIndex: 1
readonly property int secretDataIndex: 2
}
2023-04-12 19:13:41 +03:00
}