#!/usr/bin/env python3 # This file is part of Remote Support Desktop # https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.sessionservice # Copyright 2020, 2021 Jonathan Weth # Copyright 2020, 2021 Daniel Teichmann # Copyright 2020 Mike Gabriel # SPDX-License-Identifier: GPL-2.0-or-later # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import argparse from typing import Union import dbus def str2bool(v: Union[str, bool, int]) -> bool: """Return true or false if the given string can be interpreted as a boolean. If it fails, raise an exception. """ if isinstance(v, bool): return v if v.lower() in ("yes", "true", "t", "y", "1", 1): return True elif v.lower() in ("no", "false", "f", "n", "0", 0): return False else: raise argparse.ArgumentTypeError("Boolean value expected.") def main(): parser = argparse.ArgumentParser(description="D-Bus Session Service API test client") arguments = parser.add_mutually_exclusive_group() arguments.add_argument( "-s", "--start", const=True, nargs="?", default=True, help="Starts a new support session by calling the D-Bus Session Service (default)", ) arguments.add_argument("-x", "--stop", help="Stops , an existing support session.") arguments.add_argument( "-r", "--refresh_status", help="Refreshes the status of , an existing support session." ) arguments.add_argument( "-i", "--status", help="Gets the status of , an existing support session." ) args = parser.parse_args() start = args.start stop_pid = args.stop status_pid = args.status refresh_pid = args.refresh_status bus = dbus.SessionBus() req = bus.get_object("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService") if stop_pid: print(f"Sending D-Bus request 'stop': {stop_pid}") response = req.stop(stop_pid) print(f"Your response is: {response}") elif status_pid: print(f"Sending D-Bus request 'status': {status_pid}") response = req.status(status_pid) print(f"Your response is: {response}") elif refresh_pid: print(f"Sending D-Bus request 'refresh_status': {refresh_pid}") response = req.refresh_status(refresh_pid) print(f"Your response is: {response}") elif start: print("Sending D-Bus request 'start'") response = req.start() print(f"Your response is: {response}") else: print("No valid input!") return if __name__ == "__main__": main()