Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <fstream>
  5. #include <string>
  6. #include <sstream>
  7. #include <sys/resource.h>
  8. #include <sys/time.h>
  9. #include <unistd.h>
  10. #include <ctime>
  11.  
  12. #include <mysql_connection.h>
  13. #include <mysql_driver.h>
  14. #include <cppconn/exception.h>
  15. #include <cppconn/resultset.h>
  16. #include <cppconn/statement.h>
  17. #include <cppconn/prepared_statement.h>
  18. #include <cppconn/driver.h>
  19. #include "seccomp-bpf.h"
  20. #include "seccomp.h"
  21. #include <sys/resource.h>
  22. #include <sys/types.h>
  23. #include <sys/wait.h>
  24. #include <sys/prctl.h>
  25. #include <sys/ptrace.h>
  26. #include <sys/stat.h>
  27. #include <fcntl.h>
  28. #include <errno.h>
  29. #include <stddef.h>
  30. #include <linux/audit.h>
  31. #include <linux/filter.h>
  32. #include <sys/socket.h>
  33. //#include <linux/seccomp.h>
  34.  
  35. #include "pstream.h"
  36. #include "config.h"
  37.  
  38. #define BUF_SIZE    256
  39. /*
  40. static int install_syscall_filter(void)
  41. {
  42.     struct sock_filter filter[] = {
  43.     VALIDATE_ARCHITECTURE,
  44.         EXAMINE_SYSCALL,
  45.         ALLOW_SYSCALL(rt_sigreturn),
  46. #ifdef __NR_sigreturn
  47.         ALLOW_SYSCALL(sigreturn),
  48. #endif
  49.         ALLOW_SYSCALL(exit_group),
  50.         ALLOW_SYSCALL(exit),
  51.         ALLOW_SYSCALL(read),
  52.         ALLOW_SYSCALL(write),
  53.                 ALLOW_SYSCALL(brk),
  54.                 ALLOW_SYSCALL(access),
  55.                 ALLOW_SYSCALL(mmap),
  56.                 ALLOW_SYSCALL(open),
  57.                 ALLOW_SYSCALL(fstat),
  58.                 ALLOW_SYSCALL(mprotect),
  59.                 ALLOW_SYSCALL(close),
  60.                 ALLOW_SYSCALL(arch_prctl),
  61.                 ALLOW_SYSCALL(munmap),
  62.                 ALLOW_SYSCALL(execve),
  63.         KILL_PROCESS,
  64.     };
  65.     struct sock_fprog prog = {
  66.         .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
  67.         .filter = filter,
  68.     };
  69.  
  70.     if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
  71.         perror("prctl(NO_NEW_PRIVS)");
  72.         goto failed;
  73.     }
  74.     if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) {
  75.         perror("prctl(SECCOMP)");
  76.         goto failed;
  77.     }
  78.     return 0;
  79.  
  80. failed:
  81.     if (errno == EINVAL)
  82.         fprintf(stderr, "SECCOMP_FILTER is not available. :(\n");
  83.     return 1;
  84. }
  85. */
  86. using namespace std;
  87. void syscall_filter_init(bool action){
  88.    
  89.     prctl (PR_SET_NO_NEW_PRIVS, 1);
  90.     prctl (PR_SET_DUMPABLE, 0);
  91.  
  92.     scmp_filter_ctx ctx = seccomp_init (SCMP_ACT_ALLOW);
  93.    
  94. //    seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(fork), 0);
  95.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(vfork), 0);
  96.    // seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(clone), 1,
  97.      //   SCMP_A1 (SCMP_CMP_EQ, 0));
  98.    // seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(kill), 0);
  99.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(sigaction), 0);
  100.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(unlink), 0);
  101.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(unlinkat), 0);
  102.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(rename), 0);
  103.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(chdir), 0);
  104.     seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(mkdir), 0);
  105.    
  106.    // seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(bind), 0);
  107. //    seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(setsockopt), 0);
  108.  /*   seccomp_rule_add (ctx, SCMP_ACT_TRAP, SCMP_SYS(listen), 0);
  109.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(execve), 0);
  110.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0);
  111.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);
  112.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap), 0);
  113.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0);
  114.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0);
  115.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0);
  116.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
  117.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect), 0);
  118.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
  119.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(arch_prctl), 0);
  120.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(munmap), 0);
  121.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), 0);
  122.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(uname), 0);
  123.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
  124.     seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(readlink), 0);
  125.   */
  126.    if(action==true) {
  127.     seccomp_load (ctx);
  128.    }
  129.   else if(action==false)
  130.      {
  131.       seccomp_release(ctx);
  132.      }
  133.  
  134. /*scmp_filter_ctx ctx;
  135.   ctx = seccomp_init(SCMP_ACT_KILL); // default action: kill
  136.  
  137.   // setup basic whitelist
  138.   seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0);
  139.   seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), 0);
  140.   seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
  141.   seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);
  142.  
  143.   // setup our rule
  144.   seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(dup2), 2,
  145.                         SCMP_A0(SCMP_CMP_EQ, 1),
  146.                         SCMP_A1(SCMP_CMP_EQ, 2));
  147.  
  148.   // build and load the filter
  149.   seccomp_load(ctx);
  150. */
  151. }
  152.  
  153. struct tm *theTime;
  154.  
  155. //konwersja z int na string
  156. string konwertuj(int i) {
  157.  ostringstream ss;
  158.    ss << i;
  159.     string str=ss.str();
  160.     return str;
  161.   }
  162.  
  163. //dopisywanie tekstu do logów
  164. void dopisz(string log) {
  165.    fstream plik;
  166.     plik.open(LOG, ios::out|ios::app);
  167.      plik<<endl<<log;
  168.      plik.close();
  169. }
  170.  
  171. //tworzenie katalogu submita
  172. string dir(int id)
  173.  {
  174.   string dir="sudo mkdir /POJS/result/";
  175.   dir+=konwertuj(id);
  176.   dir+=" && sudo chmod -R 777 /POJS/result/";
  177.   dir+=konwertuj(id);
  178.    return dir;
  179.  }
  180.  
  181. //Uzyskiwanie czasu
  182. string get_time() {
  183.   time_t tim;
  184.    time(&tim);
  185.   theTime = localtime(&tim);
  186.    string time="";
  187.    time+=konwertuj(1900+(theTime->tm_year));
  188.    time+="-";
  189.    if(((theTime->tm_mon)+1)<10) {
  190.       time+="0";
  191.       time+=konwertuj((theTime->tm_mon)+1);
  192.      }
  193.    else {
  194.      time+=konwertuj((theTime->tm_mon)+1);
  195.      }
  196.    
  197.    time+="-";
  198.    time+=konwertuj(theTime->tm_mday);
  199.    time+=" ";
  200.    time+=konwertuj(theTime->tm_hour);
  201.    time+=":";
  202.    time+=konwertuj(theTime->tm_min);
  203.    time+=":";
  204.    time+=konwertuj(theTime->tm_sec);
  205.     return time;
  206. }
  207.  
  208. //sprawdzanie rozszerzenia submita
  209. string ext(string submit) {
  210.    int indeks=0;
  211.     for(int i=0;i<submit.length();i++)
  212.         {
  213.          if(submit[i]=='.')
  214.             {
  215.              indeks=i;
  216.             }
  217.         }
  218.    string ext="";
  219.         for(int i=indeks+1;i<submit.length();i++)
  220.              {
  221.                ext+=submit[i];
  222.              }
  223.          return ext;
  224.    }
  225.  
  226. //tworzenie polecenia kompilacji
  227. string compile(string path, string lang, int id) {
  228.     string comp="";
  229.         if(lang=="cpp"){
  230.            comp+="g++ -O2 -std=c++11 -static -lm -Wall ";
  231.            comp+=path;
  232.            comp+=" -o /POJS/result/";
  233.            comp+=konwertuj(id);
  234.            comp+="/";
  235.            comp+=konwertuj(id);
  236.            comp+=" 2> /tmp/comperror";
  237.             return comp;
  238.          }
  239.          else if(lang=="c") {
  240.           comp+="gcc -std=gnu99 -O2 -static -lm -Wall ";
  241.           comp+=path;
  242.           comp+=" -o /POJS/result/";
  243.            comp+=konwertuj(id);
  244.            comp+="/";
  245.            comp+=konwertuj(id);
  246.            comp+=" 2> /tmp/comperror";
  247.             return comp;
  248.          }
  249.         else if(lang=="ml") {
  250.           comp+="ocamlc ";
  251.           comp+=path;
  252.           comp+=" -o /POJS/result/";
  253.           comp+=konwertuj(id);
  254.           comp+="/";
  255.           comp+=konwertuj(id);
  256.           comp+=" 2> /tmp/comperror";
  257.            return comp;
  258.          }
  259.  }
  260.  
  261. //Tworzenie MySQL query
  262. string create_query(string status, int points, int id, string output) {
  263.   string query="UPDATE submits SET status='";
  264.    query+=status;
  265.    query+="', points='";
  266.    query+=konwertuj(points);
  267.    query+="', tests='";
  268.    query+=output;
  269.    query+="' WHERE id='";
  270.    query+=konwertuj(id);
  271.    query+="';";
  272.      return query;
  273. }
  274. string create_query_sec(string status, int points, int id, int section, string output) {
  275.   string query="UPDATE contest";
  276.   query+=konwertuj(section);
  277.   query+=" SET nazwa='";
  278.   query+=status;
  279.   query+="', ilosc='";
  280.   query+=konwertuj(points);
  281.   query+="', output='";
  282.   query+=output;
  283.   query+="' WHERE id='";
  284.   query+=konwertuj(id);
  285.   query+="';";
  286.    return query;
  287. }
  288. //Sprawdzanie poprawności wykonania kompilacji
  289. bool checkcomp(int id) {
  290.    fstream exist;
  291.    string name="/POJS/result/";
  292.    name+=konwertuj(id);
  293.    name+="/";
  294.    name+=konwertuj(id);
  295.     exist.open(name.c_str());
  296.    bool come;
  297.      if(exist.good()==true)
  298.         {
  299.          exist.close();
  300.         come=true;
  301.          
  302.         }
  303.      else
  304.         {
  305.              come=false;
  306.          }
  307.        name="sudo cp /tmp/comperror /POJS/result/";
  308.        name+=konwertuj(id);
  309.        name+="/ce.log";
  310.        system(name.c_str());
  311.        system("sudo rm /tmp/comperror");
  312.    return come;
  313.  }
  314.  
  315. //sprawdzanie czy istnieją różnice między wzorcem, a zgłoszeniem
  316. bool checkdiff() {
  317.     int lines_num=0;
  318.      string line;
  319.       fstream diff("/tmp/diffmerge");
  320.        while (std::getline(diff, line))
  321.         ++lines_num;
  322.         if(lines_num>0)
  323.            {
  324.             return false;
  325.            }
  326.         else {
  327.              return true;
  328.           }
  329. }
  330. bool checkdifff() {
  331.     int lines_num=0;
  332.      string line;
  333.       fstream diff("/tmp/difffault");
  334.        while (std::getline(diff, line))
  335.         ++lines_num;
  336.         if(lines_num>0)
  337.            {
  338.             return false;
  339.            }
  340.         else {
  341.              return true;
  342.           }
  343. }
  344.  
  345. //Sprawdzanie czy zaszedł while(true) z std::cout
  346. bool checktle(int id, int i) {
  347.  string name="/POJS/result/";
  348.   name+=konwertuj(id);
  349.   name+="/";
  350.   name+=konwertuj(i);
  351.   name+=".out";
  352.   struct stat filestatus;
  353.   stat( name.c_str(), &filestatus );
  354.    if(filestatus.st_size>100056128) {
  355.         return true;
  356.      }
  357.    else {
  358.        return false;
  359.    }
  360. }
  361. //Sprawdzanie bezpieczeństwa programu
  362. bool is_danger() {
  363.          fstream danger;
  364.            danger.open("/tmp/dangerous", std::ios::in);
  365.              string line;
  366.                while ( std::getline( danger, line ) ) {
  367.              if ( line.find( "clone" ) != std::string::npos || line.find( "vfork" ) != std::string::npos || line.find( "kill" ) != std::string::npos || line.find( "sigaction" ) != std::string::npos || line.find("setsockopt") != std::string::npos || line.find("rename") != std::string::npos || line.find("chdir") != std::string::npos || line.find("mkdir") != std::string::npos || line.find("unlink") != std::string::npos || line.find("unlinkat") != std::string::npos || line.find("bind") != std::string::npos || line.find("listen") != std::string::npos) {
  368.                           return true;
  369.         }
  370.  
  371.     }
  372.     return false;
  373. }
  374.  
  375. //Sprawdzanie czy nie pisze się tego outputa pod rząd
  376. bool groupcheck(int id, int tests) {
  377.   string diff="";
  378.   int k=0;
  379.   int n=0;
  380.    for(int i=1;i<tests;i++) {
  381.       diff="diff -w /POJS/result/";
  382.       diff+=konwertuj(id);
  383.       diff+="/";
  384.       diff+=konwertuj(i);
  385.       diff+=".out /POJS/result/";
  386.       int k=i+1;
  387.       diff+=konwertuj(id);
  388.       diff+="/";
  389.       diff+=konwertuj(k);
  390.       system("rm /tmp/difffault");
  391.       diff+=".out > /tmp/difffault";
  392.        system(diff.c_str());
  393.        if(checkdifff()==true) {
  394.           n++;
  395.         }
  396. }
  397.    if(n==tests) {
  398.       return true;
  399.      }
  400.    else {
  401.        return false;
  402.      }
  403. }
  404.  
  405. //Funkcja Główna
  406. int main(int argc, char ** argv)
  407.  {
  408. //    struct rlimit ml;
  409.     struct rlimit rl;
  410.     string log="Sprawdzaczka POJS uruchomiona\n";
  411.       dopisz(log);
  412.         if(argc>=7) //Jeżeli liczba argumentów jest większa niż 7
  413.            {
  414.             log="Liczba argumentów poprawna";
  415.               dopisz(log);
  416.              for(int i=1;i<argc;i++)
  417.                  {
  418.                   log="Argument ";
  419.                   log+=konwertuj(i);
  420.                   log+=": ";
  421.                   log+=argv[i];
  422.                    dopisz(log);
  423.                  }
  424.               string quest=argv[1]; //kod zadania
  425.               int id=atoi(argv[2]); //ID zgłoszenia
  426.               string submit=argv[3]; //ścieżka do submita
  427.               int tests=atoi(argv[4]); //liczba testów
  428.               int time=atoi(argv[5]); //limit czasu
  429.               int memory=atoi(argv[6]); //limit pamięci
  430.               int section=0;
  431.               int secid=0;
  432.               string output="";
  433.                 if(argc==9){
  434.                  section=atoi(argv[7]);
  435.                  secid=atoi(argv[8]);
  436.                 }
  437.               system(dir(id).c_str()); //tworzenie katalogu zgłoszenia
  438.                string comp="";
  439.                 if(ext(submit)=="cpp") { //Jeżeli język to C++
  440.                     log="Język: C++ (.cpp)";
  441.                       dopisz(log);
  442.                   }
  443.                 else if(ext(submit)=="c") { //Jeżeli język to C
  444.                     log="Język: C (.c)";
  445.                       dopisz(log);
  446.                    }
  447.                 else if(ext(submit)=="ml") { //jeżeli język to OCaml
  448.                     log="Język OCaml (.ml)";
  449.                        dopisz(log);
  450.                    }
  451.                  else {
  452.                     log="\n==ERROR==\nBłędny Format przesłanego pliku\nKoniec pracy\n\n";
  453.                      dopisz(log);
  454.                       cout<<log;
  455.                        return 0;
  456.                   }
  457.                   log="Polecenie kompilujące:";
  458.                    log+=compile(submit, ext(submit), id);
  459.                      dopisz(log);
  460.                       log="Kompilacja Rozpoczęta!!!";
  461.                         dopisz(log);
  462.                          /* Obtain the current limits. */
  463.                          getrlimit (RLIMIT_CPU, &rl);
  464.                           /* Set a CPU limit of 3 seconds. */
  465.                           rl.rlim_cur = 3;
  466.                           setrlimit (RLIMIT_CPU, &rl);
  467.                           system(compile(submit, ext(submit), id).c_str());
  468.                           system("sudo chmod -R 777 /tmp/comperror ");
  469.                           if(checkcomp(id)==true) {
  470.                              log="Zkompilowano pomyślnie !!!\n";
  471.                               dopisz(log);
  472.                               int points=0;
  473.                               string run="";
  474.                               string diff="";
  475.                              for(int i=1;i<=tests;i++) {
  476.                                  run="";
  477.                                  diff="";
  478.                                  run+="/POJS/result/";
  479.                                  run+=konwertuj(id);
  480.                                  run+="/";
  481.                                  run+=konwertuj(id);
  482.                                  run+="</POJS/quests/";
  483.                                  run+=quest;
  484.                                  run+="/";
  485.                                  run+=konwertuj(i);
  486.                                  run+=".in>/POJS/result/";
  487.                                  run+=konwertuj(id);
  488.                                  run+="/";
  489.                                  run+=konwertuj(i);
  490.                                  run+=".out";
  491.                                getrlimit (RLIMIT_CPU, &rl);
  492.                                rl.rlim_cur = time;
  493.                                 setrlimit (RLIMIT_CPU, &rl);
  494.                            //    getrlimit (RLIMIT_AS, &ml);
  495.                              //   ml.rlim_cur = memory;
  496.                                // setrlimit(RLIMIT_AS, &ml);
  497.                                 bool action=true;
  498.                                 syscall_filter_init(action);
  499.                                 system(run.c_str());
  500.                                 action=false;
  501.                                 syscall_filter_init(action);
  502.                                 diff="diff -w /POJS/quests/";
  503.                                 diff+=quest;
  504.                                 diff+="/";
  505.                                 diff+=konwertuj(i);
  506.                                 diff+=".out /POJS/result/";
  507.                                 diff+=konwertuj(id);
  508.                                 diff+="/";
  509.                                 diff+=konwertuj(i);
  510.                                 system("rm /tmp/diffmerge");
  511.                                 diff+=".out > /tmp/diffmerge";
  512.                                   system(diff.c_str());
  513.                                     system("chmod -R 777 /tmp/diffmerge");
  514.                                       if(checktle(id, i)==true) {
  515.                                         string status="TLE";
  516.                                         log+="\nStatus: TLE\nPunkty:";
  517.                                         log+=konwertuj(points);
  518.                                          for(int k=i;k<=tests;k++) {
  519.                                              output+="Test nr ";
  520.                                              output+=konwertuj(k);
  521.                                              output+=": 0pkt TLE <br>";
  522.                                             }
  523.                                              dopisz(output);
  524.                                         dopisz(log);
  525.                                          sql::mysql::MySQL_Driver *driver;
  526.                                          sql::Connection *con;
  527.                                          sql::Statement *stmt;
  528.                                          sql::ResultSet *res;
  529.                                          driver = sql::mysql::get_driver_instance();
  530.                                          con=driver->connect("tcp://156.17.4.36:3306", "root", "Kubapat1309");
  531.                                          log="Łączenie z bazą danych POJS pod ip: 156.17.4.36, Port: 3306";
  532.                                           dopisz(log);
  533.                                          con->setSchema("mysql");
  534.                                            log="Pomyślnie przesłano dane do bazy danych";
  535.                                          dopisz(log);
  536.                                         stmt = con->createStatement();
  537.                                           if(argc==9) {
  538.                                             stmt->execute(create_query_sec(status, points, secid, section, output).c_str());
  539.                                            }
  540.                                          else {
  541.                                          stmt->execute(create_query(status, points, id, output).c_str());
  542.                                           }
  543.                                            delete stmt;
  544.                                            delete con;
  545.                                              return 0;
  546.                                         }
  547.                                     system(diff.c_str());
  548.                                     system("chmod -R 777 /tmp/diffmerge");
  549.                                     if(checkdiff()==true) {
  550.                                        output+="Test nr ";
  551.                                        output+=konwertuj(i);
  552.                                        output+=": ";
  553.                                        int punkt=(100/tests);
  554.                                        output+=konwertuj(punkt);
  555.                                        output+="pkt AC <br>";
  556.                                        points+=(100/tests);
  557.                                        
  558.                                       }
  559.                                    else {
  560.                                       output+="Test nr ";
  561.                                       output+=konwertuj(i);
  562.                                       output+=": ";
  563.                                        output+="0pkt WA <br>";
  564.                                      }
  565.                               }
  566.                                cout<<points;
  567.                                    string status="";
  568.                                    // if(groupcheck(id, tests)==true) {
  569.                                      //   points=0;
  570.                                     // }
  571.                                     if(points>=95)
  572.                                         {
  573.                                           status="AC";
  574.                                         }
  575.                                     else {
  576.                                            status="WA";
  577.                                        }
  578.                                  dopisz(output);
  579.                                  log+="\nStatus: ";
  580.                                  log+=status;
  581.                                  log+="\nPunkty:";
  582.                                  log+=konwertuj(points);
  583.                                     dopisz(log);
  584.                                      sql::mysql::MySQL_Driver *driver;
  585.                                      sql::Connection *con;
  586.                                      sql::Statement *stmt;
  587.                                      sql::ResultSet *res;
  588.                                       driver = sql::mysql::get_driver_instance();
  589.                                        con=driver->connect("tcp://156.17.4.36:3306", "root", "Kubapat1309");
  590.                                        log="Łączenie z bazą danych POJS pod ip: 156.17.4.36, Port: 3306";
  591.                                          dopisz(log);
  592.                                         con->setSchema("mysql");
  593.                                            log="Pomyślnie przesłano dane do bazy danych\n\nKoniec Pracy\n";
  594.                                          dopisz(log);
  595.                                         stmt = con->createStatement();
  596.                                          if(argc==9) {
  597.                                            stmt->execute(create_query_sec(status, points, secid, section, output).c_str());
  598.                                           }
  599.                                            else {
  600.                                         stmt->execute(create_query(status, points, id, output).c_str());
  601.                                            }
  602.                                            delete stmt;
  603.                                            delete con;
  604.                                              return 0;
  605.                             }
  606.                             else if(checkcomp(id)==false) {
  607.                                 log="\n==ERROR==\nKompilacja nie powiodła się\n";
  608.                                  dopisz(log);
  609.                                cout<<log;
  610.                                 sql::mysql::MySQL_Driver *driver;
  611.                                 sql::Connection *con;
  612.                                 sql::Statement *stmt;
  613.                                 sql::ResultSet *res;
  614.                                 driver = sql::mysql::get_driver_instance();
  615.                                 con=driver->connect("tcp://156.17.4.36:3306", "root", "Kubapat1309");
  616.                                 log="Łączenie z bazą danych POJS pod ip: 156.17.4.36, Port: 3306";
  617.                                   dopisz(log);
  618.                                 con->setSchema("mysql");
  619.                                   log="Pomyślnie przesłano dane do bazy danych";
  620.                                    dopisz(log);
  621.                                   log="ID:";
  622.                                   log+=konwertuj(id);
  623.                                   log+="\nStatus: CE\nPunkty:0\n\nKoniec pracy\n";
  624.                                    dopisz(log);
  625.                                   cout<<log;
  626.                                 stmt = con->createStatement();
  627.                                 string status="CE";
  628.                                 string output="ALL TESTS CE";
  629.                                 int points=0;
  630.                                 if(argc==9) {
  631.                                 stmt->execute(create_query_sec(status, points, secid, section, output).c_str());
  632.                                    }
  633.                                 else {
  634.                                 stmt->execute(create_query(status, points, id, output).c_str());
  635.                                   }
  636.                                 delete stmt;
  637.                                 delete con;
  638.                                  return 0;
  639.                              }
  640.            }
  641.          else {
  642.            log="\n==ERROR==\nNiepoprawna liczba argumentów\nKoniec pracy\n\n";
  643.             dopisz(log);
  644.             cout<<log;
  645.              return 0;
  646.             }
  647.     return 0;
  648.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement