mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 10:29:39 +00:00
update
This commit is contained in:
parent
eb2c8dca23
commit
aabad65698
|
@ -178,7 +178,8 @@
|
|||
"17": "Check",
|
||||
"18": "How to obtain Hetzner API Token",
|
||||
"19": "1 Go via this link ",
|
||||
"20": "\n"
|
||||
"20": "\n",
|
||||
"21": "One more restart to apply your security certificates."
|
||||
},
|
||||
"modals": {
|
||||
"_comment": "messages in modals",
|
||||
|
|
|
@ -178,7 +178,8 @@
|
|||
"17": "Проверка",
|
||||
"18": "Как получить Hetzner API Token'",
|
||||
"19": "1 Переходим по ссылке ",
|
||||
"20": "\n2 Заходим в созданный нами проект. Если такового - нет, значит создаём.\n3 Наводим мышкой на боковую панель. Она должна раскрыться, показав нам пункты меню. Нас интересует последний — Security (с иконкой ключика).\n4 Далее, в верхней части интерфейса видим примерно такой список: SSH Keys, API Tokens, Certificates, Members. Нам нужен API Tokens. Переходим по нему.\n5 В правой части интерфейса, нас будет ожидать кнопка Generate API token. Если же вы используете мобильную версию сайта, в нижнем правом углу вы увидите красный плюсик. Нажимаем на эту кнопку.\n6 В поле Description, даём нашему токену название (это может быть любое название, которые вам нравиться. Сути оно не меняет."
|
||||
"20": "\n2 Заходим в созданный нами проект. Если такового - нет, значит создаём.\n3 Наводим мышкой на боковую панель. Она должна раскрыться, показав нам пункты меню. Нас интересует последний — Security (с иконкой ключика).\n4 Далее, в верхней части интерфейса видим примерно такой список: SSH Keys, API Tokens, Certificates, Members. Нам нужен API Tokens. Переходим по нему.\n5 В правой части интерфейса, нас будет ожидать кнопка Generate API token. Если же вы используете мобильную версию сайта, в нижнем правом углу вы увидите красный плюсик. Нажимаем на эту кнопку.\n6 В поле Description, даём нашему токену название (это может быть любое название, которые вам нравиться. Сути оно не меняет.",
|
||||
"21": "Сейчас будет дополнительная перезагрузка для активации сертификатов безопастности"
|
||||
},
|
||||
"modals": {
|
||||
"_comment": "messages in modals",
|
||||
|
|
|
@ -56,5 +56,6 @@ class BNames {
|
|||
static String isServerStarted = 'isServerStarted';
|
||||
static String backblazeKey = 'backblazeKey';
|
||||
static String isLoading = 'isLoading';
|
||||
static String isServerReseted = 'isServerReseted';
|
||||
static String isServerResetedFirstTime = 'isServerResetedFirstTime';
|
||||
static String isServerResetedSecondTime = 'isServerResetedSecondTime';
|
||||
}
|
||||
|
|
|
@ -65,9 +65,9 @@ final linkStyle = defaultTextStyle.copyWith(color: BrandColors.blue);
|
|||
final progressTextStyleLight = TextStyle(
|
||||
fontSize: 11,
|
||||
color: BrandColors.textColor1,
|
||||
height: 1.7,
|
||||
);
|
||||
|
||||
final progressTextStyleDark = TextStyle(
|
||||
fontSize: 11,
|
||||
final progressTextStyleDark = progressTextStyleLight.copyWith(
|
||||
color: BrandColors.white,
|
||||
);
|
||||
|
|
|
@ -94,7 +94,7 @@ class HetznerApi extends ApiMap {
|
|||
);
|
||||
var dbId = dbCreateResponse.data['volume']['id'];
|
||||
var data = jsonDecode(
|
||||
'''{"name":"selfprivacy-server","server_type":"cx11","start_after_create":false,"image":"ubuntu-20.04", "volumes":[$dbId],"networks":[],"user_data":"#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/ilchub/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-20.09 DOMAIN=$domainName LUSER=${rootUser.login} PASSWORD=${rootUser.password} HASHED_PASSWORD=${rootUser.hashPassword} CF_TOKEN=$cloudFlareKey DB_PASSWORD=$dbPassword bash 2>&1 | tee /tmp/infect.log","labels":{},"automount":true, "location": "fsn1"}''',
|
||||
'''{"name":"$domainName","server_type":"cx11","start_after_create":false,"image":"ubuntu-20.04", "volumes":[$dbId],"networks":[],"user_data":"#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/ilchub/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-20.09 DOMAIN=$domainName LUSER=${rootUser.login} PASSWORD=${rootUser.password} HASHED_PASSWORD=${rootUser.hashPassword} CF_TOKEN=$cloudFlareKey DB_PASSWORD=$dbPassword bash 2>&1 | tee /tmp/infect.log","labels":{},"automount":true, "location": "fsn1"}''',
|
||||
);
|
||||
|
||||
Response serverCreateResponse = await client.post(
|
||||
|
@ -113,12 +113,14 @@ class HetznerApi extends ApiMap {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> deleteSelfprivacyServerAndAllVolumes() async {
|
||||
Future<void> deleteSelfprivacyServerAndAllVolumes({
|
||||
required String domainName,
|
||||
}) async {
|
||||
var client = await getClient();
|
||||
|
||||
Response serversReponse = await client.get('/servers');
|
||||
List servers = serversReponse.data['servers'];
|
||||
var server = servers.firstWhere((el) => el['name'] == 'selfprivacy-server');
|
||||
var server = servers.firstWhere((el) => el['name'] == domainName);
|
||||
await client.delete('/servers/${server['id']}');
|
||||
|
||||
Response volumesReponse = await client.get('/volumes');
|
||||
|
|
|
@ -35,7 +35,10 @@ part 'app_config_state.dart';
|
|||
/// c. if server is ok wait 30 sec
|
||||
/// d. reset server
|
||||
///
|
||||
/// 2.3. a. wait 60sec |finishCheckIfServerIsOkay
|
||||
/// 2.3. a. wait 60sec |oneMoreReset()
|
||||
/// d. reset server
|
||||
///
|
||||
/// 2.4. a. wait 30sec |finishCheckIfServerIsOkay
|
||||
/// b. checkServer
|
||||
/// c. if server is okay set that fully checked
|
||||
|
||||
|
@ -54,6 +57,8 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
|||
} else if (state.progress == 7) {
|
||||
resetServerIfServerIsOkay(state: state, isImmediate: true);
|
||||
} else if (state.progress == 8) {
|
||||
oneMoreReset(state: state, isImmediate: true);
|
||||
} else if (state.progress == 9) {
|
||||
finishCheckIfServerIsOkay(state: state, isImmediate: true);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +111,61 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
|||
}
|
||||
}
|
||||
|
||||
void oneMoreReset({
|
||||
AppConfigState? state,
|
||||
bool isImmediate = false,
|
||||
}) async {
|
||||
var dataState = state ?? this.state;
|
||||
|
||||
var work = () async {
|
||||
emit(TimerState(dataState: dataState, isLoading: true));
|
||||
|
||||
var isServerWorking = await repository.isHttpServerWorking();
|
||||
|
||||
if (isServerWorking) {
|
||||
var pauseDuration = Duration(seconds: 30);
|
||||
emit(TimerState(
|
||||
dataState: dataState,
|
||||
timerStart: DateTime.now(),
|
||||
isLoading: false,
|
||||
duration: pauseDuration,
|
||||
));
|
||||
timer = Timer(pauseDuration, () async {
|
||||
var hetznerServerDetails = await repository.restart(
|
||||
dataState.hetznerServer!,
|
||||
);
|
||||
repository.saveIsServerResetedSecondTime(true);
|
||||
repository.saveServerDetails(hetznerServerDetails);
|
||||
|
||||
emit(
|
||||
dataState.copyWith(
|
||||
isServerResetedSecondTime: true,
|
||||
hetznerServer: hetznerServerDetails,
|
||||
isLoading: false,
|
||||
),
|
||||
);
|
||||
finishCheckIfServerIsOkay();
|
||||
});
|
||||
} else {
|
||||
oneMoreReset();
|
||||
}
|
||||
};
|
||||
if (isImmediate) {
|
||||
work();
|
||||
} else {
|
||||
var pauseDuration = Duration(seconds: 60);
|
||||
emit(
|
||||
TimerState(
|
||||
dataState: dataState,
|
||||
timerStart: DateTime.now(),
|
||||
duration: pauseDuration,
|
||||
isLoading: false,
|
||||
),
|
||||
);
|
||||
timer = Timer(pauseDuration, work);
|
||||
}
|
||||
}
|
||||
|
||||
void resetServerIfServerIsOkay({
|
||||
AppConfigState? state,
|
||||
bool isImmediate = false,
|
||||
|
@ -129,17 +189,17 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
|||
var hetznerServerDetails = await repository.restart(
|
||||
dataState.hetznerServer!,
|
||||
);
|
||||
repository.saveIsServerReseted(true);
|
||||
repository.saveIsServerResetedFirstTime(true);
|
||||
repository.saveServerDetails(hetznerServerDetails);
|
||||
|
||||
emit(
|
||||
dataState.copyWith(
|
||||
isServerReseted: true,
|
||||
isServerResetedFirstTime: true,
|
||||
hetznerServer: hetznerServerDetails,
|
||||
isLoading: false,
|
||||
),
|
||||
);
|
||||
finishCheckIfServerIsOkay();
|
||||
oneMoreReset();
|
||||
});
|
||||
} else {
|
||||
resetServerIfServerIsOkay();
|
||||
|
|
|
@ -30,12 +30,17 @@ class AppConfigRepository {
|
|||
hetznerServer: getIt<ApiConfigModel>().hetznerServer,
|
||||
rootUser: box.get(BNames.rootUser),
|
||||
isServerStarted: box.get(BNames.isServerStarted, defaultValue: false),
|
||||
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
|
||||
isServerResetedFirstTime:
|
||||
box.get(BNames.isServerResetedFirstTime, defaultValue: false),
|
||||
isServerResetedSecondTime:
|
||||
box.get(BNames.isServerResetedSecondTime, defaultValue: false),
|
||||
hasFinalChecked: box.get(BNames.hasFinalChecked, defaultValue: false),
|
||||
error: null,
|
||||
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
||||
);
|
||||
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -119,7 +124,8 @@ class AppConfigRepository {
|
|||
text: 'basis.delete'.tr(),
|
||||
isRed: true,
|
||||
onPressed: () async {
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes();
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes(
|
||||
domainName: domainName);
|
||||
|
||||
var serverDetails = await hetznerApi.createServer(
|
||||
cloudFlareKey: cloudFlareKey,
|
||||
|
@ -198,8 +204,12 @@ class AppConfigRepository {
|
|||
await box.put(BNames.isServerStarted, value);
|
||||
}
|
||||
|
||||
Future<void> saveIsServerReseted(bool value) async {
|
||||
await box.put(BNames.isServerReseted, value);
|
||||
Future<void> saveIsServerResetedFirstTime(bool value) async {
|
||||
await box.put(BNames.isServerResetedFirstTime, value);
|
||||
}
|
||||
|
||||
Future<void> saveIsServerResetedSecondTime(bool value) async {
|
||||
await box.put(BNames.isServerResetedSecondTime, value);
|
||||
}
|
||||
|
||||
void saveRootUser(User rootUser) async {
|
||||
|
|
|
@ -9,7 +9,8 @@ class AppConfigState extends Equatable {
|
|||
required this.rootUser,
|
||||
required this.hetznerServer,
|
||||
required this.isServerStarted,
|
||||
required this.isServerReseted,
|
||||
required this.isServerResetedFirstTime,
|
||||
required this.isServerResetedSecondTime,
|
||||
required this.hasFinalChecked,
|
||||
required this.isLoading,
|
||||
required this.error,
|
||||
|
@ -24,7 +25,7 @@ class AppConfigState extends Equatable {
|
|||
rootUser,
|
||||
hetznerServer,
|
||||
isServerStarted,
|
||||
isServerReseted,
|
||||
isServerResetedFirstTime,
|
||||
hasFinalChecked,
|
||||
isLoading,
|
||||
error,
|
||||
|
@ -37,7 +38,9 @@ class AppConfigState extends Equatable {
|
|||
final User? rootUser;
|
||||
final HetznerServerDetails? hetznerServer;
|
||||
final bool isServerStarted;
|
||||
final bool isServerReseted;
|
||||
final bool isServerResetedFirstTime;
|
||||
final bool isServerResetedSecondTime;
|
||||
|
||||
final bool hasFinalChecked;
|
||||
|
||||
final bool? isLoading;
|
||||
|
@ -51,7 +54,8 @@ class AppConfigState extends Equatable {
|
|||
User? rootUser,
|
||||
HetznerServerDetails? hetznerServer,
|
||||
bool? isServerStarted,
|
||||
bool? isServerReseted,
|
||||
bool? isServerResetedFirstTime,
|
||||
bool? isServerResetedSecondTime,
|
||||
bool? hasFinalChecked,
|
||||
bool? isLoading,
|
||||
Exception? error,
|
||||
|
@ -64,7 +68,10 @@ class AppConfigState extends Equatable {
|
|||
rootUser: rootUser ?? this.rootUser,
|
||||
hetznerServer: hetznerServer ?? this.hetznerServer,
|
||||
isServerStarted: isServerStarted ?? this.isServerStarted,
|
||||
isServerReseted: isServerReseted ?? this.isServerReseted,
|
||||
isServerResetedFirstTime:
|
||||
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
|
||||
isServerResetedSecondTime:
|
||||
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
|
||||
hasFinalChecked: hasFinalChecked ?? this.hasFinalChecked,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
error: error ?? this.error,
|
||||
|
@ -89,11 +96,11 @@ class AppConfigState extends Equatable {
|
|||
isUserFilled,
|
||||
isServerCreated,
|
||||
isServerStarted,
|
||||
isServerReseted,
|
||||
isServerResetedFirstTime,
|
||||
isServerResetedSecondTime,
|
||||
hasFinalChecked,
|
||||
];
|
||||
|
||||
print(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +115,8 @@ class InitialAppConfigState extends AppConfigState {
|
|||
rootUser: null,
|
||||
hetznerServer: null,
|
||||
isServerStarted: false,
|
||||
isServerReseted: false,
|
||||
isServerResetedFirstTime: false,
|
||||
isServerResetedSecondTime: false,
|
||||
hasFinalChecked: false,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
|
@ -129,7 +137,8 @@ class TimerState extends AppConfigState {
|
|||
rootUser: dataState.rootUser,
|
||||
hetznerServer: dataState.hetznerServer,
|
||||
isServerStarted: dataState.isServerStarted,
|
||||
isServerReseted: dataState.isServerReseted,
|
||||
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
|
||||
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
|
||||
hasFinalChecked: dataState.hasFinalChecked,
|
||||
isLoading: isLoading,
|
||||
error: dataState.error,
|
||||
|
|
|
@ -47,25 +47,27 @@ class _ProgressBarState extends State<ProgressBar> {
|
|||
i++;
|
||||
}
|
||||
|
||||
odd
|
||||
..insert(
|
||||
0,
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
)
|
||||
..add(
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
);
|
||||
odd.insert(
|
||||
0,
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
);
|
||||
even.add(
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BrandText.h2('Progress'),
|
||||
SizedBox(height: 10),
|
||||
Row(children: even),
|
||||
Row(
|
||||
children: even,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
),
|
||||
SizedBox(height: 7),
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
|
@ -96,12 +98,13 @@ class _ProgressBarState extends State<ProgressBar> {
|
|||
SizedBox(height: 5),
|
||||
Row(
|
||||
children: odd,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Expanded _stepTitle({
|
||||
Container _stepTitle({
|
||||
required int index,
|
||||
TextStyle? style,
|
||||
String? step,
|
||||
|
@ -110,17 +113,19 @@ class _ProgressBarState extends State<ProgressBar> {
|
|||
var checked = index < widget.activeIndex;
|
||||
|
||||
style = isActive ? style!.copyWith(fontWeight: FontWeight.w700) : style;
|
||||
return Expanded(
|
||||
flex: 2,
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
height: 20,
|
||||
alignment: Alignment.center,
|
||||
child: RichText(
|
||||
textAlign: TextAlign.center,
|
||||
textAlign: TextAlign.justify,
|
||||
text: TextSpan(
|
||||
style: progressTextStyleLight,
|
||||
children: [
|
||||
checked
|
||||
? WidgetSpan(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 0, right: 2),
|
||||
padding: const EdgeInsets.only(bottom: 2, right: 2),
|
||||
child: Icon(BrandIcons.check, size: 11),
|
||||
))
|
||||
: TextSpan(text: '${index + 1}.', style: style),
|
||||
|
|
|
@ -34,6 +34,7 @@ class InitializingPage extends StatelessWidget {
|
|||
() => _stepCheck(cubit),
|
||||
() => _stepCheck(cubit),
|
||||
() => _stepCheck(cubit),
|
||||
() => _stepCheck(cubit),
|
||||
() => Container(child: Text('Everythigng is initialized'))
|
||||
][cubit.state.progress]();
|
||||
return BlocListener<AppConfigCubit, AppConfigState>(
|
||||
|
@ -58,7 +59,8 @@ class InitializingPage extends StatelessWidget {
|
|||
'Server',
|
||||
' ✅',
|
||||
' ✅',
|
||||
' ✅'
|
||||
' ✅',
|
||||
' ✅',
|
||||
],
|
||||
activeIndex: cubit.state.progress,
|
||||
),
|
||||
|
@ -427,8 +429,10 @@ class InitializingPage extends StatelessWidget {
|
|||
var state = appConfigCubit.state as TimerState;
|
||||
|
||||
late String? text;
|
||||
if (state.isServerReseted) {
|
||||
if (state.isServerResetedSecondTime) {
|
||||
text = 'initializing.13'.tr();
|
||||
} else if (state.isServerResetedFirstTime) {
|
||||
text = 'initializing.21'.tr();
|
||||
} else if (state.isServerStarted) {
|
||||
text = 'initializing.14'.tr();
|
||||
} else if (state.isServerCreated) {
|
||||
|
|
Loading…
Reference in a new issue