Ejemplo n.º 1
0
Status processRequest(Row& r) {
  try {
    osquery::http::Client client_;
    osquery::http::Response response_;
    osquery::http::Request request_(r["url"]);

    // Change the user-agent for the request to be osquery
    request_ << osquery::http::Request::Header("User-Agent", r["user_agent"]);

    // Measure the rtt using the system clock
    std::chrono::time_point<std::chrono::system_clock> start =
        std::chrono::system_clock::now();
    response_ = client_.get(request_);
    std::chrono::time_point<std::chrono::system_clock> end =
        std::chrono::system_clock::now();

    r["response_code"] = INTEGER(static_cast<int>(response_.status()));
    r["round_trip_time"] = BIGINT(
        std::chrono::duration_cast<std::chrono::microseconds>(end - start)
            .count());
    r["result"] = response_.body();
    r["bytes"] = BIGINT(r["result"].size());
  } catch (const std::exception& e) {
    return Status(1, e.what());
  }

  return Status();
}
void updateIPDiscoveryServer(){
  //TODO: Using exec to call ifconfig is probably not the right way to
  // to do this
  std::string res = exec("/sbin/ifconfig");
  std::istringstream ifconfigin(res);
  std::string nibble;
  while(ifconfigin >> nibble, nibble != "wlan0"){
    //Do nothing, just throw it all away
  }
  while(ifconfigin >> nibble, nibble != "inet"){
        //Do nothing, just throw it all away
  }
  ifconfigin >> nibble;
  std::string address(nibble.begin() + 1 + nibble.find(":"),
		      nibble.end());
  //std::cout << "Server running at: |" << address << "|" << std::endl;
  http::client client_;
  try {
    http::client::request request_("http://shelvar.com/ip.php?ip=" + address);
    //request_ << http::client::header("Conection", "close");
    
    http::client::response response_ = client_.get(request_);
    //The purpose of this next line is to force the system to block
    // until the response is received. get() is async, and we
    // get a race condition if we don't wait for this to come back
    std::cout << "Discovery service update result: " << body(response_)
	      << std::endl;;
  } catch (std::exception& e) {
    // deal with exceptions here
  }
}
Ejemplo n.º 3
0
Json::Value BTSyncInterface::setFilePreferences(std::string secret,
						std::string path,
						bool download) {
  return request_("set_file_prefs&secret=" + secret +
		  "&path=" + path +
		  "&download=" + std::string(download ? "1" : "0"));
}
Ejemplo n.º 4
0
Json::Value BTSyncInterface::setFolderHosts(std::string secret, 
					    Json::Value hosts) {
  std::string csv;
  for (unsigned int i = 0; i < hosts["hosts"].size(); i++) {
    if (i != 0) csv += ",";
    csv += hosts["hosts"][i].asString();
  }

  return request_("set_folder_hosts&secret=" + secret +
		  "&hosts=" + csv);
}
Ejemplo n.º 5
0
Json::Value BTSyncInterface::setPreferences(Json::Value params) {
  std::string prefs;
  std::vector<std::string> members = params.getMemberNames();
  
  // format JSON params as "&param1=value1&param2=value2...."
  for (std::string it : members) {
    prefs += "&" + it + "=" + jsonValueToString_(params[it]);
  }
  
  return request_("set_prefs" + prefs);
}
Ejemplo n.º 6
0
Json::Value BTSyncInterface::addFolder(std::string path, std::string secret, 
				       bool selective_sync) {
  return request_("add_folder&dir=" + path + 
		  "&secret=" + std::string(secret) +
		  "&selective_sync=" + std::string(selective_sync ? "1" : "0"));
}
Ejemplo n.º 7
0
Json::Value BTSyncInterface::getFolderPreferences(std::string secret) {
  return request_("get_folder_prefs&secret=" + secret);
}
Ejemplo n.º 8
0
  Json::Value BTSyncInterface::getSecrets(std::string secret, bool encrypted) {
  return request_("get_secrets" + 
		  std::string(encrypted ? "&type=encryption" : "") +
		  "&secret=" + std::string(secret));
}
Ejemplo n.º 9
0
Json::Value BTSyncInterface::getFolderPeers(std::string secret) {
  return request_("get_folder_peers&secret=" + secret);
}
Ejemplo n.º 10
0
Json::Value BTSyncInterface::getFiles(std::string secret, std::string path) {
  return request_("get_files&secret=" + secret +
		  "&path=" + path);
}
Ejemplo n.º 11
0
Json::Value BTSyncInterface::getFiles(std::string secret) {
  return request_("get_files&secret=" + secret);
}
Ejemplo n.º 12
0
Json::Value BTSyncInterface::removeFolder(std::string secret) {
  return request_("remove_folder&secret=" + secret);
}
Ejemplo n.º 13
0
Json::Value BTSyncInterface::getFolders() {
  return request_("get_folders");
}
Ejemplo n.º 14
0
Json::Value BTSyncInterface::shutdown() {
  return request_("shutdown");
}
Ejemplo n.º 15
0
Json::Value BTSyncInterface::getSpeed() {
  return request_("get_speed");
}
Ejemplo n.º 16
0
Json::Value BTSyncInterface::getVersion() {
  return request_("get_version");
}
Ejemplo n.º 17
0
Json::Value BTSyncInterface::getOSName() {
  return request_("get_os");
}
Ejemplo n.º 18
0
Json::Value BTSyncInterface::getPreferences() {
  return request_("get_prefs");
}