This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.cpp
160 lines (145 loc) · 3.97 KB
/
work.cpp
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
#define Version "1.0.220130"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <istream>
#include <string>
using namespace std;
class OGFrp {
private:
string Arch = "Unknown";
string SubPlatform;
public:
OGFrp(string exePath, string Arch, string SubPlatform = "Other Unix") {
this->exePath = exePath;
this->Arch = Arch;
this->SubPlatform = SubPlatform;
}
void welcome() {
system("mkdir ~/.OGFrp");
printf(" ____ _____ ______\n / __ \\ / ____| ____|\n| | | | | __| |__ _ __ _ __\n| | | | | |_ | __| '__| '_ \\\n| |__| | |__| | | | | | |_) |\n \\____/ \\_____|_| |_| | .__/\n | |\n |_|\n\n");
printf("Welcome! OGFrp.Unix Core (Version %s, %s %s", Version, this->SubPlatform, this->Arch);
printf("\n");
printf(" * Website: https://ogfrp.cn \n");
printf(" * GitHub: https://github.com/oldgodshen/ogfrp \n");
printf(" * Support: https://jq.qq.com/?_wv=1027&k=whQ4pUD0 \n");
printf("\n");
printf("Type \"help\" to find more.\n");
printf("\n");
}
string token = "\0";
string exePath;
string inputToken() {
reipt:
printf("Please enter your access token:");
string t;
getline(cin, t);
if (t.length() != 16) {
printf("The token you entered does not seem to be correct.\nAre you sure to continue?[y/n]");
string yn;
getline(cin, yn);
if (yn == "y") {
return t;
}
else {
goto reipt;
}
}
}
void lsfrps() {
system(("curl --location --request POST 'https://api.ogfrp.cn' --form 'action=getnodes' --form 'token=" + token + "'").c_str());
printf("\n");
}
void startfrpc(string nodeid, string actoken) {
if (nodeid.length() < 1) {
printf("Useage: start [serverid]\n");
printf("Type \"help\" to find more.\n");
return;
}
cout << "Starting frpc..." << endl;
cout << "To stop frpc, please press Ctrl+C" << endl;
string iniPath = "~/.OGFrp/frpc.ini";
string curlsh = "curl --location --request POST 'https://api.ogfrp.cn' --form 'action=getconf' --form 'token=" + token + "' --form 'node=" + nodeid + "' -o " + iniPath;
system(curlsh.c_str());
string frpcsh = exePath + "/frpc -c " + iniPath;
system(frpcsh.c_str());
printf("\nFrpc exit.\n");
return;
}
void printHelp() {
printf("-----OGFrp.Linux helper-----\n");
printf("exit Quit.\n");
printf("lsfrps List available frp servers, access token required.\n");
printf("start [serverid] Start frpc on the specified frp server. | serverid: ID of the frp server\n");
printf("token Print the token you set.\n");
printf("token [token] Set your OGFrp access token. | token: your OGFrp access token\n");
}
int shell(string path) {
while (true) {
printf("OGFrp> ");
string script;
getline(cin, script);
string cmd;
{
char t;
for (int i = 0; i < script.length(); i++) {
t = script[i];
if (t == ' ') {
break;
}
cmd += t;
}
}
string args;
for (int i = cmd.length() + 1; i < script.length(); i++) {
args += script[i];
}
if (cmd == "exit") {
return 0;
}
else if (cmd == "help") {
printHelp();
}
else if (cmd == "token") {
if (args == "") {
cout << "The token you set is " << token << "." << endl;
}
else {
if (args.length() == 16) {
token = args;
printf("Token set.\n");
}
else {
printf("The token you entered does not seem to be correct.\nYour frp service may not work properly.\nAre you sure to continue?[y/N]");
string judge;
getline(cin, judge);
if (judge == "y") {
token = args;
printf("Token set.\n");
}
else {
printf("Token not set.\n");
}
}
}
}
else if (cmd == "start") {
startfrpc(args, token);
}
else if (cmd == "lsfrps") {
lsfrps();
}
else if (cmd != "") {
printf("%s: Command not found.\n", cmd.c_str());
}
else {
continue;
}
}
}
int main() {
welcome();
return shell(exePath);
}
};