Skip to content

Commit

Permalink
Merge pull request #16 from tindy2013/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 authored Aug 28, 2019
2 parents 9feec82 + ab63389 commit 616ea75
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 477 deletions.
74 changes: 37 additions & 37 deletions config.macos.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
#!/bin/bash
set -e
#initialize sudo so that no password entering during installation
sudo -v

echo installing brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

#install most libraries and client through brew
brew install cmake git wget [email protected] libpng yaml-cpp freetype rapidjson shadowsocks-libev

echo downloading and compiling pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake .
sudo make install -j8
#fix install error
#sudo install libPNGwriter.a /usr/local/lib/
cd ..

echo downloading and compiling shadowsocksr-libev
git clone https://github.com/shadowsocksrr/shadowsocksr-libev
cd shadowsocksr-libev
./configure --with-openssl-lib=/usr/local/opt/openssl/lib --with-openssl-include=/usr/local/opt/openssl/include --disable-documentation
make -j8
#fix dynamic lib reference error
install_name_tool -change @rpath/libssl.1.1.dylib /usr/local/opt/[email protected]/lib/libssl.1.1.dylib src/ss-local
install_name_tool -change @rpath/libcrypto.1.1.dylib /usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib src/ss-local
#will not directly install this one, use another method
sudo install src/ss-local /usr/local/bin/ssr-local
cd ..

echo installing v2ray from brew
brew tap v2ray/v2ray
brew install v2ray-core

echo all done!
#!/bin/bash
set -e
#initialize sudo so that no password entering during installation
sudo -v

echo installing brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

#install most libraries and client through brew
brew install cmake git wget [email protected] libpng yaml-cpp freetype rapidjson shadowsocks-libev

echo downloading and compiling pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake .
sudo make install -j8
#fix install error
#sudo install libPNGwriter.a /usr/local/lib/
cd ..

echo downloading and compiling shadowsocksr-libev
git clone https://github.com/shadowsocksrr/shadowsocksr-libev
cd shadowsocksr-libev
./configure --with-openssl-lib=/usr/local/opt/openssl/lib --with-openssl-include=/usr/local/opt/openssl/include --disable-documentation
make -j8
#fix dynamic lib reference error
install_name_tool -change @rpath/libssl.1.1.dylib /usr/local/opt/[email protected]/lib/libssl.1.1.dylib src/ss-local
install_name_tool -change @rpath/libcrypto.1.1.dylib /usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib src/ss-local
#will not directly install this one, use another method
sudo install src/ss-local /usr/local/bin/ssr-local
cd ..

echo installing v2ray from brew
brew tap v2ray/v2ray
brew install v2ray-core

echo all done!
64 changes: 32 additions & 32 deletions config.termux.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/bin/bash
set -e
pkg upgrade

#first install core utilities
pkg install -y git cmake clang autoconf automake libtool

#then install precompiled library from repo
pkg install -y openssl-static libcurl-static libpng-static libev-static libz-static freetype-static

#get rapidjson
git clone https://github.com/tencent/rapidjson
cd rapidjson
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get yaml-cpp
git clone https://github.com/jbeder/yaml-cpp
cd yaml-cpp
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

echo all done!
#!/bin/bash
set -e
pkg upgrade

#first install core utilities
pkg install -y git cmake clang autoconf automake libtool

#then install precompiled library from repo
pkg install -y openssl-static libcurl-static libpng-static libev-static libz-static freetype-static

#get rapidjson
git clone https://github.com/tencent/rapidjson
cd rapidjson
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get yaml-cpp
git clone https://github.com/jbeder/yaml-cpp
cd yaml-cpp
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

echo all done!
40 changes: 14 additions & 26 deletions geoip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "geoip.h"
#include "misc.h"
#include "logger.h"
#include "rapidjson_extra.h"

using namespace rapidjson;

