1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#include "headers.h"
extern config *cfg;
using namespace rapidxml;
bool p_load_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
std::ifstream file;
if(!path)
file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
else
file.open(path, std::ios::in);
if(file.is_open())
{
std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
xml_document<> doc;
doc.parse<0>(doc.allocate_string(data.c_str()));
xml_node<> *proxy_list = doc.first_node()->first_node("ProxyList");
if(!proxy_list)
return false;
for(xml_node<> *node = proxy_list->first_node("Proxy"); node; node = node->next_sibling("Proxy"))
{
config::p_proxy_entry e;
e.id = atoi(node->first_attribute("id")->value());
std::string type = node->first_attribute("type")->value();
if(type == "HTTP")
e.type = config::HTTP;
if(type == "HTTPS")
e.type = config::HTTPS;
if(type == "SOCKS4")
e.type = config::SOCKS4;
if(type == "SOCKS5")
e.type = config::SOCKS5;
e.host = node->first_node("Address")->value();
e.port = atoi(node->first_node("Port")->value());
e.options = atoi(node->first_node("Options")->value());
xml_node<> *auth = node->first_node("Authentication");
if(auth)
{
e.enable_auth = atoi(auth->first_attribute("Enabled")->value());
e.login = auth->first_node("Username")->value();
e.password = auth->first_node("Password")->value(); //TODO: detect kind of hash, decrypt (needed for set auth settings in proxy list)
}
list->push_back(e);
}
if(!list->empty())
return true; // succesfully loaded some entries
}
return false;
}
bool p_load_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
{
std::ifstream file;
if(!path)
file.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
else
file.open(path, std::ios::in);
if(file.is_open())
{
std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
xml_document<> doc;
doc.parse<0>(doc.allocate_string(data.c_str()));
xml_node<> *chain_list = doc.first_node()->first_node("ChainList");
if(!chain_list)
return false;
for(xml_node<> *node = chain_list->first_node("Chain"); node; node = node->next_sibling("Chain"))
{
config::p_proxy_chain c;
c.id = atoi(node->first_attribute("id")->value());
c.name = node->first_node("Name")->value();
for(xml_node<> *proxy = node->first_node("Proxy"); proxy; proxy = proxy->next_sibling("Proxy"))
{
config::p_proxy_chain::chain_entry e;
e.enabled = atoi(proxy->first_attribute("enabled")->value());
e.id = atoi(proxy->value());
c.chain.push_back(e);
}
list->push_back(c);
}
if(!list->empty())
return true;
}
return false;
}
bool p_save_proxy_list(std::list<config::p_proxy_entry> *list, char *path)
{
std::list<config::p_proxy_entry> *p_list = cfg->make_p_proxy_list();
if(p_list->empty())
return false;
std::ifstream infile;
if(!path)
infile.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str(), std::ios::in); //TODO: handle different locations
else
infile.open(path, std::ios::in);
if(infile.is_open())
{
std::string data((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>());
infile.close();
xml_document<> doc;
doc.parse<0>(doc.allocate_string(data.c_str()));
xml_node<> *proxy_list = doc.first_node()->first_node("ProxyList");
if(proxy_list)
{
proxy_list->remove_all_nodes();
proxy_list->remove_all_attributes();
doc.remove_node(proxy_list);
}
proxy_list = doc.allocate_node(node_element, "ProxyList");
doc.append_node(proxy_list);
for(std::list<config::p_proxy_entry>::iterator i = p_list->begin(), end = p_list->end(); i != end; ++i)
{
xml_node<> *proxy = doc.allocate_node(node_element, "Proxy");
char val[8];
snprintf(val, 7, "%d", i->id);
xml_attribute<> *attr = doc.allocate_attribute("id", doc.allocate_string(val));
proxy->append_attribute(attr);
std::string type;
switch(i->type)
{
case config::HTTP:
type = "HTTP";
break;
case config::HTTPS:
type = "HTTPS";
break;
case config::SOCKS4:
type = "SOCKS4";
break;
case config::SOCKS5:
type = "SOCKS5";
break;
}
attr = doc.allocate_attribute("type", doc.allocate_string(type.c_str()));
proxy->append_attribute(attr);
xml_node<> *node = doc.allocate_node(node_data, "Address");
node->value(doc.allocate_string(i->host.c_str()));
proxy->append_node(node);
node = doc.allocate_node(node_data, "Port");
snprintf(val, 7, "%d", i->port);
node->value(doc.allocate_string(val));
proxy->append_node(node);
node = doc.allocate_node(node_data, "Options");
snprintf(val, 7, "%d", i->options);
node->value(doc.allocate_string(val));
proxy->append_node(node);
if(!i->login.empty())
{
xml_node<> *auth = doc.allocate_node(node_element, "Authentication");
attr = doc.allocate_attribute("enabled", i->enable_auth?"true":"false");
node = doc.allocate_node(node_data, "Username");
node->value(doc.allocate_string(i->login.c_str()));
auth->append_node(node);
node = doc.allocate_node(node_data, "Password");
node->value(doc.allocate_string(i->password.c_str()));
auth->append_node(node);
proxy->append_node(auth);
}
proxy_list->append_node(proxy);
}
std::ofstream outfile;
if(!path)
outfile.open(std::string(cfg->proxifier_path()+"/Default/Default.ppx").c_str()); //TODO: handle different locations
else
outfile.open(path);
if(outfile.is_open())
{
outfile<<doc;
return true;
}
}
return false;
}
bool p_save_proxy_chains(std::list<config::p_proxy_chain> *list, char *path)
{
}
|