Example #1
0
    def start(self, user, repo_url=None, github_auth=None, github_email=None, github_name=None):
        from IPython.lib import passwd
        from random import choice
        import string

        password = ''.join([choice(string.letters + string.digits) for i in range(12)])

        c = self.docker.create(user, env={
            'IPYTHON_COOKIE_SECRET': passwd(password),
            'IPYTHON_PASSWORD': passwd(password),
            'IPYTHON_CLEAR_PASSWORD': password,
            'IPYTHON_REPO_URL': repo_url,
            'IPYTHON_REPO_AUTH': github_auth,
            'GITHUB_EMAIL': github_email,
            'GITHUB_NAME': github_name,
            'GITHUB_USER': user,
            })

        env = c.start(self.redis.port(user))

        self.redis.activate(user)

        # Keep track of the github repos that are used in the system, so we can references them in
        # nbviewer.
        self.redis.record_repo(repo_url)
        self.redis.record_user(user)

        for e in env:
            k,v = e.split('=',1)
            if k == 'IPYTHON_CLEAR_PASSWORD':
                return v
Example #2
0
def user_config(username,port):
    with settings(sudo_user=username,warn_only=True):
        # append anaconda path to .bashrc
        append('/home/%s/.bashrc' % username,'export PATH=/usr/local/anaconda/bin:$PATH',use_sudo=True)

        # create log dir
        sudo('mkdir /home/%s/logs' % username)    
        sudo('touch /home/%s/logs/ipython_supervisor.log' % username) 

        # create ipython notebook profile
        sudo('ipython profile create %s' % username,user=username)
        # sudo('chmod -r {u} /home/{u}/.ipython'.format(u=username),user=root)

        # get hashed password
        hashed = passwd()

        # write ipynb config file
        ipynb_config_file = IPYNB_CONF.format(u=username)
        backup_config(ipynb_config_file)
        append(filename=ipynb_config_file,
               text=IPYNB_CONF_TEMPLATE.format(u=username,
                                               p=port,
                                               hpw=hashed,
                                               ),
               use_sudo=True,
               )
Example #3
0
    def post(self):
        """ Creates user with the sent data
        :type name: str
        :type password: str
        :type user_id: int
        :rtype result: Json
        """
        json_data = request.get_json(force=True)
        not_valid = self.is_valid(json_data)

        if not not_valid:
            # Hashed password for jupyter notebook
            password = passwd(json_data['password'])

            # New Port number for new notebook
            port = self.get_new_port()
            url = "{0}:{1}".format(config.PUBLIC, port)

            # Only processes data when its valid
            notebook = NotebookModel(name=json_data['name'],
                                     password=password,
                                     user_id=json_data['user_id'],
                                     port=port,
                                     url=url)

            # Creates the notebook with the given data
            self.create_notebook(notebook)

            db.session.add(notebook)
            db.session.commit()

            result = notebook_schema.dump(notebook).data
            return {"Status": "Success", 'data': result}, 200

        return not_valid
def run_notebook_server(request):
    """ Deprecated now -- Launces the notebook server """
    username = request.user.username
    
    # first time actions
    user_login.initialize_user_path(username)
    
    #
    u = User.objects.get(username=username)
    users =  UserProfile.objects.filter(user=u)
    if users:
        user = users[0]
    else:
        user = UserProfile.objects.create(user=u)
        user.nbserver_port = nc.NB_SERVER_PORT_BASE + int(user.user.id)
        user.nbserver_password = _get_nbserver_password()
        user.save()
    
    if os.path.exists('/proc/{0}'.format(user.nbserver_pid)): # nb server already up
        time.sleep(1)
        return HttpResponseRedirect('{0}:{1}'.format(nc.BASE_URL, user.nbserver_port))                   
    else: # first time or server not running
        ip_dir = '{0}/{1}/.ipython'.format(nc.DATA_DIR, username)
        nbserver_password_sha1 = passwd(user.nbserver_password)
        user.nbserver_pid = _run_server(ip_dir, user.nbserver_port, nbserver_password_sha1)
        user.save()            
        # sleep to let server start listening
        time.sleep(3)
        return HttpResponseRedirect('{0}:{1}'.format(nc.BASE_URL, user.nbserver_port))
        
    # show a maint msg
    return HttpResponse("<html> Server is under maintenance! Please try later.</html>")
def account_settings(request):
    """ Shows the Notebook server settings """
    username = request.user.username
   
    # first time actions
    user_login.initialize_user_path(username)


    u = User.objects.get(username=username)
    users =  UserProfile.objects.filter(user=u)
    if users:
        user = users[0]
    else:
	user = UserProfile.objects.create(user=u)
        user.nbserver_port = nc.NB_SERVER_PORT_BASE + int(user.user.id)
        user.nbserver_password = _get_nbserver_password()
        user.save()

    # Run the server, if not running yet
    if os.path.exists('/proc/{0}'.format(user.nbserver_pid)): # nb server already up
        time.sleep(1)
    else: # first time or server not running
        ip_dir = '{0}/{1}/.ipython'.format(nc.DATA_DIR, username)
        nbserver_password_sha1 = passwd(user.nbserver_password)
        user.nbserver_pid = _run_server(ip_dir, user.nbserver_port, nbserver_password_sha1)
        user.save()
        # sleep to let server start listening
        time.sleep(3)

    ctx =  {'nbserver_password' : user.nbserver_password,
            'nbserver_url' : '{0}:{1}'.format(nc.BASE_URL, user.nbserver_port)}
    return render_to_response('account/settings.html', ctx, context_instance=RequestContext(request))
