From: Malte Bublitz Date: Sun, 11 Dec 2022 18:43:08 +0000 (+0100) Subject: Original version X-Git-Url: https://git.rt3x.de/?a=commitdiff_plain;h=058aa03fe207f79830c9b8511331d4e3f09001bf;p=bbs.git Original version --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f5604fe --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +WGET = wget +EXCUSES_URL = http://pages.cs.wisc.edu/~ballard/bofh/excuses + +all: excuses + +excuses: + $(WGET) $(EXCUSES_URL) + diff --git a/bbs_env.py b/bbs_env.py new file mode 100644 index 0000000..2b6e1fb --- /dev/null +++ b/bbs_env.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +import platform + +class BBSFakeUserEnv(object): + _user = "" + _node = "" + _name = "" + _hideRealUname = False + + def setUser(self, _user): + self._user = _user + + def getUser(self): + return self._user + + def getNode(self): + return self._node + + def getName(self): + return self._name + + def setHideRealUname(self, _hideRealUname): + self._hideRealUname = _hideRealUname + + def getHome(self): + return "/usr/home/" + self.getUser() + + def getUName(self): + if not self._hideRealUname: + return platform.uname()[0]+" "+platform.uname()[1]+" "+platform.uname()[2] + else: + return "Linux "+self.getNode()+" 0.13.37-42" + + def __init__(self): + self._user = "doctor_who" + self._node = platform.node() + #self._node = platform.uname()[1] + self._name = "I am the Doctor!" + diff --git a/bofh.py b/bofh.py new file mode 100644 index 0000000..ef698ea --- /dev/null +++ b/bofh.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from random import randint + +def get_excuse(): + f = open("excuses", "r") + excuses = f.read().split("\n") + f.close() + n = len(excuses) + i = randint(0, n-1) + return excuses[i] + +if __name__ == "__main__": + print(get_excuse()) + diff --git a/minishell b/minishell new file mode 100755 index 0000000..930416b --- /dev/null +++ b/minishell @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Minimal Shell +# Use whenever a user should be able to launch a shell, +# but not to execute commands. +# +# Copyright (c) 2013-2015 Malte Bublitz. +# All rights reserved. +# +# Licensed under the terms of the 2-clause BSD license. +# See LICENSE for details. +# + +import platform +import os +import sys +import getpass + +os.chdir(os.path.dirname(sys.argv[0])) + +import bbs_env +import bofh + +def getuser(): + return "doctorwho" + +def login(prompt1="login: ", prompt2="Password: "): + login_data = ["", ""] + while len(login_data[0]) < 2: + login_data[0] = input(prompt1) + + login_data[1] = getpass.getpass(prompt2) + + return login_data + +def main(): + env = bbs_env.BBSFakeUserEnv() + commands_allowed = ( + "", + "exit", + "logout", + "help", + "whoami", + "id", + "hostname", + "pwd", + "uname", + "clear", + "sry" + ) + command = "" + + # Log in + env._user = login()[0] + env.setHideRealUname(True) + + print("\nWelcome on "+env.getNode()+", "+env.getUser()+"!\n") + + try: + while command != "exit": + print("$ ",end="") + try: + command = input() + + except KeyboardInterrupt: + print("") + continue + + if command == "logout" or command == "exit": + command = "exit" + + elif command == "help": + print("""Minimal Shell Help +Commands: + whoami + id + hostname + pwd + uname + clear + help + logout/exit +""") + elif command == "whoami": + if not env.getUser() in ["doctor", "doctorwho", "doctor_who"]: + print(env.getUser()) + else: + #print("I am the Doctor!") + print(env.getName()) + print("") + print("I should behave politely, so maybe excuse for") + print("future mistakes with \"sry\" (Yes, an easter egg!)") + print("") + + elif command == "id": + print("uid=42(" + env.getUser() + ") gid=100(users) groups=42(" + env.getUser() + "),9999(telnet)") + + elif command == "hostname": + print(env.getNode()) + + elif command == "pwd": + # print("/usr/home/"+getuser()) + print(env.getHome()) + + elif command == "uname": + print(env.getUName()) + + elif command == "clear": + ret_code = os.system("clear") + + elif command == "sry" or command == "bofh": + print(" "+bofh.get_excuse()) + + #elif not command in commands_allowed: + # print("-minishell: "+command.split(" ")[0]+": Command not found.") + elif len(command) > 0: + print("-minishell: "+command.split(" ")[0]+": Command not found.") + + except EOFError: + print("") + + print("Good bye.") + +if __name__ == "__main__": + main() +