Exemplo n.º 1
0
string getUVALineFromFile(char *filename) {
    string res="",ts;
    FILE * fp=fopen(filename,"r");
    while (fgets(tmps,1000000,fp)) {
        res=tmps;
        if (res.find("<input type=\"hidden\" ")==0) {
            while (fgets(tmps,1000000,fp)) {
                ts=tmps;
                if (ts.find("<input type=\"hidden\" ")==string::npos) break;
                res=res+ts;
            }
            break;
        }
    }
    fclose(fp);
    int loc=0,tp;
    // cout<<res;
    string rres="";
    while ((loc=res.find("name=\"",loc))!=string::npos) {
        loc=loc+strlen("name=\"");
        tp=res.find("\"",loc);
        //cout <<loc <<" " << tp <<" "<<res.substr(loc,tp-loc)<<endl;
        rres=rres+escapeURL(res.substr(loc,tp-loc));
        loc=res.find("value=\"",tp);
        loc=loc+strlen("value=\"");
        tp=res.find("\"",loc);
        //cout <<loc <<" " << tp <<" "<<res.substr(loc,tp-loc)<<endl;
        rres=rres+"="+escapeURL(res.substr(loc,tp-loc))+"&";
    }
    return rres;
}
Exemplo n.º 2
0
std::string LLUriTemplate::expandJoin(const std::string& delim, const std::string& var_list, const LLSD& vars)
{
	std::ostringstream query;

	typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
	boost::char_separator<char> sep(",");
	tokenizer var_names(var_list, sep);
	tokenizer::const_iterator it = var_names.begin();

	// First var does not need a delimiter
	if (it != var_names.end())
	{
		const std::string& name = *it;
		if (vars.has(name))
		{
			// URL encode the value before appending the name=value pair.
			query << name << "=" << escapeURL(vars[name].asString());
		}
	}

	for (++it; it != var_names.end(); ++it)
	{
		const std::string& name = *it;
		if (vars.has(name))
		{
			// URL encode the value before appending the name=value pair.
			query << delim << name << "=" << escapeURL(vars[name].asString());
		}
	}

	return query.str();
}
Exemplo n.º 3
0
bool login()
{
    FILE * fp=fopen(tfilename,"w+");
    //cout<<tfilename<<endl;
    curl = curl_easy_init();
    if(curl)
    {
        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "loj.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.lightoj.com/login_check.php");
        string post=(string)"myuserid="+escapeURL(username)+"&mypassword="******"&Submit=Login";
        //cout<<post;
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
        res = curl_easy_perform(curl);

//        print_cookies(curl);

        curl_easy_cleanup(curl);
    }
    fclose(fp);

    if (res) return false;
    string ts=getAllFromFile(tfilename);
    //writelog((char *)ts.c_str());
    //cout<<ts;
    if (ts.find("login_main.php")!=string::npos) return false;

    return true;
}
Exemplo n.º 4
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott * HRBUSTJudger::getStatus(Bott * bott) {
    time_t begin_time = time(NULL);

    Bott * result_bott;
    while (true) {
        // check wait time
        if (time(NULL) - begin_time > info->GetMax_wait_time()) {
            throw Exception("Failed to get current result, judge time out.");
        }

        prepareCurl();
        curl_easy_setopt(
            curl, CURLOPT_URL,
            ((string) "http://acm.hrbust.edu.cn/index.php?m=Status&a="
             "showStatus&problem_id=" + escapeURL(bott->Getvid()) +
             "&user_name=" + escapeURL(info->GetUsername()) + "&language=" +
             convertLanguage(bott->Getlanguage())).c_str());
        performCurl();

        string html = loadAllFromFile(tmpfilename);
        string status;
        string runid, result, time_used, memory_used;

        // get first row
        if (html.find("var is_login=\"\";") != string::npos ||
                !RE2::PartialMatch(html,
                                   "(?s)<table class=\"ojlist\".*?<tr.*?(<tr.*?</tr>)",
                                   &status)) {
            throw Exception("Failed to get status row.");
        }

        // get result
        if (!RE2::PartialMatch(status,
                               "(?s)<td.*?<td>([0-9]*).*?<td.*?<td.*?>(.*?)</td>",
                               &runid, &result)) {
            throw Exception("Failed to get current result.");
        }
        result = convertResult(trim(result));
        if (isFinalResult(result)) {
            // result is the final one
            if (!RE2::PartialMatch(status,
                                   "(?s)>([0-9]*)ms.*?>([0-9]*)k", &time_used,
                                   &memory_used)) {
                throw Exception("Failed to parse details from status row.");
            }
            result_bott = new Bott;
            result_bott->Settype(RESULT_REPORT);
            result_bott->Setresult(result);
            result_bott->Settime_used(stringToInt(time_used));
            result_bott->Setmemory_used(stringToInt(memory_used));
            result_bott->Setremote_runid(trim(runid));
            break;
        }
    }
    return result_bott;
}
Exemplo n.º 5
0
/**
 * Login to LOJ
 */
void LOJJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.lightoj.com/login_check.php");
  string post = "myuserid=" + escapeURL(info->GetUsername()) +
      "&mypassword="******"&Submit=Login";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("login_main.php") != string::npos) {
    throw Exception("Login failed!");
  }
}
Exemplo n.º 6
0
bool submit(string pid,string lang,string source) {
	FILE * fp=fopen(tfilename,"w+");
	curl = curl_easy_init();
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
		curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "pku.cookie");
		curl_easy_setopt(curl, CURLOPT_URL, "http://poj.org/submit");
		/*
		   problem_id=1000&language=4&
		   source=%23include+%22curl.h%22%0D%0A%23include+%3Cstdio.h%3E%0D%0A%0D%0Aint+main%28%29%0D%0A%7B%0D%0A++++CURL+*curl%3B%0D%0A++++CURLcode+res%3B%0D%0A++++FILE+*+fp%3Dfopen%28%22a.txt%22%2C%22w%2B%22%29%3B%0D%0A++++curl+%3D+curl_easy_init%28%29%3B%0D%0A++++if%28curl%29%0D%0A++++%7B%0D%0A++++++++curl_easy_setopt%28curl%2C+CURLOPT_WRITEDATA%2C+fp%29%3B%0D%0A++++++++curl_easy_setopt%28curl%2C+CURLOPT_WRITEFUNCTION%2C+NULL%29%3B%0D%0A++++++++curl_easy_setopt%28curl%2C+CURLOPT_URL%2C+%22http%3A%2F%2Facm.pku.edu.cn%22%29%3B%0D%0A++++++++res+%3D+curl_easy_perform%28curl%29%3B%0D%0A++++++++curl_easy_cleanup%28curl%29%3B%0D%0A++++%7D%0D%0A++++fclose%28fp%29%3B%0D%0A++++return+0%3B%0D%0A%7D%0D%0A
		   &submit=Submit
		 */

		string post=(string)"problem_id="+pid+"&language="+lang+"&source="+escapeURL(source);
		//cout<<post;
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
		res = curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
	fclose(fp);
	if (res) return false;
	string ts=getAllFromFile(tfilename);
	cout<<ts;
	if (ts.find("Error Occurred")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
	return true;
}
Exemplo n.º 7
0
bool login() {
    string post=getPara();
    if (post=="") return false;
    FILE * fp=fopen(tfilename,"w+");
    //curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        //curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl");
        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "nbut.cookie");
        curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "nbut.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://acm.nbut.cn/User/chklogin.xhtml");
        post=post+"username="******"&password="******"1") return false;
    return true;
}
Exemplo n.º 8
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int ZJUJudger::submit(Bott * bott)
{

	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://acm.zju.edu.cn/onlinejudge/submit.do");
	string post =
	    (string) "problemCode=" + bott->Getvid() + "&languageId=" +
	    bott->Getlanguage() + "&source=" + escapeURL(bott->Getsrc());
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
	performCurl();

	// check submit status
	string html = loadAllFromFile(tmpfilename);
	if (html.find("Submit Successfully</div>") == string::npos) {
		return SUBMIT_OTHER_ERROR;
	}
	// parse remote runid from submit page
	string runid;
	if (!RE2::PartialMatch
	    (html, "(?s)The submission id is.*?>(.*?)<", &runid)) {
		return SUBMIT_OTHER_ERROR;
	}
	bott->Setremote_runid(runid);
	return VirtualJudger::SUBMIT_NORMAL;
}
Exemplo n.º 9
0
bool submit(string pid,string lang,string source) {
    FILE * fp=fopen(tfilename,"w+");
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "fzu.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://acm.fzu.edu.cn/submit.php?act=5");
/*
usr=bnuvjudge&lang=0&pid=1000&code=frji2o%3Berf%0D%0Aedgb%0D%0Afeh%0D%0Adrf%0D%0Ahdf%0D%0Ah&submit=Submit
*/

        string post=(string)"usr="******"&lang="+lang+"&pid="+pid+"&code="+escapeURL(source)+"&submit=Submit";
        //cout<<post;
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    fclose(fp);
    if (res) return false;
    string ts=getAllFromFile(tfilename);
    //cout<<ts;
    if (ts.find("Warning: This problem is not exist.")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
    return true;
}
Exemplo n.º 10
0
bool submit(string pid,string lang,string source) {
    FILE * fp=fopen(tfilename,"w+");
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "nbut.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://acm.nbut.cn/Problem/submitok.xhtml");
/*
language=1000&id=1000&code=fsafgvasfadsvgds%0AGfd%0Ah%0Aefh%0Afd%0Ahdf%0Ajh%0Afe
*/

        string post=(string)"language="+lang+"&id="+pid+"&code="+escapeURL(source);
        //cout<<post;
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    fclose(fp);
    if (res) return false;
    string ts=getAllFromFile(tfilename);
    //cout<<ts;
    if (ts.find("{\"status\":0")!=string::npos||ts.find("The page is temporarily unavailable")!=string::npos) return false;
    return true;
}
Exemplo n.º 11
0
/**
 * Login to ZJU
 */
void ZJUJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://acm.zju.edu.cn/onlinejudge/login.do");
  string post = "handle=" + escapeURL(info->GetUsername()) +
      "&password="******"Handle or password is invalid.") != string::npos) {
    throw Exception("Login failed!");
  }
}
Exemplo n.º 12
0
bool login() {
    string post=getPara();
    if (post=="") return false;
    FILE * fp=fopen(tfilename,"w+");
    //curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_REFERER, "http://livearchive.onlinejudge.org/");
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl");
        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "uvalive.cookie");
        curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "uvalive.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://livearchive.onlinejudge.org/index.php?option=com_comprofiler&task=login");
        post=post+"username="******"&passwd="+escapeURL(password)+"&remember=yes&Submit=Login";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    fclose(fp);
    if (res) return false;
    string ts=getAllFromFile(tfilename);
    //cout<<ts;
    if (ts.find("alert(\"")!=string::npos||ts.find("<div class='error'>")!=string::npos||ts.find("You are not authorized to view this page!")!=string::npos) return false;
    return true;
}
Exemplo n.º 13
0
bool submit(string pid,string lang,string source) {
	FILE * fp=fopen(tfilename,"w+");
	curl = curl_easy_init();
	headerlist=NULL;
	static const char buf[] = "Expect:";
	headerlist = curl_slist_append(headerlist, buf);
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
		curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "hdu.cookie");
		curl_easy_setopt(curl, CURLOPT_URL, "http://acm.hdu.edu.cn/submit.php?action=submit");
		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
		/*
		   check=0
		   &problemid=1000
		   &language=0
		   &usercode=%23include%3Cstdio.h%3E%0D%0Aint+main%28%29+%7B%0D%0Aint+a%2Cb%3B%0D%0Ascanf%28%22%25d%25d%22%2C%26a%2C%26b%29%3B%0D%0Aprintf%28%22%25d%5Cn%22%2Ca%2Bb%29%3B%0D%0A%7D
		 */

		string post=(string)"check=0&problemid="+pid+"&language="+lang+"&usercode="+escapeURL(source);
		//cout<<post;
		//writelog((char *)post.c_str());
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
		res = curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
	curl_slist_free_all (headerlist);
	fclose(fp);
	if (res) return false;
	string ts=getAllFromFile(tfilename);
	//cout<<ts;
	//writelog((char *)ts.c_str());
	if (ts.find("Connect(0) to MySQL Server failed.")!=string::npos||ts.find("<b>One or more following ERROR(s) occurred.")!=string::npos||ts.find("<h2>The requested URL could not be retrieved</h2>")!=string::npos||ts.find("PHP: Maximum execution time of")!=string::npos) return false;
	return true;
}
Exemplo n.º 14
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott *SCUJudger::getStatus(Bott * bott)
{
	time_t begin_time = time(NULL);

	Bott *result_bott;
	while (true) {
		// check wait time
		if (time(NULL) - begin_time > info->GetMax_wait_time()) {
			throw
			    Exception
			    ("Failed to get current result, judge time out.");
		}

		prepareCurl();
		curl_easy_setopt(curl, CURLOPT_URL,
				 ("http://cstest.scu.edu.cn/soj/solutions.action?userId="
				  + escapeURL(info->GetUsername()) +
				  "&problemId=" + bott->Getvid()).c_str());
		performCurl();

		string html = loadAllFromFile(tmpfilename);
		string status;
		string runid, result, time_used, memory_used;

		// get first row
		if (!RE2::PartialMatch(html,
				       "(?s).*<table.*?<tr.*?(<tr.*?<td height=\"44\">.*?</tr>)",
				       &status)) {
			throw Exception("Failed to get status row.");
		}
		// get result
		if (!RE2::PartialMatch(status,
				       "(?s)<td.*?>([0-9]*).*?<font.*?>(.*)</font>",
				       &runid, &result)) {
			throw Exception("Failed to get current result.");
		}
		result = trim(result);
		if (isFinalResult(result)) {
			// result is the final one
			result = convertResult(result);
			if (!RE2::PartialMatch(status,
					       "(?s)<td.*?>([0-9]*).*?<font.*?>.*</font>.*?<td>(.*?)</td>.*?<td>(.*?)</td>",
					       &runid, &time_used,
					       &memory_used)) {
				throw
				    Exception
				    ("Failed to parse details from status row.");
			}
			result_bott = new Bott;
			result_bott->Settype(RESULT_REPORT);
			result_bott->Setresult(result);
			result_bott->Settime_used(trim(time_used));
			result_bott->Setmemory_used(trim(memory_used));
			result_bott->Setremote_runid(trim(runid));
			break;
		}
	}
	return result_bott;
}
Exemplo n.º 15
0
/**
 * Login to HRBUST
 */