Example #6
0
def notebookSetup(c):
    # c is Jupyter config http://jupyter-notebook.readthedocs.io/en/latest/config.html
    print('Initializing Jupyter.', file=sys.stderr)

    if 'HOSTNAME' in os.environ:
        c.ServerApp.ip = os.environ['HOSTNAME']
    else:
        c.ServerApp.ip = '*'
    c.ServerApp.port = 8888
    c.ServerApp.open_browser = False
    # This changes current working dir, so has to be set to /data/
    c.ServerApp.root_dir = '/data/'
    c.Session.debug = False
    # If not set, there is a permission problem with the /data/ directory
    c.ServerApp.allow_root = True

    # Set a password
    if 'PASSWORD' in os.environ and os.environ['PASSWORD']:
        c.ServerApp.password = passwd(os.environ['PASSWORD'])
        del os.environ['PASSWORD']
    else:
        print('Password must be provided.')
        sys.exit(150)

    if 'ROOT_DIR' in os.environ and os.environ['ROOT_DIR']:
        c.ServerApp.base_url = os.environ['ROOT_DIR']

    c.FileContentsManager.post_save_hook = scriptPostSave
def launch_notebook(notebook_name=''):
    command = ["scripts/launch_notebook.py", notebook_name]

    # If vault/notebook_pass.txt exists, send the hashed contents of the file to AWS
    if os.path.isfile(vault + "/notebook_pass.txt"):
        logging.info("Found %s/notebook_pass.txt" % vault)

        f = open(vault + "/notebook_pass.txt", "r")
        notebook_pass = f.read().rstrip()
        logging.info("notebook_pass.txt: %s" % notebook_pass)
        f.close()

        command.append(passwd(notebook_pass))

    # Redirect stderr to stdout
    command.append("2>&1")

    # Parse the output of the launch_notebook.py command and exit once the iPython Notebook server is launched
    def detect_launch_port(line):
        launch_match = re.search(
            'IPython Notebook is running at:.*system\]:(\d+)/', line)
        already_launched_match = re.search(
            'The port (\d+) is already in use, trying another random port',
            line)

        # Check if a new instance of iPython Notebook was launched and open the URL in the default system browser
        if launch_match:
            port_no = launch_match.group(1)
            logging.info(
                "New iPython Notebook Launched, opening https://%s:%s/" %
                (instance.public_dns_name, port_no))
            print "New iPython Notebook Launched, opening https://%s:%s/" % (
                instance.public_dns_name, port_no)
            webbrowser.open("https://%s:%s/" %
                            (instance.public_dns_name, port_no))

            logging.info("LaunchNotebookServer.py finished")
            sys.exit("iPython Notebook Server Started")

        # Check if an existing instance of iPython Notebook is running and open the URL in the default system browser
        if already_launched_match:
            port_no = already_launched_match.group(1)
            logging.info(
                "iPython Notebook already running, opening https://%s:%s/" %
                (instance.public_dns_name, port_no))
            print "iPython Notebook already running, opening https://%s:%s/" % (
                instance.public_dns_name, port_no)
            webbrowser.open("https://%s:%s/" %
                            (instance.public_dns_name, port_no))

            logging.info("LaunchNotebookServer.py finished")
            sys.exit(
                "iPython Notebook Server is already running, reopening URL")

        return False

    send_command(command,
                 stderr_call_back=detect_launch_port,
                 stdout_call_back=detect_launch_port)
Example #8
0
 def set_password(password, file_path):
     with open(file_path) as f:
         r = f.read()
     r += '\nc.NotebookApp.password = u"%s"' % passwd(password)
     tempfile = file_path + ".temp"
     with open(tempfile, "w") as f:
         f.write(r)
     return tempfile
Example #9
0
def getPassword():
    message("Hello, friend! Let's set up your Jupyter notebook...")

    # this already implements the interactive dialog + hashing
    from IPython.lib import passwd
    password = passwd()

    return password
Example #10
0
def server(first_name):
    global port
    pw = ''
    for i in range(8):
        pw += random.choice(charset)
    pws = passwd(pw)
    os.system("sudo docker run -d -t -e 'PW=%s' -e 'PORT=%d' -p %d:%d -m 500m jupserver" 
			% (pws, port, port, port))
    return render_template('server.html', first_name=first_name, port=port, pw=pw)
def generate_entry(server_id, server_port_base, server_name_format=cs.NBSERVER_NAME_FORMAT, USER_DATA_DIR=cs.USER_DATA_DIR):
    """ Creates a config entry for each notebook instance
    [notebook-server-<ID>, USER_DATA_DIR/ipython_dir,  port, sha1, password]
    
    """
    txt_password = _get_nbserver_password()
    sha1 = passwd(txt_password)
    server_name =  server_name_format %server_id
    ipython_dir = os.path.join(USER_DATA_DIR, server_name)
    entry = [server_id, server_name, ipython_dir, int(server_port_base) + server_id, sha1, txt_password]
    return entry
Example #12
0
def server(first_name):
    global port
    pw = ''
    for i in range(8):
        pw += random.choice(charset)
    pws = passwd(pw)
    os.system(
        "sudo docker run -d -t -e 'PW=%s' -e 'PORT=%d' -p %d:%d -m 500m jupserver"
        % (pws, port, port, port))
    return render_template('server.html',
                           first_name=first_name,
                           port=port,
                           pw=pw)
Example #13
0
    def create(self):
        os.system("ipython profile create nbserver")
        copyfile(
            '{cloudmesh}/etc/ipython_notebook_config.py'.format(**self.data),
            '{profile_nbserver_dir}/ipython_notebook_config.py'.format(**self.data)
        )
        result = passwd()

        self._yaml_file_replace(
            '{profile_nbserver_dir}/ipython_notebook_config.py'.format(**self.data),
            replacements={'SHAPASSWD': result}
        )
        os.system("openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout {cert} -out {cert}".format(**self.data))
        os.system("chmod go-rwx {cert}".format(**self.data))
Example #14
0
def main(argv):
    mypwd = 'copd'
    try:
        opts, args = getopt.getopt(argv, "hp:", ["pwd="])
    except getopt.GetoptError:
        print 'pwd.py -p password'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'test.py -p <password>'
            sys.exit()
        elif opt in ("-p", "--pwd"):
            mypwd = arg
    print "'{}'".format(passwd(mypwd))
