mirror of
https://github.com/nomoresat/DPITunnel-android.git
synced 2025-04-12 01:28:45 +02:00
initial commit
This commit is contained in:
commit
fa57e25422
187 changed files with 11069 additions and 0 deletions
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/app/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "app/src/main/cpp/dpitunnel-cli"]
|
||||
path = app/src/main/cpp/dpitunnel-cli
|
||||
url = https://github.com/nomoresat/DPITunnel-cli
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
@ -0,0 +1 @@
|
|||
DPITunnel-cli
|
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
19
.idea/gradle.xml
generated
Normal file
19
.idea/gradle.xml
generated
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
66
.idea/misc.xml
generated
Normal file
66
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable-v31/ic_launcher_background.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable-v31/ic_launcher_background_round.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable-v31/ic_launcher_foreground.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable-v31/ic_launcher_foreground_monochrome.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable-v31/ic_selector_profiles_24dp.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_add_24dp.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/drawable/ic_add_black_24dp.xml" value="0.19" />
|
||||
<entry key="app/src/main/res/drawable/ic_check_all_24dp.xml" value="0.1515" />
|
||||
<entry key="app/src/main/res/drawable/ic_check_circle_black_24dp.xml" value="0.234" />
|
||||
<entry key="app/src/main/res/drawable/ic_check_circle_white_96dp.xml" value="0.227" />
|
||||
<entry key="app/src/main/res/drawable/ic_delete_black_24dp.xml" value="0.175" />
|
||||
<entry key="app/src/main/res/drawable/ic_edit_24dp.xml" value="0.1515" />
|
||||
<entry key="app/src/main/res/drawable/ic_edit_black_24dp.xml" value="0.175" />
|
||||
<entry key="app/src/main/res/drawable/ic_export_24dp.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.19" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_background_round.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_foreground.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_foreground_monochrome.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_more_vert_24dp.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_more_vert_black_24dp.xml" value="0.19" />
|
||||
<entry key="app/src/main/res/drawable/ic_quick_tile.xml" value="0.1715" />
|
||||
<entry key="app/src/main/res/drawable/ic_quick_tile_24dp.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/drawable/ic_save_24.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/drawable/ic_save_black_24dp.xml" value="0.19" />
|
||||
<entry key="app/src/main/res/drawable/ic_save_white_24dp.xml" value="0.19" />
|
||||
<entry key="app/src/main/res/drawable/ic_selector_dashboard_24dp.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_selector_profiles_24dp.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/drawable/ic_stop_24.xml" value="0.197" />
|
||||
<entry key="app/src/main/res/layout/activity_custom_ips.xml" value="0.22" />
|
||||
<entry key="app/src/main/res/layout/activity_edit_profile.xml" value="0.22" />
|
||||
<entry key="app/src/main/res/layout/activity_edit_profile_content.xml" value="0.1" />
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.3482789855072464" />
|
||||
<entry key="app/src/main/res/layout/activity_proxified_apps.xml" value="0.27905982905982907" />
|
||||
<entry key="app/src/main/res/layout/activity_settings.xml" value="0.3482789855072464" />
|
||||
<entry key="app/src/main/res/layout/fragment_dashboard.xml" value="0.33" />
|
||||
<entry key="app/src/main/res/layout/fragment_profiles.xml" value="0.3482789855072464" />
|
||||
<entry key="app/src/main/res/layout/view_holder_custom_ip_item.xml" value="0.33" />
|
||||
<entry key="app/src/main/res/layout/view_holder_profile_item.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/layout/view_holder_profile_item_menu.xml" value="0.3482789855072464" />
|
||||
<entry key="app/src/main/res/layout/view_holder_proxified_apps_item.xml" value="0.27905982905982907" />
|
||||
<entry key="app/src/main/res/menu/bottom_nav_menu.xml" value="0.3546875" />
|
||||
<entry key="app/src/main/res/menu/custom_ips_toolbar_menu.xml" value="0.29102564102564105" />
|
||||
<entry key="app/src/main/res/menu/edit_profile_toolbar_menu.xml" value="0.3536458333333333" />
|
||||
<entry key="app/src/main/res/menu/profile_item_menu.xml" value="0.3536458333333333" />
|
||||
<entry key="app/src/main/res/menu/proxified_apps_toolbar_menu.xml" value="0.1252136752136752" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.16" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v31/ic_launcher.xml" value="0.164" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v31/ic_launcher_round.xml" value="0.14" />
|
||||
<entry key="app/src/main/res/xml/root_preferences.xml" value="0.33" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
674
LICENSE
Normal file
674
LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
46
README.md
Normal file
46
README.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
<div align="center">
|
||||
<img src="assets/logo.webp" alt="DPI Tunnel logo" width="200">
|
||||
<br><h1>DPI Tunnel for Android</h1>
|
||||
Free, simple and serverless solution against censorship for Android
|
||||
|
||||
<a href="https://t.me/DPITunnelOFFICIAL">Telegram chat</a>
|
||||
<br>
|
||||
<a href="https://github.com/nomoresat/DPITunnel-cli">Want version for PC or router?</a>
|
||||
|
||||
<a href="https://github.com/nomoresat/DPITunnel-android/blob/master/LICENSE"><img src="https://img.shields.io/github/license/nomoresat/DPITunnel-android?style=flat-square" alt="License"/></a>
|
||||
<a href="https://github.com/nomoresat/DPITunnel-android/releases/latest"><img src="https://img.shields.io/github/v/release/nomoresat/DPITunnel-android?style=flat-square" alt="Latest release"/></a>
|
||||
<a href="https://github.com/nomoresat/DPITunnel-android/releases"><img src="https://img.shields.io/github/downloads/nomoresat/DPITunnel-android/total?style=flat-square" alt="Downloads"/></a>
|
||||
|
||||
<br>
|
||||
<img src="assets/screenshot_1.png" alt="DPI Tunnel UI" height="64.8%" width="32%" />
|
||||
<img src="assets/screenshot_2.png" alt="DPI Tunnel UI" height="64.8%" width="32%" />
|
||||
<img src="assets/screenshot_3.png" alt="DPI Tunnel UI" height="64.8%" width="32%" />
|
||||
</div>
|
||||
|
||||
### What is it
|
||||
DPI Tunnel is a proxy server, that allows you to bypass censorship
|
||||
|
||||
It is NOT VPN and won't change your IP
|
||||
|
||||
DPI Tunnel uses desync attacks to fool DPI filters
|
||||
|
||||
### Features
|
||||
* Bypass many restrictions: blocked or throttled resources
|
||||
* Create profiles for different ISP and automatically change them when switch connection
|
||||
* Auto start program on device boot
|
||||
* Easily auto configure for your ISP
|
||||
* Choose apps, which traffic handle
|
||||
* Specify working IPs for huge blocked resources (Google, Facebook, Instagram)
|
||||
|
||||
## Configuring
|
||||
For the most of ISPs you do not need any configuration. Just press start button.
|
||||
|
||||
For other ISPs program has option to automatically find proper settings
|
||||
|
||||
## Links
|
||||
[Telegram chat](https://t.me/DPITunnelOFFICIAL)
|
||||
|
||||
[4PDA](https://4pda.to/forum/index.php?showtopic=1043778)
|
||||
|
||||
## Dependencies
|
||||
* [libsu](https://github.com/topjohnwu/libsu)
|
73
app/build.gradle
Normal file
73
app/build.gradle
Normal file
|
@ -0,0 +1,73 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk 32
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.nomoresat.dpitunnelcli"
|
||||
minSdk 21
|
||||
targetSdk 32
|
||||
versionCode 3
|
||||
versionName "1.2"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
kapt {
|
||||
arguments {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
jniLibs {
|
||||
useLegacyPackaging = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.github.topjohnwu.libsu:core:3.2.1"
|
||||
implementation "androidx.room:room-runtime:2.4.1"
|
||||
implementation 'androidx.room:room-ktx:2.4.1'
|
||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||
kapt "androidx.room:room-compiler:2.4.1"
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
}
|
21
app/proguard-rules.pro
vendored
Normal file
21
app/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,142 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "52d281230c2b9088c1de0910726de4b2",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "profiles_table",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `title` TEXT, `buffer_size` INTEGER, `split_position` INTEGER, `split_at_sni` INTEGER NOT NULL, `wrong_seq` INTEGER NOT NULL, `auto_ttl` INTEGER NOT NULL, `fake_packets_ttl` INTEGER, `window_size` INTEGER, `window_scale_factor` INTEGER, `inbuilt_dns` INTEGER NOT NULL, `inbuilt_dns_ip` TEXT, `inbuilt_dns_port` INTEGER, `doh` INTEGER NOT NULL, `doh_server` TEXT, `desync_attacks` INTEGER NOT NULL, `desync_zero_attack` TEXT, `desync_first_attack` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "bufferSize",
|
||||
"columnName": "buffer_size",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "splitPosition",
|
||||
"columnName": "split_position",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "splitAtSni",
|
||||
"columnName": "split_at_sni",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wrongSeq",
|
||||
"columnName": "wrong_seq",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoTtl",
|
||||
"columnName": "auto_ttl",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fakePacketsTtl",
|
||||
"columnName": "fake_packets_ttl",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "windowSize",
|
||||
"columnName": "window_size",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "windowScaleFactor",
|
||||
"columnName": "window_scale_factor",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNS",
|
||||
"columnName": "inbuilt_dns",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNSIP",
|
||||
"columnName": "inbuilt_dns_ip",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNSPort",
|
||||
"columnName": "inbuilt_dns_port",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "doh",
|
||||
"columnName": "doh",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dohServer",
|
||||
"columnName": "doh_server",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncAttacks",
|
||||
"columnName": "desync_attacks",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncZeroAttack",
|
||||
"columnName": "desync_zero_attack",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncFirstAttack",
|
||||
"columnName": "desync_first_attack",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '52d281230c2b9088c1de0910726de4b2')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "fda85eb59bb50aa5a199ab95ddd0f532",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "profiles_table",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `enabled` INTEGER NOT NULL, `name` TEXT NOT NULL, `title` TEXT, `buffer_size` INTEGER, `split_position` INTEGER, `split_at_sni` INTEGER NOT NULL, `wrong_seq` INTEGER NOT NULL, `auto_ttl` INTEGER NOT NULL, `fake_packets_ttl` INTEGER, `window_size` INTEGER, `window_scale_factor` INTEGER, `inbuilt_dns` INTEGER NOT NULL, `inbuilt_dns_ip` TEXT, `inbuilt_dns_port` INTEGER, `doh` INTEGER NOT NULL, `doh_server` TEXT, `desync_attacks` INTEGER NOT NULL, `desync_zero_attack` TEXT, `desync_first_attack` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "enabled",
|
||||
"columnName": "enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "bufferSize",
|
||||
"columnName": "buffer_size",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "splitPosition",
|
||||
"columnName": "split_position",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "splitAtSni",
|
||||
"columnName": "split_at_sni",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wrongSeq",
|
||||
"columnName": "wrong_seq",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoTtl",
|
||||
"columnName": "auto_ttl",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fakePacketsTtl",
|
||||
"columnName": "fake_packets_ttl",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "windowSize",
|
||||
"columnName": "window_size",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "windowScaleFactor",
|
||||
"columnName": "window_scale_factor",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNS",
|
||||
"columnName": "inbuilt_dns",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNSIP",
|
||||
"columnName": "inbuilt_dns_ip",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "inBuiltDNSPort",
|
||||
"columnName": "inbuilt_dns_port",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "doh",
|
||||
"columnName": "doh",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dohServer",
|
||||
"columnName": "doh_server",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncAttacks",
|
||||
"columnName": "desync_attacks",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncZeroAttack",
|
||||
"columnName": "desync_zero_attack",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "desyncFirstAttack",
|
||||
"columnName": "desync_first_attack",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fda85eb59bb50aa5a199ab95ddd0f532')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.nomoresat.dpitunnelcli
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.nomoresat.dpitunnelcli", appContext.packageName)
|
||||
}
|
||||
}
|
103
app/src/main/AndroidManifest.xml
Normal file
103
app/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.nomoresat.dpitunnelcli">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.QUICKBOOT_POWERON" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.software.leanback"
|
||||
android:required="false" />
|
||||
<uses-feature
|
||||
android:name="android.hardware.touchscreen"
|
||||
android:required="false" />
|
||||
<uses-feature
|
||||
android:name="android.hardware.location.gps"
|
||||
android:required="false" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:banner="@string/app_name"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:extractNativeLibs="true"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.DPITunnelcli"
|
||||
tools:targetApi="31">
|
||||
|
||||
<receiver
|
||||
android:name=".receiver.BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".service.SwitchTileService"
|
||||
android:icon="@drawable/ic_quick_tile"
|
||||
android:label="@string/tile_enable_disable"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action
|
||||
android:name="android.service.quicksettings.action.QS_TILE"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity
|
||||
android:name=".ui.activity.proxifiedApps.ProxifiedAppsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_proxified_apps"
|
||||
android:theme="@style/Theme.DPITunnelcli" />
|
||||
<activity
|
||||
android:name=".ui.activity.customIPs.CustomIPsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_custom_ips"
|
||||
android:theme="@style/Theme.DPITunnelcli" />
|
||||
<activity
|
||||
android:name=".ui.activity.settings.SettingsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:theme="@style/Theme.DPITunnelcli" />
|
||||
<activity
|
||||
android:name=".ui.activity.editProfile.EditProfileActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_edit_profile"
|
||||
android:theme="@style/Theme.DPITunnelcli" />
|
||||
<activity
|
||||
android:name=".ui.activity.MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
3347
app/src/main/assets/ca.bundle
Normal file
3347
app/src/main/assets/ca.bundle
Normal file
File diff suppressed because it is too large
Load diff
50
app/src/main/cpp/CMakeLists.txt
Normal file
50
app/src/main/cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Set the minimum version of CMake that can be used
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# Set the project name
|
||||
project(DPITunnel-cli)
|
||||
|
||||
include(ExternalProject)
|
||||
|
||||
set(OPENSSL_VERSION "1.1.1m")
|
||||
|
||||
# Add OpenSSL as external project
|
||||
ExternalProject_Add(OpenSSL
|
||||
URL https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
|
||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env PATH=${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin:$ENV{PATH} CC=${CMAKE_C_COMPILER} ANDROID_NDK_HOME=${ANDROID_NDK} perl <SOURCE_DIR>/Configure android-${ANDROID_ARCH_NAME} no-shared -D__ANDROID_API__=${ANDROID_NATIVE_API_LEVEL} --openssldir=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} --libdir="" --prefix=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
||||
UPDATE_COMMAND ""
|
||||
BUILD_COMMAND ${CMAKE_COMMAND} -E env PATH=${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}/bin:$ENV{PATH} ANDROID_NDK_HOME=${ANDROID_NDK} make
|
||||
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.a ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.a
|
||||
BUILD_IN_SOURCE 1
|
||||
)
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
|
||||
set(OPENSSL_INCLUDE_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
|
||||
set(OPENSSL_SSL_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.a)
|
||||
set(OPENSSL_CRYPTO_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.a)
|
||||
|
||||
add_library(OpenSSL::SSL STATIC IMPORTED)
|
||||
add_dependencies(OpenSSL::SSL OpenSSL)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.a)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
|
||||
|
||||
add_library(OpenSSL::Crypto STATIC IMPORTED)
|
||||
add_dependencies(OpenSSL::Crypto OpenSSL)
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.a)
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
|
||||
|
||||
set(STATIC_BINARY true)
|
||||
add_subdirectory(dpitunnel-cli)
|
||||
|
||||
target_include_directories(DPITunnel-cli-exec
|
||||
PRIVATE
|
||||
dpitunnel-cli-android-includes
|
||||
)
|
||||
|
||||
# Rename binary to lib<name>.so to add it in result APK
|
||||
set_target_properties(
|
||||
DPITunnel-cli-exec
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "libdpitunnel-cli"
|
||||
SUFFIX ".so"
|
||||
)
|
1
app/src/main/cpp/dpitunnel-cli
Submodule
1
app/src/main/cpp/dpitunnel-cli
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 624389417f31c98b98875c2f8f32057da9497b9b
|
66
app/src/main/cpp/dpitunnel-cli-android-includes/LocalArray.h
Normal file
66
app/src/main/cpp/dpitunnel-cli-android-includes/LocalArray.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LOCAL_ARRAY_H_included
|
||||
#define LOCAL_ARRAY_H_included
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
/**
|
||||
* A fixed-size array with a size hint. That number of bytes will be allocated
|
||||
* on the stack, and used if possible, but if more bytes are requested at
|
||||
* construction time, a buffer will be allocated on the heap (and deallocated
|
||||
* by the destructor).
|
||||
*
|
||||
* The API is intended to be a compatible subset of C++0x's std::array.
|
||||
*/
|
||||
template <size_t STACK_BYTE_COUNT>
|
||||
class LocalArray {
|
||||
public:
|
||||
/**
|
||||
* Allocates a new fixed-size array of the given size. If this size is
|
||||
* less than or equal to the template parameter STACK_BYTE_COUNT, an
|
||||
* internal on-stack buffer will be used. Otherwise a heap buffer will
|
||||
* be allocated.
|
||||
*/
|
||||
LocalArray(size_t desiredByteCount) : mSize(desiredByteCount) {
|
||||
if (desiredByteCount > STACK_BYTE_COUNT) {
|
||||
mPtr = new char[mSize];
|
||||
} else {
|
||||
mPtr = &mOnStackBuffer[0];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Frees the heap-allocated buffer, if there was one.
|
||||
*/
|
||||
~LocalArray() {
|
||||
if (mPtr != &mOnStackBuffer[0]) {
|
||||
delete[] mPtr;
|
||||
}
|
||||
}
|
||||
// Capacity.
|
||||
size_t size() { return mSize; }
|
||||
bool empty() { return mSize == 0; }
|
||||
// Element access.
|
||||
char& operator[](size_t n) { return mPtr[n]; }
|
||||
const char& operator[](size_t n) const { return mPtr[n]; }
|
||||
private:
|
||||
char mOnStackBuffer[STACK_BYTE_COUNT];
|
||||
char* mPtr;
|
||||
size_t mSize;
|
||||
// Disallow copy and assignment.
|
||||
LocalArray(const LocalArray&);
|
||||
void operator=(const LocalArray&);
|
||||
};
|
||||
#endif // LOCAL_ARRAY_H_included
|
38
app/src/main/cpp/dpitunnel-cli-android-includes/ScopedFd.h
Normal file
38
app/src/main/cpp/dpitunnel-cli-android-includes/ScopedFd.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef SCOPED_FD_H_included
|
||||
#define SCOPED_FD_H_included
|
||||
#include <unistd.h>
|
||||
// A smart pointer that closes the given fd on going out of scope.
|
||||
// Use this when the fd is incidental to the purpose of your function,
|
||||
// but needs to be cleaned up on exit.
|
||||
class ScopedFd {
|
||||
public:
|
||||
explicit ScopedFd(int fd) : fd(fd) {
|
||||
}
|
||||
~ScopedFd() {
|
||||
close(fd);
|
||||
}
|
||||
int get() const {
|
||||
return fd;
|
||||
}
|
||||
private:
|
||||
int fd;
|
||||
// Disallow copy and assignment.
|
||||
ScopedFd(const ScopedFd&);
|
||||
void operator=(const ScopedFd&);
|
||||
};
|
||||
#endif // SCOPED_FD_H_included
|
202
app/src/main/cpp/dpitunnel-cli-android-includes/ifaddrs.h
Normal file
202
app/src/main/cpp/dpitunnel-cli-android-includes/ifaddrs.h
Normal file
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef IFADDRS_ANDROID_H_included
|
||||
#define IFADDRS_ANDROID_H_included
|
||||
#include <arpa/inet.h>
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <new>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include "LocalArray.h"
|
||||
#include "ScopedFd.h"
|
||||
// Android (bionic) doesn't have getifaddrs(3)/freeifaddrs(3).
|
||||
// We fake it here, so java_net_NetworkInterface.cpp can use that API
|
||||
// with all the non-portable code being in this file.
|
||||
// Source-compatible subset of the BSD struct.
|
||||
struct ifaddrs {
|
||||
// Pointer to next struct in list, or NULL at end.
|
||||
ifaddrs* ifa_next;
|
||||
// Interface name.
|
||||
char* ifa_name;
|
||||
// Interface flags.
|
||||
unsigned int ifa_flags;
|
||||
// Interface network address.
|
||||
sockaddr* ifa_addr;
|
||||
// Interface netmask.
|
||||
sockaddr* ifa_netmask;
|
||||
ifaddrs(ifaddrs* next)
|
||||
: ifa_next(next), ifa_name(NULL), ifa_flags(0), ifa_addr(NULL), ifa_netmask(NULL)
|
||||
{
|
||||
}
|
||||
~ifaddrs() {
|
||||
delete ifa_next;
|
||||
delete[] ifa_name;
|
||||
delete ifa_addr;
|
||||
delete ifa_netmask;
|
||||
}
|
||||
// Sadly, we can't keep the interface index for portability with BSD.
|
||||
// We'll have to keep the name instead, and re-query the index when
|
||||
// we need it later.
|
||||
bool setNameAndFlagsByIndex(int interfaceIndex) {
|
||||
// Get the name.
|
||||
char buf[IFNAMSIZ];
|
||||
char* name = if_indextoname(interfaceIndex, buf);
|
||||
if (name == NULL) {
|
||||
return false;
|
||||
}
|
||||
ifa_name = new char[strlen(name) + 1];
|
||||
strcpy(ifa_name, name);
|
||||
// Get the flags.
|
||||
ScopedFd fd(socket(AF_INET, SOCK_DGRAM, 0));
|
||||
if (fd.get() == -1) {
|
||||
return false;
|
||||
}
|
||||
ifreq ifr;
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strcpy(ifr.ifr_name, name);
|
||||
int rc = ioctl(fd.get(), SIOCGIFFLAGS, &ifr);
|
||||
if (rc == -1) {
|
||||
return false;
|
||||
}
|
||||
ifa_flags = ifr.ifr_flags;
|
||||
return true;
|
||||
}
|
||||
// Netlink gives us the address family in the header, and the
|
||||
// sockaddr_in or sockaddr_in6 bytes as the payload. We need to
|
||||
// stitch the two bits together into the sockaddr that's part of
|
||||
// our portable interface.
|
||||
void setAddress(int family, void* data, size_t byteCount) {
|
||||
// Set the address proper...
|
||||
sockaddr_storage* ss = new sockaddr_storage;
|
||||
memset(ss, 0, sizeof(*ss));
|
||||
ifa_addr = reinterpret_cast<sockaddr*>(ss);
|
||||
ss->ss_family = family;
|
||||
uint8_t* dst = sockaddrBytes(family, ss);
|
||||
memcpy(dst, data, byteCount);
|
||||
}
|
||||
// Netlink gives us the prefix length as a bit count. We need to turn
|
||||
// that into a BSD-compatible netmask represented by a sockaddr*.
|
||||
void setNetmask(int family, size_t prefixLength) {
|
||||
// ...and work out the netmask from the prefix length.
|
||||
sockaddr_storage* ss = new sockaddr_storage;
|
||||
memset(ss, 0, sizeof(*ss));
|
||||
ifa_netmask = reinterpret_cast<sockaddr*>(ss);
|
||||
ss->ss_family = family;
|
||||
uint8_t* dst = sockaddrBytes(family, ss);
|
||||
memset(dst, 0xff, prefixLength / 8);
|
||||
if ((prefixLength % 8) != 0) {
|
||||
dst[prefixLength/8] = (0xff << (8 - (prefixLength % 8)));
|
||||
}
|
||||
}
|
||||
// Returns a pointer to the first byte in the address data (which is
|
||||
// stored in network byte order).
|
||||
uint8_t* sockaddrBytes(int family, sockaddr_storage* ss) {
|
||||
if (family == AF_INET) {
|
||||
sockaddr_in* ss4 = reinterpret_cast<sockaddr_in*>(ss);
|
||||
return reinterpret_cast<uint8_t*>(&ss4->sin_addr);
|
||||
} else if (family == AF_INET6) {
|
||||
sockaddr_in6* ss6 = reinterpret_cast<sockaddr_in6*>(ss);
|
||||
return reinterpret_cast<uint8_t*>(&ss6->sin6_addr);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
private:
|
||||
// Disallow copy and assignment.
|
||||
ifaddrs(const ifaddrs&);
|
||||
void operator=(const ifaddrs&);
|
||||
};
|
||||
// FIXME: use iovec instead.
|
||||
struct addrReq_struct {
|
||||
nlmsghdr netlinkHeader;
|
||||
ifaddrmsg msg;
|
||||
};
|
||||
inline bool sendNetlinkMessage(int fd, const void* data, size_t byteCount) {
|
||||
ssize_t sentByteCount = TEMP_FAILURE_RETRY(send(fd, data, byteCount, 0));
|
||||
return (sentByteCount == static_cast<ssize_t>(byteCount));
|
||||
}
|
||||
inline ssize_t recvNetlinkMessage(int fd, char* buf, size_t byteCount) {
|
||||
return TEMP_FAILURE_RETRY(recv(fd, buf, byteCount, 0));
|
||||
}
|
||||
// Source-compatible with the BSD function.
|
||||
inline int getifaddrs(ifaddrs** result) {
|
||||
// Simplify cleanup for callers.
|
||||
*result = NULL;
|
||||
// Create a netlink socket.
|
||||
ScopedFd fd(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE));
|
||||
if (fd.get() < 0) {
|
||||
return -1;
|
||||
}
|
||||
// Ask for the address information.
|
||||
addrReq_struct addrRequest;
|
||||
memset(&addrRequest, 0, sizeof(addrRequest));
|
||||
addrRequest.netlinkHeader.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH;
|
||||
addrRequest.netlinkHeader.nlmsg_type = RTM_GETADDR;
|
||||
addrRequest.netlinkHeader.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(addrRequest)));
|
||||
addrRequest.msg.ifa_family = AF_UNSPEC; // All families.
|
||||
addrRequest.msg.ifa_index = 0; // All interfaces.
|
||||
if (!sendNetlinkMessage(fd.get(), &addrRequest, addrRequest.netlinkHeader.nlmsg_len)) {
|
||||
return -1;
|
||||
}
|
||||
// Read the responses.
|
||||
LocalArray<0> buf(65536); // We don't necessarily have std::vector.
|
||||
ssize_t bytesRead;
|
||||
while ((bytesRead = recvNetlinkMessage(fd.get(), &buf[0], buf.size())) > 0) {
|
||||
nlmsghdr* hdr = reinterpret_cast<nlmsghdr*>(&buf[0]);
|
||||
for (; NLMSG_OK(hdr, (size_t)bytesRead); hdr = NLMSG_NEXT(hdr, bytesRead)) {
|
||||
switch (hdr->nlmsg_type) {
|
||||
case NLMSG_DONE:
|
||||
return 0;
|
||||
case NLMSG_ERROR:
|
||||
return -1;
|
||||
case RTM_NEWADDR:
|
||||
{
|
||||
ifaddrmsg* address = reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(hdr));
|
||||
rtattr* rta = IFA_RTA(address);
|
||||
size_t ifaPayloadLength = IFA_PAYLOAD(hdr);
|
||||
while (RTA_OK(rta, ifaPayloadLength)) {
|
||||
if (rta->rta_type == IFA_LOCAL) {
|
||||
int family = address->ifa_family;
|
||||
if (family == AF_INET || family == AF_INET6) {
|
||||
*result = new ifaddrs(*result);
|
||||
if (!(*result)->setNameAndFlagsByIndex(address->ifa_index)) {
|
||||
return -1;
|
||||
}
|
||||
(*result)->setAddress(family, RTA_DATA(rta), RTA_PAYLOAD(rta));
|
||||
(*result)->setNetmask(family, address->ifa_prefixlen);
|
||||
}
|
||||
}
|
||||
rta = RTA_NEXT(rta, ifaPayloadLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// We only get here if recv fails before we see a NLMSG_DONE.
|
||||
return -1;
|
||||
}
|
||||
// Source-compatible with the BSD function.
|
||||
inline void freeifaddrs(ifaddrs* addresses) {
|
||||
delete addresses;
|
||||
}
|
||||
#endif // IFADDRS_ANDROID_H_included
|
|
@ -0,0 +1,63 @@
|
|||
package com.nomoresat.dpitunnelcli.cli
|
||||
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.DaemonState
|
||||
|
||||
class CliDaemon(private val execPath: String,
|
||||
private val pidFilePath: String) {
|
||||
|
||||
private val _daemonState = MutableStateFlow<DaemonState>(DaemonState.Loading)
|
||||
val daemonState: StateFlow<DaemonState> = _daemonState
|
||||
|
||||
fun check() {
|
||||
return when (val exitCode = Shell.su("[ -f /proc/\$(cat \"$pidFilePath\")/status ]").exec().code) {
|
||||
0 -> _daemonState.value = DaemonState.Running
|
||||
1 -> _daemonState.value = DaemonState.Stopped
|
||||
else -> _daemonState.value = DaemonState.Error(exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
fun start(persistentOptions: PersistentOptions, profiles: List<Profile>) {
|
||||
val argsStr = StringBuilder()
|
||||
argsStr.append("$execPath --pid \"$pidFilePath\"")
|
||||
argsStr.append(' ')
|
||||
argsStr.append(persistentOptions.toString())
|
||||
profiles.forEach {
|
||||
if (!it.default && !it.enabled)
|
||||
return@forEach
|
||||
argsStr.append(' ')
|
||||
argsStr.append(it.toString())
|
||||
}
|
||||
Shell.su(argsStr.toString()).exec()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
Shell.su("kill -INT \$(cat \"$pidFilePath\")").exec()
|
||||
}
|
||||
|
||||
data class PersistentOptions(
|
||||
val caBundlePath: String,
|
||||
val ip: String?,
|
||||
val port: Int?,
|
||||
val customIPsPath: String?,
|
||||
val proxyMode: ProxyMode
|
||||
) {
|
||||
override fun toString(): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
stringBuilder.append("--daemon --ca-bundle-path \"${this.caBundlePath}\"")
|
||||
ip?.let { stringBuilder.append(" --ip $it") }
|
||||
port?.let { stringBuilder.append(" --port $it") }
|
||||
customIPsPath?.let { stringBuilder.append(" --custom-ips \"$it\"") }
|
||||
stringBuilder.append(" --mode ")
|
||||
when(proxyMode) {
|
||||
ProxyMode.HTTP -> { stringBuilder.append("proxy") }
|
||||
ProxyMode.TRANSPARENT -> { stringBuilder.append("transparent") }
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IAutoConfigUseCase
|
||||
import java.io.*
|
||||
|
||||
class AutoConfigUseCase: IAutoConfigUseCase {
|
||||
|
||||
private var _process: Process? = null
|
||||
@Synchronized
|
||||
set(value) {
|
||||
field?.destroy()
|
||||
field?.inputStream?.close()
|
||||
field?.errorStream?.close()
|
||||
field?.outputStream?.close()
|
||||
field = value
|
||||
}
|
||||
|
||||
private var _outputStream: OutputStream? = null
|
||||
private var _inputFlow = MutableSharedFlow<String>(replay = 0)
|
||||
override var inputFlow: SharedFlow<String> = _inputFlow.asSharedFlow()
|
||||
|
||||
override fun run(externalScope: CoroutineScope, cmd: List<String>,
|
||||
exceptionCallBack: (Throwable) -> Unit) {
|
||||
externalScope.launch(Dispatchers.IO) {
|
||||
runCatching {
|
||||
_process = ProcessBuilder(cmd)
|
||||
.redirectErrorStream(true)
|
||||
.start().also { process ->
|
||||
_outputStream = process.outputStream
|
||||
val br = BufferedReader(InputStreamReader(process.inputStream))
|
||||
val stringBuilder = StringBuilder()
|
||||
var c: Int = br.read()
|
||||
while (c != -1) {
|
||||
stringBuilder.append((Char(c)))
|
||||
if (br.ready())
|
||||
c = br.read()
|
||||
else {
|
||||
val str = stringBuilder.toString()
|
||||
_inputFlow.emit(str)
|
||||
stringBuilder.setLength(0)
|
||||
c = br.read()
|
||||
}
|
||||
}
|
||||
}
|
||||
}.onFailure(exceptionCallBack)
|
||||
}
|
||||
}
|
||||
|
||||
override fun input(input: String) {
|
||||
try {
|
||||
_outputStream?.let {
|
||||
OutputStreamWriter(it, Charsets.UTF_8).apply {
|
||||
write(input)
|
||||
flush()
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.cli.CliDaemon
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IDaemonUseCase
|
||||
|
||||
class DaemonUseCase(private val execPath: String,
|
||||
private val pidFilePath: String): IDaemonUseCase {
|
||||
private val cliDaemon = CliDaemon(execPath, pidFilePath)
|
||||
override val daemonState = cliDaemon.daemonState
|
||||
|
||||
override fun check() {
|
||||
cliDaemon.check()
|
||||
}
|
||||
|
||||
override fun start(persistentOptions: CliDaemon.PersistentOptions, profiles: List<Profile>) {
|
||||
cliDaemon.start(persistentOptions, profiles)
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
cliDaemon.stop()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IDeleteProfileUseCase
|
||||
|
||||
class DeleteProfileUseCase(private val context: Context): IDeleteProfileUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
|
||||
override suspend fun delete(id: Long) {
|
||||
profileDao.delete(id)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IEnableDisableProfileUseCase
|
||||
|
||||
class EnableDisableProfileUseCase(private val context: Context): IEnableDisableProfileUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
|
||||
override suspend fun enable(id: Long) {
|
||||
profileDao.setEnable(id, true)
|
||||
}
|
||||
|
||||
override suspend fun disable(id: Long) {
|
||||
profileDao.setEnable(id, false)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncFirstAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncZeroAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IFetchAllProfilesUseCase
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
|
||||
class FetchAllProfilesUseCase(private val context: Context): IFetchAllProfilesUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
private val appPreferences = AppPreferences.getInstance(context)
|
||||
|
||||
override suspend fun fetch(): List<Profile> = convertList(profileDao.getAll())
|
||||
|
||||
override fun fetchLive(): LiveData<List<Profile>> {
|
||||
val mediatorLiveData = MediatorLiveData<List<Profile>>()
|
||||
val profilesLive = profileDao.getAllLive()
|
||||
mediatorLiveData.addSource(profilesLive) {
|
||||
mediatorLiveData.value = convertList(it)
|
||||
}
|
||||
return mediatorLiveData
|
||||
}
|
||||
|
||||
private fun convertList(list: List<com.nomoresat.dpitunnelcli.database.Profile>): List<Profile> {
|
||||
val newList = mutableListOf<Profile>()
|
||||
val defaultProfileId = appPreferences.defaultProfileId
|
||||
var defaultExist = false
|
||||
list.forEach { profile ->
|
||||
if (profile.id == defaultProfileId)
|
||||
defaultExist = true
|
||||
newList += Profile(
|
||||
id = profile.id,
|
||||
enabled = profile.enabled,
|
||||
name = profile.name,
|
||||
title = profile.title,
|
||||
bufferSize = profile.bufferSize,
|
||||
splitPosition = profile.splitPosition,
|
||||
splitAtSni = profile.splitAtSni,
|
||||
wrongSeq = profile.wrongSeq,
|
||||
autoTtl = profile.autoTtl,
|
||||
fakePacketsTtl = profile.fakePacketsTtl,
|
||||
windowSize = profile.windowSize,
|
||||
windowScaleFactor = profile.windowScaleFactor,
|
||||
inBuiltDNS = profile.inBuiltDNS,
|
||||
inBuiltDNSIP = profile.inBuiltDNSIP,
|
||||
inBuiltDNSPort = profile.inBuiltDNSPort,
|
||||
doh = profile.doh,
|
||||
dohServer = profile.dohServer,
|
||||
desyncAttacks = profile.desyncAttacks,
|
||||
desyncZeroAttack = profile.desyncZeroAttack?.ordinal?.let { DesyncZeroAttack.values()[it] },
|
||||
desyncFirstAttack = profile.desyncFirstAttack?.ordinal?.let { DesyncFirstAttack.values()[it] },
|
||||
default = profile.id == defaultProfileId
|
||||
)
|
||||
}
|
||||
newList.sortWith { lhs, rhs ->
|
||||
// -1 - less than, 1 - greater than, 0 - equal
|
||||
if (lhs.default) -1 else if (lhs.enabled && !rhs.default) -1 else 1
|
||||
}
|
||||
|
||||
if (!defaultExist) {
|
||||
newList.getOrNull(0)?.let {
|
||||
it.default = true
|
||||
appPreferences.defaultProfileId = it.id
|
||||
}
|
||||
}
|
||||
return newList
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import android.net.wifi.SupplicantState
|
||||
import android.net.wifi.WifiManager
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IFetchDefaultIfaceWifiAPUseCase
|
||||
import java.net.*
|
||||
|
||||
|
||||
class FetchDefaultIfaceWifiAPUseCase : IFetchDefaultIfaceWifiAPUseCase {
|
||||
override suspend fun fetch(context: Context): Pair<String?, String?> {
|
||||
return Pair(fetchDefaultIface(), fetchWifiAP(context))
|
||||
}
|
||||
|
||||
private fun fetchDefaultIface(): String? {
|
||||
// Find the default publicly routed network interface in the machine.
|
||||
// return null if we can't, otherwise its name.
|
||||
val globalHost = "a.root-servers.net" // Must exist.
|
||||
val globalIp = "198.41.0.4" // 'A' root server IP
|
||||
|
||||
var name: String? = null
|
||||
var remoteAddress: InetAddress?
|
||||
|
||||
try {
|
||||
// This requires we can do name resolution, if we can't we probably don't have
|
||||
// an interface that's publicly routed or we don't have access to ICANN root name servers,
|
||||
// because they are blocked for example and we can use only something like НСДИ (Russian National System of Domain Names)
|
||||
remoteAddress = InetAddress.getByName(globalHost)
|
||||
} catch (e: UnknownHostException) {
|
||||
e.printStackTrace()
|
||||
// So in case we can't resolve root name server's IP, fallback to hardcoded one
|
||||
// It should never happen in Internet, but it's need for future
|
||||
remoteAddress = InetAddress.getByName(globalIp)
|
||||
}
|
||||
|
||||
if (remoteAddress != null) {
|
||||
try {
|
||||
DatagramSocket().use { s ->
|
||||
// UDP does not actually open a connection, we just need to do this to get the
|
||||
// interface we would send packets on if we actually tried.
|
||||
s.connect(remoteAddress, 80)
|
||||
name = NetworkInterface.getByInetAddress(s.localAddress)?.name
|
||||
}
|
||||
} catch (e: SocketException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
private fun fetchWifiAP(context: Context): String? {
|
||||
var ssid: String? = null
|
||||
|
||||
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
val wifiInfo = wifiManager.connectionInfo
|
||||
if (wifiInfo != null && wifiInfo.supplicantState === SupplicantState.COMPLETED && wifiInfo.ssid.isNotBlank() && wifiInfo.ssid != "<unknown ssid>") {
|
||||
ssid = wifiInfo.ssid.removeSurrounding("\"")
|
||||
}
|
||||
|
||||
return ssid
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncFirstAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncZeroAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IFetchProfileUseCase
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
|
||||
class FetchProfileUseCase(private val context: Context): IFetchProfileUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
private val appPreferences = AppPreferences.getInstance(context)
|
||||
|
||||
override suspend fun fetch(id: Long): Profile? = profileDao.findById(id)?.let { profile ->
|
||||
Profile(
|
||||
id = profile.id,
|
||||
enabled = profile.enabled,
|
||||
name = profile.name,
|
||||
title = profile.title,
|
||||
bufferSize = profile.bufferSize,
|
||||
splitPosition = profile.splitPosition,
|
||||
splitAtSni = profile.splitAtSni,
|
||||
wrongSeq = profile.wrongSeq,
|
||||
autoTtl = profile.autoTtl,
|
||||
fakePacketsTtl = profile.fakePacketsTtl,
|
||||
windowSize = profile.windowSize,
|
||||
windowScaleFactor = profile.windowScaleFactor,
|
||||
inBuiltDNS = profile.inBuiltDNS,
|
||||
inBuiltDNSIP = profile.inBuiltDNSIP,
|
||||
inBuiltDNSPort = profile.inBuiltDNSPort,
|
||||
doh = profile.doh,
|
||||
dohServer = profile.dohServer,
|
||||
desyncAttacks = profile.desyncAttacks,
|
||||
desyncZeroAttack = profile.desyncZeroAttack?.ordinal?.let { DesyncZeroAttack.values()[it] },
|
||||
desyncFirstAttack = profile.desyncFirstAttack?.ordinal?.let { DesyncFirstAttack.values()[it] },
|
||||
default = profile.id == appPreferences.defaultProfileId
|
||||
) }
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IGetStringResourceUseCase
|
||||
|
||||
class GetStringResourceUseCase(private val context: Context): IGetStringResourceUseCase {
|
||||
override fun getString(res: Int): String = context.getString(res)
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import java.io.File
|
||||
|
||||
class LoadCustomIPsUseCase(context: Context): ILoadCustomIPsUseCase {
|
||||
|
||||
private val path = context.filesDir.absolutePath + "/${Constants.CUSTOM_IPS_FILENAME}"
|
||||
|
||||
override fun load(): List<CustomIPEntry> {
|
||||
val entryList = mutableListOf<CustomIPEntry>()
|
||||
|
||||
val file = File(path)
|
||||
if (file.exists())
|
||||
file.inputStream().bufferedReader().forEachLine { line ->
|
||||
val splitted = line.split(' ')
|
||||
entryList.add(CustomIPEntry(splitted.first(), splitted.last()))
|
||||
}
|
||||
|
||||
return entryList
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISettingsUseCase
|
||||
|
||||
class LoadProxifiedAppsUseCase(context: Context): ILoadProxifiedAppsUseCase {
|
||||
|
||||
private val packageManager = context.packageManager
|
||||
private val settingsUseCase: ISettingsUseCase = SettingsUseCase(context)
|
||||
|
||||
override fun load(): List<ProxifiedApp> {
|
||||
val installedApps = packageManager.getInstalledApplications(0)
|
||||
val proxifiedApps = settingsUseCase.getProxifiedApps()
|
||||
val list = mutableListOf<ProxifiedApp>()
|
||||
installedApps.forEach {
|
||||
list.add(
|
||||
ProxifiedApp(
|
||||
icon = it.loadIcon(packageManager),
|
||||
name = it.loadLabel(packageManager) as String,
|
||||
isProxified = false,
|
||||
uid = it.uid,
|
||||
username = packageManager.getNameForUid(it.uid)!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
list.sortWith(compareBy { it.username })
|
||||
for (proxifiedApp in proxifiedApps) {
|
||||
var left: Int
|
||||
var right: Int
|
||||
val index = list.binarySearchBy(proxifiedApp) { it.username }
|
||||
if (index >= 0) {
|
||||
val username = list[index].username
|
||||
left = index
|
||||
right = index
|
||||
while (left - 1 >= 0) {
|
||||
if (list[left - 1].username == username)
|
||||
left--
|
||||
else
|
||||
break
|
||||
}
|
||||
while (right + 1 < list.size) {
|
||||
if (list[right + 1].username == username)
|
||||
right++
|
||||
else
|
||||
break
|
||||
}
|
||||
|
||||
for(i in left..right)
|
||||
list[i].isProxified = true
|
||||
}
|
||||
}
|
||||
|
||||
list.sortWith(compareBy({ !it.isProxified }, { it.name }))
|
||||
return list.toList()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IProxyUseCase
|
||||
|
||||
class ProxyUseCase: IProxyUseCase {
|
||||
override fun set(ip: String, port: Int, proxyMode: ProxyMode, proxifiedApps: List<ProxifiedApp>) {
|
||||
when (proxyMode) {
|
||||
ProxyMode.HTTP -> {
|
||||
Shell.su("settings put global http_proxy $ip:$port").exec()
|
||||
}
|
||||
ProxyMode.TRANSPARENT -> {
|
||||
val commands = mutableListOf(CMD_IPTABLES_RETURN.format(ip), CMD_DISABLE_IPV6)
|
||||
proxifiedApps.forEach { app ->
|
||||
if (app.isProxified) {
|
||||
commands.add(CMD_IPTABLES_ADD.format(app.uid, 80, port))
|
||||
commands.add(CMD_IPTABLES_ADD.format(app.uid, 443, port))
|
||||
}
|
||||
}
|
||||
Shell.su(*commands.toTypedArray()).exec()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun unset(proxyMode: ProxyMode) {
|
||||
when (proxyMode) {
|
||||
ProxyMode.HTTP -> {
|
||||
Shell.su("settings put global http_proxy :0").exec()
|
||||
}
|
||||
ProxyMode.TRANSPARENT -> {
|
||||
Shell.su(CMD_IPTABLES_RESET, CMD_ENABLE_IPV6).exec()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CMD_IPTABLES_RETURN = "iptables -t nat -A OUTPUT -p tcp -d %s -j RETURN"
|
||||
private const val CMD_IPTABLES_ADD = "iptables -t nat -m owner --uid-owner %d -A OUTPUT -p tcp --dport %d -j DNAT --to-destination 127.0.0.1:%d"
|
||||
private const val CMD_IPTABLES_RESET = "iptables -t nat -F OUTPUT"
|
||||
// Disable IPv6 as DPITunnel don't support it
|
||||
// Without this blocked sites that supports IPv6 won't be processed in transparent mode
|
||||
private const val CMD_DISABLE_IPV6 = "ip6tables -A OUTPUT -j REJECT"
|
||||
private const val CMD_ENABLE_IPV6 = "ip6tables -D OUTPUT -j REJECT"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.IRenameProfileUseCase
|
||||
|
||||
class RenameProfileUseCase(private val context: Context): IRenameProfileUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
|
||||
override suspend fun rename(id: Long, newTitle: String) {
|
||||
profileDao.rename(id, newTitle)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import java.io.File
|
||||
|
||||
class SaveCustomIPsUseCase(context: Context): ISaveCustomIPsUseCase {
|
||||
|
||||
private val path = context.filesDir.absolutePath + "/${Constants.CUSTOM_IPS_FILENAME}"
|
||||
|
||||
override fun save(entries: List<CustomIPEntry>) {
|
||||
File(path).bufferedWriter().use { out ->
|
||||
entries.forEach { entry->
|
||||
out.write("${entry.domain} ${entry.ip}")
|
||||
out.newLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.database.AppDatabase
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveProfileUseCase
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
|
||||
class SaveProfileUseCase(private val context: Context): ISaveProfileUseCase {
|
||||
|
||||
private val profileDao = AppDatabase.getInstance(context).profileDao()
|
||||
private val appPreferences = AppPreferences.getInstance(context)
|
||||
|
||||
override suspend fun save(profile: Profile) {
|
||||
val insertedId = profileDao.insertOrUpdate(profile = com.nomoresat.dpitunnelcli.database.Profile(
|
||||
id = profile.id,
|
||||
enabled = profile.enabled,
|
||||
name = profile.name,
|
||||
title = profile.title,
|
||||
bufferSize = profile.bufferSize,
|
||||
splitPosition = profile.splitPosition,
|
||||
splitAtSni = profile.splitAtSni,
|
||||
wrongSeq = profile.wrongSeq,
|
||||
autoTtl = profile.autoTtl,
|
||||
fakePacketsTtl = profile.fakePacketsTtl,
|
||||
windowSize = profile.windowSize,
|
||||
windowScaleFactor = profile.windowScaleFactor,
|
||||
inBuiltDNS = profile.inBuiltDNS,
|
||||
inBuiltDNSIP = profile.inBuiltDNSIP,
|
||||
inBuiltDNSPort = profile.inBuiltDNSPort,
|
||||
doh = profile.doh,
|
||||
dohServer = profile.dohServer,
|
||||
desyncAttacks = profile.desyncAttacks,
|
||||
desyncZeroAttack = profile.desyncZeroAttack?.ordinal?.let { com.nomoresat.dpitunnelcli.database.DesyncZeroAttack.values()[it] },
|
||||
desyncFirstAttack = profile.desyncFirstAttack?.ordinal?.let { com.nomoresat.dpitunnelcli.database.DesyncFirstAttack.values()[it] }
|
||||
))
|
||||
if (profile.default)
|
||||
appPreferences.defaultProfileId = insertedId
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISettingsUseCase
|
||||
|
||||
class SaveProxifiedAppsUseCase(context: Context): ISaveProxifiedAppsUseCase {
|
||||
|
||||
private val settingsUseCase: ISettingsUseCase = SettingsUseCase(context)
|
||||
|
||||
override fun save(list: List<ProxifiedApp>) {
|
||||
val proxifiedApps = mutableListOf<String>()
|
||||
list.forEach {
|
||||
if (it.isProxified)
|
||||
proxifiedApps.add(it.username)
|
||||
}
|
||||
proxifiedApps.sort()
|
||||
settingsUseCase.setProxifiedApps(proxifiedApps)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.nomoresat.dpitunnelcli.data.usecases
|
||||
|
||||
import android.content.Context
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISettingsUseCase
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
|
||||
class SettingsUseCase(val context: Context): ISettingsUseCase {
|
||||
private val appPreferences = AppPreferences.getInstance(context)
|
||||
|
||||
override fun getStartOnBoot(): Boolean = appPreferences.startOnBoot
|
||||
override fun getCABundlePath() = appPreferences.caBundlePath
|
||||
override fun getProxyMode(): ProxyMode? = appPreferences.proxyMode
|
||||
override fun getProxifiedApps(): List<String> = appPreferences.proxifiedApps
|
||||
override fun setProxifiedApps(value: List<String>) {
|
||||
appPreferences.proxifiedApps = value
|
||||
}
|
||||
override fun getSystemWide(): Boolean = appPreferences.systemWide
|
||||
override fun getIP(): String? = appPreferences.ip
|
||||
override fun getPort(): Int? = appPreferences.port
|
||||
override fun getCustomIPsPath(): String? = appPreferences.customIPsPath
|
||||
override fun getDefaultProfileId(): Long? = appPreferences.defaultProfileId
|
||||
override fun setDefaultProfileId(value: Long?) {
|
||||
appPreferences.defaultProfileId = value
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.nomoresat.dpitunnelcli.database
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Database(entities = [Profile::class], version = 2)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun profileDao(): ProfileDao
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
|
||||
fun getInstance(context: Context): AppDatabase {
|
||||
val instance = INSTANCE
|
||||
if (instance != null) return instance
|
||||
synchronized(this) {
|
||||
INSTANCE = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
AppDatabase::class.java,
|
||||
"app_database"
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
prepopulateDb(getInstance(context))
|
||||
}
|
||||
})
|
||||
.build()
|
||||
INSTANCE!!.query("select 1", null)
|
||||
|
||||
return INSTANCE as AppDatabase
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepopulateDb(db: AppDatabase) = CoroutineScope(Dispatchers.IO).launch {
|
||||
db.profileDao().insertProfile(
|
||||
Profile(
|
||||
id = null,
|
||||
enabled = false,
|
||||
name = "",
|
||||
title = "Wrong SEQ universal",
|
||||
bufferSize = null,
|
||||
splitPosition = 3,
|
||||
splitAtSni = true,
|
||||
wrongSeq = true,
|
||||
autoTtl = false,
|
||||
fakePacketsTtl = null,
|
||||
windowSize = 1,
|
||||
windowScaleFactor = 6,
|
||||
inBuiltDNS = true,
|
||||
inBuiltDNSIP = "8.8.8.8",
|
||||
inBuiltDNSPort = null,
|
||||
doh = true,
|
||||
dohServer = "https://dns.google/dns-query",
|
||||
desyncAttacks = true,
|
||||
desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_FAKE,
|
||||
desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_DISORDER_FAKE
|
||||
)
|
||||
)
|
||||
db.profileDao().insertProfile(
|
||||
Profile(
|
||||
id = null,
|
||||
enabled = false,
|
||||
name = "",
|
||||
title = "Auto TTL universal",
|
||||
bufferSize = null,
|
||||
splitPosition = 3,
|
||||
splitAtSni = true,
|
||||
wrongSeq = false,
|
||||
autoTtl = true,
|
||||
fakePacketsTtl = null,
|
||||
windowSize = 1,
|
||||
windowScaleFactor = 6,
|
||||
inBuiltDNS = true,
|
||||
inBuiltDNSIP = "8.8.8.8",
|
||||
inBuiltDNSPort = null,
|
||||
doh = true,
|
||||
dohServer = "https://dns.google/dns-query",
|
||||
desyncAttacks = true,
|
||||
desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_FAKE,
|
||||
desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_DISORDER_FAKE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.nomoresat.dpitunnelcli.database
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
|
||||
class Converters {
|
||||
|
||||
@TypeConverter
|
||||
fun toDesyncZeroAttack(value: String?) = value?.let { enumValueOf<DesyncZeroAttack>(it) }
|
||||
|
||||
@TypeConverter
|
||||
fun fromDesyncZeroAttack(value: DesyncZeroAttack?) = value?.name
|
||||
|
||||
@TypeConverter
|
||||
fun toDesyncFirstAttack(value: String?) = value?.let { enumValueOf<DesyncFirstAttack>(it) }
|
||||
|
||||
@TypeConverter
|
||||
fun fromDesyncFirstAttack(value: DesyncFirstAttack?) = value?.name
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.nomoresat.dpitunnelcli.database
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
enum class DesyncZeroAttack {
|
||||
DESYNC_ZERO_FAKE,
|
||||
DESYNC_ZERO_RST,
|
||||
DESYNC_ZERO_RSTACK
|
||||
}
|
||||
|
||||
enum class DesyncFirstAttack {
|
||||
DESYNC_FIRST_DISORDER,
|
||||
DESYNC_FIRST_DISORDER_FAKE,
|
||||
DESYNC_FIRST_SPLIT,
|
||||
DESYNC_FIRST_SPLIT_FAKE
|
||||
}
|
||||
|
||||
@Entity(tableName = "profiles_table")
|
||||
data class Profile(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long?,
|
||||
@ColumnInfo(name = "enabled") var enabled: Boolean,
|
||||
@ColumnInfo(name = "name") val name: String,
|
||||
@ColumnInfo(name = "title") val title: String?,
|
||||
@ColumnInfo(name = "buffer_size") val bufferSize: Int?,
|
||||
@ColumnInfo(name = "split_position") val splitPosition: Int?,
|
||||
@ColumnInfo(name = "split_at_sni") val splitAtSni: Boolean,
|
||||
@ColumnInfo(name = "wrong_seq") val wrongSeq: Boolean,
|
||||
@ColumnInfo(name = "auto_ttl") var autoTtl: Boolean,
|
||||
@ColumnInfo(name = "fake_packets_ttl") val fakePacketsTtl: Int?,
|
||||
@ColumnInfo(name = "window_size") val windowSize: Int?,
|
||||
@ColumnInfo(name = "window_scale_factor") val windowScaleFactor: Int?,
|
||||
@ColumnInfo(name = "inbuilt_dns") val inBuiltDNS: Boolean,
|
||||
@ColumnInfo(name = "inbuilt_dns_ip") val inBuiltDNSIP: String?,
|
||||
@ColumnInfo(name = "inbuilt_dns_port") val inBuiltDNSPort: Int?,
|
||||
@ColumnInfo(name = "doh") val doh: Boolean,
|
||||
@ColumnInfo(name = "doh_server") val dohServer: String?,
|
||||
@ColumnInfo(name = "desync_attacks") val desyncAttacks: Boolean,
|
||||
@ColumnInfo(name = "desync_zero_attack") val desyncZeroAttack: DesyncZeroAttack?,
|
||||
@ColumnInfo(name = "desync_first_attack") val desyncFirstAttack: DesyncFirstAttack?
|
||||
)
|
|
@ -0,0 +1,41 @@
|
|||
package com.nomoresat.dpitunnelcli.database
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
|
||||
@Dao
|
||||
interface ProfileDao {
|
||||
@Query("SELECT * FROM profiles_table")
|
||||
suspend fun getAll(): List<Profile>
|
||||
|
||||
@Query("SELECT * FROM profiles_table")
|
||||
fun getAllLive(): LiveData<List<Profile>>
|
||||
|
||||
@Query("SELECT * FROM profiles_table WHERE id = :id")
|
||||
suspend fun findById(id: Long): Profile?
|
||||
|
||||
@Insert
|
||||
suspend fun insertProfile(profile: Profile): Long
|
||||
|
||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun update(profile: Profile)
|
||||
|
||||
@Query("UPDATE profiles_table SET title = :newTitle WHERE id = :id")
|
||||
suspend fun rename(id: Long, newTitle: String)
|
||||
|
||||
@Query("UPDATE profiles_table SET enabled = :enabled WHERE id = :id")
|
||||
suspend fun setEnable(id: Long, enabled: Boolean)
|
||||
|
||||
@Query("DELETE FROM profiles_table WHERE id = :id")
|
||||
suspend fun delete(id: Long)
|
||||
|
||||
suspend fun insertOrUpdate(profile: Profile): Long {
|
||||
val profileFromDB = profile.id?.let { findById(it) }
|
||||
return if (profileFromDB == null) {
|
||||
insertProfile(profile)
|
||||
} else {
|
||||
update(profile)
|
||||
profile.id
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
data class AutoConfigDefaults(
|
||||
val domain: String,
|
||||
val caBundlePath: String,
|
||||
val dohServer: String,
|
||||
val inBuiltDNS: String
|
||||
)
|
|
@ -0,0 +1,13 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
data class ConfiguredProfile(
|
||||
var splitAtSni: Boolean,
|
||||
var wrongSeq: Boolean,
|
||||
var autoTtl: Boolean,
|
||||
var fakePacketsTtl: Int?,
|
||||
var windowSize: Int?,
|
||||
var windowScaleFactor: Int?,
|
||||
var desyncAttacks: Boolean,
|
||||
var desyncZeroAttack: DesyncZeroAttack?,
|
||||
var desyncFirstAttack: DesyncFirstAttack?
|
||||
)
|
|
@ -0,0 +1,6 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
data class CustomIPEntry(
|
||||
var domain: String,
|
||||
var ip: String
|
||||
)
|
|
@ -0,0 +1,81 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
enum class DesyncZeroAttack {
|
||||
DESYNC_ZERO_FAKE,
|
||||
DESYNC_ZERO_RST,
|
||||
DESYNC_ZERO_RSTACK
|
||||
}
|
||||
|
||||
enum class DesyncFirstAttack {
|
||||
DESYNC_FIRST_DISORDER,
|
||||
DESYNC_FIRST_DISORDER_FAKE,
|
||||
DESYNC_FIRST_SPLIT,
|
||||
DESYNC_FIRST_SPLIT_FAKE
|
||||
}
|
||||
|
||||
data class Profile(
|
||||
var id: Long?,
|
||||
var enabled: Boolean,
|
||||
var name: String,
|
||||
var title: String?,
|
||||
var bufferSize: Int?,
|
||||
var splitPosition: Int?,
|
||||
var splitAtSni: Boolean,
|
||||
var wrongSeq: Boolean,
|
||||
var autoTtl: Boolean,
|
||||
var fakePacketsTtl: Int?,
|
||||
var windowSize: Int?,
|
||||
var windowScaleFactor: Int?,
|
||||
var inBuiltDNS: Boolean,
|
||||
var inBuiltDNSIP: String?,
|
||||
var inBuiltDNSPort: Int?,
|
||||
var doh: Boolean,
|
||||
var dohServer: String?,
|
||||
var desyncAttacks: Boolean,
|
||||
var desyncZeroAttack: DesyncZeroAttack?,
|
||||
var desyncFirstAttack: DesyncFirstAttack?,
|
||||
var default: Boolean = false
|
||||
) {
|
||||
override fun toString(): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
if (default)
|
||||
stringBuilder.append("--profile default")
|
||||
else
|
||||
stringBuilder.append("--profile \"$name\"")
|
||||
bufferSize?.let { stringBuilder.append(" --buffer-size \"$it\"") }
|
||||
splitPosition?.let { stringBuilder.append(" --split-position \"$it\"") }
|
||||
if (wrongSeq)
|
||||
stringBuilder.append(" --wrong-seq")
|
||||
if (autoTtl)
|
||||
stringBuilder.append(" --auto-ttl \"1-4-10\"")
|
||||
fakePacketsTtl?.let { stringBuilder.append(" --ttl \"$it\"") }
|
||||
windowSize?.let { stringBuilder.append(" --wsize \"$it\"") }
|
||||
windowScaleFactor?.let { stringBuilder.append(" --wsfactor \"$it\"") }
|
||||
if (inBuiltDNS)
|
||||
stringBuilder.append(" --builtin-dns")
|
||||
inBuiltDNSIP?.let { stringBuilder.append(" --builtin-dns-ip \"$it\"") }
|
||||
inBuiltDNSPort?.let { stringBuilder.append(" --builtin-dns-port \"$it\"") }
|
||||
if (doh)
|
||||
stringBuilder.append(" --doh")
|
||||
dohServer?.let { stringBuilder.append(" --doh-server \"$it\"") }
|
||||
if(splitAtSni)
|
||||
stringBuilder.append(" --split-at-sni")
|
||||
if(desyncAttacks) {
|
||||
stringBuilder.append(" --desync-attacks ${desyncZeroAttack?.enumToString() ?: ""}")
|
||||
desyncFirstAttack?.let {
|
||||
if (desyncZeroAttack != null) stringBuilder.append(',')
|
||||
stringBuilder.append(it.enumToString())
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
private fun DesyncZeroAttack.enumToString() = zeroEnumNames[ordinal]
|
||||
|
||||
private fun DesyncFirstAttack.enumToString() = firstEnumNames[ordinal]
|
||||
|
||||
companion object {
|
||||
private val zeroEnumNames = listOf("fake", "rst", "rstack")
|
||||
private val firstEnumNames = listOf("disorder", "disorder_fake", "split", "split_fake")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class ProxifiedApp(
|
||||
val icon: Drawable,
|
||||
val name: String,
|
||||
var isProxified: Boolean,
|
||||
val uid: Int,
|
||||
val username: String
|
||||
)
|
|
@ -0,0 +1,6 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.entities
|
||||
|
||||
enum class ProxyMode {
|
||||
HTTP,
|
||||
TRANSPARENT
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
|
||||
interface IAutoConfigUseCase {
|
||||
val inputFlow: SharedFlow<String>
|
||||
fun run(externalScope: CoroutineScope, cmd: List<String>,
|
||||
exceptionCallBack: (Throwable) -> Unit)
|
||||
fun input(input: String)
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import com.nomoresat.dpitunnelcli.cli.CliDaemon
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
|
||||
interface IDaemonUseCase {
|
||||
val daemonState: StateFlow<DaemonState>
|
||||
fun check()
|
||||
fun start(persistentOptions: CliDaemon.PersistentOptions, profiles: List<Profile>)
|
||||
fun stop()
|
||||
}
|
||||
|
||||
sealed class DaemonState {
|
||||
object Running: DaemonState()
|
||||
object Stopped: DaemonState()
|
||||
object Loading: DaemonState()
|
||||
class Error(exitCode: Int): DaemonState()
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
interface IDeleteProfileUseCase {
|
||||
suspend fun delete(id: Long)
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
interface IEnableDisableProfileUseCase {
|
||||
suspend fun enable(id: Long)
|
||||
suspend fun disable(id: Long)
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
|
||||
interface IFetchAllProfilesUseCase {
|
||||
suspend fun fetch(): List<Profile>
|
||||
fun fetchLive(): LiveData<List<Profile>>
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import android.content.Context
|
||||
|
||||
interface IFetchDefaultIfaceWifiAPUseCase {
|
||||
suspend fun fetch(context: Context): Pair<String?, String?>
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
|
||||
interface IFetchProfileUseCase {
|
||||
suspend fun fetch(id: Long): Profile?
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
interface IGetStringResourceUseCase {
|
||||
fun getString(res: Int): String
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
|
||||
interface ILoadCustomIPsUseCase {
|
||||
fun load(): List<CustomIPEntry>
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
|
||||
interface ILoadProxifiedAppsUseCase {
|
||||
fun load(): List<ProxifiedApp>
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
|
||||
interface IProxyUseCase {
|
||||
fun set(ip: String, port: Int, proxyMode: ProxyMode, proxifiedApps: List<ProxifiedApp>)
|
||||
fun unset(proxyMode: ProxyMode)
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
interface IRenameProfileUseCase {
|
||||
suspend fun rename(id: Long, newTitle: String)
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
|
||||
interface ISaveCustomIPsUseCase {
|
||||
fun save(entries: List<CustomIPEntry>)
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
|
||||
interface ISaveProfileUseCase {
|
||||
suspend fun save(profile: Profile)
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
|
||||
interface ISaveProxifiedAppsUseCase {
|
||||
fun save(list: List<ProxifiedApp>)
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.nomoresat.dpitunnelcli.domain.usecases
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
|
||||
interface ISettingsUseCase {
|
||||
fun getStartOnBoot(): Boolean
|
||||
fun getCABundlePath(): String?
|
||||
fun getProxyMode(): ProxyMode?
|
||||
fun getProxifiedApps(): List<String>
|
||||
fun setProxifiedApps(value: List<String>)
|
||||
fun getSystemWide(): Boolean
|
||||
fun getIP(): String?
|
||||
fun getPort(): Int?
|
||||
fun getCustomIPsPath(): String?
|
||||
fun getDefaultProfileId(): Long?
|
||||
fun setDefaultProfileId(value: Long?)
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.nomoresat.dpitunnelcli.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import java.io.File
|
||||
|
||||
class AppPreferences private constructor() {
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
private lateinit var customIPsFilePath: String
|
||||
|
||||
val startOnBoot: Boolean
|
||||
get() = sharedPreferences.getBoolean(START_ON_BOOT_PROPERTY_NAME, false)
|
||||
|
||||
var caBundlePath: String?
|
||||
set(value) {
|
||||
with(sharedPreferences.edit()){
|
||||
putString(CA_BUNDLE_PROPERTY_NAME, value)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
get() = sharedPreferences.getString(CA_BUNDLE_PROPERTY_NAME, "")?.ifEmpty { null }
|
||||
|
||||
val proxyMode: ProxyMode?
|
||||
get() = sharedPreferences.getString(PROXY_MODE_PROPERTY_NAME, "")?.ifEmpty { null }?.let { mode->
|
||||
when(mode) {
|
||||
"http" -> ProxyMode.HTTP
|
||||
"transparent" -> ProxyMode.TRANSPARENT
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
var proxifiedApps: List<String>
|
||||
set(value) {
|
||||
value.let { list ->
|
||||
val usernames = StringBuffer()
|
||||
list.forEach {
|
||||
usernames.append("$it|")
|
||||
}
|
||||
usernames.removeSuffix("|")
|
||||
|
||||
with(sharedPreferences.edit()){
|
||||
putString(PROXIFIED_APPS_PROPERTY_NAME, usernames.toString())
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
get() = sharedPreferences.getString(PROXIFIED_APPS_PROPERTY_NAME, "")?.ifEmpty { null }
|
||||
?.split('|') ?: listOf()
|
||||
|
||||
val systemWide: Boolean
|
||||
get() = sharedPreferences.getBoolean(SYSTEM_WIDE_PROXY_PROPERTY_NAME, false)
|
||||
|
||||
val ip: String?
|
||||
get() = sharedPreferences.getString(IP_PROPERTY_NAME, "")?.ifEmpty { null }
|
||||
|
||||
val port: Int?
|
||||
get() = sharedPreferences.getString(PORT_PROPERTY_NAME, "")?.ifEmpty { null }?.toIntOrNull()
|
||||
|
||||
val customIPsPath: String?
|
||||
get() = File(customIPsFilePath).let {
|
||||
if (it.exists())
|
||||
customIPsFilePath
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
val firstRun: Boolean
|
||||
get() {
|
||||
val first = sharedPreferences.getBoolean(FIRST_RUN_PROPERTY_NAME, true)
|
||||
if (first) with(sharedPreferences.edit()){
|
||||
putBoolean(FIRST_RUN_PROPERTY_NAME, false)
|
||||
apply()
|
||||
}
|
||||
return first
|
||||
}
|
||||
|
||||
var defaultProfileId: Long?
|
||||
set(value) {
|
||||
with(sharedPreferences.edit()){
|
||||
putLong(DEFAULT_PROFILE_ID_PROPERTY_NAME, value ?: 0L)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
get() = sharedPreferences.getLong(DEFAULT_PROFILE_ID_PROPERTY_NAME, 0L).let { if (it == 0L) null else it }
|
||||
|
||||
companion object {
|
||||
const val SETTINGS_STORAGE_NAME = "PERSISTENT_SETTINGS"
|
||||
private const val START_ON_BOOT_PROPERTY_NAME = "preference_start_on_boot"
|
||||
private const val CA_BUNDLE_PROPERTY_NAME = "preference_ca_bundle_path"
|
||||
private const val PROXY_MODE_PROPERTY_NAME = "preference_proxy_mode"
|
||||
private const val PROXIFIED_APPS_PROPERTY_NAME = "preference_proxified_apps"
|
||||
private const val SYSTEM_WIDE_PROXY_PROPERTY_NAME = "preference_proxy_system_wide"
|
||||
private const val IP_PROPERTY_NAME = "preference_proxy_ip"
|
||||
private const val PORT_PROPERTY_NAME = "preference_proxy_port"
|
||||
private const val FIRST_RUN_PROPERTY_NAME = "first_run"
|
||||
private const val DEFAULT_PROFILE_ID_PROPERTY_NAME = "default_profile_id"
|
||||
|
||||
fun setDefaults(context: Context) {
|
||||
PreferenceManager.setDefaultValues(context, SETTINGS_STORAGE_NAME, Context.MODE_PRIVATE, R.xml.root_preferences, false)
|
||||
}
|
||||
|
||||
fun getInstance(context: Context): AppPreferences {
|
||||
val instance = AppPreferences()
|
||||
instance.sharedPreferences = context.getSharedPreferences(SETTINGS_STORAGE_NAME, Context.MODE_PRIVATE)
|
||||
instance.customIPsFilePath = context.filesDir.absolutePath + "/${Constants.CUSTOM_IPS_FILENAME}"
|
||||
return instance
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.nomoresat.dpitunnelcli.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import com.nomoresat.dpitunnelcli.cli.CliDaemon
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.DaemonState
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import com.nomoresat.dpitunnelcli.utils.goAsync
|
||||
|
||||
class BootReceiver: BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
context?.let {
|
||||
goAsync(GlobalScope, Dispatchers.IO) {
|
||||
val daemonUseCase = DaemonUseCase(context.applicationInfo.nativeLibraryDir + '/' + Constants.DPITUNNEL_BINARY_NAME,
|
||||
Constants.DPITUNNEL_DAEMON_PID_FILE)
|
||||
val fetchAllProfilesUseCase = FetchAllProfilesUseCase(context)
|
||||
val settingsUseCase = SettingsUseCase(context)
|
||||
val proxyUseCase = ProxyUseCase()
|
||||
val loadProxifiedAppsUseCase = LoadProxifiedAppsUseCase(context)
|
||||
if (settingsUseCase.getStartOnBoot()) {
|
||||
daemonUseCase.start(
|
||||
CliDaemon.PersistentOptions(
|
||||
caBundlePath = settingsUseCase.getCABundlePath()!!,
|
||||
ip = settingsUseCase.getIP(),
|
||||
port = settingsUseCase.getPort(),
|
||||
customIPsPath = settingsUseCase.getCustomIPsPath(),
|
||||
proxyMode = settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE
|
||||
),
|
||||
fetchAllProfilesUseCase.fetch()
|
||||
)
|
||||
// Check is daemon started
|
||||
var isStarted = false
|
||||
withTimeoutOrNull(2000) {
|
||||
while (true) {
|
||||
daemonUseCase.check()
|
||||
if (daemonUseCase.daemonState.value == DaemonState.Running) {
|
||||
isStarted = true
|
||||
break
|
||||
}
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
if (settingsUseCase.getSystemWide()) {
|
||||
if (isStarted)
|
||||
proxyUseCase.set("127.0.0.1", settingsUseCase.getPort() ?: Constants.DPITUNNEL_DEFAULT_PORT,
|
||||
settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE,
|
||||
loadProxifiedAppsUseCase.load())
|
||||
else
|
||||
proxyUseCase.unset(settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package com.nomoresat.dpitunnelcli.service
|
||||
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
import androidx.annotation.RequiresApi
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.cli.CliDaemon
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
class SwitchTileService: TileService() {
|
||||
|
||||
private var lastDaemonState: DaemonState? = null
|
||||
private var coroutineScope: CoroutineScope? = null
|
||||
private lateinit var fetchAllProfilesUseCase: IFetchAllProfilesUseCase
|
||||
private lateinit var settingsUseCase: ISettingsUseCase
|
||||
private lateinit var daemonUseCase: IDaemonUseCase
|
||||
private lateinit var proxyUseCase: IProxyUseCase
|
||||
private lateinit var loadProxifiedAppsUseCase: ILoadProxifiedAppsUseCase
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
fetchAllProfilesUseCase = FetchAllProfilesUseCase(this)
|
||||
settingsUseCase = SettingsUseCase(this)
|
||||
daemonUseCase = DaemonUseCase(
|
||||
execPath = this.applicationInfo.nativeLibraryDir + '/' + Constants.DPITUNNEL_BINARY_NAME,
|
||||
pidFilePath = Constants.DPITUNNEL_DAEMON_PID_FILE)
|
||||
proxyUseCase = ProxyUseCase()
|
||||
loadProxifiedAppsUseCase = LoadProxifiedAppsUseCase(this)
|
||||
}
|
||||
|
||||
override fun onStartListening() {
|
||||
super.onStartListening()
|
||||
coroutineScope?.cancel()
|
||||
coroutineScope = CoroutineScope(Job() + Dispatchers.Main.immediate).apply {
|
||||
launch(CoroutineName("SwitchTileService.DaemonStateFlow")) {
|
||||
daemonUseCase.daemonState.collect { state ->
|
||||
when(state) {
|
||||
is DaemonState.Loading -> {}
|
||||
is DaemonState.Running -> {
|
||||
if (lastDaemonState is DaemonState.Stopped || lastDaemonState is DaemonState.Error)
|
||||
if (settingsUseCase.getSystemWide())
|
||||
proxyUseCase.set("127.0.0.1", settingsUseCase.getPort() ?: Constants.DPITUNNEL_DEFAULT_PORT,
|
||||
settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE,
|
||||
loadProxifiedAppsUseCase.load())
|
||||
}
|
||||
is DaemonState.Stopped -> {
|
||||
if (lastDaemonState is DaemonState.Running)
|
||||
if (settingsUseCase.getSystemWide())
|
||||
proxyUseCase.unset(settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE)
|
||||
}
|
||||
is DaemonState.Error -> {}
|
||||
}
|
||||
lastDaemonState = state
|
||||
updateTile()
|
||||
}
|
||||
}
|
||||
launch(CoroutineName("SwitchTileService.DaemonStateCheck")) {
|
||||
while (true) {
|
||||
daemonUseCase.check()
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
daemonUseCase.check()
|
||||
updateTile()
|
||||
}
|
||||
|
||||
override fun onStopListening() {
|
||||
super.onStopListening()
|
||||
coroutineScope?.cancel()
|
||||
coroutineScope = null
|
||||
updateTile()
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
super.onClick()
|
||||
coroutineScope?.launch(Job() + Dispatchers.Main.immediate) {
|
||||
when(daemonUseCase.daemonState.value) {
|
||||
is DaemonState.Running -> daemonUseCase.stop()
|
||||
is DaemonState.Stopped -> fetchAllProfilesUseCase.fetch().let {
|
||||
if (it.isNotEmpty())
|
||||
daemonUseCase.start(
|
||||
CliDaemon.PersistentOptions(
|
||||
caBundlePath = settingsUseCase.getCABundlePath()!!,
|
||||
ip = settingsUseCase.getIP(),
|
||||
port = settingsUseCase.getPort(),
|
||||
customIPsPath = settingsUseCase.getCustomIPsPath(),
|
||||
proxyMode = settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE
|
||||
),
|
||||
it
|
||||
)
|
||||
}
|
||||
is DaemonState.Error -> {}
|
||||
is DaemonState.Loading -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTile() {
|
||||
qsTile.icon = Icon.createWithResource(this@SwitchTileService, R.drawable.ic_quick_tile)
|
||||
qsTile.label = getString(R.string.tile_enable_disable)
|
||||
qsTile.state = when (daemonUseCase.daemonState.value) {
|
||||
is DaemonState.Loading -> { qsTile.state }
|
||||
is DaemonState.Running -> { Tile.STATE_ACTIVE }
|
||||
is DaemonState.Stopped -> { Tile.STATE_INACTIVE }
|
||||
is DaemonState.Error -> { Tile.STATE_INACTIVE }
|
||||
}
|
||||
qsTile.updateTile()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.databinding.ActivityMainBinding
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import java.io.*
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
init {
|
||||
Shell.setDefaultBuilder(Shell.Builder.create()
|
||||
.setFlags(Shell.FLAG_REDIRECT_STDERR)
|
||||
.setTimeout(10)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
Shell.getShell { shell ->
|
||||
if (!shell.isRoot) {
|
||||
Toast.makeText(this, R.string.no_root_failed, Toast.LENGTH_LONG).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
AppPreferences.setDefaults(this)
|
||||
val appPreferences = AppPreferences.getInstance(this)
|
||||
if (appPreferences.firstRun) {
|
||||
extractAssets()
|
||||
appPreferences.caBundlePath = filesDir.absolutePath + "/${Constants.INBUILT_CA_BUNDLE_FILE_NAME}"
|
||||
}
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.mainToolbar)
|
||||
|
||||
val navView: BottomNavigationView = binding.navView
|
||||
|
||||
val navController = findNavController(R.id.nav_host_fragment_activity_main)
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
val appBarConfiguration = AppBarConfiguration(setOf(
|
||||
R.id.navigation_dashboard, R.id.navigation_profiles
|
||||
))
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
}
|
||||
|
||||
private fun extractAssets() {
|
||||
extractFileFromAssets("ca.bundle")
|
||||
}
|
||||
|
||||
private fun extractFileFromAssets(filename: String) {
|
||||
try {
|
||||
val input = assets.open(filename)
|
||||
val outFile = File(filesDir, filename)
|
||||
val out = FileOutputStream(outFile)
|
||||
copyFile(input, out)
|
||||
input.close()
|
||||
out.flush()
|
||||
out.close()
|
||||
} catch (e: IOException) {
|
||||
Log.e("tag", "Failed to copy asset file: $filename", e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun copyFile(input: InputStream, out: OutputStream) {
|
||||
val buffer = ByteArray(1024)
|
||||
var read: Int
|
||||
while (input.read(buffer).also { read = it } != -1) {
|
||||
out.write(buffer, 0, read)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.customIPs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.Menu
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.LoadCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.SaveCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.databinding.ActivityCustomIpsBinding
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
import com.nomoresat.dpitunnelcli.utils.Utils
|
||||
class CustomIPsActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityCustomIpsBinding
|
||||
|
||||
private val customIPsViewModel by viewModels<CustomIPsViewModel> {
|
||||
CustomIPsViewModelFactory(
|
||||
loadCustomIPsUseCase = LoadCustomIPsUseCase(this),
|
||||
saveCustomIPsUseCase = SaveCustomIPsUseCase(this)
|
||||
)
|
||||
}
|
||||
|
||||
private val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
result?.data?.data?.also { uri ->
|
||||
this.contentResolver.openInputStream(uri)?.let {
|
||||
customIPsViewModel.import(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (customIPsViewModel.isModified) {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(R.string.title_confirmation_custom_ips_dialog)
|
||||
.setMessage(R.string.message_confirmation_custom_ips_dialog)
|
||||
.setPositiveButton(R.string.save_confirmation_custom_ips_dialog) { _, _ ->
|
||||
customIPsViewModel.saveUnsaved()
|
||||
}
|
||||
.setNegativeButton(R.string.discard_confirmation_custom_ips_dialog) { _, _ ->
|
||||
customIPsViewModel.discardUnsaved()
|
||||
}
|
||||
.setNeutralButton(R.string.cancel_confirmation_custom_ips_dialog, null)
|
||||
.create()
|
||||
dialog.show()
|
||||
} else
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityCustomIpsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.customIpsToolbar)
|
||||
binding.customIpsToolbar.setOnMenuItemClickListener {
|
||||
when(it.itemId) {
|
||||
R.id.custom_ips_toolbar_menu_save -> {
|
||||
customIPsViewModel.saveUnsaved()
|
||||
true
|
||||
}
|
||||
R.id.custom_ips_toolbar_menu_import -> {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "*/*"
|
||||
resultLauncher.launch(intent)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
customIPsViewModel.uiState.observe(this) { state ->
|
||||
when (state) {
|
||||
is CustomIPsViewModel.UIState.Normal -> {}
|
||||
is CustomIPsViewModel.UIState.Error -> {}
|
||||
is CustomIPsViewModel.UIState.Finish -> returnResult()
|
||||
}
|
||||
}
|
||||
|
||||
binding.customIpsRecycler.adapter = CustomIPsAdapter(
|
||||
entryEditListener = { position, entry ->
|
||||
editEntryDialog(position, entry)
|
||||
},
|
||||
entryDeleteListener = { position, entry ->
|
||||
customIPsViewModel.deleteEntry(position)
|
||||
}
|
||||
)
|
||||
|
||||
binding.customIpsRecycler.layoutManager = LinearLayoutManager(
|
||||
this,
|
||||
LinearLayoutManager.VERTICAL, false
|
||||
)
|
||||
|
||||
binding.customIpsFab.setOnClickListener {
|
||||
editEntryDialog(null, CustomIPEntry("", ""))
|
||||
}
|
||||
|
||||
customIPsViewModel.entries.observe(this) {
|
||||
(binding.customIpsRecycler.adapter as CustomIPsAdapter).bindEntries(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun editEntryDialog(position: Int? = null, entry: CustomIPEntry) {
|
||||
editDomainDialog(position, entry)
|
||||
}
|
||||
|
||||
private fun editDomainDialog(position: Int? = null, entry: CustomIPEntry) {
|
||||
val inputEditTextField = EditText(this)
|
||||
inputEditTextField.setText(entry.domain)
|
||||
inputEditTextField.maxLines = 1
|
||||
inputEditTextField.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.dialog_custom_ip_edit_domain_title))
|
||||
.setView(inputEditTextField)
|
||||
.setPositiveButton(getString(R.string.dialog_custom_ip_edit_domain_positive)) { _, _ ->
|
||||
entry.domain = inputEditTextField.text.toString()
|
||||
|
||||
if (entry.domain.isBlank()) {
|
||||
Toast.makeText(this, getString(R.string.dialog_custom_ip_edit_domain_invalid_domain), Toast.LENGTH_SHORT).show()
|
||||
return@setPositiveButton
|
||||
}
|
||||
|
||||
editIpDialog(position, entry)
|
||||
}
|
||||
.setNegativeButton(getString(R.string.dialog_custom_ip_edit_domain_negative), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun editIpDialog(position: Int? = null, entry: CustomIPEntry) {
|
||||
val inputEditTextField = EditText(this)
|
||||
inputEditTextField.setText(entry.ip)
|
||||
inputEditTextField.maxLines = 1
|
||||
inputEditTextField.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.dialog_custom_ip_edit_ip_title))
|
||||
.setView(inputEditTextField)
|
||||
.setPositiveButton(getString(R.string.dialog_custom_ip_edit_ip_positive)) { _, _ ->
|
||||
entry.ip = inputEditTextField.text.toString()
|
||||
|
||||
val isValid = Utils.validateIp(entry.ip)
|
||||
if (!isValid) {
|
||||
Toast.makeText(this, getString(R.string.dialog_custom_ip_edit_ip_invalid_ip), Toast.LENGTH_SHORT).show()
|
||||
return@setPositiveButton
|
||||
}
|
||||
|
||||
if (position == null)
|
||||
customIPsViewModel.addEntry(entry)
|
||||
else
|
||||
customIPsViewModel.editEntry(position, entry)
|
||||
}
|
||||
.setNegativeButton(getString(R.string.dialog_custom_ip_edit_ip_negative), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun returnResult() {
|
||||
val returnIntent = Intent()
|
||||
setResult(RESULT_OK, returnIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.custom_ips_toolbar_menu, menu)
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.customIPs
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
|
||||
class CustomIPsAdapter(val entryEditListener: (Int, CustomIPEntry) -> Unit,
|
||||
val entryDeleteListener: (Int, CustomIPEntry) -> Unit): RecyclerView.Adapter<CustomIPsViewHolder>() {
|
||||
|
||||
private var entries = listOf<CustomIPEntry>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomIPsViewHolder {
|
||||
return CustomIPsViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.view_holder_custom_ip_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CustomIPsViewHolder, position: Int) {
|
||||
holder.onBind(position, entries[position], entryEditListener, entryDeleteListener)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = entries.size
|
||||
|
||||
fun bindEntries(newEntries: List<CustomIPEntry>?) {
|
||||
newEntries?.let {
|
||||
entries = it
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CustomIPsViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
val domain: TextView = itemView.findViewById(R.id.view_holder_custom_ip_domain)
|
||||
val ip: TextView = itemView.findViewById(R.id.view_holder_custom_ip_ip)
|
||||
val edit: MaterialButton = itemView.findViewById(R.id.view_holder_custom_ip_edit)
|
||||
val delete: MaterialButton = itemView.findViewById(R.id.view_holder_custom_ip_delete)
|
||||
|
||||
fun onBind(entryPosition: Int,
|
||||
entry: CustomIPEntry,
|
||||
entryEditListener: (Int, CustomIPEntry) -> Unit,
|
||||
entryDeleteListener: (Int, CustomIPEntry) -> Unit) {
|
||||
domain.text = entry.domain
|
||||
|
||||
ip.text = entry.ip
|
||||
|
||||
edit.setOnClickListener {
|
||||
entryEditListener(entryPosition, entry)
|
||||
}
|
||||
|
||||
delete.setOnClickListener{
|
||||
entryDeleteListener(entryPosition, entry)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.customIPs
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.CustomIPEntry
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveCustomIPsUseCase
|
||||
import java.io.InputStream
|
||||
|
||||
class CustomIPsViewModel(val loadCustomIPsUseCase: ILoadCustomIPsUseCase,
|
||||
val saveCustomIPsUseCase: ISaveCustomIPsUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private var _entriesList: MutableList<CustomIPEntry>
|
||||
|
||||
private val _entries = MutableLiveData<List<CustomIPEntry>>()
|
||||
val entries: LiveData<List<CustomIPEntry>> = _entries
|
||||
|
||||
private val _uiState = MutableLiveData<UIState>()
|
||||
val uiState: LiveData<UIState> get() = _uiState
|
||||
|
||||
var isModified: Boolean = false
|
||||
private set(newValue: Boolean) {
|
||||
field = newValue
|
||||
}
|
||||
|
||||
init {
|
||||
_entriesList = loadCustomIPsUseCase.load().toMutableList()
|
||||
_entries.postValue(_entriesList)
|
||||
}
|
||||
|
||||
fun import(stream: InputStream) {
|
||||
val entryList = mutableListOf<CustomIPEntry>()
|
||||
stream.bufferedReader().forEachLine { line ->
|
||||
val splitted = line.split(' ')
|
||||
entryList.add(CustomIPEntry(splitted.first(), splitted.last()))
|
||||
}
|
||||
_entriesList = entryList
|
||||
isModified = true
|
||||
_entries.postValue(_entriesList)
|
||||
}
|
||||
|
||||
fun addEntry(entry: CustomIPEntry) {
|
||||
_entriesList.add(entry)
|
||||
isModified = true
|
||||
_entries.postValue(_entriesList)
|
||||
}
|
||||
|
||||
fun deleteEntry(position: Int) {
|
||||
_entriesList.removeAt(position)
|
||||
isModified = true
|
||||
_entries.postValue(_entriesList)
|
||||
}
|
||||
|
||||
fun editEntry(position: Int, newValue: CustomIPEntry) {
|
||||
_entriesList[position] = newValue
|
||||
isModified = true
|
||||
_entries.postValue(_entriesList)
|
||||
}
|
||||
|
||||
fun save() {
|
||||
saveCustomIPsUseCase.save(_entriesList)
|
||||
}
|
||||
|
||||
fun saveUnsaved() {
|
||||
save()
|
||||
_uiState.value = UIState.Finish
|
||||
}
|
||||
|
||||
fun discardUnsaved() {
|
||||
_uiState.value = UIState.Finish
|
||||
}
|
||||
|
||||
enum class UIErrorType {
|
||||
}
|
||||
|
||||
sealed class UIState {
|
||||
object Normal: UIState()
|
||||
data class Error(val error: UIErrorType, val errorString: String? = null): UIState()
|
||||
object Finish: UIState()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.customIPs
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadCustomIPsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveCustomIPsUseCase
|
||||
|
||||
class CustomIPsViewModelFactory(val loadCustomIPsUseCase: ILoadCustomIPsUseCase,
|
||||
val saveCustomIPsUseCase: ISaveCustomIPsUseCase
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.getConstructor(ILoadCustomIPsUseCase::class.java,
|
||||
ISaveCustomIPsUseCase::class.java)
|
||||
.newInstance(loadCustomIPsUseCase, saveCustomIPsUseCase)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,404 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.editProfile
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.LocationManager
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.text.InputType
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.databinding.ActivityEditProfileBinding
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import com.nomoresat.dpitunnelcli.utils.MinMaxFilter
|
||||
import com.nomoresat.dpitunnelcli.utils.scrollToBottom
|
||||
|
||||
|
||||
class EditProfileActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityEditProfileBinding
|
||||
|
||||
private val requestLocationPermission =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
||||
var granted = true
|
||||
permissions.forEach {
|
||||
if(!it.value) granted = false
|
||||
}
|
||||
if (granted) {
|
||||
if (checkLocationEnabled())
|
||||
editProfilesViewModel.getDefaultIfaceWifiAP(applicationContext)
|
||||
} else {
|
||||
Toast.makeText(this, R.string.location_permission_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
private val editProfilesViewModel by viewModels<EditProfileViewModel> {
|
||||
EditProfileViewModelFactory(
|
||||
getDefaultIfaceUseCase = FetchDefaultIfaceWifiAPUseCase(),
|
||||
autoConfigUseCase = AutoConfigUseCase(),
|
||||
settingsUseCase = SettingsUseCase(applicationContext),
|
||||
saveProfileUseCase = SaveProfileUseCase(applicationContext),
|
||||
fetchProfileUseCase = FetchProfileUseCase(applicationContext)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (editProfilesViewModel.isModified) {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(R.string.title_confirmation_edit_profile_dialog)
|
||||
.setMessage(R.string.message_confirmation_edit_profile_dialog)
|
||||
.setPositiveButton(R.string.save_confirmation_edit_profile_dialog) { _, _ ->
|
||||
editProfilesViewModel.saveUnsaved()
|
||||
}
|
||||
.setNegativeButton(R.string.discard_confirmation_edit_profile_dialog) { _, _ ->
|
||||
editProfilesViewModel.discardUnsaved()
|
||||
}
|
||||
.setNeutralButton(R.string.cancel_confirmation_edit_profile_dialog, null)
|
||||
.create()
|
||||
dialog.show()
|
||||
} else
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityEditProfileBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.editProfileToolbar)
|
||||
binding.editProfileToolbar.setOnMenuItemClickListener {
|
||||
when(it.itemId) {
|
||||
R.id.edit_profile_toolbar_menu_rename -> {
|
||||
val inputEditTextField = EditText(this)
|
||||
inputEditTextField.setText(editProfilesViewModel.title)
|
||||
inputEditTextField.maxLines = 1
|
||||
inputEditTextField.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.dialog_profile_rename_title))
|
||||
.setView(inputEditTextField)
|
||||
.setPositiveButton(getString(R.string.dialog_profile_rename_positive)) { _, _ ->
|
||||
editProfilesViewModel.title = inputEditTextField.text.toString()
|
||||
}
|
||||
.setNegativeButton(getString(R.string.dialog_profile_rename_negative), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
editProfilesViewModel.uiState.observe(this) { state ->
|
||||
when(state) {
|
||||
is EditProfileViewModel.UIState.Normal -> {}
|
||||
is EditProfileViewModel.UIState.Error -> {
|
||||
when(state.error) {
|
||||
EditProfileViewModel.UIErrorType.ERROR_INVALID_PROFILE_ID -> {
|
||||
Toast.makeText(this, R.string.invalid_profile_id_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
is EditProfileViewModel.UIState.Finish -> returnResult()
|
||||
}
|
||||
}
|
||||
|
||||
val fabSave = binding.editProfileFab
|
||||
fabSave.setOnClickListener {
|
||||
editProfilesViewModel.save()
|
||||
}
|
||||
|
||||
val butSetProfileFromCurrentSettings = binding.editProfileProfileIdButton
|
||||
|
||||
butSetProfileFromCurrentSettings.setOnClickListener {
|
||||
checkLocationPermissions()
|
||||
}
|
||||
|
||||
val checkboxDefault = binding.editProfileProfileIdDefault
|
||||
checkboxDefault.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.default = isChecked
|
||||
}
|
||||
|
||||
val textviewProfileIdDesc = binding.editProfileProfileIdDesc
|
||||
val edittextProfileId = binding.editProfileProfileIdEdit
|
||||
edittextProfileId.doAfterTextChanged {
|
||||
editProfilesViewModel.profileId = it.toString()
|
||||
}
|
||||
|
||||
val spinnerZeroLevel = binding.editProfileDesyncAttacksZeroLevel
|
||||
ArrayAdapter.createFromResource(
|
||||
this,
|
||||
R.array.zero_attacks,
|
||||
android.R.layout.simple_spinner_item
|
||||
).also { adapter ->
|
||||
// Specify the layout to use when the list of choices appears
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
// Apply the adapter to the spinner
|
||||
spinnerZeroLevel.adapter = adapter
|
||||
}
|
||||
spinnerZeroLevel.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, pos: Int, id: Long) {
|
||||
editProfilesViewModel.zeroAttack = pos
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val spinnerFirstLevel = binding.editProfileDesyncAttacksFirstLevel
|
||||
ArrayAdapter.createFromResource(
|
||||
this,
|
||||
R.array.first_attacks,
|
||||
android.R.layout.simple_spinner_item
|
||||
).also { adapter ->
|
||||
// Specify the layout to use when the list of choices appears
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
// Apply the adapter to the spinner
|
||||
spinnerFirstLevel.adapter = adapter
|
||||
}
|
||||
spinnerFirstLevel.onItemSelectedListener = object : AdapterView.OnItemSelectedListener{
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, pos: Int, id: Long) {
|
||||
editProfilesViewModel.firstAttack = pos
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val switchAutoTtl = binding.editProfileDesyncAttacksAutoTtl
|
||||
|
||||
val edittextTtl = binding.editProfileDesyncAttacksTtl
|
||||
edittextTtl.filters = arrayOf(MinMaxFilter(Constants.TTL_VALUE_RANGE))
|
||||
edittextTtl.doAfterTextChanged {
|
||||
editProfilesViewModel.ttl = it.toString()
|
||||
}
|
||||
switchAutoTtl.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.autoTtl = isChecked
|
||||
edittextTtl.isEnabled = !isChecked
|
||||
}
|
||||
|
||||
val switchWrongSeq = binding.editProfileDesyncAttacksWrongSeq
|
||||
switchWrongSeq.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.wrongSeq = isChecked
|
||||
}
|
||||
|
||||
val edittextWindowSize = binding.editProfileDesyncAttacksWindowSize
|
||||
edittextWindowSize.filters = arrayOf(MinMaxFilter(Constants.TCP_WINDOW_SIZE_VALUE_RANGE))
|
||||
edittextWindowSize.doAfterTextChanged {
|
||||
editProfilesViewModel.windowSize = it.toString()
|
||||
}
|
||||
|
||||
val edittextWindowScaleFactor = binding.editProfileDesyncAttacksWindowScaleFactor
|
||||
edittextWindowScaleFactor.filters = arrayOf(MinMaxFilter(Constants.TCP_WINDOW_SCALE_FACTOR_VALUE_RANGE))
|
||||
edittextWindowScaleFactor.doAfterTextChanged {
|
||||
editProfilesViewModel.windowScaleFactor = it.toString()
|
||||
}
|
||||
|
||||
val edittextSplitPosition = binding.editProfileDesyncAttacksSplitPosition
|
||||
edittextSplitPosition.filters = arrayOf(MinMaxFilter(Constants.SPLIT_POSITION_VALUE_RANGE))
|
||||
edittextSplitPosition.doAfterTextChanged {
|
||||
editProfilesViewModel.splitPosition = it.toString()
|
||||
}
|
||||
|
||||
val switchSplitAtSNI = binding.editProfileDesyncAttacksSplitAtSni
|
||||
switchSplitAtSNI.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.splitAtSNI = isChecked
|
||||
}
|
||||
|
||||
val showLog = binding.editProfileDesyncAttacksAutoconfigShowLog
|
||||
showLog.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.showLog(isChecked)
|
||||
}
|
||||
|
||||
val progress = binding.editProfileDesyncAttacksAutoconfigProgress
|
||||
|
||||
val terminalScroll = binding.editProfileDesyncAttacksAutoconfigTerminalScroll
|
||||
val terminalOutput = binding.editProfileDesyncAttacksAutoconfigTerminalOutput
|
||||
|
||||
editProfilesViewModel.autoConfigOutput.observe(this) {
|
||||
terminalOutput.text = it
|
||||
terminalScroll.scrollToBottom()
|
||||
}
|
||||
|
||||
editProfilesViewModel.showLog.observe(this) {
|
||||
terminalOutput.visibility = if (it) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
val buttonAutoConfig = binding.editProfileDesyncAttacksAutoconfigButton
|
||||
buttonAutoConfig.setOnClickListener {
|
||||
val inputEditTextField = EditText(this)
|
||||
inputEditTextField.hint = getString(R.string.hint_autoconfigure_edit_profile_dialog)
|
||||
inputEditTextField.maxLines = 1
|
||||
inputEditTextField.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.title_autoconfigure_edit_profile_dialog))
|
||||
.setView(inputEditTextField)
|
||||
.setPositiveButton(getString(R.string.positive_autoconfigure_edit_profile_dialog)) { _, _ ->
|
||||
editProfilesViewModel.runAutoConfig(applicationContext, inputEditTextField.text.toString())
|
||||
}
|
||||
.setNegativeButton(getString(R.string.negative_autoconfigure_edit_profile_dialog), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
val switchDoh = binding.editProfileDnsUseDoh
|
||||
switchDoh.setOnCheckedChangeListener { _, isChecked ->
|
||||
editProfilesViewModel.doh = isChecked
|
||||
}
|
||||
|
||||
val edittextDohServer = binding.editProfileDnsDohServer
|
||||
edittextDohServer.doAfterTextChanged {
|
||||
editProfilesViewModel.dohServer = it.toString()
|
||||
}
|
||||
|
||||
val edittextDns = binding.editProfileDnsDnsServer
|
||||
edittextDns.doAfterTextChanged {
|
||||
editProfilesViewModel.dnsServer = it.toString()
|
||||
}
|
||||
|
||||
editProfilesViewModel.autoConfigState.observe(this) { state ->
|
||||
when(state) {
|
||||
is EditProfileViewModel.AutoconfigState.Running -> {
|
||||
showLog.visibility = View.VISIBLE
|
||||
progress.visibility = View.VISIBLE
|
||||
progress.progress = state.progress
|
||||
}
|
||||
is EditProfileViewModel.AutoconfigState.Success -> {
|
||||
progress.visibility = View.GONE
|
||||
Toast.makeText(this, R.string.profile_successfully_configured, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
is EditProfileViewModel.AutoconfigState.Error -> {
|
||||
progress.visibility = View.GONE
|
||||
when(state.error) {
|
||||
EditProfileViewModel.AutoconfigErrorType.ERROR_NO_ATTACKS_FOUND -> {
|
||||
Toast.makeText(this, R.string.no_working_attacks_found, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
EditProfileViewModel.AutoconfigErrorType.ERROR_RESOLVE_DOMAIN_FAILED -> {
|
||||
Toast.makeText(this, R.string.resolve_domain_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
EditProfileViewModel.AutoconfigErrorType.ERROR_CALCULATE_HOPS_FAILED -> {
|
||||
Toast.makeText(this, R.string.calculate_hops_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
EditProfileViewModel.AutoconfigErrorType.ERROR_CONFIG_PARSE_FAILED -> {
|
||||
Toast.makeText(this, R.string.config_parse_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
EditProfileViewModel.AutoconfigErrorType.ERROR_EXCEPTION -> {
|
||||
terminalOutput.text = state.errorString
|
||||
terminalScroll.scrollToBottom()
|
||||
}
|
||||
}
|
||||
}
|
||||
is EditProfileViewModel.AutoconfigState.Stopped -> {
|
||||
showLog.visibility = View.GONE
|
||||
progress.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
editProfilesViewModel.profile.observe(this) { profile ->
|
||||
supportActionBar?.title = profile?.title ?: getString(R.string.unnamed_profile_name)
|
||||
checkboxDefault.isChecked = profile?.default == true
|
||||
edittextProfileId.visibility = if (profile?.default == true)
|
||||
View.GONE
|
||||
else
|
||||
View.VISIBLE
|
||||
textviewProfileIdDesc.visibility = if (profile?.default == true)
|
||||
View.GONE
|
||||
else
|
||||
View.VISIBLE
|
||||
butSetProfileFromCurrentSettings.visibility = if (profile?.default == true)
|
||||
View.GONE
|
||||
else
|
||||
View.VISIBLE
|
||||
edittextProfileId.setText(profile.name)
|
||||
spinnerZeroLevel.setSelection(profile.desyncZeroAttack?.ordinal?.plus(1) ?: 0)
|
||||
spinnerFirstLevel.setSelection(profile.desyncFirstAttack?.ordinal?.plus(1) ?: 0)
|
||||
switchWrongSeq.isChecked = profile.wrongSeq
|
||||
switchAutoTtl.isChecked = profile.autoTtl
|
||||
edittextTtl.isEnabled = !profile.autoTtl
|
||||
edittextTtl.setText(profile.fakePacketsTtl?.toString() ?: "")
|
||||
edittextWindowSize.setText(profile.windowSize?.toString() ?: "")
|
||||
edittextWindowScaleFactor.setText(profile.windowScaleFactor?.toString() ?: "")
|
||||
edittextSplitPosition.setText(profile.splitPosition?.toString() ?: "")
|
||||
switchSplitAtSNI.isChecked = profile.splitAtSni
|
||||
switchDoh.isChecked = profile.doh
|
||||
edittextDohServer.setText(profile.dohServer ?: "")
|
||||
edittextDns.setText(profile.inBuiltDNSIP?.plus(profile.inBuiltDNSPort?.let { ":$it" } ?: "") ?: "")
|
||||
}
|
||||
|
||||
editProfilesViewModel.loadProfile(intent.getLongExtra(PROFILE_ID_KEY, 0L))
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.edit_profile_toolbar_menu, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun returnResult() {
|
||||
val returnIntent = Intent()
|
||||
setResult(RESULT_OK, returnIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun checkLocationPermissions() {
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestLocationPermission.launch(arrayOf(
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
)
|
||||
} else {
|
||||
if (checkLocationEnabled())
|
||||
editProfilesViewModel.getDefaultIfaceWifiAP(applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkLocationEnabled(): Boolean {
|
||||
val lm = this.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
var gpsEnabled = false
|
||||
var networkEnabled = false
|
||||
var locationEnabled = true
|
||||
|
||||
try {
|
||||
gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
if(!gpsEnabled && !networkEnabled) {
|
||||
Toast.makeText(this, R.string.location_disabled_failed, Toast.LENGTH_LONG).show()
|
||||
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
|
||||
|
||||
locationEnabled = false
|
||||
}
|
||||
|
||||
return locationEnabled
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PROFILE_ID_KEY = "profile_id_key"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,348 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.editProfile
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.*
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.utils.AutoConfigOutputFilter
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
|
||||
class EditProfileViewModel(private val fetchDefaultIfaceWifiAPUseCase: IFetchDefaultIfaceWifiAPUseCase,
|
||||
private val autoConfigUseCase: IAutoConfigUseCase,
|
||||
private val settingsUseCase: ISettingsUseCase,
|
||||
private val saveProfileUseCase: ISaveProfileUseCase,
|
||||
private val fetchProfileUseCase: IFetchProfileUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private val _autoConfigOutput = MutableLiveData<String>()
|
||||
val autoConfigOutput: LiveData<String> get() = _autoConfigOutput
|
||||
|
||||
private val _outputFiler = AutoConfigOutputFilter { input -> autoConfigUseCase.input(input) }
|
||||
|
||||
private var _profileCurrentUnmodified: Profile? = null
|
||||
val isModified: Boolean
|
||||
get() {
|
||||
return _profileCurrent != _profileCurrentUnmodified
|
||||
}
|
||||
private var _profileCurrent: Profile? = null
|
||||
@Synchronized
|
||||
get() = field
|
||||
@Synchronized
|
||||
set(value) {
|
||||
field = value
|
||||
if (_profileCurrentUnmodified == null)
|
||||
_profileCurrentUnmodified = value?.copy()
|
||||
value?.let { _profile.postValue(it) }
|
||||
}
|
||||
|
||||
private val _profile = MutableLiveData<Profile>()
|
||||
val profile: LiveData<Profile> get() = _profile
|
||||
|
||||
private val _autoconfigState = MutableLiveData<AutoconfigState>()
|
||||
val autoConfigState: LiveData<AutoconfigState> get() = _autoconfigState
|
||||
|
||||
private val _showLog = MutableLiveData<Boolean>()
|
||||
val showLog: LiveData<Boolean> get() = _showLog
|
||||
|
||||
private val _uiState = MutableLiveData<UIState>()
|
||||
val uiState: LiveData<UIState> get() = _uiState
|
||||
|
||||
var title: String
|
||||
get() = _profileCurrent?.title ?: ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.title = value
|
||||
_profileCurrent = _profileCurrent
|
||||
}
|
||||
}
|
||||
|
||||
var default: Boolean
|
||||
get() = false
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
if (value && it.name == DEFAULT_PROFILE_ID)
|
||||
it.name = ""
|
||||
it.default = value
|
||||
_profileCurrent = _profileCurrent
|
||||
}
|
||||
}
|
||||
var profileId: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.enabled = value.isNotBlank()
|
||||
it.name = value
|
||||
}
|
||||
}
|
||||
var zeroAttack: Int
|
||||
get() = 0
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.desyncAttacks = !(value == 0 && it.desyncFirstAttack == null)
|
||||
it.desyncZeroAttack = if (value == 0) null else DesyncZeroAttack.values()[value.minus(1)]
|
||||
}
|
||||
}
|
||||
var firstAttack: Int
|
||||
get() = 0
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.desyncAttacks = !(value == 0 && it.desyncZeroAttack == null)
|
||||
it.desyncFirstAttack = if (value == 0) null else DesyncFirstAttack.values()[value.minus(1)]
|
||||
}
|
||||
}
|
||||
var wrongSeq: Boolean
|
||||
get() = false
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.wrongSeq = value
|
||||
}
|
||||
}
|
||||
var autoTtl: Boolean
|
||||
get() = false
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.autoTtl = value
|
||||
}
|
||||
}
|
||||
var ttl: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.fakePacketsTtl = value.ifEmpty { null }?.toInt()
|
||||
}
|
||||
}
|
||||
var windowSize: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.windowSize = value.ifEmpty { null }?.toInt()
|
||||
}
|
||||
}
|
||||
var windowScaleFactor: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.windowScaleFactor = value.ifEmpty { null }?.toInt()
|
||||
}
|
||||
}
|
||||
var splitPosition: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.splitPosition = value.ifEmpty { null }?.toInt()
|
||||
}
|
||||
}
|
||||
var splitAtSNI: Boolean
|
||||
get() = false
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.splitAtSni = value
|
||||
}
|
||||
}
|
||||
var doh: Boolean
|
||||
get() = false
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.doh = value
|
||||
}
|
||||
}
|
||||
var dohServer: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let {
|
||||
it.dohServer = value.ifEmpty { null }
|
||||
}
|
||||
}
|
||||
var dnsServer: String
|
||||
get() = ""
|
||||
set(value) {
|
||||
_profileCurrent?.let { it ->
|
||||
if (value.isEmpty()) {
|
||||
it.inBuiltDNS = true
|
||||
it.inBuiltDNSIP = Constants.DEFAULT_PROFILE.inBuiltDNSIP
|
||||
it.inBuiltDNSPort = null
|
||||
}
|
||||
else {
|
||||
it.inBuiltDNS = true
|
||||
it.inBuiltDNSIP = value.split(':').getOrNull(0)
|
||||
it.inBuiltDNSPort = value.split(':').getOrNull(1)?.toIntOrNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
autoConfigUseCase.inputFlow.collect {
|
||||
_outputFiler.feed(it)
|
||||
}
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_outputFiler.configuredProfile.collect { state ->
|
||||
when(state) {
|
||||
is AutoConfigOutputFilter.ConfiguredProfileState.Success -> {
|
||||
loadConfiguredProfile(state.configuredProfile)
|
||||
_autoconfigState.postValue(AutoconfigState.Success)
|
||||
}
|
||||
is AutoConfigOutputFilter.ConfiguredProfileState.Error -> {
|
||||
when(state.error) {
|
||||
AutoConfigOutputFilter.ErrorType.ERROR_NO_ATTACKS_FOUND ->
|
||||
_autoconfigState.postValue(AutoconfigState.Error(AutoconfigErrorType.ERROR_NO_ATTACKS_FOUND))
|
||||
AutoConfigOutputFilter.ErrorType.ERROR_RESOLVE_DOMAIN_FAILED ->
|
||||
_autoconfigState.postValue(AutoconfigState.Error(AutoconfigErrorType.ERROR_RESOLVE_DOMAIN_FAILED))
|
||||
AutoConfigOutputFilter.ErrorType.ERROR_CALCULATE_HOPS_FAILED ->
|
||||
_autoconfigState.postValue(AutoconfigState.Error(AutoconfigErrorType.ERROR_CALCULATE_HOPS_FAILED))
|
||||
AutoConfigOutputFilter.ErrorType.ERROR_CONFIG_PARSE_FAILED ->
|
||||
_autoconfigState.postValue(AutoconfigState.Error(AutoconfigErrorType.ERROR_CONFIG_PARSE_FAILED))
|
||||
}
|
||||
}
|
||||
is AutoConfigOutputFilter.ConfiguredProfileState.InProcess -> {
|
||||
_autoconfigState.postValue(AutoconfigState.Running(state.progress))
|
||||
}
|
||||
is AutoConfigOutputFilter.ConfiguredProfileState.Stopped -> {
|
||||
_autoconfigState.postValue(AutoconfigState.Stopped)
|
||||
_showLog.postValue(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_outputFiler.output.collect {
|
||||
it?.let { _autoConfigOutput.postValue(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun save() {
|
||||
_profileCurrent?.let {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!it.default && (it.name.isBlank() || it.name == DEFAULT_PROFILE_ID)) {
|
||||
_uiState.postValue(UIState.Error(UIErrorType.ERROR_INVALID_PROFILE_ID))
|
||||
return@launch
|
||||
}
|
||||
saveProfileUseCase.save(it)
|
||||
_uiState.postValue(UIState.Finish)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getDefaultIfaceWifiAP(context: Context) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_profileCurrent?.let {
|
||||
val profile = it
|
||||
profile.name = fetchDefaultIfaceWifiAPUseCase.fetch(context).let { it ->
|
||||
var defaultIfaceWifi = it
|
||||
defaultIfaceWifi.first?.let {
|
||||
if (it.startsWith(RMNET_IFACE_NAME) && it.last().isDigit())
|
||||
defaultIfaceWifi = defaultIfaceWifi.copy(first = it.dropLastWhile { it.isDigit() }.plus('*'))
|
||||
}
|
||||
defaultIfaceWifi.first?.plus(defaultIfaceWifi.second?.let {
|
||||
":$it"
|
||||
} ?: "") ?: ""
|
||||
}
|
||||
_profileCurrent = profile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun runAutoConfig(context: Context, domain: String) {
|
||||
_outputFiler.reset(AutoConfigDefaults(
|
||||
domain = domain,
|
||||
caBundlePath = settingsUseCase.getCABundlePath()!!,
|
||||
dohServer = _profileCurrent?.dohServer ?: Constants.DEFAULT_PROFILE.dohServer!!,
|
||||
inBuiltDNS = _profileCurrent?.inBuiltDNSIP?.plus(_profileCurrent?.inBuiltDNSPort?.let { ":$it" } ?: "") ?: Constants.DEFAULT_PROFILE.inBuiltDNSIP!!
|
||||
))
|
||||
autoConfigUseCase.run(
|
||||
viewModelScope,
|
||||
listOf(
|
||||
"su",
|
||||
"-c",
|
||||
context.applicationInfo.nativeLibraryDir + '/' + Constants.DPITUNNEL_BINARY_NAME + ' ' +
|
||||
"--auto"
|
||||
)
|
||||
) { throwable ->
|
||||
_autoconfigState.postValue(
|
||||
AutoconfigState.Error(
|
||||
AutoconfigErrorType.ERROR_EXCEPTION,
|
||||
throwable.stackTraceToString()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun showLog(isShow: Boolean) {
|
||||
_showLog.value = isShow
|
||||
}
|
||||
|
||||
fun loadProfile(id: Long) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (id == 0L)
|
||||
loadProfile(null as Profile?)
|
||||
else
|
||||
loadProfile(fetchProfileUseCase.fetch(id))
|
||||
}
|
||||
}
|
||||
|
||||
fun saveUnsaved() {
|
||||
save()
|
||||
}
|
||||
|
||||
fun discardUnsaved() {
|
||||
_uiState.value = UIState.Finish
|
||||
}
|
||||
|
||||
private fun loadProfile(profile: Profile?) {
|
||||
if (profile == null)
|
||||
_profileCurrent = Constants.DEFAULT_PROFILE.copy()
|
||||
else
|
||||
_profileCurrent = profile
|
||||
}
|
||||
|
||||
private fun loadConfiguredProfile(configuredProfile: ConfiguredProfile) {
|
||||
_profileCurrent?.let {
|
||||
val profile = it
|
||||
profile.splitAtSni = configuredProfile.splitAtSni
|
||||
profile.wrongSeq = configuredProfile.wrongSeq
|
||||
profile.autoTtl = configuredProfile.autoTtl
|
||||
profile.fakePacketsTtl = configuredProfile.fakePacketsTtl
|
||||
profile.windowSize = configuredProfile.windowSize
|
||||
profile.windowScaleFactor = configuredProfile.windowScaleFactor
|
||||
profile.desyncAttacks = configuredProfile.desyncAttacks
|
||||
profile.desyncZeroAttack = configuredProfile.desyncZeroAttack
|
||||
profile.desyncFirstAttack = configuredProfile.desyncFirstAttack
|
||||
_profileCurrent = it
|
||||
}
|
||||
}
|
||||
|
||||
enum class AutoconfigErrorType {
|
||||
ERROR_NO_ATTACKS_FOUND,
|
||||
ERROR_RESOLVE_DOMAIN_FAILED,
|
||||
ERROR_CALCULATE_HOPS_FAILED,
|
||||
ERROR_CONFIG_PARSE_FAILED,
|
||||
ERROR_EXCEPTION
|
||||
}
|
||||
|
||||
sealed class AutoconfigState {
|
||||
data class Running(val progress: Int): AutoconfigState()
|
||||
object Success: AutoconfigState()
|
||||
data class Error(val error: AutoconfigErrorType, val errorString: String? = null): AutoconfigState()
|
||||
object Stopped: AutoconfigState()
|
||||
}
|
||||
|
||||
enum class UIErrorType {
|
||||
ERROR_INVALID_PROFILE_ID
|
||||
}
|
||||
|
||||
sealed class UIState {
|
||||
object Normal: UIState()
|
||||
data class Error(val error: UIErrorType, val errorString: String? = null): UIState()
|
||||
object Finish: UIState()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val RMNET_IFACE_NAME = "rmnet"
|
||||
private const val DEFAULT_PROFILE_ID = "default"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.editProfile
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
|
||||
class EditProfileViewModelFactory(val getDefaultIfaceUseCase: IFetchDefaultIfaceWifiAPUseCase,
|
||||
val autoConfigUseCase: IAutoConfigUseCase,
|
||||
val settingsUseCase: ISettingsUseCase,
|
||||
val saveProfileUseCase: ISaveProfileUseCase,
|
||||
val fetchProfileUseCase: IFetchProfileUseCase
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.getConstructor(IFetchDefaultIfaceWifiAPUseCase::class.java,
|
||||
IAutoConfigUseCase::class.java,
|
||||
ISettingsUseCase::class.java,
|
||||
ISaveProfileUseCase::class.java,
|
||||
IFetchProfileUseCase::class.java)
|
||||
.newInstance(getDefaultIfaceUseCase, autoConfigUseCase, settingsUseCase, saveProfileUseCase, fetchProfileUseCase)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.proxifiedApps
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.LoadProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.SaveProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.databinding.ActivityProxifiedAppsBinding
|
||||
|
||||
class ProxifiedAppsActivity: AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityProxifiedAppsBinding
|
||||
|
||||
private val proxifiedAppsViewModel by viewModels<ProxifiedAppsViewModel> {
|
||||
ProxifiedAppsViewModelFactory(
|
||||
loadProxifiedAppsUseCase = LoadProxifiedAppsUseCase(this),
|
||||
saveProxifiedAppsUseCase = SaveProxifiedAppsUseCase(this)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (proxifiedAppsViewModel.isModified) {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(R.string.title_confirmation_proxified_apps_dialog)
|
||||
.setMessage(R.string.message_confirmation_proxified_apps_dialog)
|
||||
.setPositiveButton(R.string.save_confirmation_proxified_apps_dialog) { _, _ ->
|
||||
proxifiedAppsViewModel.saveUnsaved()
|
||||
}
|
||||
.setNegativeButton(R.string.discard_confirmation_proxified_apps_dialog) { _, _ ->
|
||||
proxifiedAppsViewModel.discardUnsaved()
|
||||
}
|
||||
.setNeutralButton(R.string.cancel_confirmation_proxified_apps_dialog, null)
|
||||
.create()
|
||||
dialog.show()
|
||||
} else
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityProxifiedAppsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.proxifiedAppsToolbar)
|
||||
binding.proxifiedAppsToolbar.setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.proxified_apps_toolbar_menu_save -> {
|
||||
proxifiedAppsViewModel.save()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
binding.proxifiedAppsCheckAll.setOnClickListener {
|
||||
proxifiedAppsViewModel.checkAll()
|
||||
}
|
||||
|
||||
proxifiedAppsViewModel.uiState.observe(this) { state ->
|
||||
when (state) {
|
||||
is ProxifiedAppsViewModel.UIState.Normal -> {}
|
||||
is ProxifiedAppsViewModel.UIState.Error -> {}
|
||||
is ProxifiedAppsViewModel.UIState.Finish -> returnResult()
|
||||
}
|
||||
}
|
||||
|
||||
binding.proxifiedAppsRecycler.adapter = ProxifiedAppsAdapter(
|
||||
appIsProxifiedListener = { username, isProxified ->
|
||||
proxifiedAppsViewModel.setProxified(username, isProxified)
|
||||
}
|
||||
)
|
||||
|
||||
binding.proxifiedAppsRecycler.layoutManager = LinearLayoutManager(
|
||||
this,
|
||||
LinearLayoutManager.VERTICAL, false
|
||||
)
|
||||
|
||||
proxifiedAppsViewModel.apps.observe(this) {
|
||||
(binding.proxifiedAppsRecycler.adapter as ProxifiedAppsAdapter).bindEntries(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun returnResult() {
|
||||
val returnIntent = Intent()
|
||||
setResult(RESULT_OK, returnIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.proxified_apps_toolbar_menu, menu)
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.proxifiedApps
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
|
||||
class ProxifiedAppsAdapter(val appIsProxifiedListener: (String, Boolean) -> Unit): RecyclerView.Adapter<ProxifiedAppsViewHolder>() {
|
||||
|
||||
private var apps = listOf<ProxifiedApp>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProxifiedAppsViewHolder {
|
||||
return ProxifiedAppsViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.view_holder_proxified_apps_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProxifiedAppsViewHolder, position: Int) {
|
||||
holder.onBind(apps[position], appIsProxifiedListener)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = apps.size
|
||||
|
||||
fun bindEntries(newApps: List<ProxifiedApp>?) {
|
||||
newApps?.let {
|
||||
apps = it
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProxifiedAppsViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
val icon: ImageView = itemView.findViewById(R.id.view_holder_proxified_apps_icon)
|
||||
val name: TextView = itemView.findViewById(R.id.view_holder_proxified_apps_name)
|
||||
val isProxified: MaterialCheckBox = itemView.findViewById(R.id.view_holder_proxified_apps_proxified_checkbox)
|
||||
|
||||
fun onBind(app: ProxifiedApp,
|
||||
appIsProxifiedListener: (String, Boolean) -> Unit) {
|
||||
icon.setImageDrawable(app.icon)
|
||||
|
||||
name.text = app.name
|
||||
|
||||
isProxified.setOnCheckedChangeListener(null)
|
||||
isProxified.isChecked = app.isProxified
|
||||
isProxified.setOnCheckedChangeListener { _, isChecked ->
|
||||
appIsProxifiedListener(app.username, isChecked)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.proxifiedApps
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxifiedApp
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveProxifiedAppsUseCase
|
||||
|
||||
class ProxifiedAppsViewModel(private val loadProxifiedAppsUseCase: ILoadProxifiedAppsUseCase,
|
||||
private val saveProxifiedAppsUseCase: ISaveProxifiedAppsUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private var _appsList: MutableList<ProxifiedApp>? = null
|
||||
|
||||
private val _apps = MutableLiveData<List<ProxifiedApp>>()
|
||||
val apps: LiveData<List<ProxifiedApp>> = _apps
|
||||
|
||||
private val _uiState = MutableLiveData<UIState>()
|
||||
val uiState: LiveData<UIState> get() = _uiState
|
||||
|
||||
var isModified: Boolean = false
|
||||
private set(newValue: Boolean) {
|
||||
field = newValue
|
||||
}
|
||||
|
||||
init {
|
||||
viewModelScope.launch (Dispatchers.IO) {
|
||||
_appsList = loadProxifiedAppsUseCase.load().toMutableList()
|
||||
_apps.postValue(_appsList!!)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkAll() {
|
||||
_appsList?.let { _appsList ->
|
||||
if (_appsList.all { it.isProxified })
|
||||
_appsList.forEach { it.isProxified = false }
|
||||
else
|
||||
_appsList.forEach { it.isProxified = true }
|
||||
|
||||
isModified = true
|
||||
_apps.postValue(_appsList)
|
||||
}
|
||||
}
|
||||
|
||||
fun setProxified(username: String, isProxified: Boolean) {
|
||||
_appsList?.let { _appsList ->
|
||||
_appsList.forEach {
|
||||
if (it.username == username)
|
||||
it.isProxified = isProxified
|
||||
}
|
||||
|
||||
isModified = true
|
||||
_apps.postValue(_appsList)
|
||||
}
|
||||
}
|
||||
|
||||
fun save() {
|
||||
_appsList?.let { _appsList ->
|
||||
viewModelScope.launch (Dispatchers.IO) {
|
||||
saveProxifiedAppsUseCase.save(_appsList)
|
||||
_uiState.postValue(UIState.Finish)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun saveUnsaved() {
|
||||
save()
|
||||
}
|
||||
|
||||
fun discardUnsaved() {
|
||||
_uiState.value = UIState.Finish
|
||||
}
|
||||
|
||||
enum class UIErrorType {
|
||||
}
|
||||
|
||||
sealed class UIState {
|
||||
object Normal: UIState()
|
||||
data class Error(val error: UIErrorType, val errorString: String? = null): UIState()
|
||||
object Finish: UIState()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.proxifiedApps
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ILoadProxifiedAppsUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.ISaveProxifiedAppsUseCase
|
||||
|
||||
class ProxifiedAppsViewModelFactory(val loadProxifiedAppsUseCase: ILoadProxifiedAppsUseCase,
|
||||
val saveProxifiedAppsUseCase: ISaveProxifiedAppsUseCase
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.getConstructor(ILoadProxifiedAppsUseCase::class.java,
|
||||
ISaveProxifiedAppsUseCase::class.java
|
||||
)
|
||||
.newInstance(loadProxifiedAppsUseCase, saveProxifiedAppsUseCase)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.activity.settings
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import com.nomoresat.dpitunnelcli.databinding.ActivitySettingsBinding
|
||||
import com.nomoresat.dpitunnelcli.ui.settings.SettingsFragment
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivitySettingsBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.settingsToolbar)
|
||||
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(binding.settingsFragmentContainer.id, SettingsFragment())
|
||||
.commit()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.dashboard
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.databinding.FragmentDashboardBinding
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.ui.activity.settings.SettingsActivity
|
||||
|
||||
|
||||
class DashboardFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentDashboardBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val dashboardViewModel by viewModels<DashboardViewModel> {
|
||||
DashboardViewModelFactory(
|
||||
daemonUseCase = DaemonUseCase(
|
||||
execPath = requireContext().applicationInfo.nativeLibraryDir + '/' + Constants.DPITUNNEL_BINARY_NAME,
|
||||
pidFilePath = Constants.DPITUNNEL_DAEMON_PID_FILE),
|
||||
fetchAllProfilesUseCase = FetchAllProfilesUseCase(requireContext().applicationContext),
|
||||
settingsUseCase = SettingsUseCase(requireContext().applicationContext),
|
||||
proxyUseCase = ProxyUseCase(),
|
||||
loadProxifiedAppsUseCase = LoadProxifiedAppsUseCase(requireContext().applicationContext)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentDashboardBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val imageViewStatus = binding.dashboardStatusCardImage
|
||||
|
||||
val progressBarLoading = binding.dashboardStatusCardProgress
|
||||
|
||||
val buttonSettings = binding.dashboardStatusCardSettings
|
||||
buttonSettings.setOnClickListener {
|
||||
val intent = Intent(requireContext(), SettingsActivity::class.java)
|
||||
requireContext().startActivity(intent)
|
||||
}
|
||||
|
||||
val buttonStartStop = binding.dashboardStatusCardStartStop
|
||||
buttonStartStop.setOnClickListener {
|
||||
dashboardViewModel.startStop()
|
||||
}
|
||||
|
||||
val buttonRestart = binding.dashboardStatusCardRestart
|
||||
buttonRestart.setOnClickListener{
|
||||
dashboardViewModel.restart()
|
||||
}
|
||||
|
||||
dashboardViewModel.uiState.observe(viewLifecycleOwner) { state ->
|
||||
when (state) {
|
||||
is DashboardViewModel.UIState.Loading -> {
|
||||
buttonSettings.isEnabled = true
|
||||
progressBarLoading.visibility = View.VISIBLE
|
||||
imageViewStatus.visibility = View.INVISIBLE
|
||||
buttonStartStop.isClickable = false
|
||||
buttonRestart.isClickable = false
|
||||
}
|
||||
is DashboardViewModel.UIState.Running -> {
|
||||
buttonSettings.isEnabled = false
|
||||
progressBarLoading.visibility = View.GONE
|
||||
imageViewStatus.visibility = View.VISIBLE
|
||||
imageViewStatus.setImageDrawable(AppCompatResources.getDrawable(requireContext().applicationContext, R.drawable.ic_check_circle_white_96dp))
|
||||
imageViewStatus.setBackgroundColor(ContextCompat.getColor(requireContext().applicationContext, R.color.green_300))
|
||||
buttonStartStop.text = getText(R.string.button_status_stop_text)
|
||||
buttonStartStop.setIconResource(R.drawable.ic_stop_24)
|
||||
buttonStartStop.isClickable = true
|
||||
buttonRestart.isClickable = true
|
||||
}
|
||||
is DashboardViewModel.UIState.Stopped -> {
|
||||
buttonSettings.isEnabled = true
|
||||
progressBarLoading.visibility = View.GONE
|
||||
imageViewStatus.visibility = View.VISIBLE
|
||||
imageViewStatus.setImageDrawable(AppCompatResources.getDrawable(requireContext().applicationContext, R.drawable.ic_cancel_white_96dp))
|
||||
imageViewStatus.setBackgroundColor(ContextCompat.getColor(requireContext().applicationContext, R.color.red_300))
|
||||
buttonStartStop.text = getText(R.string.button_status_start_text)
|
||||
buttonStartStop.setIconResource(R.drawable.ic_play_24dp)
|
||||
buttonStartStop.isClickable = true
|
||||
buttonRestart.isClickable = true
|
||||
}
|
||||
is DashboardViewModel.UIState.Error -> {
|
||||
when(state.code) {
|
||||
DashboardViewModel.UIError.NO_ONE_PROFILE -> {
|
||||
Toast.makeText(requireContext(), R.string.no_one_profile_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.dashboard
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import com.nomoresat.dpitunnelcli.cli.CliDaemon
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
|
||||
class DashboardViewModel(private val daemonUseCase: IDaemonUseCase,
|
||||
private val fetchAllProfilesUseCase: IFetchAllProfilesUseCase,
|
||||
private val settingsUseCase: ISettingsUseCase,
|
||||
private val proxyUseCase: IProxyUseCase,
|
||||
private val loadProxifiedAppsUseCase: ILoadProxifiedAppsUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private val _uiState = MutableLiveData<UIState>()
|
||||
val uiState: LiveData<UIState> get() = _uiState
|
||||
|
||||
private var lastDaemonState: DaemonState? = null
|
||||
|
||||
init {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
daemonUseCase.daemonState.collect { state ->
|
||||
when(state) {
|
||||
is DaemonState.Loading -> {
|
||||
_uiState.postValue(UIState.Loading)
|
||||
}
|
||||
is DaemonState.Running -> {
|
||||
_uiState.postValue(UIState.Running)
|
||||
if (lastDaemonState is DaemonState.Stopped || lastDaemonState is DaemonState.Error)
|
||||
if (settingsUseCase.getSystemWide())
|
||||
proxyUseCase.set("127.0.0.1", settingsUseCase.getPort() ?: Constants.DPITUNNEL_DEFAULT_PORT,
|
||||
settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE,
|
||||
loadProxifiedAppsUseCase.load())
|
||||
}
|
||||
is DaemonState.Stopped -> {
|
||||
_uiState.postValue(UIState.Stopped)
|
||||
if (lastDaemonState is DaemonState.Running)
|
||||
if (settingsUseCase.getSystemWide())
|
||||
proxyUseCase.unset(settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE)
|
||||
}
|
||||
is DaemonState.Error -> {
|
||||
_uiState.postValue(UIState.Stopped)
|
||||
}
|
||||
}
|
||||
lastDaemonState = state
|
||||
}
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
while (true) {
|
||||
daemonUseCase.check()
|
||||
delay(2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun startStop() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when(daemonUseCase.daemonState.value) {
|
||||
is DaemonState.Running -> daemonUseCase.stop()
|
||||
is DaemonState.Stopped -> fetchAllProfilesUseCase.fetch().let {
|
||||
if (it.isEmpty())
|
||||
_uiState.postValue(UIState.Error(UIError.NO_ONE_PROFILE))
|
||||
else
|
||||
daemonUseCase.start(
|
||||
CliDaemon.PersistentOptions(
|
||||
caBundlePath = settingsUseCase.getCABundlePath()!!,
|
||||
ip = settingsUseCase.getIP(),
|
||||
port = settingsUseCase.getPort(),
|
||||
customIPsPath = settingsUseCase.getCustomIPsPath(),
|
||||
proxyMode = settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE
|
||||
),
|
||||
it
|
||||
)
|
||||
}
|
||||
is DaemonState.Error -> {}
|
||||
is DaemonState.Loading -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun restart() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
daemonUseCase.stop()
|
||||
var isStopped = false
|
||||
withTimeoutOrNull(2000) {
|
||||
daemonUseCase.daemonState.collect { state ->
|
||||
if (state is DaemonState.Stopped)
|
||||
isStopped = true
|
||||
}
|
||||
}
|
||||
if (isStopped)
|
||||
fetchAllProfilesUseCase.fetch().let {
|
||||
if (it.isEmpty())
|
||||
_uiState.postValue(UIState.Error(UIError.NO_ONE_PROFILE))
|
||||
else
|
||||
daemonUseCase.start(
|
||||
CliDaemon.PersistentOptions(
|
||||
caBundlePath = settingsUseCase.getCABundlePath()!!,
|
||||
ip = settingsUseCase.getIP(),
|
||||
port = settingsUseCase.getPort(),
|
||||
customIPsPath = settingsUseCase.getCustomIPsPath(),
|
||||
proxyMode = settingsUseCase.getProxyMode() ?: Constants.DPITUNNEL_DEFAULT_PROXY_MODE
|
||||
),
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class UIError {
|
||||
NO_ONE_PROFILE
|
||||
}
|
||||
|
||||
sealed class UIState {
|
||||
object Running: UIState()
|
||||
object Stopped: UIState()
|
||||
object Loading: UIState()
|
||||
data class Error(val code: UIError): UIState()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.dashboard
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
|
||||
class DashboardViewModelFactory(val daemonUseCase: IDaemonUseCase,
|
||||
val fetchAllProfilesUseCase: IFetchAllProfilesUseCase,
|
||||
val settingsUseCase: ISettingsUseCase,
|
||||
val proxyUseCase: IProxyUseCase,
|
||||
val loadProxifiedAppsUseCase: ILoadProxifiedAppsUseCase
|
||||
): ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.getConstructor(IDaemonUseCase::class.java,
|
||||
IFetchAllProfilesUseCase::class.java,
|
||||
ISettingsUseCase::class.java,
|
||||
IProxyUseCase::class.java,
|
||||
ILoadProxifiedAppsUseCase::class.java)
|
||||
.newInstance(daemonUseCase,
|
||||
fetchAllProfilesUseCase,
|
||||
settingsUseCase,
|
||||
proxyUseCase,
|
||||
loadProxifiedAppsUseCase)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.profiles
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.FetchProfileUseCase
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
|
||||
class ProfilesAdapter(val profileListener: (Profile) -> Unit,
|
||||
val profileRenameListener: (Profile) -> Unit,
|
||||
val profileDeleteListener: (Profile) -> Unit,
|
||||
val profileDefaultListener: (Profile) -> Unit,
|
||||
val profileEnabledListener: (Profile) -> Unit,): RecyclerView.Adapter<ProfileViewHolder>() {
|
||||
private var profiles = listOf<Profile>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder {
|
||||
return ProfileViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.view_holder_profile_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) {
|
||||
holder.onBind(profiles[position])
|
||||
holder.itemView.setOnClickListener {
|
||||
profileListener(profiles[position])
|
||||
}
|
||||
holder.options.setOnClickListener { view ->
|
||||
val popupMenu = PopupMenu(view.context, view)
|
||||
popupMenu.inflate(R.menu.profile_item_menu)
|
||||
popupMenu.setOnMenuItemClickListener {
|
||||
when(it.itemId) {
|
||||
R.id.profile_item_menu_rename -> {
|
||||
profileRenameListener(profiles[position])
|
||||
true
|
||||
}
|
||||
R.id.profile_item_menu_delete -> {
|
||||
profileDeleteListener(profiles[position])
|
||||
true
|
||||
}
|
||||
R.id.profile_item_menu_default -> {
|
||||
profileDefaultListener(profiles[position])
|
||||
true
|
||||
}
|
||||
R.id.profile_item_menu_enabled -> {
|
||||
profileEnabledListener(profiles[position])
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
popupMenu.show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = profiles.size
|
||||
|
||||
fun bindProfiles(newProfiles: List<Profile>?) {
|
||||
newProfiles?.let {
|
||||
profiles = it
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
val card: MaterialCardView = itemView.findViewById(R.id.view_holder_profile_card)
|
||||
val title: TextView = itemView.findViewById(R.id.view_holder_profile_title)
|
||||
val options: ImageButton = itemView.findViewById(R.id.view_holder_profile_options)
|
||||
|
||||
fun onBind(profile: Profile) {
|
||||
card.isChecked = profile.default || profile.enabled
|
||||
|
||||
val titleStr = StringBuilder(profile.title ?: itemView.context.getString(R.string.unnamed_profile_name))
|
||||
if (profile.default)
|
||||
titleStr.append(" ").append(itemView.context.getString(R.string.default_profile_mark))
|
||||
title.text = titleStr.toString()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.profiles
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.data.usecases.*
|
||||
import com.nomoresat.dpitunnelcli.ui.activity.editProfile.EditProfileActivity
|
||||
import com.nomoresat.dpitunnelcli.databinding.FragmentProfilesBinding
|
||||
|
||||
class ProfilesFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentProfilesBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val profilesViewModel by viewModels<ProfilesViewModel> {
|
||||
ProfilesViewModelFactory(
|
||||
fetchAllProfilesUseCase = FetchAllProfilesUseCase(requireContext().applicationContext),
|
||||
fetchProfileUseCase = FetchProfileUseCase(requireContext().applicationContext),
|
||||
deleteProfileUseCase = DeleteProfileUseCase(requireContext().applicationContext),
|
||||
renameProfileUseCase = RenameProfileUseCase(requireContext().applicationContext),
|
||||
settingsUseCase = SettingsUseCase(requireContext().applicationContext),
|
||||
enableDisableProfileUseCase = EnableDisableProfileUseCase(requireContext().applicationContext)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentProfilesBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.profilesRecycler.adapter = ProfilesAdapter(
|
||||
profileListener = {
|
||||
resultLauncher.launch(Intent(context, EditProfileActivity::class.java)
|
||||
.putExtra(EditProfileActivity.PROFILE_ID_KEY, it.id))
|
||||
},
|
||||
profileRenameListener = {
|
||||
val inputEditTextField = EditText(requireActivity())
|
||||
inputEditTextField.setText(it.title)
|
||||
inputEditTextField.maxLines = 1
|
||||
inputEditTextField.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
val dialog = AlertDialog.Builder(requireContext())
|
||||
.setTitle(getString(R.string.dialog_profile_rename_title))
|
||||
.setView(inputEditTextField)
|
||||
.setPositiveButton(getString(R.string.dialog_profile_rename_positive)) { _, _ ->
|
||||
profilesViewModel.rename(it.id!!, inputEditTextField.text.toString())
|
||||
}
|
||||
.setNegativeButton(getString(R.string.dialog_profile_rename_negative), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
},
|
||||
profileDeleteListener = {
|
||||
profilesViewModel.delete(it.id!!)
|
||||
},
|
||||
profileDefaultListener = {
|
||||
profilesViewModel.setDefaultProfile(it.id!!)
|
||||
},
|
||||
profileEnabledListener = {
|
||||
profilesViewModel.enableDisable(it.id!!)
|
||||
}
|
||||
)
|
||||
|
||||
binding.profilesRecycler.layoutManager = LinearLayoutManager(
|
||||
context,
|
||||
LinearLayoutManager.VERTICAL, false
|
||||
)
|
||||
|
||||
profilesViewModel.uiState.observe(viewLifecycleOwner) { state ->
|
||||
when(state) {
|
||||
is ProfilesViewModel.UIState.Normal -> {}
|
||||
is ProfilesViewModel.UIState.Error -> {
|
||||
when(state.error) {
|
||||
ProfilesViewModel.UIErrorType.ERROR_PROFILE_NAME_EMPTY -> {
|
||||
Toast.makeText(requireContext(), R.string.empty_profile_name_failed, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
profilesViewModel.profiles.observe(viewLifecycleOwner) {
|
||||
(binding.profilesRecycler.adapter as ProfilesAdapter).bindProfiles(it)
|
||||
}
|
||||
|
||||
binding.profilesAddProfileButton.setOnClickListener {
|
||||
resultLauncher.launch(Intent(context, EditProfileActivity::class.java)
|
||||
.putExtra(EditProfileActivity.PROFILE_ID_KEY, 0L))
|
||||
}
|
||||
}
|
||||
|
||||
private val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.profiles
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
|
||||
class ProfilesViewModel(private val fetchAllProfilesUseCase: IFetchAllProfilesUseCase,
|
||||
private val fetchProfileUseCase: IFetchProfileUseCase,
|
||||
private val deleteProfileUseCase: IDeleteProfileUseCase,
|
||||
private val renameProfileUseCase: IRenameProfileUseCase,
|
||||
private val settingsUseCase: ISettingsUseCase,
|
||||
private val enableDisableProfileUseCase: IEnableDisableProfileUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private val _profiles = MediatorLiveData<List<Profile>>()
|
||||
val profiles: LiveData<List<Profile>> = _profiles
|
||||
|
||||
private val _uiState = MutableLiveData<UIState>()
|
||||
val uiState: LiveData<UIState> get() = _uiState
|
||||
|
||||
init {
|
||||
_profiles.addSource(fetchAllProfilesUseCase.fetchLive()) {
|
||||
_profiles.value = it
|
||||
}
|
||||
}
|
||||
|
||||
fun delete(id: Long) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
deleteProfileUseCase.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
fun rename(id: Long, newTitle: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
renameProfileUseCase.rename(id, newTitle)
|
||||
}
|
||||
}
|
||||
|
||||
fun setDefaultProfile(id: Long) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsUseCase.setDefaultProfileId(id)
|
||||
_profiles.postValue(fetchAllProfilesUseCase.fetch())
|
||||
}
|
||||
}
|
||||
|
||||
fun enableDisable(id: Long) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val profile = fetchProfileUseCase.fetch(id)!!
|
||||
if (profile.enabled)
|
||||
enableDisableProfileUseCase.disable(profile.id!!)
|
||||
else {
|
||||
if (profile.name.isBlank()) {
|
||||
_uiState.postValue(UIState.Error(UIErrorType.ERROR_PROFILE_NAME_EMPTY))
|
||||
return@launch
|
||||
}
|
||||
enableDisableProfileUseCase.enable(profile.id!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class UIErrorType {
|
||||
ERROR_PROFILE_NAME_EMPTY
|
||||
}
|
||||
|
||||
sealed class UIState {
|
||||
object Normal: UIState()
|
||||
data class Error(val error: UIErrorType, val errorString: String? = null): UIState()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.profiles
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.nomoresat.dpitunnelcli.domain.usecases.*
|
||||
|
||||
class ProfilesViewModelFactory(val fetchAllProfilesUseCase: IFetchAllProfilesUseCase,
|
||||
val fetchProfileUseCase: IFetchProfileUseCase,
|
||||
val deleteProfileUseCase: IDeleteProfileUseCase,
|
||||
val renameProfileUseCase: IRenameProfileUseCase,
|
||||
val settingsUseCase: ISettingsUseCase,
|
||||
val enableDisableProfileUseCase: IEnableDisableProfileUseCase
|
||||
): ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.getConstructor(IFetchAllProfilesUseCase::class.java,
|
||||
IFetchProfileUseCase::class.java,
|
||||
IDeleteProfileUseCase::class.java,
|
||||
IRenameProfileUseCase::class.java,
|
||||
ISettingsUseCase::class.java,
|
||||
IEnableDisableProfileUseCase::class.java)
|
||||
.newInstance(fetchAllProfilesUseCase,
|
||||
fetchProfileUseCase,
|
||||
deleteProfileUseCase,
|
||||
renameProfileUseCase,
|
||||
settingsUseCase,
|
||||
enableDisableProfileUseCase)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.nomoresat.dpitunnelcli.ui.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import com.nomoresat.dpitunnelcli.R
|
||||
import com.nomoresat.dpitunnelcli.preferences.AppPreferences
|
||||
import com.nomoresat.dpitunnelcli.ui.activity.customIPs.CustomIPsActivity
|
||||
import com.nomoresat.dpitunnelcli.ui.activity.proxifiedApps.ProxifiedAppsActivity
|
||||
import com.nomoresat.dpitunnelcli.utils.Constants
|
||||
import com.nomoresat.dpitunnelcli.utils.MinMaxFilter
|
||||
import com.nomoresat.dpitunnelcli.utils.Utils
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
preferenceManager.sharedPreferencesName = AppPreferences.SETTINGS_STORAGE_NAME
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
|
||||
val appPreferences = AppPreferences.getInstance(requireContext())
|
||||
|
||||
val customCaBundle = findPreference<SwitchPreferenceCompat>("preference_custom_ca_bundle")
|
||||
customCaBundle!!.setOnPreferenceChangeListener { _, newValue ->
|
||||
appPreferences.caBundlePath = if (newValue as Boolean)
|
||||
requireContext().filesDir.absolutePath + "/${Constants.USER_CA_BUNDLE_FILE_NAME}"
|
||||
else
|
||||
requireContext().filesDir.absolutePath + "/${Constants.INBUILT_CA_BUNDLE_FILE_NAME}"
|
||||
true
|
||||
}
|
||||
|
||||
val caBundlePath = findPreference<Preference>("preference_ca_bundle_path")
|
||||
caBundlePath!!.setOnPreferenceClickListener {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "*/*"
|
||||
resultLauncher.launch(intent)
|
||||
true
|
||||
}
|
||||
|
||||
val proxifiedApps = findPreference<Preference>("preference_proxified_apps")
|
||||
proxifiedApps!!.setOnPreferenceClickListener {
|
||||
resultLauncher.launch(Intent(context, ProxifiedAppsActivity::class.java))
|
||||
true
|
||||
}
|
||||
|
||||
val proxyIP = findPreference<EditTextPreference>("preference_proxy_ip")
|
||||
proxyIP!!.setOnPreferenceChangeListener { _, newValue ->
|
||||
val isValid = Utils.validateIp(newValue.toString())
|
||||
if (!isValid)
|
||||
Toast.makeText(requireContext(), getString(R.string.preference_proxy_ip_invalid_ip), Toast.LENGTH_SHORT).show()
|
||||
isValid
|
||||
}
|
||||
|
||||
val proxyPort = findPreference<EditTextPreference>("preference_proxy_port")
|
||||
proxyPort!!.setOnBindEditTextListener {
|
||||
it.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
it.filters = arrayOf(MinMaxFilter(Constants.SERVER_PORT_RANGE))
|
||||
}
|
||||
|
||||
val customIPs = findPreference<Preference>("preference_dns_custom_ips")
|
||||
customIPs!!.setOnPreferenceClickListener {
|
||||
val intent = Intent(context, CustomIPsActivity::class.java)
|
||||
startActivity(intent)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
result?.data?.data?.also { uri ->
|
||||
val userCABundlePath = requireContext().filesDir.absolutePath + "/${Constants.USER_CA_BUNDLE_FILE_NAME}"
|
||||
val file = File(userCABundlePath)
|
||||
try {
|
||||
file.outputStream().use {
|
||||
requireContext().contentResolver.openInputStream(uri)?.copyTo(it)
|
||||
}
|
||||
AppPreferences.getInstance(requireContext()).caBundlePath = userCABundlePath
|
||||
} catch (exception: FileNotFoundException) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val resultLauncherProxifiedApps = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.nomoresat.dpitunnelcli.utils
|
||||
|
||||
import kotlinx.coroutines.flow.*
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.AutoConfigDefaults
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ConfiguredProfile
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncFirstAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncZeroAttack
|
||||
|
||||
class AutoConfigOutputFilter(private val _input: (String) -> Unit) {
|
||||
|
||||
private val _output = StringBuffer()
|
||||
|
||||
private var _defaults: AutoConfigDefaults? = null
|
||||
|
||||
private val _outputFlow = MutableStateFlow<String?>(null)
|
||||
val output: StateFlow<String?> = _outputFlow
|
||||
|
||||
private val _configuredProfile = MutableStateFlow<ConfiguredProfileState>(ConfiguredProfileState.Stopped)
|
||||
val configuredProfile: StateFlow<ConfiguredProfileState> = _configuredProfile
|
||||
|
||||
fun feed(output: String) {
|
||||
_output.append(output)
|
||||
processOutput()
|
||||
_outputFlow.value = _output.toString()
|
||||
}
|
||||
|
||||
fun reset(defaults: AutoConfigDefaults? = null) {
|
||||
defaults?.let { _defaults = defaults }
|
||||
_output.setLength(0)
|
||||
_configuredProfile.value = ConfiguredProfileState.InProcess(0)
|
||||
}
|
||||
|
||||
fun input(input: String) {
|
||||
_output.append(input)
|
||||
|
||||
_outputFlow.value = _output.toString()
|
||||
|
||||
_input(input)
|
||||
}
|
||||
|
||||
private fun processOutput() {
|
||||
with(_output.lines()) {
|
||||
when {
|
||||
last().startsWith(ENTER_SITE_PROMPT) -> input("${_defaults?.domain}\n")
|
||||
last().startsWith(DOH_PROMPT) -> input("${_defaults?.dohServer}\n")
|
||||
last().startsWith(CA_BUNDLE_PROMPT) -> input("${_defaults?.caBundlePath}\n")
|
||||
last().startsWith(INBUILT_DNS_PROMPT) -> input("${_defaults?.inBuiltDNS}\n")
|
||||
getOrNull(size - 2)?.startsWith(FAIL_RESOLVE_HOST_PROMPT) == true -> { // 1nd line from end
|
||||
_configuredProfile.value = ConfiguredProfileState.Error(ErrorType.ERROR_RESOLVE_DOMAIN_FAILED)
|
||||
}
|
||||
getOrNull(size - 3)?.startsWith(SUCCESSFUL_PROMPT) == true -> { // 2nd line from end
|
||||
val ret = parseOptions()
|
||||
if (ret == null) {
|
||||
_configuredProfile.value = ConfiguredProfileState.Error(ErrorType.ERROR_CONFIG_PARSE_FAILED)
|
||||
}
|
||||
else {
|
||||
_configuredProfile.value = ConfiguredProfileState.Success(ret)
|
||||
}
|
||||
}
|
||||
getOrNull(size - 3)?.startsWith(CALCULATING_HOPS) == true
|
||||
&& getOrNull(size - 2)?.startsWith(FAIL_PROMPT) == true -> {
|
||||
_configuredProfile.value = ConfiguredProfileState.Error(ErrorType.ERROR_CALCULATE_HOPS_FAILED)
|
||||
}
|
||||
getOrNull(size - 2)?.startsWith(NO_ATTACK_FOUND_PROMPT) == true -> {
|
||||
_configuredProfile.value = ConfiguredProfileState.Error(ErrorType.ERROR_NO_ATTACKS_FOUND)
|
||||
}
|
||||
getOrNull(size - 2)?.startsWith(TRYING_ATTACK_START) == true -> {
|
||||
getOrNull(size - 2)!!.removePrefix(TRYING_ATTACK_START).removeSuffix(TRYING_ATTACK_END).split('/').let {
|
||||
val curr = it.first().toIntOrNull()
|
||||
val all = it.last().toIntOrNull()
|
||||
if (curr != null && all != null)
|
||||
_configuredProfile.value = ConfiguredProfileState.InProcess(curr * 100 / all)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseOptions(): ConfiguredProfile? {
|
||||
// 2nd line from end
|
||||
_output.lines().let { it.getOrNull(it.size - 2) }?.split(' ')?.let { argsStr ->
|
||||
val configuredProfile = ConfiguredProfile(
|
||||
splitAtSni = false,
|
||||
wrongSeq = false,
|
||||
autoTtl = false,
|
||||
fakePacketsTtl = null,
|
||||
windowSize = null,
|
||||
windowScaleFactor = null,
|
||||
desyncAttacks = false,
|
||||
desyncZeroAttack = null,
|
||||
desyncFirstAttack = null
|
||||
)
|
||||
val args = Utils.getOpt(argsStr)
|
||||
for ((key,value) in args) {
|
||||
when(key) {
|
||||
"-desync-attacks" -> {
|
||||
configuredProfile.desyncAttacks = true
|
||||
value.first().split(',').forEach { when(it){
|
||||
"fake" -> configuredProfile.desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_FAKE
|
||||
"rst" -> configuredProfile.desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_RST
|
||||
"rstack" -> configuredProfile.desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_RSTACK
|
||||
"disorder" -> configuredProfile.desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_DISORDER
|
||||
"disorder_fake" -> configuredProfile.desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_DISORDER_FAKE
|
||||
"split" -> configuredProfile.desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_SPLIT
|
||||
"split_fake" -> configuredProfile.desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_SPLIT_FAKE
|
||||
} }
|
||||
}
|
||||
"-split-at-sni" -> configuredProfile.splitAtSni = true
|
||||
"-wrong-seq" -> configuredProfile.wrongSeq = true
|
||||
"-wsize" -> configuredProfile.windowSize = value.first().toInt()
|
||||
"-wsfactor" -> configuredProfile.windowScaleFactor = value.first().toInt()
|
||||
"-ttl" -> configuredProfile.fakePacketsTtl = value.first().toInt()
|
||||
}
|
||||
}
|
||||
return configuredProfile
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
enum class ErrorType {
|
||||
ERROR_NO_ATTACKS_FOUND,
|
||||
ERROR_RESOLVE_DOMAIN_FAILED,
|
||||
ERROR_CALCULATE_HOPS_FAILED,
|
||||
ERROR_CONFIG_PARSE_FAILED
|
||||
}
|
||||
|
||||
sealed class ConfiguredProfileState {
|
||||
data class InProcess(val progress: Int): ConfiguredProfileState()
|
||||
data class Success(val configuredProfile: ConfiguredProfile): ConfiguredProfileState()
|
||||
data class Error(val error: ErrorType) : ConfiguredProfileState()
|
||||
object Stopped: ConfiguredProfileState()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ENTER_SITE_PROMPT = "(http://example.com or https://example.com or example.com. Can contain port): "
|
||||
private const val DOH_PROMPT = "DoH server (press enter to use default"
|
||||
private const val CA_BUNDLE_PROMPT = "CA bundle path (press enter to use default location"
|
||||
private const val INBUILT_DNS_PROMPT = "DNS server (press enter to use default "
|
||||
|
||||
private const val SUCCESSFUL_PROMPT = "Configuration successful! Apply these options when run program:"
|
||||
private const val CALCULATING_HOPS = "\tCalculating network distance to server..."
|
||||
private const val TRYING_ATTACK_START = "\tTrying "
|
||||
private const val TRYING_ATTACK_END = "..."
|
||||
private const val NO_ATTACK_FOUND_PROMPT = "Failed to find any working attack!"
|
||||
private const val FAIL_RESOLVE_HOST_PROMPT = "Failed to resolve host "
|
||||
private const val FAIL_PROMPT = "\tFail"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.nomoresat.dpitunnelcli.utils
|
||||
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncFirstAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.DesyncZeroAttack
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.Profile
|
||||
import com.nomoresat.dpitunnelcli.domain.entities.ProxyMode
|
||||
|
||||
object Constants {
|
||||
val TTL_VALUE_RANGE = 1..255
|
||||
val TCP_WINDOW_SIZE_VALUE_RANGE = 1..65535
|
||||
val TCP_WINDOW_SCALE_FACTOR_VALUE_RANGE = 0..14
|
||||
val SPLIT_POSITION_VALUE_RANGE = 1..65535
|
||||
val SERVER_PORT_RANGE = 1..65535
|
||||
const val DPITUNNEL_DEFAULT_PORT = 8080
|
||||
val DPITUNNEL_DEFAULT_PROXY_MODE = ProxyMode.HTTP
|
||||
const val DPITUNNEL_BINARY_NAME = "libdpitunnel-cli.so"
|
||||
const val DPITUNNEL_DAEMON_PID_FILE = "/dev/dpitunnel-cli-daemon.pid"
|
||||
const val INBUILT_CA_BUNDLE_FILE_NAME = "ca.bundle"
|
||||
const val USER_CA_BUNDLE_FILE_NAME = "ca.bundle_user"
|
||||
const val CUSTOM_IPS_FILENAME = "custom-ips.txt"
|
||||
val DEFAULT_PROFILE = Profile(
|
||||
id = null,
|
||||
enabled = false,
|
||||
name = "",
|
||||
title = null,
|
||||
bufferSize = null,
|
||||
splitPosition = 3,
|
||||
splitAtSni = true,
|
||||
wrongSeq = false,
|
||||
autoTtl = true,
|
||||
fakePacketsTtl = null,
|
||||
windowSize = 1,
|
||||
windowScaleFactor = 6,
|
||||
inBuiltDNS = true,
|
||||
inBuiltDNSIP = "8.8.8.8",
|
||||
inBuiltDNSPort = null,
|
||||
doh = true,
|
||||
dohServer = "https://dns.google/dns-query",
|
||||
desyncAttacks = true,
|
||||
desyncZeroAttack = DesyncZeroAttack.DESYNC_ZERO_FAKE,
|
||||
desyncFirstAttack = DesyncFirstAttack.DESYNC_FIRST_DISORDER_FAKE
|
||||
)
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.nomoresat.dpitunnelcli.utils
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.widget.ScrollView
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
fun NestedScrollView.scrollToBottom() {
|
||||
smoothScrollTo(0, getChildAt(0).height)
|
||||
}
|
||||
|
||||
fun ScrollView.scrollToBottom() {
|
||||
smoothScrollTo(0, getChildAt(0).height)
|
||||
}
|
||||
|
||||
fun BroadcastReceiver.goAsync(
|
||||
coroutineScope: CoroutineScope,
|
||||
dispatcher: CoroutineDispatcher,
|
||||
block: suspend () -> Unit
|
||||
) {
|
||||
val pendingResult = goAsync()
|
||||
coroutineScope.launch(dispatcher) {
|
||||
block()
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.nomoresat.dpitunnelcli.utils
|
||||
|
||||
import android.text.InputFilter
|
||||
import android.text.Spanned
|
||||
|
||||
|
||||
class MinMaxFilter(private val range: IntRange): InputFilter{
|
||||
override fun filter(
|
||||
source: CharSequence,
|
||||
start: Int,
|
||||
end: Int,
|
||||
dest: Spanned,
|
||||
dstart: Int,
|
||||
dend: Int
|
||||
): CharSequence? {
|
||||
try {
|
||||
val inputStr = dest.toString() + source.toString()
|
||||
val inputInt = inputStr.toInt()
|
||||
if (inputInt in range)
|
||||
if (inputStr.first() == '0') { // Check for leading zeros
|
||||
if (inputStr.length == 1) return null
|
||||
} else
|
||||
return null
|
||||
} catch (nfe: NumberFormatException) {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
18
app/src/main/java/com/nomoresat/dpitunnelcli/utils/Utils.kt
Normal file
18
app/src/main/java/com/nomoresat/dpitunnelcli/utils/Utils.kt
Normal file
|
@ -0,0 +1,18 @@
|
|||
package com.nomoresat.dpitunnelcli.utils
|
||||
|
||||
import android.net.InetAddresses
|
||||
import android.os.Build
|
||||
import android.util.Patterns
|
||||
|
||||
object Utils {
|
||||
fun getOpt(args: List<String>) = args.fold(Pair(emptyMap<String, List<String>>(), "")) { (map, lastKey), elem ->
|
||||
if (elem.startsWith("-")) Pair(map + (elem to emptyList()), elem)
|
||||
else Pair(map + (lastKey to map.getOrElse(lastKey) { emptyList() } + elem), lastKey)
|
||||
}.first
|
||||
|
||||
fun validateIp(ip: String) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
InetAddresses.isNumericAddress(ip)
|
||||
} else {
|
||||
Patterns.IP_ADDRESS.matcher(ip).matches() || ip == "0.0.0.0"
|
||||
}
|
||||
}
|
5
app/src/main/res/drawable/ic_add_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_add_24dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_bookmark_added_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_bookmark_added_24dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,21l-7,-3l-7,3V5c0,-1.1 0.9,-2 2,-2l7,0c-0.63,0.84 -1,1.87 -1,3c0,2.76 2.24,5 5,5c0.34,0 0.68,-0.03 1,-0.1V21zM17.83,9L15,6.17l1.41,-1.41l1.41,1.41l3.54,-3.54l1.41,1.41L17.83,9z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_cancel_white_96dp.xml
Normal file
5
app/src/main/res/drawable/ic_cancel_white_96dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="96dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="96dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM15.59,7L12,10.59 8.41,7 7,8.41 10.59,12 7,15.59 8.41,17 12,13.41 15.59,17 17,15.59 13.41,12 17,8.41z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_check_all_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_check_all_24dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M3,5h2L5,3c-1.1,0 -2,0.9 -2,2zM3,13h2v-2L3,11v2zM7,21h2v-2L7,19v2zM3,9h2L5,7L3,7v2zM13,3h-2v2h2L13,3zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM5,21v-2L3,19c0,1.1 0.9,2 2,2zM3,17h2v-2L3,15v2zM9,3L7,3v2h2L9,3zM11,21h2v-2h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2zM19,9h2L21,7h-2v2zM19,17h2v-2h-2v2zM15,21h2v-2h-2v2zM15,5h2L17,3h-2v2zM7,17h10L17,7L7,7v10zM9,9h6v6L9,15L9,9z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_check_circle_white_96dp.xml
Normal file
5
app/src/main/res/drawable/ic_check_circle_white_96dp.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="96dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="96dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_dashboard_24dp.xml
Normal file
10
app/src/main/res/drawable/ic_dashboard_24dp.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
|
||||
</vector>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue