mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Enhancements
Add support for applying renames/Emojis to a specific group. Add support for adding stream and expiry info to SSD subscriptions. Optimize codes.
This commit is contained in:
5 files changed
+94
-36
No files matched your search
+1
-1
@@ -1185,7 +1185,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
else if(target == "ssd")
|
else if(target == "ssd")
|
||||||
{
|
{
|
||||||
std::cerr<<"SSD"<<std::endl;
|
std::cerr<<"SSD"<<std::endl;
|
||||||
output_content = netchToSSD(nodes, group, ext);
|
output_content = netchToSSD(nodes, group, subInfo, ext);
|
||||||
if(upload == "true")
|
if(upload == "true")
|
||||||
uploadGist("ssd", upload_path, output_content, false);
|
uploadGist("ssd", upload_path, output_content, false);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -897,15 +897,15 @@ void shortDisassemble(int source, unsigned short &num_a, unsigned short &num_b)
|
|||||||
num_b = (unsigned short)(source >> 16);
|
num_b = (unsigned short)(source >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
int to_int(const std::string &str, int def_vaule)
|
int to_int(const std::string &str, int def_value)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char c;
|
char c;
|
||||||
std::stringstream ss(str);
|
std::stringstream ss(str);
|
||||||
if(!(ss >> retval))
|
if(!(ss >> retval))
|
||||||
return def_vaule;
|
return def_value;
|
||||||
else if(ss >> c)
|
else if(ss >> c)
|
||||||
return def_vaule;
|
return def_value;
|
||||||
else
|
else
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -55,7 +55,6 @@ void urlParse(const std::string &url, std::string &host, std::string &path, int
|
|||||||
void removeUTF8BOM(std::string &data);
|
void removeUTF8BOM(std::string &data);
|
||||||
int shortAssemble(unsigned short num_a, unsigned short num_b);
|
int shortAssemble(unsigned short num_a, unsigned short num_b);
|
||||||
void shortDisassemble(int source, unsigned short &num_a, unsigned short &num_b);
|
void shortDisassemble(int source, unsigned short &num_a, unsigned short &num_b);
|
||||||
int to_int(const std::string &str, int def_vaule = 0);
|
|
||||||
std::string UTF8ToCodePoint(const std::string &data);
|
std::string UTF8ToCodePoint(const std::string &data);
|
||||||
std::string GetEnv(const std::string &name);
|
std::string GetEnv(const std::string &name);
|
||||||
|
|
||||||
@@ -91,6 +90,21 @@ template <typename T> static inline void eraseElements(T &target)
|
|||||||
T().swap(target);
|
T().swap(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> static inline T to_number(const std::string &str, T def_value)
|
||||||
|
{
|
||||||
|
T retval = 0.0;
|
||||||
|
char c;
|
||||||
|
std::stringstream ss(str);
|
||||||
|
if(!(ss >> retval))
|
||||||
|
return def_value;
|
||||||
|
else if(ss >> c)
|
||||||
|
return def_value;
|
||||||
|
else
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int to_int(const std::string &str, int def_value = 0);
|
||||||
|
|
||||||
#ifndef HAVE_TO_STRING
|
#ifndef HAVE_TO_STRING
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
|
|||||||
+74
-30
@@ -242,23 +242,34 @@ std::string vmessLinkConstruct(std::string remarks, std::string add, std::string
|
|||||||
return sb.GetString();
|
return sb.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string nodeRename(std::string remark, const string_array &rename_array)
|
std::string nodeRename(std::string remark, int groupID, const string_array &rename_array)
|
||||||
{
|
{
|
||||||
string_array vArray;
|
string_array vArray;
|
||||||
|
int targetGroupID = groupID;
|
||||||
|
string_size pos;
|
||||||
|
|
||||||
for(const std::string &x : rename_array)
|
for(const std::string &x : rename_array)
|
||||||
{
|
{
|
||||||
vArray = split(x, "@");
|
vArray = split(x, "@");
|
||||||
if(vArray.size() == 1)
|
if(vArray.size() == 1)
|
||||||
{
|
{
|
||||||
remark = regReplace(remark, vArray[0], "");
|
vArray.emplace_back("");
|
||||||
}
|
}
|
||||||
else if(vArray.size() == 2)
|
else if(vArray.size() != 2)
|
||||||
{
|
|
||||||
remark = regReplace(remark, vArray[0], vArray[1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
|
if(startsWith(vArray[0], "!!GROUPID="))
|
||||||
|
{
|
||||||
|
pos = vArray[0].find("!!", vArray[0].find("!!") + 2);
|
||||||
|
if(pos != vArray[0].npos)
|
||||||
|
{
|
||||||
|
targetGroupID = to_int(vArray[0].substr(10, pos - 10), groupID);
|
||||||
|
vArray[0] = vArray[0].substr(pos + 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(groupID == targetGroupID)
|
||||||
|
remark = regReplace(remark, vArray[0], vArray[1]);
|
||||||
}
|
}
|
||||||
return remark;
|
return remark;
|
||||||
}
|
}
|
||||||
@@ -276,15 +287,29 @@ std::string removeEmoji(std::string remark)
|
|||||||
return remark;
|
return remark;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string addEmoji(std::string remark, const string_array &emoji_array)
|
std::string addEmoji(std::string remark, int groupID, const string_array &emoji_array)
|
||||||
{
|
{
|
||||||
string_array vArray;
|
string_array vArray;
|
||||||
|
int targetGroupID = groupID;
|
||||||
|
string_size pos;
|
||||||
|
|
||||||
for(const std::string &x : emoji_array)
|
for(const std::string &x : emoji_array)
|
||||||
{
|
{
|
||||||
vArray = split(x, ",");
|
vArray = split(x, ",");
|
||||||
if(vArray.size() != 2)
|
if(vArray.size() != 2)
|
||||||
continue;
|
continue;
|
||||||
if(regFind(remark, vArray[0]))
|
if(startsWith(vArray[0], "!!GROUPID="))
|
||||||
|
{
|
||||||
|
pos = vArray[0].find("!!", vArray[0].find("!!") + 2);
|
||||||
|
if(pos != vArray[0].npos)
|
||||||
|
{
|
||||||
|
targetGroupID = to_int(vArray[0].substr(10, pos - 10), groupID);
|
||||||
|
vArray[0] = vArray[0].substr(pos + 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(groupID == targetGroupID && regFind(remark, vArray[0]))
|
||||||
{
|
{
|
||||||
remark = vArray[1] + " " + remark;
|
remark = vArray[1] + " " + remark;
|
||||||
break;
|
break;
|
||||||
@@ -566,12 +591,12 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -836,12 +861,12 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1048,12 +1073,12 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1120,12 +1145,12 @@ std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1193,12 +1218,12 @@ std::string netchToSSR(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1254,12 +1279,12 @@ std::string netchToVMess(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1337,12 +1362,12 @@ void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rules
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1561,12 +1586,12 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1735,7 +1760,7 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
|
|||||||
rulesetToSurge(ini, ruleset_content_array, -1, ext.overwrite_original_rules, ext.managed_config_prefix);
|
rulesetToSurge(ini, ruleset_content_array, -1, ext.overwrite_original_rules, ext.managed_config_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_settings &ext)
|
std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::string &userinfo, extra_settings &ext)
|
||||||
{
|
{
|
||||||
rapidjson::Document json;
|
rapidjson::Document json;
|
||||||
rapidjson::StringBuffer sb;
|
rapidjson::StringBuffer sb;
|
||||||
@@ -1757,17 +1782,36 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
|
|||||||
writer.String("aes-128-gcm");
|
writer.String("aes-128-gcm");
|
||||||
writer.Key("password");
|
writer.Key("password");
|
||||||
writer.String("password");
|
writer.String("password");
|
||||||
|
if(userinfo.size())
|
||||||
|
{
|
||||||
|
std::string data = replace_all_distinct(userinfo, "; ", "&");
|
||||||
|
std::string upload = getUrlArg(data, "upload"), download = getUrlArg(data, "download"), total = getUrlArg(data, "total"), expiry = getUrlArg(data, "expire");
|
||||||
|
double used = (to_number(upload, 0.0) + to_number(download, 0.0)) / std::pow(1024, 3) * 1.0, tot = to_number(total, 0.0) / std::pow(1024, 3) * 1.0;
|
||||||
|
writer.Key("traffic_used");
|
||||||
|
writer.Double(used);
|
||||||
|
writer.Key("traffic_total");
|
||||||
|
writer.Double(tot);
|
||||||
|
if(expiry.size())
|
||||||
|
{
|
||||||
|
const time_t rawtime = to_int(expiry);
|
||||||
|
char buffer[30];
|
||||||
|
struct tm *dt = localtime(&rawtime);
|
||||||
|
strftime(buffer, sizeof(buffer), "%F %R", dt);
|
||||||
|
writer.Key("expiry");
|
||||||
|
writer.String(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
writer.Key("servers");
|
writer.Key("servers");
|
||||||
writer.StartArray();
|
writer.StartArray();
|
||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
@@ -1877,12 +1921,12 @@ void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rul
|
|||||||
|
|
||||||
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
|
||||||
{
|
{
|
||||||
x.remarks = nodeRename(x.remarks, ext.rename_array);
|
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
|
||||||
if(ext.remove_emoji)
|
if(ext.remove_emoji)
|
||||||
x.remarks = trim(removeEmoji(x.remarks));
|
x.remarks = trim(removeEmoji(x.remarks));
|
||||||
|
|
||||||
if(ext.add_emoji)
|
if(ext.add_emoji)
|
||||||
x.remarks = addEmoji(x.remarks, ext.emoji_array);
|
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ext.sort_flag)
|
if(ext.sort_flag)
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ std::string netchToQuanX(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
|||||||
void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
||||||
std::string netchToQuan(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
std::string netchToQuan(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
||||||
void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
||||||
std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_settings &ext);
|
std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::string &userinfo, extra_settings &ext);
|
||||||
std::string buildGistData(std::string name, std::string content);
|
std::string buildGistData(std::string name, std::string content);
|
||||||
int uploadGist(std::string name, std::string path, std::string content, bool writeManageURL);
|
int uploadGist(std::string name, std::string path, std::string content, bool writeManageURL);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user