Example #15
0
    def setup_spark(self, is_finished):
        def install_packages():
            # Install python dev
            self.send_command(["yum", "install", "-y", "python27-devel"])
            # Install pip
            self.send_command(["wget", "https://bootstrap.pypa.io/get-pip.py"])
            self.send_command(["python2.7", "get-pip.py"])
            # Install boto
            self.send_command(["pip", "install", "--upgrade", "boto"])
            # Install Jupyter
            self.send_command(["pip", "install", "--upgrade", "numpy"])
            self.send_command(["pip", "install", "--upgrade", "jupyter"])
            # Install matplotlib and networkx
            self.send_command(["yum", "install", "-y", "freetype-devel"])
            self.send_command(["yum", "install", "-y", "libpng-devel"])
            self.send_command(["yum", "install", "-y", "graphviz-devel"])
            self.send_command(["pip", "install", "--upgrade", "matplotlib"])
            self.send_command(["pip", "install", "--upgrade", "networkx"])
            self.send_command(["pip", "install", "--upgrade", "pygraphviz"])
            # Install requests
            self.send_command(["pip", "install", "--upgrade", "requests"])
            # Jupyter helper functions
            self.send_file("./server/init_sc.py", "~")
            self.send_file("./server/s3helper.py", "~")
            # Sync Python2.7 libraries
            self.send_command([
                "/root/spark-ec2/copy-dir",
                "/usr/local/lib64/python2.7/site-packages/"
            ])

        if not is_finished:
            self.dead = True
            print "Launching Spark failed."
            return

        print "setting up cluster..."
        self.init_cluster(self.name)

        # Write .bashrc
        self.write_file("~/.bashrc", BASHRC)

        # Set up IPython Notebook
        self.write_file(IPY_CONFIG_FILE_PATH, IPY_CONFIG)
        self.write_file(IPYNB_CONFIG_FILE_PATH,
                        IPYNB_CONFIG % passwd(self.passwd))
        install_packages()

        self.ready = True
        self.duration = int(time.time() - self.timer)
        print "The cluster is up! Total: %d seconds." % self.duration
Example #16
0
def main(unused_argv):
    sys.argv = ORIG_ARGV

    if not IS_KERNEL:
        # Drop all flags.
        sys.argv = [sys.argv[0]]
        # NOTE(sadovsky): For some reason, putting this import at the top level
        # breaks inline plotting.  It's probably a bug in the stone-age version of
        # matplotlib.
        from IPython.html.notebookapp import NotebookApp  # pylint: disable=g-import-not-at-top
        notebookapp = NotebookApp.instance()
        notebookapp.open_browser = True

        # password functionality adopted from quality/ranklab/main/tools/notebook.py
        # add options to run with "password"
        if FLAGS.password:
            from IPython.lib import passwd  # pylint: disable=g-import-not-at-top
            notebookapp.ip = "0.0.0.0"
            notebookapp.password = passwd(FLAGS.password)
        else:
            print(
                "\nNo password specified; Notebook server will only be available"
                " on the local machine.\n")
        notebookapp.initialize(argv=["--notebook-dir", FLAGS.notebook_dir])

        if notebookapp.ip == "0.0.0.0":
            proto = "https" if notebookapp.certfile else "http"
            url = "%s://%s:%d%s" % (proto, socket.gethostname(),
                                    notebookapp.port,
                                    notebookapp.base_project_url)
            print("\nNotebook server will be publicly available at: %s\n" %
                  url)

        notebookapp.start()
        return

    # Drop the --flagfile flag so that notebook doesn't complain about an
    # "unrecognized alias" when parsing sys.argv.
    sys.argv = ([sys.argv[0]] +
                [z for z in sys.argv[1:] if not z.startswith("--flagfile")])
    from IPython.kernel.zmq.kernelapp import IPKernelApp  # pylint: disable=g-import-not-at-top
    kernelapp = IPKernelApp.instance()
    kernelapp.initialize()

    # Enable inline plotting. Equivalent to running "%matplotlib inline".
    ipshell = kernelapp.shell
    ipshell.enable_matplotlib("inline")

    kernelapp.start()
Example #17
0
def create():
    from IPython.lib import passwd
    from fabfile.util import yaml_file_replace

    local("ipython profile create nbserver")
    local('cp etc/ipython_notebook_config.py ~/.ipython/profile_nbserver')
    result = passwd()

    yaml_file_replace(filename='/../.ipython/profile_nbserver/ipython_notebook_config.py',
                      replacements={'SHAPASSWD': result}
                      )

    progress.off()
    filename = "~/.ipython/profile_nbserver/mycert.pem"
    local("openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout {0} -out {0}".format(filename))
    local("chmod go-rw ~/.ipython/profile_nbserver/mycert.pem")
Example #18
0
def main(unused_argv):
  sys.argv = ORIG_ARGV

  if not IS_KERNEL:
    # Drop all flags.
    sys.argv = [sys.argv[0]]
    # NOTE(sadovsky): For some reason, putting this import at the top level
    # breaks inline plotting.  It's probably a bug in the stone-age version of
    # matplotlib.
    from IPython.html.notebookapp import NotebookApp  # pylint: disable=g-import-not-at-top
    notebookapp = NotebookApp.instance()
    notebookapp.open_browser = True

    # password functionality adopted from quality/ranklab/main/tools/notebook.py
    # add options to run with "password"
    if FLAGS.password:
      from IPython.lib import passwd  # pylint: disable=g-import-not-at-top
      notebookapp.ip = "0.0.0.0"
      notebookapp.password = passwd(FLAGS.password)
    else:
      print("\nNo password specified; Notebook server will only be available"
            " on the local machine.\n")
    notebookapp.initialize(argv=["--notebook-dir", FLAGS.notebook_dir])

    if notebookapp.ip == "0.0.0.0":
      proto = "https" if notebookapp.certfile else "http"
      url = "%s://%s:%d%s" % (proto, socket.gethostname(), notebookapp.port,
                              notebookapp.base_project_url)
      print("\nNotebook server will be publicly available at: %s\n" % url)

    notebookapp.start()
    return

  # Drop the --flagfile flag so that notebook doesn't complain about an
  # "unrecognized alias" when parsing sys.argv.
  sys.argv = ([sys.argv[0]] +
              [z for z in sys.argv[1:] if not z.startswith("--flagfile")])
  from IPython.kernel.zmq.kernelapp import IPKernelApp  # pylint: disable=g-import-not-at-top
  kernelapp = IPKernelApp.instance()
  kernelapp.initialize()

  # Enable inline plotting. Equivalent to running "%matplotlib inline".
  ipshell = kernelapp.shell
  ipshell.enable_matplotlib("inline")

  kernelapp.start()
