Giter VIP home page Giter VIP logo

Comments (6)

kiarn avatar kiarn commented on June 2, 2024

Hi @mailinglists35

You can achieve this kind of behaviour by developping your own plugin and integrating it in Ajenti.
It's also possible to set different permissions for the users.

Regards

Arnaud

from ajenti.

mailinglists35 avatar mailinglists35 commented on June 2, 2024

Arnaud, at first look through the demo plugins it seems a bit complicated - I only know shell scripting.

Could you show a starting point? I could then clone and multiply to all commands that I need.

An example with running system command "/usr/bin/systemctl restart someservice" and printing it's output would be sufficiently exactly what I need.

from ajenti.

kiarn avatar kiarn commented on June 2, 2024

Hello @mailinglists35

Sorry for the late reply, I did not see your answer !
There's some demo plugin with minimal examples here : https://github.com/ajenti/demo-plugins

I think it's a goog starting point for understanding how it is working. Just ask if you need help ! (i will follow your answers ;) )

Arnaud

from ajenti.

mailinglists35 avatar mailinglists35 commented on June 2, 2024

yes, about those demo plugins I was referring them as too difficult to start with for someone with only bash scripting skills

from ajenti.

kiarn avatar kiarn commented on June 2, 2024

Each plugin contains a frontend part (javascript) and a backend part (python).
I will take an example with https://github.com/ajenti/demo-plugins/blob/master/demo_4_http/views.py, and say you want to write a new plugin named myplugin
You will need to copy the whole demo_4_http directory and replace each reference to demo_4_http into myplugin (e.g. https://github.com/ajenti/demo-plugins/blob/master/demo_4_http/plugin.yml).

But in order to achieve this, you will need ajenti-dev-multitool in order to build the javascript part (follow the readme https://github.com/ajenti/demo-plugins/tree/master ).

The backend part for your request could simply be:

import time
import subprocess
from jadi import component

from aj.api.http import url, HttpPlugin

from aj.api.endpoint import endpoint, EndpointError, EndpointReturn


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url(r'/api/myplugin/someservice/restart')
    @endpoint(api=True)
    def handle_api_calculate(self, http_context):
        try:
            subprocess.check_output(['systemctl', 'restart', 'someservice'])
            return "Success"
        except Exception as e:
            raise EndpointError(e)
   

For the frontend:

$scope.restart_my_service = () ->
        $http.get("/api/myplugin/someservice/restart").success (data) ->
            $scope.result = data
        .error (err) ->
            notify.error 'Restart failed', err.message
            $scope.result = null
<a ng:click="restart_my_service()" class="btn btn-default">Restart my service</a>

I hope it helps.

Arnaud

from ajenti.

stale avatar stale commented on June 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days unless you comment.
Thank you for your contributions.

from ajenti.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.