以后想自己写个ubuntu下的虚拟主机管理系统,嘿嘿!目前已搞定了apache新建用户、删除用户、vsftp mysql管理。
C++代码
- #include <iostream>
- #include <fstream>
- #include <string>
- #include<stdlib.h>
- using namespace std;
- string stringReplace(const string& input,const string& find,const string& replaceWith)
- {
- string strOut(input);
- int curPos = 0;
- int pos;
- while((pos = strOut.find(find, curPos)) != -1)
- {
- strOut.replace(pos, find.size(), replaceWith);
- curPos = pos + replaceWith.size();
- }
- return strOut;
- }
- int main(int argc,char *argv[])
- {
- int i=3;
- cout<<argv[1]<<"|"<<argv[2]<<endl;
- if(argv[1]=="diyweb"){
- cout<<"error,diyweb is system user"<<endl;
- return 0;
- }
- if(argv[1]=="000-default"){
- cout<<"error,000-default is system user"<<endl;
- return 0;
- }
- //cin.get();
- string filename="/etc/apache2/sites-enabled/"+string(argv[1]);
- ofstream f1(filename.c_str());
- if(!f1){
- cout<<"error,file not open!"<<endl;
- return 0;
- }
- string doname=stringReplace(string(argv[2]),"@"," ");
- string content="<VirtualHost *:80>\nServerName "+string(argv[1])+".ye55.net \nServerAlias "+string(argv[1])+".armos.cn "+doname+" \nDocumentRoot \"/home/web/diyweb/company/"+string(argv[1])+"\"\n</VirtualHost>";
- f1<<content<<endl;
- f1.close();
- system("sudo /etc/init.d/apache2 reload >tmp.out");
- cout<<"success"<<endl;
- return 0;
- }