Example #19
0
def configure_ipython_notebook():
    'Configure IPython Notebook server'
    print 'Please specify a password for your IPython server'
    from IPython.lib import passwd
    ipythonPassword = passwd()
    # Set paths
    certificatePath = os.path.join(f.securityFolder, 'ssl.pem')
    profilePath = os.path.join(f.profileFolder, 'ipython_notebook_config.py')
    userCrontabPath = os.path.join(f.profileFolder, 'server.crt')
    run('rm -Rf %s %s' % (f.profileFolder, f.notebookFolder))
    # Prepare dictionary
    d = {
        'certificatePath': certificatePath,
        'ipythonPassword': ipythonPassword,
        'virtualenv.path': v.path,
        'crtPrefix': CRT_PREFIX,
        'notebookFolder': f.notebookFolder,
        'profileName': IPYTHON_PROFILE_NAME,
        'logPath': f.logPath,
    }
    # Download documents
    run('mkdir -p %s' % f.documentFolder)
    with cd(f.documentFolder):
        run('git clone https://github.com/invisibleroads/%s.git' %
            NOTEBOOK_REPOSITORY_NAME)
    # Create profile
    with virtualenv():
        run('ipython profile create %s' % IPYTHON_PROFILE_NAME)
    # Generate certificate
    with cd(f.securityFolder):
        run('openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout ssl.pem -out ssl.pem'
            )
    # Configure server
    upload_text(profilePath, IPYTHON_NOTEBOOK_CONFIG_PY % d, append=True)
    # Add crontab
    upload_text(userCrontabPath, SERVER_CRT % d)
    run('crontab %s' % userCrontabPath)
    # Setup proxy
    configure_proxy()
    # Open ports
    upload_file('/etc/sysconfig/iptables', sourcePath='iptables', su=True)
    # Update notebooks on boot
    upload_text('/etc/rc.d/rc.local', RC_LOCAL % d, su=True)
    sudo('chmod 755 /etc/rc.d/rc.local')
    # Clear history
    clear_history()
def launch_notebook(notebook_name=''):
    command = ["scripts/launch_notebook.py", notebook_name]

    # If vault/notebook_pass.txt exists, send the hashed contents of the file to AWS
    if os.path.isfile(vault + "/notebook_pass.txt"):
        logging.info("Found %s/notebook_pass.txt" % vault)

        f = open(vault + "/notebook_pass.txt", "r")
        notebook_pass = f.read().rstrip()
        logging.info("notebook_pass.txt: %s" % notebook_pass)
        f.close()

        command.append(passwd(notebook_pass))

    # Redirect stderr to stdout
    command.append("2>&1")

    # Parse the output of the launch_notebook.py command and exit once the iPython Notebook server is launched
    def detect_launch_port(line):
        launch_match = re.search('IPython Notebook is running at:.*system\]:(\d+)/', line)
        already_launched_match = re.search('The port (\d+) is already in use, trying another random port', line)

        # Check if a new instance of iPython Notebook was launched and open the URL in the default system browser
        if launch_match:
            port_no = launch_match.group(1)
            logging.info("New iPython Notebook Launched, opening https://%s:%s/" % (instance.public_dns_name, port_no))
            print "New iPython Notebook Launched, opening https://%s:%s/" % (instance.public_dns_name, port_no)
            webbrowser.open("https://%s:%s/" % (instance.public_dns_name, port_no))

            logging.info("LaunchNotebookServer.py finished")
            sys.exit("iPython Notebook Server Started")

        # Check if an existing instance of iPython Notebook is running and open the URL in the default system browser
        if already_launched_match:
            port_no = already_launched_match.group(1)
            logging.info("iPython Notebook already running, opening https://%s:%s/" %
                         (instance.public_dns_name, port_no))
            print "iPython Notebook already running, opening https://%s:%s/" % (instance.public_dns_name, port_no)
            webbrowser.open("https://%s:%s/" % (instance.public_dns_name, port_no))

            logging.info("LaunchNotebookServer.py finished")
            sys.exit("iPython Notebook Server is already running, reopening URL")

        return False

    send_command(command, stderr_call_back=detect_launch_port, stdout_call_back=detect_launch_port)
Example #21
0
def create():
    from IPython.lib import passwd
    from fabfile.util import yaml_file_replace

    local("ipython profile create nbserver")
    local('cp etc/ipython_notebook_config.py ~/.ipython/profile_nbserver')
    result = passwd()

    yaml_file_replace(
        filename='/../.ipython/profile_nbserver/ipython_notebook_config.py',
        replacements={'SHAPASSWD': result})

    progress.off()
    filename = "~/.ipython/profile_nbserver/mycert.pem"
    local(
        "openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout {0} -out {0}"
        .format(filename))
    local("chmod go-rw ~/.ipython/profile_nbserver/mycert.pem")
