This repository has been archived on 2023-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
ACMS/src/Server/miscCommands.py

82 lines
3.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Miscellaneous commands: A.K.A. "What wouldn't be elsewhere"...
"""
import os
from .fileCommands import DATA_PATH
from .CommandException import CommandException
__author__ = "HorlogeSkynet"
__copyright__ = "Copyright 2017, ACMS"
__license__ = "GPLv3"
__status__ = "Production"
__date__ = "04/06/2017"
def helpController(admin):
result = "Commands available for you at the moment:\n\n"
result += "\thelp: Displays this man page\n"
result += "\tclear: Clears the console\n"
result += "\tstartx: Run both VNC client and server (prototype)\n"
result += "\thistory: Displays your commands history (available everywhere)\n"
result += "\tvim [FILE]: Opens a text editor (on `FILE` if chosen) in read / write mode\n"
result += "\tview [FILE]: Opens a text editor (on `FILE` if chosen) in read only mode\n"
result += "\tcd [PATH]: Changes your current directory (`~` and `/` supported)\n"
result += "\trm [-r] FILE: Removes a file / directory (recursive mode supported)\n"
result += "\tls [-l] [PATH]: Lists the content of a directory (list mode supported)\n"
result += "\tmkdir [-p] FILE: Creates a directory (parent creation mode supported)\n"
result += "\tmv OLD_PATH NEW_PATH: Moves (or renames) a file or a directory\n"
result += "\tcp [-r] SRC_PATH DST_PATH: Copies a file or a directory (recursive mode supported)\n"
result += "\trights FILE: Displays the rights set on the file\n"
result += "\tchown FILE NEW_OWNER: Changes the owner of a file\n"
result += "\tfind FILE: Finds a file in the server\n"
result += "\tchmod [-r] FILE {USER,GROUP}{+,-,=}{r,w,x} Changes the rights for a file or a directory\n"
if admin:
result += '\n'
result += "\tgroups: Displays the ACMS groups and their users\n"
result += "\tpasswd [USER]: Changes the password of an user (or yours without any argument)\n"
result += "\tadduser USER: Creates a new user\n"
result += "\tremoveuser USER: Removes an existing user\n"
result += "\taddgroup GROUP: Creates a new empty group\n"
result += "\tdelgroup GROUP: Removes an empty group (other than `administrator`)\n"
result += "\taddusergroup USER GROUP: Sets an user in a group (and creates it if it does not exist yet)\n"
result += "\tremoveusergroup USER GROUP: Unsets an user from a group (other than `admin`)\n"
else:
result += "\tgroups: Displays the ACMS groups you are member of\n"
result += "\tpasswd: Changes your password\n"
return result
def historyController(username):
historyFile = DATA_PATH + username + '/.history'
if not os.path.exists(historyFile):
raise CommandException("An error occurred, you don\'t have any history yet ! You should retry yet ;)")
with open(historyFile, 'r') as file:
result = file.readlines()
return "\nWhat you typed on ACMS:\n\n" + ''.join([' ' + str(i) + '\t' + result[i] for i in range(len(result))])
# A simple method to append a command to a history file...
def addToHistory(username, command, acl):
historyFile = DATA_PATH + username + '/.history'
if not os.path.exists(historyFile):
acl.addFile(username, historyFile)
else:
command = '\n' + command
with open(historyFile, 'a') as file:
file.write(command)