Monday, August 22, 2016

Really simple remote administration tool for linux (To simple to be useful)

 I hammered out the basics of this tool. Basically it will do a conditional get request every second then if the remote file is newer than the file on the system it will download the remote file and read the file and imput the line of text into a system call to execute the command. Afterword it will delete the text file.

#include <string>
#include <sstream>
#include <iostream>
#include <cctype>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;


//time interval for checking file
const int NUM_SECONDS = 1;

int main()
{
    int count = 1;

    double time_counter = 0;

    clock_t this_time = clock();
    clock_t last_time = this_time;

    while(true)
    {
        this_time = clock();

        time_counter += (double)(this_time - last_time);

        last_time = this_time;

        if(time_counter > (double)(NUM_SECONDS * CLOCKS_PER_SEC))
        {
            time_counter -= (double)(NUM_SECONDS * CLOCKS_PER_SEC);



time_counter -= (double)(NUM_SECONDS * CLOCKS_PER_SEC);

//We'll need to make this a conditional get and check if the file already exists. Error handling as well.
//download file
system("wget http://192.168.1.7/commands.txt");

//open a stream reader and read from the file
{ string line; ifstream infile ("commands.txt");

//check if file is open
if (infile.is_open())
//if file is open we'll get lines each line of text from the file as a string
{ while (getline (infile,line)){

//convert string to std::string whatever fuck strings in c++
std::string str = static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << line).str();

//convert string to something system(); can use
const char * c = str.c_str();

//make system call
system(c);
//remove text file we'll need to change this later
system("rm commands.txt");

}
}
}

            count++;
        }


    }
    return 0;
}

No comments:

Post a Comment