Example #22
0
def configure_ipython_notebook():
    'Configure IPython Notebook server'
    print 'Please specify a password for your IPython server'
    from IPython.lib import passwd
    ipythonPassword = passwd()
    # Set paths
    certificatePath = os.path.join(f.securityFolder, 'ssl.pem')
    profilePath = os.path.join(f.profileFolder, 'ipython_notebook_config.py')
    userCrontabPath = os.path.join(f.profileFolder, 'server.crt')
    run('rm -Rf %s %s' % (f.profileFolder, f.notebookFolder))
    # Prepare dictionary
    d = {
        'certificatePath': certificatePath,
        'ipythonPassword': ipythonPassword,
        'virtualenv.path': v.path,
        'crtPrefix': CRT_PREFIX,
        'notebookFolder': f.notebookFolder,
        'profileName': IPYTHON_PROFILE_NAME,
        'logPath': f.logPath,
    }
    # Download documents
    run('mkdir -p %s' % f.documentFolder)
    with cd(f.documentFolder):
        run('git clone https://github.com/invisibleroads/%s.git' % NOTEBOOK_REPOSITORY_NAME)
    # Create profile
    with virtualenv():
        run('ipython profile create %s' % IPYTHON_PROFILE_NAME)
    # Generate certificate
    with cd(f.securityFolder):
        run('openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout ssl.pem -out ssl.pem')
    # Configure server
    upload_text(profilePath, IPYTHON_NOTEBOOK_CONFIG_PY % d, append=True)
    # Add crontab
    upload_text(userCrontabPath, SERVER_CRT % d)
    run('crontab %s' % userCrontabPath)
    # Setup proxy
    configure_proxy()
    # Open ports
    upload_file('/etc/sysconfig/iptables', sourcePath='iptables', su=True)
    # Update notebooks on boot
    upload_text('/etc/rc.d/rc.local', RC_LOCAL % d, su=True)
    sudo('chmod 755 /etc/rc.d/rc.local')
    # Clear history
    clear_history()
Example #23
0
    def action_createusers(self, args):
        """Create users JSON file"""
        user_config = {
            'users': OrderedDict() #OrderedDict() or #dict()  or #{}
        }
        
        port = args.port
        
        for i in range(1, args.number + 1):
            username = '******' + args.number_format % (i)
            #print(username)
            
            pwd = ''.join(random.choice(
                string.ascii_lowercase + string.digits) for x in range(6))
                
            hash_pwd = passwd(pwd)
            directory = os.path.join(args.basepath, 'users', username)

            data_user = OrderedDict()
            data_user['pwd'] = pwd
            data_user['port'] = port
            data_user['directory'] = os.path.abspath(directory)
            data_user['hash_pwd'] = hash_pwd
            data_user['created'] = datetime.datetime.utcnow().isoformat()
            
            user_config['users'][username] = data_user
            port += 1
                
        user_config_json = json.dumps(user_config)
        
        print(json.dumps(user_config, indent=4))
        
        filename = os.path.join(args.basepath, args.usersfilename)
        print("Write user config file '{filename}'".format(filename=filename))
        with open(filename, 'w') as file_users:
            file_users.write(user_config_json)
        print_success("Done")
         
        filename = os.path.join(args.basepath, args.userstextfilename)
        print("Write user name text file '{filename}'".format(filename=filename))
        with open(filename, 'w') as file_users:
            for user, datauser in self.users(args):
                file_users.write(user+'\n')        
        print_success("Done")
Example #24
0
def check_update_password():
    password_file = '/ipython/password'
    search_string = 'c.NotebookApp.password'
    search_regex = '^' + search_string + '.*'
    destination = os.getenv('HOME', '/home/ipython') \
            + '/.ipython/profile_default/ipython_notebook_config.py'
    replaced = False

    if os.path.isfile(password_file):
        password = passwd(open(password_file, 'r').read().strip('\n'))

        for line in fileinput.input(destination, inplace=True):
            if re.search(search_regex, line):
                print search_string + " =u'" + password + "'"
                replaced = True
            else:
                print line
        if not replaced:
            with open(destination, "a") as dst:
                dst.write(search_string + " =u'" + password + "'")
Example #25
0
def check_update_password():
    password_file = '/ipython/password'
    search_string = 'c.NotebookApp.password'
    search_regex = '^' + search_string + '.*'
    destination = os.getenv('HOME', '/home/ipython') \
            + '/.ipython/profile_default/ipython_notebook_config.py'
    replaced = False

    if os.path.isfile(password_file):
        password = passwd(open(password_file, 'r').read().strip('\n'))

        for line in fileinput.input(destination, inplace=True):
            if re.search(search_regex, line):
                print search_string + " =u'" + password + "'"
                replaced = True
            else:
                print line
        if not replaced:
            with open(destination, "a") as dst:
                dst.write(search_string + " =u'" + password + "'")
Example #26
0
def main(unused_argv):
    sys.argv = ORIG_ARGV

    if not IS_KERNEL:
        sys.argv = [sys.argv[0]]
        from IPython.html.notebookapp import NotebookApp
        notebookapp = NotebookApp.instance()
        notebookapp.open_browser = True

        if FLAGS.password:
            from IPython.lib import passwd
            notebook.ip = "0.0.0.0"
            notebook.password = passwd(FLAGS.password)
        else:
            print(
                "\nNo password specified: Notebook server will only be available"
                " on the local machine.\n")
        notebookapp.initialize(argv=["--notebook-dir", FLAGS.notebook_dir])

        if notebookapp.ip == "0.0.0.0":
            proto = "https" if notebookapp.certfile else "http"
            url = "%s://%s:%d%s" % (proto, socket.gethostname(),
                                    notebookapp.port,
                                    notebookapp.base_project_url)
            print("\nNotebook server will be publicly available at: %s\n" %
                  url)

        notebookapp.start()
        return
    sys.argv = ([sys.argv[0]] +
                [z for z in sys.argv[1:] if not z.startswith("--flagfile")])
    from IPython.kernel.zmq.kernelapp import IPKernelApp
    kernelapp = IPKernelApp.instance()
    kernelapp.initialize()

    ipshell = kernelapp.shell
    ipshell.enable_matplotlib("inline")

    kernelapp.start()
