CBrother scripting language 10 minutes to write a program to save the "Dogbuster Server"
In a new company, I took over a piece of c++ server code and leaked memory everywhere. This server has no database. Just restart it after hanging up. The company has been living for several years. Restart it regularly or every day. It may hang up any day.
Small companies, from writing code to maintaining on my own, whenever the phone rings after work or on the weekend, I know I'm hanging up. I have to find a computer to restart. If I go out to play, I still need to find the Internet bar, install remote software. The company persuader was previously blacked by remote software, so it's not allowed to install and annoyed.
Just think about what program to click on your mobile phone and restart it. For people like me who have been writing C++ in the background for more than 10 years, mobile APP will not open. Get a web app, select it for half a day, and python's grammar will faint me.PHP research hasn't been set up all morning.Find another one, find a CBrother script with common syntax and C++, write http interface is very simple, chat with the author, write what I want in 10 minutes, now I give one account to other colleagues in the company, anyone can restart the service.To thank the author of CBrother, here is an article to publicize it.
Main function:
//Entry function, and c++Like, start the call main Function, which I like function main(params) { var httpServer = new HttpServer(); //Create a http service httpServer.addAction("hello.cb",new HelloAction()); //register hello.cb Interface Response Class HelloAction httpServer.addAction("120120.cb",new Action120()); //Register Restart Interface is 20120.cb httpServer.setNormalAction("hello.cb"); //Set Default Page Call hello.cb httpServer.startServer(11120); //Set the service port to 1120 //The main thread does not exit, except for syntax simplification, routines and c++It's exactly the same while (1) { Sleep(1000); } }
hello.cb:
class HelloAction { //Execution function of interface function DoAction(request,respone) { //Write a form, it's all what you learned in college. For more than a decade, thanks to a little bit of it, Ha-ha respone.write("<html><head><title>Rescue Server</title><meta http-equiv=\"content-type\" content=\"txt/html; charset=utf-8\" /></head><body>"); respone.write("<br><FORM method=\"post\" action=\"120120.cb\">"); respone.write("<INPUT type=\"text\" name=\"username\"><br>"); respone.write("<input type=\"password\" name=\"userpass\"><br>"); respone.write("<input type=\"submit\" value=\"rescue\"></FORM></body><html>"); respone.flush(); } }
120120.cb Restart Server Operation:
var g_userMap = {"admin":"123.123","huangyi":"256.256","boss":".boss1boss"};//Define user password var g_exepath = "D:\\work\\FVServer\\FVServer.exe"; //Process Path var g_exeName = "FVServer.exe"; //Process name class Action120 { function DoAction(request,respone) { respone.write("<html><head><title>Rescue Server</title><meta http-equiv=\"content-type\" content=\"txt/html; charset=utf-8\" /></head><body>"); var fromdata = request.getFormData(); //Get Form Data if (fromdata == null) { respone.write("I don't know you.</body><html>"); respone.flush(); return; } var userName = strlower(fromdata.getText("username")); //Get user name, lower case var pwd = fromdata.getText("userpass"); var pwdlocal = g_userMap[userName]; //Determine whether the user exists if (pwdlocal == null) { respone.write("I don't know you.</body><html>"); respone.flush(); return; } if (pwdlocal != pwd) //Determine if the password is correct { respone.write("Password error</body><html>"); respone.flush(); return; } var oldid = 0; respone.write("Rescue in progress..."); var pidarr = GetProcessByName(g_exeName); //Get Process ID List, there should be only one if (pidarr != null) { for (var i = 0; i < pidarr.size() ; i++) { print "Kill process ID: " + pidarr[i]; KillProcessByID(pidarr[i]); //Kill process } Sleep(2000); } respone.write("<br>Rescue in progress..."); var pid = CreateProcess(g_exepath); //Restart a respone.write("<br>Rescue was successful.process ID:" + pid); respone.flush(); //Print out the current time var t = new Time(); print userName + "Server rescued." + oldid + "===>" + pid + t.strftime(" [%Y/%m/%d %H:%M:%S]"); } }
Then from the official website ( http://www.cbrother.net/ ) Download CBrother and enter the startup command in the console
D:\cbrother_v2.1.0_win64\cbrother.exe d:\cbrothercheck.cb, the server is up.
Then you can restart the server by accessing this port from your mobile phone
Enter account password to restart
No longer need to rush to find a computer to make a phone call. The phone will be OK at a click and the caller's own page can be restarted.(
Server Interface Display
Overall, the CBrother script fits my programming philosophy very well, and it's very simple to encapsulate, so I need to learn more about it later.