1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/*
* RemoteAccessFeaturePlugin.cpp - implementation of RemoteAccessFeaturePlugin class
*
* Copyright (c) 2017-2019 Tobias Junghans <tobydox@veyon.io>
*
* This file is part of Veyon - http://veyon.io
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include <QApplication>
#include <QInputDialog>
#include "AuthenticationCredentials.h"
#include "RemoteAccessFeaturePlugin.h"
#include "RemoteAccessWidget.h"
#include "VeyonMasterInterface.h"
RemoteAccessFeaturePlugin::RemoteAccessFeaturePlugin( QObject* parent ) :
QObject( parent ),
m_remoteViewFeature( Feature::Session | Feature::Master,
Feature::Uid( "a18e545b-1321-4d4e-ac34-adc421c6e9c8" ),
Feature::Uid(),
tr( "Remote view" ), QString(),
tr( "Open a remote view for a computer without interaction." ),
QStringLiteral(":/remoteaccess/kmag.png") ),
m_remoteControlFeature( Feature::Session | Feature::Master,
Feature::Uid( "ca00ad68-1709-4abe-85e2-48dff6ccf8a2" ),
Feature::Uid(),
tr( "Remote control" ), QString(),
tr( "Open a remote control window for a computer." ),
QStringLiteral(":/remoteaccess/krdc.png") ),
m_features( { m_remoteViewFeature, m_remoteControlFeature } ),
m_commands( {
{ QStringLiteral("view"), m_remoteViewFeature.displayName() },
{ QStringLiteral("control"), m_remoteControlFeature.displayName() },
{ QStringLiteral("help"), tr( "Show help about command" ) },
} )
{
}
RemoteAccessFeaturePlugin::~RemoteAccessFeaturePlugin()
{
}
const FeatureList &RemoteAccessFeaturePlugin::featureList() const
{
return m_features;
}
bool RemoteAccessFeaturePlugin::startFeature( VeyonMasterInterface& master, const Feature& feature,
const ComputerControlInterfaceList& computerControlInterfaces )
{
// determine which computer to access and ask if neccessary
ComputerControlInterface::Pointer remoteAccessComputer;
if( ( feature.uid() == m_remoteViewFeature.uid() ||
feature.uid() == m_remoteControlFeature.uid() ) &&
computerControlInterfaces.count() != 1 )
{
QString hostName = QInputDialog::getText( master.mainWindow(),
tr( "Remote access" ),
tr( "Please enter the hostname or IP address of the computer to access:" ) );
if( hostName.isEmpty() )
{
return false;
}
Computer customComputer;
customComputer.setHostAddress( hostName );
remoteAccessComputer = ComputerControlInterface::Pointer::create( customComputer );
}
else
{
if( computerControlInterfaces.count() >= 1 )
{
remoteAccessComputer = computerControlInterfaces.first();
}
}
if( remoteAccessComputer.isNull() )
{
return false;
}
if( feature.uid() == m_remoteViewFeature.uid() )
{
new RemoteAccessWidget( remoteAccessComputer, true );
return true;
}
else if( feature.uid() == m_remoteControlFeature.uid() )
{
new RemoteAccessWidget( remoteAccessComputer, false );
return true;
}
return false;
}
QStringList RemoteAccessFeaturePlugin::commands() const
{
return m_commands.keys();
}
QString RemoteAccessFeaturePlugin::commandHelp( const QString& command ) const
{
return m_commands.value( command );
}
CommandLinePluginInterface::RunResult RemoteAccessFeaturePlugin::handle_view( const QStringList& arguments )
{
if( arguments.count() < 1 )
{
return NotEnoughArguments;
}
return remoteAccess( arguments.first(), true ) ? Successful : Failed;
}
CommandLinePluginInterface::RunResult RemoteAccessFeaturePlugin::handle_control( const QStringList& arguments )
{
if( arguments.count() < 1 )
{
return NotEnoughArguments;
}
return remoteAccess( arguments.first(), false ) ? Successful : Failed;
}
CommandLinePluginInterface::RunResult RemoteAccessFeaturePlugin::handle_help( const QStringList& arguments )
{
if( arguments.value( 0 ) == QStringLiteral("view") )
{
printf( "\nremoteaccess view <host>\n\n" );
return NoResult;
}
else if( arguments.value( 0 ) == QStringLiteral("control") )
{
printf( "\nremoteaccess control <host>\n}n" );
return NoResult;
}
return InvalidCommand;
}
bool RemoteAccessFeaturePlugin::initAuthentication()
{
if( VeyonCore::instance()->initAuthentication( AuthenticationCredentials::AllTypes ) == false )
{
qWarning() << "Could not initialize authentication";
return false;
}
return true;
}
bool RemoteAccessFeaturePlugin::remoteAccess( const QString& hostAddress, bool viewOnly )
{
if( initAuthentication() == false )
{
return false;
}
Computer remoteComputer;
remoteComputer.setName( hostAddress );
remoteComputer.setHostAddress( hostAddress );
new RemoteAccessWidget( ComputerControlInterface::Pointer::create( remoteComputer ), viewOnly );
qApp->exec();
return true;
}
|