Expand Down Expand Up @@ -63,32 +64,19 @@ geoIPInfo getGeoIPInfo(string ip, string proxy)
return info;
}
}
if(json.HasMember("ip"))
info.ip = json["ip"].GetString();
if(json.HasMember("country_code"))
info.country_code = json["country_code"].GetString();
if(json.HasMember("country"))
info.country = json["country"].GetString();
if(json.HasMember("region_code"))
info.region_code = json["region_code"].GetString();
if(json.HasMember("region"))
info.region = json["region"].GetString();
if(json.HasMember("city"))
info.city = json["city"].GetString();
if(json.HasMember("postal_code"))
info.postal_code = json["postal_code"].GetString();
if(json.HasMember("continent_code"))
info.continent_code = json["continent_code"].GetString();
if(json.HasMember("latitude"))
info.latitude = to_string(json["latitude"].GetFloat());
if(json.HasMember("longitude"))
info.longitude = to_string(json["longitude"].GetFloat());
if(json.HasMember("organization"))
info.organization = json["organization"].GetString();
if(json.HasMember("asn"))
info.asn = to_string(json["asn"].GetInt());
if(json.HasMember("timezone"))
info.timezone = json["timezone"].GetString();
info.ip = GetMember(json, "ip");
info.country_code = GetMember(json, "country_code");
info.country = GetMember(json, "country");
info.region_code = GetMember(json, "region_code");
info.region = GetMember(json, "region");
info.city = GetMember(json, "city");
info.postal_code = GetMember(json, "postal_code");
info.continent_code = GetMember(json, "continent_code");
info.latitude = GetMember(json, "latitude");
info.longitude = GetMember(json, "longitude");
info.organization = GetMember(json, "organization");
info.asn = GetMember(json, "asn");
info.timezone = GetMember(json, "timezone");

