Iniitla Commit

This commit is contained in:
zontreck 2024-11-21 21:27:09 -07:00
commit 456c22e820
9 changed files with 215 additions and 0 deletions

32
.gitignore vendored Normal file
View file

@ -0,0 +1,32 @@
# See https://www.dartlang.org/guides/libraries/private-files
# Files and directories created by pub
.dart_tool/
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock
# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/
# dotenv environment variables file
.env*
# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map
.flutter-plugins
.flutter-plugins-dependencies
ipv4_ranges.txt
ipv6_ranges.txt
awsparser
out

3
CHANGELOG.md Normal file
View file

@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

2
README.md Normal file
View file

@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.

30
analysis_options.yaml Normal file
View file

@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

51
bin/awsparser.dart Normal file
View file

@ -0,0 +1,51 @@
import 'dart:convert';
import 'dart:io';
import 'package:awsparser/awsparser.dart';
import 'package:dio/dio.dart';
Future<void> main(List<String> arguments) async {
print(">> WELCOME <<");
print(">> Downloading AWS IP Range list..");
// First, download the AWS IP Ranges config
Dio dio = new Dio();
Response<dynamic> awsResponse =
await dio.get("https://ip-ranges.amazonaws.com/ip-ranges.json");
if (awsResponse.statusCode! == 200) {
// Get body as string
AWSJson aws = AWSJson.parse(awsResponse.data as Map<String, dynamic>);
print(">> Generating IP blocklist");
String blockListv4 = "";
String blockListv6 = "";
for (var entry in aws.prefixes) {
blockListv4 += "${entry.ip_prefix} AWS IPv4\n";
}
for (var entry in aws.ipv6_prefixes) {
blockListv6 += "${entry.ipv6_prefix} AWS IPv6\n";
}
print(">> Stripping trailing newline");
blockListv4 = blockListv4.trim();
blockListv6 = blockListv6.trim();
print(">> Report complete");
print(">> Saving to ipv4_ranges.txt");
File fi = File("ipv4_ranges.txt");
await fi.open(mode: FileMode.write);
await fi.writeAsString(blockListv4);
print(">> Saving to ipv6_ranges.txt");
fi = File("ipv6_ranges.txt");
await fi.open(mode: FileMode.write);
await fi.writeAsString(blockListv6);
print(">> Goodbye!");
} else {
print("/!\\ FATAL ERROR /!\\ Failed to download the IP Range list");
}
}

6
build.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
rm -rf out || true
mkdir -pv out || true
dart compile exe -o out/awsparser bin/awsparser.dart

64
lib/awsparser.dart Normal file
View file

@ -0,0 +1,64 @@
class AWSJson {
String syncToken = "";
String createDate = "";
List<AWSIPv4> prefixes = [];
List<AWSIPv6> ipv6_prefixes = [];
AWSJson._();
factory AWSJson.parse(Map<String, dynamic> js) {
AWSJson ajs = AWSJson._();
ajs.syncToken = js['syncToken'] as String;
ajs.createDate = js['createDate'] as String;
List<dynamic> LPv4 = js['prefixes'] as List<dynamic>;
for (var entry in LPv4) {
ajs.prefixes.add(AWSIPv4.parse(entry as Map<String, dynamic>));
}
List<dynamic> LPv6 = js['ipv6_prefixes'] as List<dynamic>;
for (var entry in LPv6) {
ajs.ipv6_prefixes.add(AWSIPv6.parse(entry as Map<String, dynamic>));
}
return ajs;
}
}
class AWSIPv4 {
String ip_prefix = "";
String region = "";
String service = "";
String network_border_group = "";
AWSIPv4._();
factory AWSIPv4.parse(Map<String, dynamic> js) {
AWSIPv4 ip = AWSIPv4._();
ip.ip_prefix = js['ip_prefix'] as String;
ip.region = js['region'] as String;
ip.service = js['service'] as String;
ip.network_border_group = js['network_border_group'] as String;
return ip;
}
}
class AWSIPv6 {
String ipv6_prefix = "";
String region = "";
String service = "";
String network_border_group = "";
AWSIPv6._();
factory AWSIPv6.parse(Map<String, dynamic> js) {
AWSIPv6 ip = AWSIPv6._();
ip.ipv6_prefix = js['ipv6_prefix'] as String;
ip.region = js['region'] as String;
ip.service = js['service'] as String;
ip.network_border_group = js['network_border_group'] as String;
return ip;
}
}

19
pubspec.yaml Normal file
View file

@ -0,0 +1,19 @@
name: awsparser
description: A sample command-line application.
version: 1.0.0
# repository: https://github.com/my_org/my_repo
environment:
sdk: ^3.5.4
# Add regular dependencies here.
dependencies:
libac_dart:
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
version: 1.2.90324+0325
dio: ^5.7.0
# path: ^1.8.0
dev_dependencies:
lints: ^4.0.0
test: ^1.24.0

8
test/awsparser_test.dart Normal file
View file

@ -0,0 +1,8 @@
import 'package:awsparser/awsparser.dart';
import 'package:test/test.dart';
void main() {
test('calculate', () {
expect(calculate(), 42);
});
}