|
|
@@ -2,6 +2,7 @@
|
|
2
|
2
|
#include <boost/archive/iterators/base64_from_binary.hpp>
|
|
3
|
3
|
#include <boost/archive/iterators/binary_from_base64.hpp>
|
|
4
|
4
|
#include <boost/archive/iterators/transform_width.hpp>
|
|
|
5
|
+#include <boost/algorithm/string.hpp>
|
|
5
|
6
|
#include <iostream>
|
|
6
|
7
|
#include <sstream>
|
|
7
|
8
|
#include <regex>
|
|
|
@@ -26,42 +27,91 @@ bool SoftAuth::MakeAuth(std::string machCode)
|
|
26
|
27
|
return ret;
|
|
27
|
28
|
}
|
|
28
|
29
|
|
|
|
30
|
+bool SoftAuth::MakeAuthV2(std::string machCode)
|
|
|
31
|
+{
|
|
|
32
|
+ std::string data; //
|
|
|
33
|
+ std::cout << "输入授权日期如:20200715" << std::endl;
|
|
|
34
|
+ std::cin >> data;
|
|
|
35
|
+
|
|
|
36
|
+ std::string trunkNum;
|
|
|
37
|
+ std::cout << "输入授权中继数量(输入整数):" << std::endl;
|
|
|
38
|
+ std::cin >> trunkNum;
|
|
|
39
|
+
|
|
|
40
|
+ std::string acdNum;
|
|
|
41
|
+ std::cout << "输入授权ACD坐席数量(输入整数):" << std::endl;
|
|
|
42
|
+ std::cin >> acdNum;
|
|
|
43
|
+
|
|
|
44
|
+ std::string out;
|
|
|
45
|
+ bool ret = Base64Encode(machCode + data + "#" + trunkNum + "#" + acdNum, out);
|
|
|
46
|
+
|
|
|
47
|
+ std::cout << "授权码如下:" << std::endl;
|
|
|
48
|
+ std::cout << out << std::endl;
|
|
|
49
|
+ return ret;
|
|
|
50
|
+}
|
|
|
51
|
+
|
|
29
|
52
|
bool SoftAuth::Auth()
|
|
30
|
53
|
{
|
|
31
|
54
|
ifstream is(MSHY, ios_base::in | ios_base::binary);
|
|
32
|
55
|
if (is) {
|
|
33
|
56
|
//is.read(reinterpret_cast<char *>(&aInfo), sizeof(aInfo));
|
|
34
|
|
- char str[200] = { 0 };
|
|
35
|
|
- /*is.read(str, sizeof(str));*/
|
|
36
|
|
- is.read(str, 200);
|
|
|
57
|
+ char str[200];
|
|
|
58
|
+ is.read(str, sizeof(str));
|
|
37
|
59
|
is.close();
|
|
38
|
60
|
std::string out; // 解密后
|
|
39
|
|
- //std::cout << "解密前" << str << std::endl;
|
|
40
|
|
- Base64Decode(std::string(str),out);
|
|
|
61
|
+ Base64Decode(str, out);
|
|
41
|
62
|
std::string machcode1; // 机器码-本机
|
|
42
|
63
|
__getdiskid(machcode1);
|
|
43
|
|
- if (machcode1.empty())
|
|
|
64
|
+ std::string data = std::regex_replace(out, std::regex(machcode1), "");
|
|
|
65
|
+ std::string machcode2; // 授权文件中的机器码
|
|
|
66
|
+ machcode2 = std::regex_replace(out, std::regex(data), "");
|
|
|
67
|
+ if (machcode2 != machcode1)
|
|
44
|
68
|
{
|
|
45
|
|
- LOG_ERROR_S("机器码获取失败,请用root权限运行!");
|
|
46
|
69
|
return false;
|
|
47
|
70
|
}
|
|
48
|
|
- //std::cout << "解密后" << out << std::endl;
|
|
49
|
|
- //std::cout << "machcode1" << machcode1 << std::endl;
|
|
50
|
|
- const std::string data = std::regex_replace(out, std::regex(machcode1), "");
|
|
51
|
|
- // std::cout << "data" << data << std::endl;
|
|
52
|
|
- std::string machcode2; // 授权文件中的机器码
|
|
|
71
|
+ aInfo.data = data;
|
|
|
72
|
+ aInfo.code = machcode1;
|
|
|
73
|
+ return true;
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ return false;
|
|
|
77
|
+}
|
|
|
78
|
+
|
|
|
79
|
+bool SoftAuth::AuthV2()
|
|
|
80
|
+{
|
|
|
81
|
+ ifstream is(MSHY, ios_base::in | ios_base::binary);
|
|
|
82
|
+ if (is) {
|
|
|
83
|
+ char str[1024];
|
|
|
84
|
+ is.read(str, sizeof(str));
|
|
|
85
|
+ is.close();
|
|
|
86
|
+ // std::cout << "解密前:" << str << std::endl;
|
|
|
87
|
+ std::string out; // 解密后
|
|
|
88
|
+ Base64Decode(str, out);
|
|
|
89
|
+ // std::cout << "解密后:" << out << std::endl;
|
|
|
90
|
+ std::string machcode1; // 机器码-本机
|
|
|
91
|
+ __getdiskid(machcode1);
|
|
|
92
|
+ // std::cout << machcode1 << std::endl;
|
|
|
93
|
+ std::string data = std::regex_replace(out, std::regex(machcode1), "");
|
|
|
94
|
+ // std::cout << data << std::endl;
|
|
|
95
|
+ std::string machcode2; // 授权文件中的机器码
|
|
|
96
|
+ //machcode2 = std::regex_replace(out, std::regex(data), "");
|
|
53
|
97
|
machcode2 = out.substr(0, out.find(data));
|
|
54
|
|
- //std::cout << "machcode1" << machcode1 << std::endl;
|
|
55
|
|
- //std::cout << "machcode2" << machcode2 << std::endl;
|
|
|
98
|
+ // std::cout << machcode2 << std::endl;
|
|
56
|
99
|
if (machcode2 != machcode1)
|
|
57
|
100
|
{
|
|
58
|
101
|
return false;
|
|
59
|
102
|
}
|
|
60
|
|
- aInfo.data = data;
|
|
|
103
|
+ std::vector<std::string> vects;
|
|
|
104
|
+ boost::split(vects, data, boost::is_any_of("#"));
|
|
|
105
|
+ if (vects.size() < 3)
|
|
|
106
|
+ return false;
|
|
|
107
|
+
|
|
|
108
|
+ aInfo.data = vects[0];
|
|
|
109
|
+ aInfo.trunkNum = atoi(vects[1].c_str());
|
|
|
110
|
+ aInfo.agentNum = atoi(vects[2].c_str());
|
|
61
|
111
|
aInfo.code = machcode1;
|
|
62
|
112
|
return true;
|
|
63
|
113
|
}
|
|
64
|
|
-
|
|
|
114
|
+
|
|
65
|
115
|
return false;
|
|
66
|
116
|
}
|
|
67
|
117
|
|
|
|
@@ -72,18 +122,13 @@ bool SoftAuth::Auth(std::string& encode)
|
|
72
|
122
|
return false;
|
|
73
|
123
|
ofstream os(MSHY, ios_base::out | ios_base::binary);
|
|
74
|
124
|
//os.write(reinterpret_cast<char *>(&employee1), sizeof(employee1));
|
|
75
|
|
- os.write(encode.c_str(),encode.length());
|
|
|
125
|
+ os.write(encode.c_str(), encode.length());
|
|
76
|
126
|
os.close();
|
|
77
|
|
-
|
|
|
127
|
+ /*AuthInfo* aInfo = (AuthInfo*)out.c_str();*/
|
|
|
128
|
+ // aInfo = (AuthInfo*)out.c_str();
|
|
78
|
129
|
std::string hardc;
|
|
79
|
130
|
__getdiskid(hardc);
|
|
80
|
|
- /*std::cout << "encode--" << encode << std::endl;
|
|
81
|
|
- std::cout << "out--" << out << std::endl;
|
|
82
|
|
- std::cout << "hardc--" << hardc << std::endl;
|
|
83
|
|
- std::cout << "out.find(hardc)" << out.find(hardc) << std::endl;
|
|
84
|
|
- std::cout << "strstr(out.c_str(),hardc.c_str())" << strstr(out.c_str(), hardc.c_str()) << std::endl;*/
|
|
85
|
131
|
if (out.find(hardc) == string::npos)
|
|
86
|
|
- //if(strstr(out.c_str(),hardc.c_str())==NULL)
|
|
87
|
132
|
{
|
|
88
|
133
|
std::cout << "机器码和授权码中不相符" << std::endl;
|
|
89
|
134
|
return false;
|
|
|
@@ -97,11 +142,41 @@ bool SoftAuth::Auth(std::string& encode)
|
|
97
|
142
|
return true;
|
|
98
|
143
|
}
|
|
99
|
144
|
|
|
100
|
|
-bool SoftAuth::isExpire()
|
|
|
145
|
+bool SoftAuth::AuthV2(std::string & encode)
|
|
101
|
146
|
{
|
|
102
|
|
- if (aInfo.data.empty())
|
|
|
147
|
+ std::string out;
|
|
|
148
|
+ if (!Base64Decode(encode, out))
|
|
103
|
149
|
return false;
|
|
104
|
|
- //std::cout << "aInfo.data" << aInfo.data << std::endl;
|
|
|
150
|
+ ofstream os(MSHY, ios_base::out | ios_base::binary);
|
|
|
151
|
+ os.write(encode.c_str(), encode.length());
|
|
|
152
|
+ os.close();
|
|
|
153
|
+
|
|
|
154
|
+ std::string hardc;
|
|
|
155
|
+ __getdiskid(hardc);
|
|
|
156
|
+ if (out.find(hardc) == string::npos)
|
|
|
157
|
+ {
|
|
|
158
|
+ std::cout << "机器码和授权码中不相符" << std::endl;
|
|
|
159
|
+ return false;
|
|
|
160
|
+ }
|
|
|
161
|
+ std::string data = std::regex_replace(out, std::regex(hardc), "");
|
|
|
162
|
+ std::vector<std::string> vects;
|
|
|
163
|
+ boost::split(vects, data, boost::is_any_of("#"));
|
|
|
164
|
+ if (vects.size() < 3)
|
|
|
165
|
+ return false;
|
|
|
166
|
+
|
|
|
167
|
+ aInfo.data = vects[0];
|
|
|
168
|
+ aInfo.trunkNum = atoi(vects[1].c_str());
|
|
|
169
|
+ aInfo.agentNum = atoi(vects[2].c_str());
|
|
|
170
|
+ aInfo.code = hardc;
|
|
|
171
|
+ if (aInfo.code != hardc || hardc.empty())
|
|
|
172
|
+ {
|
|
|
173
|
+ return false;
|
|
|
174
|
+ }
|
|
|
175
|
+ return true;
|
|
|
176
|
+}
|
|
|
177
|
+
|
|
|
178
|
+bool SoftAuth::isExpire()
|
|
|
179
|
+{
|
|
105
|
180
|
boost::gregorian::date curData = Util::CurData();
|
|
106
|
181
|
boost::gregorian::date dData = boost::gregorian::from_undelimited_string(aInfo.data);
|
|
107
|
182
|
/*boost::gregorian::date dData = boost::gregorian::from_undelimited_string("20200716");*/
|
|
|
@@ -109,7 +184,7 @@ bool SoftAuth::isExpire()
|
|
109
|
184
|
{
|
|
110
|
185
|
return false;
|
|
111
|
186
|
}
|
|
112
|
|
- return dData>curData;
|
|
|
187
|
+ return dData > curData;
|
|
113
|
188
|
}
|
|
114
|
189
|
|
|
115
|
190
|
bool SoftAuth::getMachineCode(std::string & code)
|
|
|
@@ -137,7 +212,7 @@ int SoftAuth::__getdiskid(std::string & hardc)
|
|
137
|
212
|
if (strstr(buff, "/dev/sda1: UUID=") != NULL) // /dev/sda1: UUID="1a2dffc7-a5c4-49a0-8158-147b3fa07f78" TYPE="ext4" PARTUUID="b48e27f0-01"
|
|
138
|
213
|
{
|
|
139
|
214
|
hardc = buff;
|
|
140
|
|
- hardc = std::regex_replace(hardc, std::regex("(/)|( )|(\")|(\\n)"), ""); // devsda1:UUID=1a2dffc7-a5c4-49a0-8158-147b3fa07f78TYPE=ext4PARTUUID=b48e27f0-01
|
|
|
215
|
+ hardc = std::regex_replace(hardc, std::regex("(/)|( )|(\")|(\\n)"), ""); // devsda1:UUID=1a2dffc7-a5c4-49a0-8158-147b3fa07f78TYPE=ext4PARTUUID=b48e27f0-01
|
|
141
|
216
|
hardc = std::regex_replace(hardc, std::regex("devsda1:UUID=(.*)TYPE=(.*)PARTUUID=(.*)"), "$1");
|
|
142
|
217
|
pclose(file);
|
|
143
|
218
|
return 0;
|
|
|
@@ -150,35 +225,35 @@ int SoftAuth::__getdiskid(std::string & hardc)
|
|
150
|
225
|
|
|
151
|
226
|
bool SoftAuth::Base64Encode(const string & input, string & output)
|
|
152
|
227
|
{
|
|
153
|
|
- typedef base64_from_binary<transform_width<string::const_iterator, 6, 8>> Base64EncodeIterator;
|
|
154
|
|
- stringstream result;
|
|
155
|
|
- try {
|
|
156
|
|
- copy(Base64EncodeIterator(input.begin()), Base64EncodeIterator(input.end()), ostream_iterator<char>(result));
|
|
157
|
|
- }
|
|
158
|
|
- catch (...) {
|
|
159
|
|
- return false;
|
|
160
|
|
- }
|
|
161
|
|
- size_t equal_count = (3 - input.length() % 3) % 3;
|
|
162
|
|
- for (size_t i = 0; i < equal_count; i++)
|
|
163
|
|
- {
|
|
164
|
|
- result.put('=');
|
|
165
|
|
- }
|
|
166
|
|
- output = result.str();
|
|
167
|
|
- return output.empty() == false;
|
|
|
228
|
+ typedef base64_from_binary<transform_width<string::const_iterator, 6, 8>> Base64EncodeIterator;
|
|
|
229
|
+ stringstream result;
|
|
|
230
|
+ try {
|
|
|
231
|
+ copy(Base64EncodeIterator(input.begin()), Base64EncodeIterator(input.end()), ostream_iterator<char>(result));
|
|
|
232
|
+ }
|
|
|
233
|
+ catch (...) {
|
|
|
234
|
+ return false;
|
|
|
235
|
+ }
|
|
|
236
|
+ size_t equal_count = (3 - input.length() % 3) % 3;
|
|
|
237
|
+ for (size_t i = 0; i < equal_count; i++)
|
|
|
238
|
+ {
|
|
|
239
|
+ result.put('=');
|
|
|
240
|
+ }
|
|
|
241
|
+ output = result.str();
|
|
|
242
|
+ return output.empty() == false;
|
|
168
|
243
|
}
|
|
169
|
244
|
|
|
170
|
245
|
bool SoftAuth::Base64Decode(const string & input, string & output)
|
|
171
|
246
|
{
|
|
172
|
|
- typedef transform_width<binary_from_base64<string::const_iterator>, 8, 6> Base64DecodeIterator;
|
|
173
|
|
- stringstream result;
|
|
174
|
|
- try {
|
|
175
|
|
- copy(Base64DecodeIterator(input.begin()), Base64DecodeIterator(input.end()), ostream_iterator<char>(result));
|
|
176
|
|
- }
|
|
177
|
|
- catch (...) {
|
|
178
|
|
- return false;
|
|
179
|
|
- }
|
|
180
|
|
- output = result.str();
|
|
181
|
|
- return output.empty() == false;
|
|
|
247
|
+ typedef transform_width<binary_from_base64<string::const_iterator>, 8, 6> Base64DecodeIterator;
|
|
|
248
|
+ stringstream result;
|
|
|
249
|
+ try {
|
|
|
250
|
+ copy(Base64DecodeIterator(input.begin()), Base64DecodeIterator(input.end()), ostream_iterator<char>(result));
|
|
|
251
|
+ }
|
|
|
252
|
+ catch (...) {
|
|
|
253
|
+ return false;
|
|
|
254
|
+ }
|
|
|
255
|
+ output = result.str();
|
|
|
256
|
+ return output.empty() == false;
|
|
182
|
257
|
}
|
|
183
|
258
|
|
|
184
|
259
|
SoftAuth SoftAuth::instance;
|