void HRBUSTJudger::login() {
    prepareCurl();
    curl_easy_setopt(curl, CURLOPT_URL,
                     "http://acm.hrbust.edu.cn/index.php?m=User&a=login");
    string post = (string) "m=User&a=login&ajax=1&user_name=" +
                  escapeURL(info->GetUsername()) + "&password="******"{\"status\":0") != string::npos ||
            html.find("<div class='body'>Sorry!Login Error,Please Retry!</div>") !=
            string::npos) {
        throw Exception("Login failed!");
    }
}
Exemplo n.º 16
0
/**
 * Login to CodeChef
 */
void CCJudger::login() {
  string hiddenParams = getLoginHiddenParams();

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "https://www.codechef.com/node?destination=node");
  string post = hiddenParams + "name=" + escapeURL(info->GetUsername()) +
      "&pass="******"&submit.x=0&submit.y=0";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("<a class=\"login-link\"") != string::npos) {
    throw Exception("Login failed!");
  }
}
Exemplo n.º 17
0
/**
 * Login to SPOJ
 */
void SPOJJudger::login() {

  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_REFERER, "http://www.spoj.com/logout");
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.spoj.com/logout");
  string post = "login_user="******"&password="******"&submit=Log+In";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  // check login status
  string html = loadAllFromFile(tmpfilename);
  if (html.find("Authentication failed! <br/><a href=\"/forgot\">") !=
      string::npos) {
    throw Exception("Login failed!");
  }
}
Exemplo n.º 18
0
/**
 * Login to SCU
 */
