Guest User

SHT

a guest
Jan 31st, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. /*
  2.  * SHT.cpp
  3.  *
  4.  *  Created on: 29.01.2016
  5.  *      Author: armised
  6.  */
  7.  
  8. #include <sstream>
  9. #include <iostream>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <fstream>
  13. #include <sys/stat.h>
  14. #include <sys/types.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17.  
  18. using namespace std;
  19. int ghi = 0;
  20.  
  21. bool replace(std::string& str, const std::string& from, const std::string& to) { size_t start_pos = str.find(from); if(start_pos == std::string::npos) return false; str.replace(start_pos, from.length(), to); return true; }
  22. bool is_file_exist(const char *fileName) { std::ifstream infile(fileName); return infile.good(); }
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26.     char path[256];
  27.     getcwd(path, 256);
  28.     char rawin[256];
  29.     string exit =rawin;
  30.  
  31.     cout << "SHT Shell - Version 1.0.3\nBereit Befehle entgegen zu nehmen.\n";
  32.  
  33.     while (true)
  34.     {
  35.         system("echo -e \"\\e[36m\\c\"");
  36.         cout << path << "-§ ";
  37.         cin.getline(rawin, 256);
  38.         system("echo -e \"\\e[00m\\c\"");
  39.         //cin >> rawin;
  40.         //cout << rawin << endl;
  41.  
  42.         string in = rawin;
  43.         string args[90];
  44.         int i = 0;
  45.         stringstream ssin(in);
  46.  
  47.         while (ssin.good() && i < 90)
  48.         {
  49.             ssin >> args[i];
  50.             ++i;
  51.         }
  52.  
  53.         string xstr = "/system/bin/"+args[0];
  54.  
  55.         if (args[0] == "print")
  56.         {
  57.             int ix;
  58.             int argv = sizeof(args)/sizeof(*args);
  59.  
  60.             for(int ix = 1; ix < argv; ix++)
  61.             {
  62.                 cout << args[ix] << " ";
  63.             }
  64.  
  65.             cout << endl;
  66.         }
  67.         else if (args[0] == "exit")
  68.         {
  69.             string ans;
  70.             cout << "Wollen sie die Shell wirklich stoppen?\n[j/n]: ";
  71.             cin >> ans;
  72.             if (ans == "j" || ans == "J")
  73.             {
  74.                 cout << "Shuttding down...\nBB ;)" << endl;
  75.                 system("shutdown -s 1");
  76.                 return 0;
  77.             }
  78.             else
  79.             {
  80.                 cout << "Vorgang vom User abgebrochen.\n";
  81.             }
  82.  
  83.         }
  84.         else if (args[0] == "list")
  85.         {
  86.             system("ls");
  87.         }
  88.         else if (args[0] == "cd")
  89.         {
  90.             string x = args[1].c_str();
  91.             const char* f = x.c_str();
  92.             if (chdir(f) != 0)
  93.             {
  94.                 cout << "Das angegebene Verzeichnis konnte nicht gefunden werden\noder sie besitzen keine Berechtigung dazu.\n";
  95.             }
  96.             else
  97.             {
  98.                 char xpath[256];
  99.                 getcwd(xpath, 256);
  100.                 getcwd(path, 256);
  101.                 cout << "Du befindest dich jetzt in: " << xpath << endl;
  102.             }
  103.         }
  104.         else if(args[0] == "mf")
  105.         {
  106.             string f = args[1];
  107.             const char *x = f.c_str();
  108.  
  109.             ofstream file;
  110.             file.open(x);
  111.             file << "New File";
  112.             file.close();
  113.  
  114.             if (::ghi == 0)
  115.             {
  116.                 cout << "Hinweis: Sie können nur eine Datei pro Kommando erstellen.\n";
  117.                 ::ghi++;
  118.             }
  119.         }
  120.         else if(args[0] == "cls")
  121.         {
  122.             int li = 0;
  123.             while ( li <= 300)
  124.             {
  125.                 cout << " " << endl;
  126.                 li++;
  127.             }
  128.         }
  129.         else if(args[0] == "md")
  130.         {
  131.             if(!mkdir(args[1].c_str(), 0755))
  132.             {
  133.                 cout << "Das Verzeichnis "+args[1]+" wirde erfolgreich erstellt!" << endl;
  134.             }
  135.             else
  136.             {
  137.                 cout << "Unbekannter Error beim erstellen aufgetreten!" << endl;
  138.             }
  139.         }
  140.         else if(args[0] == "help")
  141.         {
  142.             cout << "Zurzeit gibt es folgende Befehle:\n\nexit - Beendet die Shell\ncls  - Löscht die Bildschirmausgabe\nmf   - Erstellt eine neue Datei\nmd   - Erstellt einen neuen Ordner\ndel  - Kann Dateien und Ordner löschen\nmov  - Verschiebt Dateien\nlist - Listet alle Dateien im aktuellen Verzeichnis auf\nprint  - Gibt eine Zeile Text aus\nwhoami  - Gibt den aktuellen User aus." << endl;
  143.         }
  144.         if(args[0] == "del")
  145.         {
  146.             string answer;
  147.  
  148.             cout << "Sind Sie sich sicher? [J/N]: ";
  149.             cin >> answer;
  150.  
  151.             if (answer == "j" || answer == "J")
  152.             {
  153.                 remove(args[1].c_str());
  154.                 cout << endl;
  155.             }
  156.             else if (answer == "n" || answer == "N")
  157.             {
  158.                 cout << "Vorgang vom User abgebrochen.\n";
  159.             }
  160.             else
  161.             {
  162.                 cout << "Ungueltige Eingabe: " << answer << endl;
  163.             }
  164.         }
  165.         else if(args[0] == "mov")
  166.         {
  167.             try
  168.             {
  169.                 rename(args[1].c_str(), args[2].c_str());
  170.             }
  171.             catch(int ex)
  172.             {
  173.                 cout << "Datei oder Ordner nicht gefunden!" << endl;
  174.             }
  175.         }
  176.         else if(args[0] == "shell")
  177.         {
  178.             //#define NELEMS(args) (sizeof(args) / (sizeof(args[0]))
  179.             string cmd = "";
  180.             strncat(cmd.c_str(), args);
  181.             system(cmd.c_str());
  182.         }
  183.         else if(args[0] == "whoami")
  184.         {
  185.             cout << "User: " << getuid() << endl;
  186.         }
  187.         else if(args[0] == "")
  188.         {
  189.             cout << "Bestanden!" << endl;
  190.         }
  191.         /*else if(args[0].find("") == 0)
  192.         {
  193.  
  194.         }
  195.         else if(args[0].find("") == 0)
  196.         {
  197.  
  198.         }
  199.         else if(args[0].find("") == 0)
  200.         {
  201.  
  202.         }
  203.         else if(args[0].find("") == 0)
  204.         {
  205.  
  206.         }
  207.         else if(args[0].find("") == 0)
  208.         {
  209.  
  210.         }
  211.         else if(args[0].find("") == 0)
  212.         {
  213.  
  214.         }
  215.         else if(args[0].find("") == 0)
  216.         {
  217.  
  218.         }
  219.         else if(args[0].find("") == 0)
  220.         {
  221.  
  222.         }*/
  223.         else
  224.         {
  225.             //cout << endl;
  226.         }
  227.     }
  228.  
  229. }
Advertisement
Add Comment
Please, Sign In to add comment