from PLC.Methods.GetBootMedium import compute_key # key generation function
WORK_DIR = "/tmp/DummynetBoxMedium"
+BASE_IMAGE = "/usr/share/dummynet/picobsd.bin"
class GetDummyBoxMedium(Method):
"""
file += 'IP_GATEWAY="%s"\n' % dummybox['gateway']
file += 'IP_DNS1="%s"\n' % dummybox['dns1']
file += 'IP_DNS2="%s"\n' % dummybox['dns2']
- file += 'DUMMYBOX_ID=%s\n' % dummybox['dummybox_id']
- file += 'DUMMYBOX_KEY=%s\n' % new_key
+ file += 'DUMMYBOX_ID="%s"\n' % dummybox['dummybox_id']
+ file += 'DUMMYBOX_KEY="%s"\n' % new_key
- file += 'CS_IP=%s\n' % self.api.config.PLC_API_HOST
+ file += 'CS_IP="%s"\n' % self.api.config.PLC_API_HOST
# write the configuration file
# WORK_DIR must be writable
def call(self, auth, dummybox_id):
# set file names
- BASE_IMAGE = WORK_DIR + '/picobsd.bin'
IMAGE_NAME = str(WORK_DIR) + "/dummybox_" + str(dummybox_id) + ".bin"
configfile = WORK_DIR + '/dummybox.conf'
lockfile = WORK_DIR + '/lockfile'
dummybox.sync()
# return the file
- #return IMAGE_NAME
+ return IMAGE_NAME
return base64.b64encode(file(IMAGE_NAME).read())
# to format the output files
# port-forwarding should be denied in the main sshd configuration file
ssh_command = "/home/user/dbox.cmd "
- ssh_configuration = ",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty "
+ ssh_configuration = ",no-port-forwarding,no-agent-forwarding,no-X11-forwarding "
# Get dummyboxes information
dummyboxes = DummyBoxes(self.api, dummybox_id, ['site_id'])
authorized_keys_file += "# and $SSH_ORIGINAL_COMMAND is the command line inserted by the node\n"
for i in authorized_keys_dict:
- authorized_keys_file += "command=" + "\"" + ssh_command + str(authorized_keys_dict[i]);
- authorized_keys_file += " $SSH_ORIGINAL_COMMAND" + "\"" + ssh_configuration + str(i) + "\n"
+ # index of the key
+ key_index = str(authorized_keys_dict[i])
+
+ # create the dummynet box command
+ authorized_keys_file += "command=\"" + ssh_command + key_index;
+ authorized_keys_file += " $SSH_ORIGINAL_COMMAND\"" + ssh_configuration + str(i) + "\n"
return user_map+NEWFILE_MARK+"\n"+authorized_keys_file