void SCUJudger::login()
{

	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://cstest.scu.edu.cn/soj/login.action");
	string post =
	    "back=2&submit=login&id=" + escapeURL(info->GetUsername()) +
	    "&password="******"<title>ERROR</title>") != string::npos) {
		throw Exception("Login failed!");
	}
}
Exemplo n.º 19
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int NJUPTJudger::submit(Bott * bott)
{
	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://acm.njupt.edu.cn/acmhome/submitcode.do");
	string post =
	    (string) "problemId=" + bott->Getvid() + "&language=" +
	    escapeURL(bott->Getlanguage()) + "&code=" +
	    escapeURL(bott->Getsrc());
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());

	try {
		performCurl();
	} catch(Exception & e) {
		return SUBMIT_OTHER_ERROR;
	}

	string html = loadAllFromFile(tmpfilename);
	if (html.find("<div style=\"color:red;\"><UL><LI>") != string::npos)
		return SUBMIT_OTHER_ERROR;
	return SUBMIT_NORMAL;
}
Exemplo n.º 20
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int AizuJudger::submit(Bott * bott) {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://judge.u-aizu.ac.jp/onlinejudge/servlet/Submit");
  string post = (string) "userID=" + escapeURL(info->GetUsername()) +
      "&password="******"&problemNO=" + bott->Getvid() +
      "&language=" + escapeURL(convertLanguage(bott->Getlanguage())) +
      "&sourceCode=" + escapeURL(bott->Getsrc());
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());

  try {
    performCurl();
  } catch (Exception & e) {
    return SUBMIT_OTHER_ERROR;
  }

  string html = loadAllFromFile(tmpfilename);
  if (html.find("UserID or Password is Wrong.") != string::npos ||
      html.find("<span class=\"line\">Login</span>") != string::npos)
    return SUBMIT_OTHER_ERROR;
  return SUBMIT_NORMAL;
}
Exemplo n.º 21
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int SCUJudger::submit(Bott * bott)
{
	string code = getCode();
	log("Validation Code: " + code);
	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL,
			 "http://cstest.scu.edu.cn/soj/submit.action");
	string post =
	    (string) "problemId=" + bott->Getvid() +
	    "&submit=Submit&validation=" + code + "&language=" +
	    escapeURL(bott->Getlanguage()) + "&source=" +
	    escapeURL(bott->Getsrc());
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
	performCurl();

	// check submit status
	string html = loadAllFromFile(tmpfilename);
	if (html.find("<title>ERROR</title>") != string::npos ||
	    html.find("The page is temporarily unavailable") != string::npos) {
		return SUBMIT_OTHER_ERROR;
	}
	return VirtualJudger::SUBMIT_NORMAL;
}
Exemplo n.º 22
0
/**
 * Get input=hidden stuffs for login
 * @return Hidden params in string
 */
string CCJudger::getLoginHiddenParams()
{
	prepareCurl();
	curl_easy_setopt(curl, CURLOPT_URL, "http://www.codechef.com/");
	performCurl();

	string html = loadAllFromFile(tmpfilename);
	string form;
	// login form
	if (!RE2::PartialMatch(html, "(?s)(<form.*?user-login-form.*?</form>)",
			       &form)) {
		throw Exception("Failed to get hidden params.");
	}
	string key, value, result = "";
	// get all hidden params
	re2::StringPiece formString(form);
	while (RE2::FindAndConsume(&formString,
				   "(?s)<input type=\"hidden\".*?name=\"(.*?)\".*?value=\"(.*?)\"",
				   &key, &value)) {
		result += escapeURL(key) + "=" + escapeURL(value) + "&";
	}
	return result;
}
Exemplo n.º 23
0
/**
 * Login to Aizu
 */
void AizuJudger::login() {
  prepareCurl();
  curl_easy_setopt(curl, CURLOPT_URL,
                   "http://judge.u-aizu.ac.jp/onlinejudge/index.jsp");
  string post = (string) "loginUserID=" + info->GetUsername() +
      "&loginPassword="******"&submit=Sign+in";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
  performCurl();

  string html = loadAllFromFile(tmpfilename);
  //cout<<ts;
  if (html.find("<span class=\"line\">Login</span>") != string::npos) {
    throw Exception("Login failed!");
  }
}
Exemplo n.º 24
0
/**
 * Submit a run
 * @param bott      Bott file for Run info
 * @return Submit status
 */
int HRBUSTJudger::submit(Bott * bott) {
    prepareCurl();
    curl_easy_setopt(curl,
                     CURLOPT_URL,
                     "http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=postCode");
    string post = (string) "jumpUrl=&language=" +
                  convertLanguage(bott->Getlanguage()) + "&problem_id=" + bott->Getvid() +
                  "&source_code=" + escapeURL(bott->Getsrc());
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
    performCurl();

    string html = loadAllFromFile(tmpfilename);
    if (html.find("<html") == string::npos ||
            html.find("var is_login=\"\";") != string::npos)
        return SUBMIT_OTHER_ERROR;
    return SUBMIT_NORMAL;
}
Exemplo n.º 25
0
bool submit(string pid,string lang,string source) {
    FILE * fp=fopen(tfilename,"w+");
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "sgu.cookie");
        curl_easy_setopt(curl, CURLOPT_URL, "http://acm.sgu.ru/sendfile.php?contest=0");
/*
id=050600&pass=asdf1234%23&problem=100&elang=GNU+CPP+%28MinGW%2C+GCC+4%29&source=hfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
*/

        string post=(string)"id="+username+"&pass="******"&problem="+pid+"&elang="+escapeURL(lang)+"&source="+escapeURL(source);
        //cout<<post;
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    fclose(fp);
    if (res) return false;
    string ts=getAllFromFile(tfilename);
    //cout<<ts;
    if (ts.find("Your solution was successfully submitted.")==string::npos) {
        cout<<ts<<endl;
        return false;
    }
    return true;
}
Exemplo n.º 26
0
void
outputOPML(
        const MyClip *mp,
        int          numOfClips,
        const char   *title,
        int          codeChange,
        FILE         *fp
    )
{
    int         i;
    int         rate;
    char        buf[BUFSIZ];
    char        tag[4096];
    char        comment[4096];

    struct tm   tm, *tt;
    time_t      t;
    int         yyyy, mm, dd, HH, MM, SS;
    char        *p = NULL;

    /* OPML ファイル書き出し */
    switch ( codeChange ) {
    case SJIS2UTF:
        p = sjis2utf( title );
        break;

    case EUC2UTF:
        p = euc2utf( title );
        break;

    case UTF8:
    default:
        p = NULL;
        break;
    }
    fprintf( fp,
             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
             "<opml version=\"1.1\">\n<head>\n"
             "<title>%s</title>\n",
             p ? p : title );
    fprintf( fp, "</head>\n<body>\n" );

    for ( i = 0; i < numOfClips; i++ ) {
        switch ( codeChange ) {
        case SJIS2UTF:
         // p = sjis2utf( mp[i].title );
         // strcpy( buf, p ? p : mp[i].title );
            p = sjis2utf( mp[i].tags );
            strcpy( tag, p ? p : mp[i].tags );
            p = sjis2utf( mp[i].comment );
            strcpy( comment, p ? p : mp[i].comment );
            break;

        case EUC2UTF:
         // p = euc2utf( mp[i].title );
         // strcpy( buf, p ? p : mp[i].title );
            p = euc2utf( mp[i].tags );
            strcpy( tag, p ? p : mp[i].tags );
            p = euc2utf( mp[i].comment );
            strcpy( comment, p ? p : mp[i].comment );
            break;

        case UTF8:
        default:
         // strcpy( buf, mp[i].title );
            strcpy( tag, mp[i].tags );
            strcpy( comment, mp[i].comment );
            break;
        }

        // MM/Memo 形式の title を扱うための処理
        strcpy( buf, mp[i].title );
        rate = getEvaluation( buf, UTF8 );

        regularize( buf );
        regularize( tag );
        regularize( comment );

        tm.tm_year = mp[i].yyyy - 1900;
        tm.tm_mon  = mp[i].mm - 1;
        tm.tm_mday = mp[i].dd;
        tm.tm_hour = mp[i].HH;
        tm.tm_min  = mp[i].MM;
        tm.tm_sec  = mp[i].SS;
        t = timelocal( &tm );
#ifdef  WIN32
        if ( _timezone != 0 )
            t += _timezone;
#else
        t -= 9 * 60 * 60;   /* JST → GMT */
#endif

        tt = gmtime( &t );
        if ( !tt )
            tt = localtime( &t );
        if ( tt ) {
            yyyy = tt->tm_year + 1900;
            mm   = tt->tm_mon + 1;
            dd   = tt->tm_mday;
            HH   = tt->tm_hour;
            MM   = tt->tm_min;
            SS   = tt->tm_sec;
        }
        else {
            yyyy = mp[i].yyyy;
            mm   = mp[i].mm;
            dd   = mp[i].dd;
            HH   = mp[i].HH;
            MM   = mp[i].MM;
            SS   = mp[i].SS;
        }

        strcpy( buf, escapeQuote( buf ) );
        fprintf( fp,
                 "<outline text=\"%s\" type=\"Link\" "
                 "url=\"%s\" title=\"%s\" notes=\"%s\" "
                 "date=\"%04d-%02d-%02dT%02d:%02d:%02dZ\"",
                 buf,
                 escapeURL( mp[i].url ),
                 tag,
                 escapeQuote( comment ),
                 yyyy, mm, dd, HH, MM, SS );

        // 以下は bookey 独自拡張 [OPML 1.0 の仕様書を読む限りは、独自に属性を
        //                         追加するのは問題なさそう]
        //   -- 2006年11月17日現在、OPML validator は Internal database error
        //      が発生して利用できない(新しいデータベースでサービス再開するま
        //      で待っていてください、云々と表示される)ため、本当に valid なの
        //      かどうかは未確認
        if ( ((rate >= EVL_ONE)  &&
              (rate <= EVL_FIVE)    )             ||
             ((mp[i].evaluation >= EVL_ONE)  &&
              (mp[i].evaluation <= EVL_FIVE)    )    )
            fprintf( fp,
                     " evaluation=\"%d\"",
                     mp[i].evaluation );
        if ( (mp[i].rating >= RAT_ONE) && (mp[i].rating <= RAT_THREE) )
            fprintf( fp,
                     " rating=\"%d\"",
                     mp[i].rating );
        if ((mp[i].affirmation == AFF_GOOD) || (mp[i].affirmation == AFF_BAD))
            fprintf( fp,
                     " affirmation=\"%s\"",
                     mp[i].affirmation == AFF_GOOD ? "good" : "bad" );

        if ( mp[i].publication != PUB_EVERYONE ) {
            switch ( mp[i].publication ) {
            case PUB_FRIENDS:
                fprintf( fp, " publication=\"friends\"" );
                break;
            case PUB_PRIVATE:
                fprintf( fp, " publication=\"private\"" );
                break;
            }
        }

        fputs( " />\n", fp );
#ifdef  _DEBUG
        fprintf( stderr, "%d) %s (URL: %s)\n",
                 i + 1, utf2sjis(buf),
                 mp[i].url );
#endif
    }

 // fprintf( fp, "</body>\n</opml>\n" );
    fputs( "</body>\n</opml>\n", fp );
}
Exemplo n.º 27
0
void HRBUSTJudger::submit() {
//	prepareCurl();
	string sub_url = "http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=postCode";
	stringstream sStream;
	cout << "Submit start................" << endl;
	string post_par[][2] = {
		"jumpUrl=", "",
		"&language=", "2",
		"&problem_id=", "1000",
		"&source_code=", ""
	};
	cout << "Lang: " << judgeInfo.getLang() << "| id:" << judgeInfo.getId() << "| Code:" << judgeInfo.getCode() << endl;

	sStream << judgeInfo.getLang();
	sStream >> post_par[1][1];
	
	sStream << judgeInfo.getId();
	sStream >> post_par[2][1];
	post_par[3][1]  = judgeInfo.getCode();
	
	cout << "Url done!" << endl;
	string submit = post_par[0][0]+post_par[0][1]+post_par[1][0]+post_par[1][1]+post_par[2][0]+post_par[2][1]+post_par[3][0]+escapeURL(post_par[3][1]);
	cout << submit << endl;
	curl_easy_setopt(easy_handle, CURLOPT_URL, sub_url.c_str());
	curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS, submit.c_str());
	performCurl("tmpfiles/submitdata.html");
	if (code != CURLE_OK) syslog(LOG_ERR, "submit failed."); 
}
Exemplo n.º 28
0
// static
void LLWeb::loadURLExternal(const std::string& url)
{
	std::string escaped_url = escapeURL(url);
	gViewerWindow->getWindow()->spawnWebBrowser(escaped_url);
}
Exemplo n.º 29
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott *CCJudger::getStatus(Bott * bott)
{
	time_t begin_time = time(NULL);

	Bott *result_bott;
	while (true) {
		// check wait time
		if (time(NULL) - begin_time > info->GetMax_wait_time()) {
			throw
			    Exception
			    ("Failed to get current result, judge time out.");
		}

		prepareCurl();
		curl_easy_setopt(curl, CURLOPT_URL, ((string)
						     "http://www.codechef.com/get_submission_status/"
						     +
						     bott->
						     Getremote_runid()).c_str
				 ());
		performCurl();

		string html = loadAllFromFile(tmpfilename);
		string result, time_used, memory_used;

		// get result
		if (!RE2::PartialMatch
		    (html, "\"result_code\":\"(.*?)\"", &result)) {
			throw Exception("Failed to get current result.");
		}
		result = convertResult(result);
		if (isFinalResult(result)) {
			// if result if final, get details
			if (!RE2::PartialMatch(html,
					       "(?s)\"time\":\"(.*?)\"",
					       &time_used)) {
				throw
				    Exception
				    ("Failed to parse details from status row.");
			}
			int time_ms = stringToDouble(time_used) * 1000 + 0.001;
			int memory_kb;
			result_bott = new Bott;
			result_bott->Settype(RESULT_REPORT);
			result_bott->Setresult(result);
			result_bott->Settime_used(intToString(time_ms));

			if (result != "Compile Error") {
				// CodeChef will update Memory usage later in submission table
				// Weird... why don't they put in get_submission_status api...
				memory_used = "0";
				prepareCurl();
				curl_easy_setopt(curl, CURLOPT_URL, ((string)
								     "http://www.codechef.com/submissions?handle="
								     +
								     escapeURL
								     (info->
								      GetUsername
								      ()) +
								     "&pcode=" +
								     escapeURL
								     (bott->Getvid
								      ())).
						 c_str());
				performCurl();
				html = loadAllFromFile(tmpfilename);
				string status;
				if (!RE2::PartialMatch(html,
						       "(?s)(<tr class=\"kol.*?<td width=\"60\">"
						       +
						       bott->Getremote_runid() +
						       "</td>.*?</tr>)",
						       &status)) {
					// Status row is not updated in time...
					log("Memory data not ready yet... Never mind, use 0 instead.");
					memory_used = "0";
				} else
				    if (!RE2::PartialMatch
					(status, ">([0-9\\.]*)M",
					 &memory_used)) {
					memory_used = "0";
				}
				memory_kb =
				    stringToDouble(memory_used) * 1024 + 0.001;
			}
			result_bott->Setmemory_used(intToString(memory_kb));
			result_bott->Setremote_runid(bott->Getremote_runid());
			break;
		}
	}
	return result_bott;
}
Exemplo n.º 30
0
/**
 * Get result and related info
 * @param bott  Original Bott info
 * @return Result Bott file
 */