Example #27
0
#Create the password field for the configuration file with the proper format

from IPython.lib import passwd

pw = passwd(algorithm="sha256")
print(
    "Copy and paste the following line in the configMap under the [settings] section:"
)
print("phoenix-password = " + pw)
# Copyright (c) IPython Development Team.
# (c) Copyright IBM Corp. 2015
import subprocess
import os

PEM_FILE = os.path.join(os.path.dirname(__file__), 'security/notebook.pem')

c = get_config()
c.NotebookApp.ip = os.getenv('INTERFACE', '') or '*'
c.NotebookApp.port = int(os.getenv('PORT', '') or 8888)
c.NotebookApp.open_browser = False
c.NotebookApp.token = ''

# Set a certificate if USE_HTTPS is set to any value
if 'USE_HTTPS' in os.environ:
    if not os.path.isfile(PEM_FILE):
        # Generate a certificate if one doesn't exist on disk
        subprocess.check_call([
            'openssl', 'req', '-new', '-newkey', 'rsa:2048', '-days', '365',
            '-nodes', '-x509', '-subj',
            '/C=XX/ST=XX/L=XX/O=generated/CN=generated', '-keyout', PEM_FILE,
            '-out', PEM_FILE
        ])
    c.NotebookApp.certfile = PEM_FILE

# Set a password if PASSWORD is set
if 'PASSWORD' in os.environ:
    from IPython.lib import passwd
    c.NotebookApp.password = passwd(os.environ['PASSWORD'])
    del os.environ['PASSWORD']
def test_roundtrip():
    p = passwd('passphrase')
    nt.assert_equals(passwd_check(p, 'passphrase'), True)
from IPython.lib import passwd
import os

c = get_config()

if 'JUPYTER_PASSWORD' in os.environ:
    c.NotebookApp.password = passwd(os.environ["JUPYTER_PASSWORD"])

c.NotebookApp.open_browser = False
c.NotebookApp.notebook_dir = '/projects'
Example #31
0
from IPython.lib import passwd
hsh = passwd()
with open('hash.txt', 'w') as f:
    f.write('hash=%s\n' % hsh)
Example #32
0
from IPython.lib import passwd
import sys, string, os

myPass = str(sys.argv[1]) 
myHash = passwd(myPass)
print(myHash)
c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False

# Set a certificate if USE_HTTPS is set to any value
if 'USE_HTTPS' in os.environ:
    if not os.path.isfile(PEM_FILE):
        # Ensure PEM_FILE directory exists
        dir_name = os.path.dirname(PEM_FILE)
        try:
            os.makedirs(dir_name)
        except OSError as exc: # Python >2.5
            if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
                pass
            else: raise
        # Generate a certificate if one doesn't exist on disk
        subprocess.check_call(['openssl', 'req', '-new',
            '-newkey', 'rsa:2048', '-days', '365', '-nodes', '-x509',
            '-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated',
            '-keyout', PEM_FILE, '-out', PEM_FILE])
        # Restrict access to PEM_FILE
        os.chmod(PEM_FILE, stat.S_IRUSR | stat.S_IWUSR)
    c.NotebookApp.certfile = PEM_FILE

# Set a password if PASSWORD is set
if 'PASSWORD' in os.environ:
    from IPython.lib import passwd
    c.NotebookApp.password = passwd(os.environ['PASSWORD'])
    del os.environ['PASSWORD']
from IPython.lib import passwd
print passwd('1337')
    setup_py                = ipython_profile + "/startup/00-pyspark-setup.py"

    if not os.path.exists(ipython_profile):
        print "creating new ipython notebook profile"
        cmd = "ipython profile create %s" % ipython_profile_name
        #print cmd
        os.system(cmd)

    if not os.path.exists(passwd_txt):
        get_password()
        while(password != password2):
            print "passwords do not match!\n"
            get_password()
        print "writing new encrypted password"
        passwd_fh = open(passwd_txt, "w")
        passwd_fh.write(passwd(password))
        passwd_fh.close()
        os.chmod(passwd_txt, 0600)
    
    #if not os.path.exists(setup_py):
    shutil.copy(pyspark_startup_src, setup_py)
    os.chmod(setup_py, 0600)
 
    if not os.path.exists(ipython_notebook_config) or passwd_txt not in open(ipython_notebook_config).read():
        print "writing new ipython notebook config"
        config = open(ipython_notebook_config, "w")
        config.write(template.render(passwd_txt = passwd_txt, ip = ip, name = os.path.basename(sys.argv[0]), date = time.ctime(), template_path = template_file ) )
        config.close()
        os.chmod(ipython_notebook_config, 0600)
    # PYSPARK_SUBMIT_ARGS is reset to "" by pyspark wrapper script, call IPython Notebook drectly to avoid this :-/
    #cmd = "IPYTHON_OPTS='notebook --profile=%s' pyspark" % ipython_profile_name
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import os
from IPython.lib import passwd

c = c  # pylint:disable=undefined-variable
c.NotebookApp.ip = '*'
c.NotebookApp.port = int(os.getenv('PORT', 8888))
c.NotebookApp.open_browser = False

# sets a password if PASSWORD is set in the environment
if 'PASSWORD' in os.environ:
  password = os.environ['PASSWORD']
  if password:
    c.NotebookApp.password = passwd(password)
  else:
    c.NotebookApp.password = ''
    c.NotebookApp.token = ''
  del os.environ['PASSWORD']
Example #37
0
import os, sys
from IPython.terminal.ipapp import launch_new_instance
from IPython.lib import passwd
import warnings

# set the password you want to use
notebook_password = "******"

