156 lines
6.7 KiB
Dart
156 lines
6.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:footer/footer.dart';
|
|
import 'package:footer/footer_view.dart';
|
|
import 'package:zontreck/Constants.dart';
|
|
import 'package:zontreck/Packets.dart';
|
|
import 'package:zontreck/Settings.dart';
|
|
|
|
class OpenSimPage extends StatefulWidget {
|
|
const OpenSimPage({super.key});
|
|
|
|
@override
|
|
OpenSimPageState createState() => OpenSimPageState();
|
|
}
|
|
|
|
class OpenSimPageState extends State<OpenSimPage> {
|
|
Settings settings = Settings();
|
|
|
|
TextEditingController databaseHostController = TextEditingController();
|
|
TextEditingController databaseUsernameController = TextEditingController();
|
|
TextEditingController databasePasswordController = TextEditingController();
|
|
TextEditingController databaseNameController = TextEditingController();
|
|
TextEditingController PSKController = TextEditingController();
|
|
String clientPSK = "";
|
|
String PSKHash = "";
|
|
|
|
@override
|
|
Future<void> didChangeDependencies() async {
|
|
var reply = await settings.sendPacketToEndpoint(
|
|
APIEndpoint.SetupCheck, NullPacket());
|
|
var simpleReply = reply as S2CSimpleReplyPacket;
|
|
if (simpleReply.done) {
|
|
settings.OpenSimSetupCompleted = true;
|
|
} else {
|
|
settings.OpenSimSetupCompleted = false;
|
|
}
|
|
|
|
var pong =
|
|
await settings.sendPacketToEndpoint(APIEndpoint.Ping, NullPacket());
|
|
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Constants.TITLEBAR_COLOR,
|
|
title: const Text("Zontreck.com - OpenSim Manager"),
|
|
),
|
|
body: FooterView(
|
|
footer: Footer(
|
|
alignment: Alignment.center,
|
|
backgroundColor: ThemeData.dark().focusColor,
|
|
child: const Text("${Constants.COPYRIGHT}\n${Constants.VERSION}")),
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: SingleChildScrollView(
|
|
child: settings.OpenSimSetupCompleted
|
|
? const Column(
|
|
children: [],
|
|
)
|
|
: Column(
|
|
children: [
|
|
const ListTile(
|
|
title: Text("Initial Setup Required"),
|
|
subtitle: Text(
|
|
"Please use the same database/user as robust's database\n\nNOTE: Only MySQL/MariaDB is supported by this interface"),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
),
|
|
ListTile(
|
|
title: const Text("Database Host"),
|
|
subtitle: TextField(
|
|
controller: databaseHostController,
|
|
decoration:
|
|
const InputDecoration(hintText: "example.com:3306"),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text("Database Username"),
|
|
subtitle: TextField(
|
|
controller: databaseUsernameController,
|
|
decoration: const InputDecoration(hintText: "Username"),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text("Database Password"),
|
|
subtitle: TextField(
|
|
decoration: const InputDecoration(
|
|
hintText: "****", hintMaxLines: 1),
|
|
obscureText: true,
|
|
obscuringCharacter: "*",
|
|
controller: databasePasswordController,
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text("Database Name"),
|
|
subtitle: TextField(
|
|
decoration: const InputDecoration(
|
|
hintText: "acwi", hintMaxLines: 1),
|
|
controller: databaseNameController,
|
|
),
|
|
),
|
|
const ListTile(
|
|
title: Text(
|
|
"For the PreShared Secret, please enter any text you wish. This is hashed 8192 times for the server key. And an additional 16384 times for the client, and any derived key thereafter"),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
),
|
|
ListTile(
|
|
title: const Text("PreShared Secret"),
|
|
subtitle: TextField(
|
|
controller: PSKController,
|
|
decoration: const InputDecoration(
|
|
hintText:
|
|
"Pre-Shared Key. Some text that gets hashed several thousand times to create a server and client key"),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
PSKHash =
|
|
await settings.hashPSK(PSKController.text);
|
|
|
|
clientPSK = await settings.createDerivedPSK(
|
|
PSKHash, "client");
|
|
|
|
C2SPerformSetupPacket packet =
|
|
C2SPerformSetupPacket(
|
|
PSK: PSKHash,
|
|
ClientPSK: clientPSK,
|
|
host: databaseHostController.text,
|
|
user: databaseUsernameController.text,
|
|
pass: databasePasswordController.text,
|
|
db: databaseHostController.text);
|
|
|
|
var responsePacket =
|
|
await settings.sendPacketToEndpoint(
|
|
APIEndpoint.Setup, packet)
|
|
as S2CSimpleReplyPacket;
|
|
|
|
if (responsePacket.done) {
|
|
settings.OpenSimSetupCompleted = true;
|
|
} else {
|
|
settings.OpenSimSetupCompleted = false;
|
|
}
|
|
|
|
setState(() {});
|
|
},
|
|
child: const Text("Submit"))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
));
|
|
}
|
|
}
|