Bott *NJUPTJudger::getStatus(Bott * bott)
{
	time_t begin_time = time(NULL);

	Bott *result_bott;
	while (true) {
		// check wait time
		if (time(NULL) - begin_time > info->GetMax_wait_time()) {
			throw
			    Exception
			    ("Failed to get current result, judge time out.");
		}

		prepareCurl();
		curl_easy_setopt(curl, CURLOPT_URL, ((string)
						     "http://acm.njupt.edu.cn/acmhome/showstatus.do").
				 c_str());
		string post =
		    (string) "problemId=" + bott->Getvid() + "&languageS=" +
		    escapeURL(bott->Getlanguage()) + "&userName="******"&resultS=All";
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
		performCurl();

		string html = loadAllFromFile(tmpfilename);
		string status;
		string runid, result, time_used, memory_used;

		// get first row
		if (!RE2::PartialMatch
		    (html, "(?s)<table.*?</thead>.*?(<tr.*?</tr>)", &status)) {
			throw Exception("Failed to get status row.");
		}
		// get result
		if (!RE2::PartialMatch(status,
				       "(?s)method=showdetail.*?value=\"(.*?)\".*?<b acc=\"acc\"></b>\\s*(.*?)\\s*<b acc=\"acc\"></b>",
				       &runid, &result)) {
			throw Exception("Failed to get current result.");
		}
		result = convertResult(trim(result));
		if (isFinalResult(result)) {
			// result is the final one, get details
			if (result == "Accepted") {
				// only accepted run has details
				if (!RE2::PartialMatch(status,
						       "(?s)([0-9]*)<b ms=\"ms\"></b>MS.*?([0-9]*)<b k=\"k\"></b>K",
						       &time_used,
						       &memory_used)) {
					throw
					    Exception
					    ("Failed to parse details from status row.");
				}
			} else {
				memory_used = time_used = "0";
			}
			result_bott = new Bott;
			result_bott->Settype(RESULT_REPORT);
			result_bott->Setresult(convertResult(result));
			result_bott->Settime_used(trim(time_used));
			result_bott->Setmemory_used(trim(memory_used));
			result_bott->Setremote_runid(trim(runid));
			break;
		}
	}
	return result_bott;
}