sys.argv.append("notebook")
sys.argv.append("--IPKernelApp.pylab='inline'")
sys.argv.append("--NotebookApp.ip='*'")
sys.argv.append("--NotebookApp.port=" + os.environ["ASPNETCORE_PORT"])
sys.argv.append("--NotebookApp.open_browser=False")
sys.argv.append("--NotebookApp.notebook_dir=./notebooks")
sys.argv.append("--NotebookApp.password=" + passwd(notebook_password))

launch_new_instance()
        PEM_FILE = str(os.getenv("ENV_JUPYTER_PEM_FILE", "/opt/work/certs/jupyter.pem"))

    if not os.path.isfile(PEM_FILE):
        # Ensure PEM_FILE directory exists
        dir_name = os.path.dirname(PEM_FILE)
        try:
            os.makedirs(dir_name)
        except OSError as exc: # Python >2.5
            if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
                pass
            else: raise
        # Generate a certificate if one doesn"t exist on disk
        subprocess.check_call(["openssl", "req", "-new", 
            "-newkey", "rsa:2048", "-days", "365", "-nodes", "-x509",
            "-subj", "/C=XX/ST=XX/L=XX/O=generated/CN=generated",
            "-keyout", PEM_FILE, "-out", PEM_FILE])
        # Restrict access to PEM_FILE
        os.chmod(PEM_FILE, stat.S_IRUSR | stat.S_IWUSR)
    c.NotebookApp.certfile = PEM_FILE

# Set a password if PASSWORD is set
if "ENV_JUPYTER_PASSWORD" in os.environ:
    from IPython.lib import passwd
    c.NotebookApp.password = passwd(os.environ["ENV_JUPYTER_PASSWORD"])
    del os.environ["ENV_JUPYTER_PASSWORD"]
else:
    c.NotebookApp.token = ''
    c.NotebookApp.password = ''
# end if password-securing this Jupyter instance

c = get_config()

headers = {'X-Frame-Options': 'ALLOWALL'}

c.NotebookApp.allow_origin = '*'
c.NotebookApp.allow_credentials = True

c.NotebookApp.webapp_settings = {'headers': headers}

import os
password = os.environ.get("PASSWORD", "ipynb")

from IPython.lib import passwd
password = passwd(password)

c.NotebookApp.password = unicode(password)

def test_passwd_structure():
    p = passwd('passphrase')
    algorithm, salt, hashed = p.split(':')
    nt.assert_equals(algorithm, 'sha1')
    nt.assert_equals(len(salt), salt_len)
    nt.assert_equals(len(hashed), 40)
Example #41
0
def test_passwd_structure():
    p = passwd('passphrase')
    algorithm, salt, hashed = p.split(':')
    nt.assert_equal(algorithm, 'sha1')
    nt.assert_equal(len(salt), salt_len)
    nt.assert_equal(len(hashed), 40)
Example #42
0
#!/usr/bin/env python

#
# Copyright (C) 2015 ClassCat(R) Co.,Ltd. All rights reserved.
#

import os,sys

from IPython.lib import passwd

if len(sys.argv) != 2:
    sys.exit(-1)

pw = sys.argv[1].strip()

print(passwd(pw))

sys.exit(0)


### End of Script ###
import sys
from IPython.lib import passwd

print(sys.argv)

# Create hash of password
passwdhash = passwd(sys.argv[1])
c  = open("passwdhash.txt", "w")
c.write(passwdhash)
c.close()
Example #44
0
from IPython.lib import passwd
import os
hashed_password = passwd()
profile_name = 'nbserver'

os.system('ipython profile create %s' % profile_name)

ipython_config_file_contents = """
c = get_config()
c.IPKernelApp.matplotlib = 'inline'
"""
ipython_config_file_loc = os.path.join(os.getenv('HOME'), '.ipython/profile_%s/ipython_config.py' % (profile_name, ))

with open(ipython_config_file_loc, 'w') as f:
    f.write(ipython_config_file_contents)


