diff --git a/README.md b/README.md index ea2333c..902e595 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,63 @@ -# Magisk Installer +# V2ray Magisk Module -**Update `README.md` if you want to submit your module to the online repo!** +This is a v2ray module for Magisk, and includes binaries for arm, arm64, x86, x64. -For more information about how to use this module installer, please refer to [documentations](https://topjohnwu.github.io/Magisk/guides.html) -If you are not familiar with the Markdown syntax, you can start by experimenting on GitHub's online Markdown editor, which will let you preview before publishing. If you need more help, the [Markdown Cheat Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) will be handy. + +## Included + +* [V2Ray]() +* [magisk-module-installer](https://github.com/topjohnwu/magisk-module-installer) + + + +## Install + +- You can download the release installer zip file and install it via the Magisk Manager App. + + + +## Config + +V2ray config file is store in `/data/v2ray/config.json` . + +Please make sure the config is correct. You can do that by running a command `v2ray -test -config /data/v2ray/config.json` in android terminal. + + + +## Start/Stop service + +- V2ray service is autorun on boot. If you don't want it run automatically, you can just add a file `/data/v2ray/no-autostart` . + +- You can also start / stop manually by run the service script in `$MODDIR` . For example, in my environment , the script's absolute path is `/sbin/.magisk/img/v2ray/v2ray.service` . + +- So, if you want to start v2ray service, just run: + + `/sbin/.magisk/img/v2ray/v2ray.service start` + + or stop v2ray service: + + `/sbin/.magisk/img/v2ray/v2ray.service stop ` + + or restart v2ray service: + + `/sbin/.magisk/img/v2ray/v2ray.service restart` + + + +## Uninstall + +1. Uninstall the module via Magisk Manager App. +2. Remove the directory with command `rm -rf /data/v2ray` . + + + +## Project V + +Project V is a set of network tools that help you to build your own computer network. It secures your network connections and thus protects your privacy. See [ProjectV website](https://www.v2ray.com/) for more information. + + + +## License + +[The MIT License (MIT)](https://raw.githubusercontent.com/v2ray/v2ray-core/master/LICENSE) \ No newline at end of file diff --git a/common/service.sh b/common/service.sh index e891a9b..b370f94 100644 --- a/common/service.sh +++ b/common/service.sh @@ -7,3 +7,5 @@ MODDIR=${0%/*} # This script will be executed in late_start service mode + +if [ ! -f /data/v2ray/no-autostart ] ; then $MODDIR/v2ray.service start ; fi diff --git a/install.sh b/install.sh index e999dcf..7e7bf97 100644 --- a/install.sh +++ b/install.sh @@ -31,7 +31,7 @@ PROPFILE=false POSTFSDATA=false # Set to true if you need late_start service script -LATESTARTSERVICE=false +LATESTARTSERVICE=true ########################################################################################## # Replace list @@ -123,7 +123,7 @@ REPLACE=" print_modname() { ui_print "*******************************" - ui_print " Magisk Module Template " + ui_print " V2Ray for Android " ui_print "*******************************" } @@ -134,6 +134,24 @@ on_install() { # Extend/change the logic to whatever you want ui_print "- Extracting module files" unzip -o "$ZIPFILE" 'system/*' -d $MODPATH >&2 + + # install v2ray execute file + ui_print "- Install V2Ray core $ARCH execute files" + mkdir -p $MODPATH/system/bin + mkdir -p $MODPATH/system/etc + unzip -j -o "$ZIPFILE" "v2ray/etc/v2ray.service" -d $MODPATH >&2 + unzip -j -o "$ZIPFILE" "v2ray/bin/$ARCH/*" -d $MODPATH/system/bin >&2 + + # copy v2ray data and config + ui_print "- Copy V2Ray config and data files" + mkdir -p /data/v2ray + mkdir -p /data/v2ray/run + [ -f /data/v2ray/config.json ] || \\ + unzip -j -o "$ZIPFILE" "v2ray/etc/config.json" -d /data/v2ray >&2 + unzip -j -o "$ZIPFILE" "v2ray/etc/resolv.conf" -d /data/v2ray >&2 + unzip -j -o "$ZIPFILE" "v2ray/etc/geosite.dat" -d /data/v2ray >&2 + unzip -j -o "$ZIPFILE" "v2ray/etc/geoip.dat" -d /data/v2ray >&2 + ln -s /data/v2ray/resolv.conf $MODPATH/system/etc/resolv.conf } # Only some special files require specific permissions @@ -141,8 +159,13 @@ on_install() { # The default permissions should be good enough for most cases set_permissions() { + inet_uid="3003" # The following is the default rule, DO NOT remove set_perm_recursive $MODPATH 0 0 0755 0644 + set_perm $MODPATH/v2ray.service 0 0 0755 + set_perm $MODPATH/system/bin/v2ray ${inet_uid} ${inet_uid} 6755 + set_perm $MODPATH/system/bin/v2ctl ${inet_uid} ${inet_uid} 6755 + set_perm /data/v2ray ${inet_uid} ${inet_uid} 0755 # Here are some examples: # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 diff --git a/module.prop b/module.prop index 8b32b58..5ffe525 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ -id=template -name=Template Module -version=v1 -versionCode=1 -author=topjohnwu -description=A short description +id=v2ray +name=V2ray for Android +version=v4.18 +versionCode=20190329 +author=chendefine +description=V2ray core with service scripts for Android diff --git a/v2ray/etc/config.json b/v2ray/etc/config.json new file mode 100644 index 0000000..e79155d --- /dev/null +++ b/v2ray/etc/config.json @@ -0,0 +1,142 @@ +// Config file of V2Ray. This file follows standard JSON format, with comments support. +// Uncomment entries below to satisfy your needs. Also read our manual for more detail at +// https://www.v2ray.com/ +{ + "log": { + // By default, V2Ray writes access log to stdout. + // "access": "/path/to/access/log/file", + + // By default, V2Ray write error log to stdout. + // "error": "/path/to/error/log/file", + + // Log level, one of "debug", "info", "warning", "error", "none" + "loglevel": "warning" + }, + // List of inbound proxy configurations. + "inbounds": [{ + // Port to listen on. You may need root access if the value is less than 1024. + "port": 1080, + + // IP address to listen on. Change to "0.0.0.0" to listen on all network interfaces. + "listen": "127.0.0.1", + + // Tag of the inbound proxy. May be used for routing. + "tag": "socks-inbound", + + // Protocol name of inbound proxy. + "protocol": "socks", + + // Settings of the protocol. Varies based on protocol. + "settings": { + "auth": "noauth", + "udp": false, + "ip": "127.0.0.1" + }, + + // Enable sniffing on TCP connection. + "sniffing": { + "enabled": true, + // Target domain will be overriden to the one carried by the connection, if the connection is HTTP or HTTPS. + "destOverride": ["http", "tls"] + } + }], + // List of outbound proxy configurations. + "outbounds": [{ + // Protocol name of the outbound proxy. + "protocol": "freedom", + + // Settings of the protocol. Varies based on protocol. + "settings": {}, + + // Tag of the outbound. May be used for routing. + "tag": "direct" + },{ + "protocol": "blackhole", + "settings": {}, + "tag": "blocked" + }], + + // Transport is for global transport settings. If you have multiple transports with same settings + // (say mKCP), you may put it here, instead of in each individual inbound/outbounds. + //"transport": {}, + + // Routing controls how traffic from inbounds are sent to outbounds. + "routing": { + "domainStrategy": "IPOnDemand", + "rules":[ + { + // Blocks access to private IPs. Remove this if you want to access your router. + "type": "field", + "ip": ["geoip:private"], + "outboundTag": "blocked" + }, + { + // Blocks major ads. + "type": "field", + "domain": ["geosite:category-ads"], + "outboundTag": "blocked" + } + ] + }, + + // Dns settings for domain resolution. + "dns": { + // Static hosts, similar to hosts file. + "hosts": { + // Match v2ray.com to another domain on CloudFlare. This domain will be used when querying IPs for v2ray.com. + "domain:v2ray.com": "www.vicemc.net", + + // The following settings help to eliminate DNS poisoning in mainland China. + // It is safe to comment these out if this is not the case for you. + "domain:github.io": "pages.github.com", + "domain:wikipedia.org": "www.wikimedia.org", + "domain:shadowsocks.org": "electronicsrealm.com" + }, + "servers": [ + "1.1.1.1", + { + "address": "114.114.114.114", + "port": 53, + // List of domains that use this DNS first. + "domains": [ + "geosite:cn" + ] + }, + "8.8.8.8", + "localhost" + ] + }, + + // Policy controls some internal behavior of how V2Ray handles connections. + // It may be on connection level by user levels in 'levels', or global settings in 'system.' + "policy": { + // Connection policys by user levels + "levels": { + "0": { + "uplinkOnly": 0, + "downlinkOnly": 0 + } + }, + "system": { + "statsInboundUplink": false, + "statsInboundDownlink": false + } + }, + + // Stats enables internal stats counter. + // This setting can be used together with Policy and Api. + //"stats":{}, + + // Api enables gRPC APIs for external programs to communicate with V2Ray instance. + //"api": { + //"tag": "api", + //"services": [ + // "HandlerService", + // "LoggerService", + // "StatsService" + //] + //}, + + // You may add other entries to the configuration, but they will not be recognized by V2Ray. + "other": {} +} diff --git a/v2ray/etc/resolv.conf b/v2ray/etc/resolv.conf new file mode 100644 index 0000000..f81b9a9 --- /dev/null +++ b/v2ray/etc/resolv.conf @@ -0,0 +1,4 @@ +nameserver 114.114.114.114 +nameserver 223.5.5.5 +nameserver 1.1.1.1 +nameserver 9.9.9.9 diff --git a/v2ray/etc/v2ray.service b/v2ray/etc/v2ray.service new file mode 100644 index 0000000..80368fa --- /dev/null +++ b/v2ray/etc/v2ray.service @@ -0,0 +1,59 @@ +#!/system/bin/sh + +NAME=v2ray +V2RAY=/system/bin/${NAME} +DATAPATH=/data/${NAME} +RUNPATH=${DATAPATH}/run +PIDFILE=${RUNPATH}/${NAME}.pid +CONFFILE=${DATAPATH}/config.json + +V2RAY_OPTS="-config ${CONFFILE}" + +export V2RAY_LOCATION_ASSET=${DATAPATH} + +probe_service() { + PID=`cat ${PIDFILE} 2>/dev/null` + CMDFILE="/proc/${PID}/cmdline" + if [ -f ${PIDFILE} ] && [ -f ${CMDFILE} ] && [ `grep -c ${NAME} ${CMDFILE}` -gt 0 ] ; then + echo "${NAME} service is running. ( PID: ${PID} )" + return 0 + else + return 1 + fi +} + +do_start() { + if ! probe_service && [ -f ${CONFFILE} ] && ${V2RAY} ${V2RAY_OPTS} -test ; then + echo "Starting ${NAME} service." + mkdir -p ${RUNPATH} + chown -R inet:inet ${DATAPATH} + chown inet:inet ${V2RAY} + chmod 6755 ${V2RAY} + ${V2RAY} ${V2RAY_OPTS} & + echo -n $! > ${PIDFILE} + fi +} + +do_stop() { + if probe_service ; then + echo "Stopping ${NAME} service." + kill ${PID} + fi + rm -f ${PIDFILE} +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + do_start + ;; + *) + echo "$0: usage: $0 {start|stop|restart}" + ;; +esac