Esempio n. 1
0
 def handle_api_core_upgrade(self, http_context, version=None):
     try:
         subprocess.check_output(
             ['pip', 'install',
              'ajenti-panel==%s' % version])
     except subprocess.CalledProcessError as e:
         raise EndpointError(e.output)
Esempio n. 2
0
 def handle_api_fs_upload(self, http_context, path=None):
     try:
         with open(path, 'w') as f:
             f.write(http_context.query['upload'])
     except OSError as e:
         raise EndpointError(e)
     return True
Esempio n. 3
0
 def handle_api_pypi_uninstall(self, http_context, name=None):
     try:
         subprocess.check_output(
             ['pip', 'uninstall', '-y',
              'ajenti.plugin.%s' % name])
     except subprocess.CalledProcessError as e:
         raise EndpointError(e.output)
Esempio n. 4
0
 def handle_api_fs_read(self, http_context, path=None):
     if not os.path.exists(path):
         raise EndpointReturn(404)
     try:
         return open(path).read()
     except OSError as e:
         raise EndpointError(e)
Esempio n. 5
0
 def handle_api_pypi_install(self, http_context, name=None, version=None):
     # TODO replaced with a task
     try:
         subprocess.call(
             ['pip', 'install',
              'ajenti.plugin.%s==%s' % (name, version)])
     except subprocess.CalledProcessError as e:
         raise EndpointError(e.output)
Esempio n. 6
0
 def handle_api_fs_chmod(self, http_context, path=None):
     if not os.path.exists(path):
         raise EndpointReturn(404)
     data = json.loads(http_context.body)
     try:
         os.chmod(path, data['mode'])
     except OSError as e:
         raise EndpointError(e)
Esempio n. 7
0
 def handle_api_core_check_upgrade(self, http_context):
     url = 'https://pypi.python.org/pypi/%s/json' % 'ajenti-panel'
     try:
         data = requests.get(url).json()
     except Exception as e:
         raise EndpointError(e)
     version = data['info']['version']
     if version != aj.version:
         return version
     return None
Esempio n. 8
0
    def handle_api_fs_list(self, http_context, path=None):
        if not os.path.exists(path):
            raise EndpointReturn(404)
        try:
            items = []
            for name in os.listdir(path):
                item_path = os.path.join(path, name)

                data = {
                    'name': name,
                    'path': item_path,
                    'isDir': os.path.isdir(item_path),
                    'isFile': os.path.isfile(item_path),
                    'isLink': os.path.islink(item_path),
                }

                try:
                    stat = os.stat(item_path)
                    data.update({
                        'mode': stat.st_mode,
                        'mtime': stat.st_mtime,
                        'uid': stat.st_uid,
                        'gid': stat.st_gid,
                        'size': stat.st_size,
                    })
                except OSError as e:
                    data['accessError'] = str(e)
                    if e.errno == errno.ENOENT and os.path.islink(item_path):
                        data['brokenLink'] = True

                items.append(data)

            return {
                'parent':
                os.path.dirname(os.path.normpath(path))
                if path != '/' else None,
                'items':
                items,
            }
        except OSError as e:
            raise EndpointError(e)
Esempio n. 9
0
 def handle_api_repo_list(self, http_context):
     try:
         return requests.get('http://ajenti.org/plugins/list').json()
     except Exception as e:
         raise EndpointError(e)
Esempio n. 10
0
 def handle_api_fs_write(self, http_context, path=None):
     try:
         with open(path, 'w') as f:
             f.write(http_context.body)
     except OSError as e:
         raise EndpointError(e)
Esempio n. 11
0
 def handle_api_fs_create_directory(self, http_context, path=None):
     try:
         os.makedirs(path)
     except OSError as e:
         raise EndpointError(e)
Esempio n. 12
0
 def handle_api_fs_create_file(self, http_context, path=None):
     try:
         os.mknod(path, int('644', 8))
     except OSError as e:
         raise EndpointError(e)