writeLog(LOG_TYPE_GEOIP, "Parse GeoIP complete. Leaving.");
return info;
Expand Down
137 changes: 1 addition & 136 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,8 @@ int main(int argc, char* argv[])
{
vector<nodeInfo> nodes;
nodeInfo node;
string link, strSub, strInput, fileContent, strProxy;
string link;
string curPNGPath, curPNGPathPrefix;
//int linkType = -1;
cout << fixed;
cout << setprecision(2);
signal(SIGINT, signalHandler);
Expand Down Expand Up @@ -915,140 +914,6 @@ int main(int argc, char* argv[])
writeLog(LOG_TYPE_ERROR, "No valid link found.");
printMsgDirect(SPEEDTEST_ERROR_NORECOGLINK, rpcmode);
}
/*
writeLog(LOG_TYPE_INFO, "Received Link.");
if(strFind(link, "vmess://"))
linkType = SPEEDTEST_MESSAGE_FOUNDVMESS;
else if(strFind(link, "ss://"))
linkType = SPEEDTEST_MESSAGE_FOUNDSS;
else if(strFind(link, "ssr://"))
linkType = SPEEDTEST_MESSAGE_FOUNDSSR;
else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS;
else if(strFind(link, "http://") || strFind(link, "https://") || strFind(link, "surge:///install-config"))
linkType = SPEEDTEST_MESSAGE_FOUNDSUB;
else if(link == "data:upload")
linkType = SPEEDTEST_MESSAGE_FOUNDUPD;
else if(fileExist(link))
linkType = SPEEDTEST_MESSAGE_FOUNDLOCAL;
switch(linkType)
{
case SPEEDTEST_MESSAGE_FOUNDSUB:
printMsgDirect(SPEEDTEST_MESSAGE_FOUNDSUB, rpcmode);
if(!rpcmode)
{
printMsgDirect(SPEEDTEST_MESSAGE_GROUP, rpcmode);
getline(cin, strInput);
if(strInput.size())
{
custom_group = GBKToUTF8(strInput);
writeLog(LOG_TYPE_INFO, "Received custom group: " + custom_group);
}
}
switchCodepage();
writeLog(LOG_TYPE_INFO, "Downloading subscription data...");
printMsgDirect(SPEEDTEST_MESSAGE_FETCHSUB, rpcmode);
if(strFind(link, "surge:///install-config")) //surge config link
link = UrlDecode(getUrlArg(link, "url"));
strSub = webGet(link);
if(strSub.size() == 0)
{
//try to get it again with system proxy
strProxy = getSystemProxy();
if(strProxy != "")
strSub = webGet(link, strProxy);
}
writeLog(LOG_TYPE_INFO, "Parsing subscription data...");
if(strSub.size())
{
explodeConfContent(strSub, override_conf_port, socksport, ss_libev, ssr_libev, &nodes, &exclude_remarks, &include_remarks);
batchTest(nodes);
writeLog(LOG_TYPE_INFO, "Subscription test completed.");
}
else
{
writeLog(LOG_TYPE_ERROR, "Cannot download subscription data.");
printMsgDirect(SPEEDTEST_ERROR_INVALIDSUB, rpcmode);
}
break;
case SPEEDTEST_MESSAGE_FOUNDLOCAL:
printMsgDirect(SPEEDTEST_MESSAGE_FOUNDLOCAL, rpcmode);
if(!rpcmode)
{
printMsgDirect(SPEEDTEST_MESSAGE_GROUP, rpcmode);
getline(cin, strInput);
if(strInput.size())
{
custom_group = GBKToUTF8(strInput);
writeLog(LOG_TYPE_INFO, "Received custom group: " + custom_group);
}
}
switchCodepage();
writeLog(LOG_TYPE_INFO, "Parsing configuration file data...");
printMsgDirect(SPEEDTEST_MESSAGE_PARSING, rpcmode);
if(explodeConf(link, override_conf_port, socksport, ss_libev, ssr_libev, &nodes, &exclude_remarks, &include_remarks) == SPEEDTEST_ERROR_UNRECOGFILE)
{
printMsgDirect(SPEEDTEST_ERROR_UNRECOGFILE, rpcmode);
writeLog(LOG_TYPE_ERROR, "Invalid configuration file!");
}
else
{
batchTest(nodes);
}
writeLog(LOG_TYPE_INFO, "Configuration test completed.");
break;
case SPEEDTEST_MESSAGE_FOUNDUPD:
printMsgDirect(SPEEDTEST_MESSAGE_FOUNDUPD, rpcmode);
cin.clear();
//now we should ready to receive a large amount of data from stdin
getline(cin, fileContent);
//writeLog(LOG_TYPE_RAW, fileContent);
fileContent = base64_decode(fileContent.substr(fileContent.find(",") + 1));
writeLog(LOG_TYPE_RAW, fileContent);
writeLog(LOG_TYPE_INFO, "Parsing configuration file data...");
printMsgDirect(SPEEDTEST_MESSAGE_PARSING, rpcmode);
if(explodeConfContent(fileContent, override_conf_port, socksport, ss_libev, ssr_libev, &nodes, &exclude_remarks, &include_remarks) == SPEEDTEST_ERROR_UNRECOGFILE)
{
printMsgDirect(SPEEDTEST_ERROR_UNRECOGFILE, rpcmode);
writeLog(LOG_TYPE_ERROR, "Invalid configuration file!");
}
else
{
batchTest(nodes);
}
writeLog(LOG_TYPE_INFO, "Configuration test completed.");
break;
default:
if(linkType > 0)
{
node_count = 1;
switchCodepage();
printMsg(linkType, &node, rpcmode);
explode(link, ss_libev, ssr_libev, override_conf_port, socksport, &node);
if(custom_group.size() != 0)
node.group = custom_group;
if(node.server == "")
{
writeLog(LOG_TYPE_ERROR, "No valid link found.");
printMsgDirect(SPEEDTEST_ERROR_NORECOGLINK, rpcmode);
}
else
{
printMsgDirect(SPEEDTEST_MESSAGE_BEGIN, rpcmode);
printMsg(SPEEDTEST_MESSAGE_GOTSERVER, &node, rpcmode);
singleTest(&node);
}
writeLog(LOG_TYPE_INFO, "Single node test completed.");
}
else
{
writeLog(LOG_TYPE_ERROR, "No valid link found.");
printMsgDirect(SPEEDTEST_ERROR_NORECOGLINK, rpcmode);
}
}
*/
logEOF();
printMsgDirect(SPEEDTEST_MESSAGE_EOF, rpcmode);
sleep(1);
Expand Down
42 changes: 42 additions & 0 deletions rapidjson_extra.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "rapidjson_extra.h"

void operator >> (const rapidjson::Value& value, std::string& i)
{
if(value.IsNull())
i = std::string();
else if(value.IsInt64())
i = std::to_string(value.GetInt64());
else if(value.IsDouble())
i = std::to_string(value.GetDouble());
else if(value.IsString())
i = std::string(value.GetString());
else
i = std::string();
}

void operator >> (const rapidjson::Value& value, int& i)
{
if(value.IsNull())
i = 0;
else if(value.IsInt())
i = value.GetInt();
else if(value.IsString())
i = std::stoi(value.GetString());
else
i = 0;
}

std::string GetMember(const rapidjson::Value& value, std::string member)
{
std::string retStr;
if(value.HasMember(member.data()))
value[member.data()] >> retStr;
return retStr;
}

void GetMember(const rapidjson::Value& value, std::string member, std::string* target)
{
std::string retStr = GetMember(value, member);
if(retStr.size())
target->assign(retStr);
}
Loading

0 comments on commit 616ea75

Please sign in to comment.