CH-J SM Mobileδιαχείριση διακομιστή πάνω από SSH
Μενού
Δημοσίευση πηγής

CH-J SM Mobile

Περιηγηθείτε σε καταλόγους και αρχεία για μια συγκεκριμένη έκδοση εφαρμογών.

Κατεβάστε την πηγή ZIP
CH-J / SM Mobile 134 αρχεία
sm-mobile-20261016T050549Z-3678f2a05fa9 Προστέθηκε: · Χτισμένο:
Αρχεία
server_profile.dart Προστέθηκε: Ημερομηνία που δεν έχει καταγραφεί 2,7 KB · 93 γραμμές
Λήψη αρχείου
1import 'dart:convert';
2import 'dart:io';
3import 'dart:math';
4import '../core/failure.dart';
6enum AuthMethod { password, privateKey }
8String newId() => List.generate(
9 16,
10 (_) => Random.secure().nextInt(256),
11).map((e) => e.toRadixString(16).padLeft(2, '0')).join();
13String normalizeHost(String input) {
14 var host = input.trim();
15 if (host.startsWith('[') && host.endsWith(']')) {
16 host = host.substring(1, host.length - 1);
17 if (InternetAddress.tryParse(host)?.type != InternetAddressType.IPv6) {
18 throw const Failure('invalidProfile');
19 }
20 }
21 final ip = InternetAddress.tryParse(host);
22 final dns = RegExp(
23 r'^(?=.{1,253}$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$',
24 );
25 if (ip == null && !dns.hasMatch(host)) throw const Failure('invalidProfile');
26 return host;
29class ServerProfile {
30 final String id, name, host, username;
31 final int port;
32 final AuthMethod auth;
33 ServerProfile({
34 String? id,
35 required String name,
36 required String host,
37 required String username,
38 this.port = 22,
39 this.auth = AuthMethod.password,
40 }) : id = id ?? newId(),
41 name = name.trim(),
42 host = normalizeHost(host),
43 username = username.trim() {
44 if (this.name.isEmpty ||
45 this.name.length > 100 ||
46 this.username.isEmpty ||
47 this.username.length > 128 ||
48 RegExp(r'[\x00-\x1f\x7f]').hasMatch(this.name + this.username) ||
49 port < 1 ||
50 port > 65535) {
51 throw const Failure('invalidProfile');
52 }
53 }
54 String get endpoint {
55 final ip = InternetAddress.tryParse(host);
56 final canonical = ip == null
57 ? host.toLowerCase()
58 : InternetAddress.fromRawAddress(ip.rawAddress).address;
59 return ip?.type == InternetAddressType.IPv6
60 ? '[$canonical]:$port'
61 : '$canonical:$port';
62 }
64 String get identity => jsonEncode([endpoint, username]);
65 Map<String, dynamic> portable() => {
66 'name': name,
67 'host': host,
68 'username': username,
69 'port': port,
70 };
71 Map<String, dynamic> toJson() => {...portable(), 'id': id, 'auth': auth.name};
72 factory ServerProfile.fromJson(
73 Map<String, dynamic> json, {
74 bool portable = false,
75 }) {
76 if (json['name'] is! String ||
77 json['host'] is! String ||
78 json['username'] is! String ||
79 (json.containsKey('port') && json['port'] is! int)) {
80 throw const Failure('invalidProfile');
81 }
82 return ServerProfile(
83 id: portable ? null : json['id'] as String?,
84 name: json['name'],
85 host: json['host'],
86 username: json['username'],
87 port: json['port'] ?? 22,
88 auth: !portable && json['auth'] == 'privateKey'
89 ? AuthMethod.privateKey
90 : AuthMethod.password,
91 );
92 }
SHA-256b113b315481958d2c705a4f91b25d61761555eff0369ee3fd2698cf9069b33e9

CH-J Proprietary Software License 1.14 · Η πηγή παρέχεται στο CH-J Proprietary Software License 1.14. Η διαθεσιμότητά του δεν αλλάζει τους όρους της άδειας χρήσης ούτε χορηγεί πρόσθετα δικαιώματα.

Archive SHA-256c486a807e4828998b9c57ab0f2e760f7980b31965fe118e89d3e1a5a2b65be65