notebook_config_file_contents = """
# Following directions in: http://ipython.org/ipython-doc/1/interactive/public_server.html
c = get_config()

# Kernel config
c.IPKernelApp.pylab = 'inline'  # if you want plotting support always

# Notebook config
#c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
# It is a good idea to put it on a known, fixed port
c.NotebookApp.port = 9999
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import os
from IPython.lib import passwd

c.NotebookApp.ip = '*'
c.NotebookApp.port = int(os.getenv('PORT', 8888))
c.NotebookApp.open_browser = False
c.MultiKernelManager.default_kernel_name = 'python2'
c.NotebookApp.password = passwd('1')

Example #46
0
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import os
from IPython.lib import passwd

c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
c.MultiKernelManager.default_kernel_name = 'python2'
c.NotebookApp.notebook_dir='/root/workspace/'
c.NotebookApp.password=passwd('password')
Example #47
0
#!{{ python_path }}

import sys

from IPython.lib import passwd

pw_hash = passwd()

with open("{{ ipython_config }}", "a") as f:
    f.write("c.NotebookApp.password = u'%s'" % pw_hash)
# The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = '/Users/eczech/repos/portfolio/demonstrative/python/notebooks'

# 
# c.NotebookApp.file_to_run = ''

# Hashed password to use for web authentication.
# 
# To generate, type in a python/IPython shell:
# 
#   from notebook.auth import passwd; passwd()
# 
# The string should be of the form type:salt:hashed-password.
from IPython.lib import passwd;
c.NotebookApp.password = passwd(u'portfolio')

# extra paths to look for Javascript notebook extensions
# c.NotebookApp.extra_nbextensions_path = traitlets.Undefined

# The base URL for websockets, if it differs from the HTTP server (hint: it
# almost certainly doesn't).
# 
# Should be in the form of an HTTP origin: ws[s]://hostname[:port]
# c.NotebookApp.websocket_url = ''

# The notebook manager class to use.
# c.NotebookApp.contents_manager_class = <class 'notebook.services.contents.filemanager.FileContentsManager'>

# The base URL for the notebook server.
# 
Example #49
0
def notebook(args):
    """ Starts interactive notebook session """

    notebook_file = args.filename

    import IPython
    from IPython.lib import passwd
    from socket import gethostname
    if not notebook_file.endswith('.ipynb'):
        notebook_file += '.ipynb'

    if not os.path.isfile(notebook_file):
        with open(notebook_file, 'w') as f:
            f.write("""{
 "metadata": {
  "name": "",
  "signature": "sha256:0f5ff51613f8ce0a6edf3b69cfa09d0dbecf33f4c03078419f58189b6059a373"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sisyphus.notebook import *\\n",
      "tk.gs.SIS_COMMAND = ['../sis']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "manager.load_file('config.py')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "manager.start()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}""")

    password = gs.SIS_HASH(random.random())

    argv = []
    argv.append("notebook")
    argv.append(notebook_file)
    argv.append("--IPKernelApp.pylab='inline'")
    argv.append("--NotebookApp.ip=" + gethostname())
    argv.append("--NotebookApp.open_browser=False")
    argv.append("--NotebookApp.password="******"Notebook password: %s" % password)

    IPython.start_ipython(argv=argv)
# Configuration file for ipython-notebook.
from os import getenv
from IPython.lib import passwd

c = get_config()


#------------------------------------------------------------------------------
# NotebookApp configuration
#------------------------------------------------------------------------------

# NotebookApp will inherit config from: BaseIPythonApplication, Application

# The IPython password to use i.e. "datajoint".
c.NotebookApp.password = passwd(getenv('JUPYTER_PASSWORD', 'datajoint')).encode("ascii")

# Allow root access.
c.NotebookApp.allow_root = True

# The IP to serve on.
c.NotebookApp.ip = u'0.0.0.0'

# The Port to serve on.
c.NotebookApp.port = 8888

c.NotebookApp.default_url = '/tree'

c.NotebookApp.notebook_dir = '/home/dja'

c.FileContentsManager.root_dir = '/home/dja'
Example #51
0
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import os
from IPython.lib import passwd

c.NotebookApp.ip = '*'
c.NotebookApp.port = int(os.getenv('PORT', 8888))
c.NotebookApp.open_browser = False

c.NotebookApp.password = passwd("Your_password")
Example #52
0
def test_roundtrip():
    p = passwd('passphrase')
    nt.assert_equal(passwd_check(p, 'passphrase'), True)
Example #53
0
    setup_py = ipython_profile + "/startup/00-pyspark-setup.py"

    if not os.path.exists(ipython_profile):
        print("creating new ipython notebook profile")
        cmd = "ipython profile create %s" % ipython_profile_name
        #print(cmd)
        os.system(cmd)

    if not os.path.exists(passwd_txt):
        get_password()
        while password != password2:
            print("passwords do not match!\n")
            get_password()
        print("writing new encrypted password")
        passwd_fh = open(passwd_txt, "w")
        passwd_fh.write(passwd(password))
        passwd_fh.close()
        os.chmod(passwd_txt, 0o600)

    #if not os.path.exists(setup_py):
    shutil.copy(pyspark_startup_src, setup_py)
    os.chmod(setup_py, 0o600)

    try:
        ipython_notebook_config_contents = open(ipython_notebook_config).read()
    except IOError:
        ipython_notebook_config_contents = ""
    if not os.path.exists(ipython_notebook_config) or passwd_txt not in ipython_notebook_config_contents \
        or "c.NotebookApp.ip = '%s'" % ip not in ipython_notebook_config_contents:
        print("writing new ipython notebook config")
        config = open(ipython_notebook_config, "w")
Example #54
0
def test_bad():
    p = passwd('passphrase')
    nt.assert_equal(passwd_check(p, p), False)
    nt.assert_equal(passwd_check(p, 'a:b:c:d'), False)
    nt.assert_equal(passwd_check(p, 'a:b'), False)
def test_bad():
    p = passwd('passphrase')
    nt.assert_equals(passwd_check(p, p), False)
    nt.assert_equals(passwd_check(p, 'a:b:c:d'), False)
    nt.assert_equals(passwd_check(p, 'a:b'), False)
Example #56
0
from IPython.lib import passwd

c.NotebookApp.iopub_data_rate_limit = 1000000000
c.NotebookApp.ip = "*"
c.NotebookApp.allow_root = True
c.NotebookApp.password = passwd("dl4img")

import os
from IPython.lib import passwd

c = c  # pylint:disable=undefined-variable
c.NotebookApp.ip = '*'
c.NotebookApp.port = int(os.getenv('PORT', 8888))
c.NotebookApp.open_browser = False

# sets a password if PASSWORD is set in the environment
if 'PASSWORD' in os.environ:
  password = os.environ['PASSWORD']
  if password:
    c.NotebookApp.password = passwd(password)
  else:
    c.NotebookApp.password = ''
    c.NotebookApp.token = ''
  del os.environ['PASSWORD']
args = parser.parse_args()

# set argument
iPort = args.listen
bVerbose = args.verbose
sPath = os.path.expanduser('~') + '/.jupyter/'
sFilename = 'jupyter_notebook_config.py'

if os.path.exists(sPath):
    print(sPath + ' already exists.\nexit configure.')
    sys.exit()

# set ipython notebook login password
sPassword = args.password or ''.join(
    [choice(string.ascii_letters + string.digits) for i in range(8)])
sSha1 = passwd(sPassword)

# create ipython profile
s = subprocess.Popen('jupyter notebook --generate-config --allow-root',
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE)
o = s.communicate()
bVerbose and print(o[0].decode())
bVerbose and print(o[1].decode())

# create private key and certificate
s = subprocess.Popen("""
openssl req -x509 -nodes -days 1000 -newkey rsa:1024 -keyout {sPath}mykey.key -out {sPath}mycert.pem <<EOF
EOF
""".format(sPath=sPath),