Skip to content

Instantly share code, notes, and snippets.

@spellancer
Created April 3, 2014 14:18
Show Gist options
  • Save spellancer/9955228 to your computer and use it in GitHub Desktop.
Save spellancer/9955228 to your computer and use it in GitHub Desktop.
lab3_infsecure
# -*- coding: utf-8 -*-
# Нанян Саркис АК5-81
# Вариант 11, 5 субъектов 3 объекта
import random
# Массив пользователей системы
subjects = {'Michael':0, 'Gabriel':0, 'Raphael':0, 'Uriel':0,'Salaphiel':0}
# Массив объектов системы
objects = {'file1.doc':0, 'report.doc':0, 'config.txt':0}
atribut = {'top secret':3, 'secret':2, 'open':1}
# Заполнение случайными числами векторов OV и UV
for i in subjects:
subjects[i] = random.randint(1,3)
#print subjects
for j in objects:
objects[j] = random.randint(1,3)
#print objects
# Вывод информации о субъктах, объектах и их уровнях доступа
print "\nУровни конфиденциальности субъектов:\n"
for name, i in subjects.iteritems():
for aname, ai in atribut.iteritems():
if i == ai:
print "Субъект: ", name, "; Уровень доступа: ", aname
print "\n--------------------------------------------------------"
print "\nУровни конфиденциальности субъектов:\n"
for name, i in objects.iteritems():
for aname, ai in atribut.iteritems():
if i == ai:
print "Объект: ", name, "; Уровень доступа: ", aname
print "\n--------------------------------------------------------"
# Авторизация пользователя
auth = False
while not auth:
username = raw_input('Введите идентификатор пользователя: ')
if username in subjects:
print "Вход выполнен! %s, добро пожаловать в систему!" % username
auth = True
else:
print "Пользователь не найден! Попробуйте еще раз."
auth = False
# Если авторизация прошла успешно:
files= []
files_wr = []
if auth:
print "\nСписок доступных объектов: "
for i in objects:
if objects[i] <= subjects[username]:
files.append(i)
print i
if objects[i] >= subjects[username]:
files_wr.append(i)
exk = False
while not exk:
command = raw_input ('%s:~$ ' % username)
command = command.split()
argk = False
try:
arg = command[1]
argk = True
except:
print "Укажите аргумент для команды %s !" % command[0]
command = command[0]
if argk:
if command == 'read':
if arg in files and arg in objects:
print "Операция чтения выполнена успешно!"
elif arg in objects and arg not in files:
print "У вас нет доступа чтения к данному файлу!"
else:
print "Такой файл не существует, проверьте правильность ввода!"
elif command == 'write':
if arg in files_wr and arg in objects:
print "Операция записи выполнена успешно!"
elif arg in objects and arg not in files_wr:
print "У вас нет доступа записи к данному файлу!"
else:
print "Такой файл не существует, проверьте правильность ввода!"
elif command =='exit' and arg=='now':
print "Выход из системы"
exk = True
else:
print "Команда не найдена! Попробуйте еще раз! "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment