mirror of https://github.com/CGAL/cgal
Add a way to upload a scene through ssh.
This commit is contained in:
parent
e868586bd7
commit
b1a8ec6d76
|
|
@ -0,0 +1,39 @@
|
||||||
|
# - Try to find the LibSSH libraries
|
||||||
|
# This module defines:
|
||||||
|
# LIBSSH_FOUND - system has LibSSH lib
|
||||||
|
# LIBSSH_INCLUDE_DIR - the LibSSH include directory
|
||||||
|
# LIBSSH_LIBRARIES_DIR - directory where the LibSSH libraries are located
|
||||||
|
# LIBSSH_LIBRARIES - Link these to use LibSSH
|
||||||
|
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/CGAL_GeneratorSpecificSettings.cmake)
|
||||||
|
|
||||||
|
if(LIBSSH_INCLUDE_DIR)
|
||||||
|
set(LIBSSH_in_cache TRUE)
|
||||||
|
else()
|
||||||
|
set(LIBSSH_in_cache FALSE)
|
||||||
|
endif()
|
||||||
|
if(NOT LIBSSH_LIBRARIES)
|
||||||
|
set(LIBSSH_in_cache FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Is it already configured?
|
||||||
|
if( NOT LIBSSH_in_cache )
|
||||||
|
|
||||||
|
find_path(LIBSSH_INCLUDE_DIR
|
||||||
|
NAMES "libssh/libssh.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(LIBSSH_LIBRARIES NAMES ssh libssh
|
||||||
|
HINTS "/usr/lib"
|
||||||
|
"usr/lib/x86_64-linux-gnu"
|
||||||
|
PATH_SUFFIXES lib
|
||||||
|
DOC "Path to the LIBSSH library"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
SET(LIBSSH_FOUND TRUE)
|
||||||
|
if( NOT LIBSSH_LIBRARIES OR NOT LIBSSH_INCLUDE_DIR)
|
||||||
|
SET(LIBSSH_FOUND FALSE)
|
||||||
|
endif()
|
||||||
|
|
@ -95,6 +95,11 @@ if( POLYHEDRON_DEMO_ACTIVATE_CONCURRENCY )
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
#find libssh for scene sharing
|
||||||
|
find_package(LibSSH)
|
||||||
|
if( NOT LIBSSH_FOUND )
|
||||||
|
message("NOTICE : The SSH features will be disabled.")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Activate concurrency ? (turned OFF by default)
|
# Activate concurrency ? (turned OFF by default)
|
||||||
option(CGAL_ACTIVATE_CONCURRENT_MESH_3
|
option(CGAL_ACTIVATE_CONCURRENT_MESH_3
|
||||||
|
|
@ -131,7 +136,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND)
|
||||||
qt5_wrap_ui( statisticsUI_FILES Statistics_on_item_dialog.ui)
|
qt5_wrap_ui( statisticsUI_FILES Statistics_on_item_dialog.ui)
|
||||||
qt5_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui )
|
qt5_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui )
|
||||||
qt5_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui )
|
qt5_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui )
|
||||||
qt5_wrap_ui( PreferencesUI_FILES Preferences.ui Details.ui)
|
qt5_wrap_ui( PreferencesUI_FILES Preferences.ui Details.ui SSH_dialog.ui)
|
||||||
qt5_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui )
|
qt5_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui )
|
||||||
qt5_wrap_ui( ViewerUI_FILES LightingDialog.ui)
|
qt5_wrap_ui( ViewerUI_FILES LightingDialog.ui)
|
||||||
qt5_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" )
|
qt5_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" )
|
||||||
|
|
@ -322,11 +327,16 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND)
|
||||||
MainWindow.cpp
|
MainWindow.cpp
|
||||||
Polyhedron_demo.cpp
|
Polyhedron_demo.cpp
|
||||||
File_loader_dialog_moc.cpp
|
File_loader_dialog_moc.cpp
|
||||||
|
Use_ssh.cpp
|
||||||
${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES}
|
${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES}
|
||||||
${FileLoaderDialogUI_files} ${MainWindowUI_files} ${PreferencesUI_FILES}
|
${FileLoaderDialogUI_files} ${MainWindowUI_files} ${PreferencesUI_FILES}
|
||||||
${statisticsUI_FILES} ${SubViewerUI_files})
|
${statisticsUI_FILES} ${SubViewerUI_files})
|
||||||
target_link_libraries(polyhedron_demo PUBLIC
|
target_link_libraries(polyhedron_demo PUBLIC
|
||||||
demo_framework point_dialog Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Script)
|
demo_framework point_dialog Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Script)
|
||||||
|
if(LIBSSH_FOUND)
|
||||||
|
add_definitions(-DCGAL_USE_SSH)
|
||||||
|
target_link_libraries(polyhedron_demo PUBLIC ${LIBSSH_LIBRARIES})
|
||||||
|
endif() #libssh
|
||||||
add_executable ( Polyhedron_3 Polyhedron_3.cpp )
|
add_executable ( Polyhedron_3 Polyhedron_3.cpp )
|
||||||
target_link_libraries( Polyhedron_3 PRIVATE polyhedron_demo )
|
target_link_libraries( Polyhedron_3 PRIVATE polyhedron_demo )
|
||||||
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyhedron_3 )
|
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyhedron_3 )
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@
|
||||||
#include "ui_Preferences.h"
|
#include "ui_Preferences.h"
|
||||||
#include "ui_Details.h"
|
#include "ui_Details.h"
|
||||||
#include "ui_Statistics_on_item_dialog.h"
|
#include "ui_Statistics_on_item_dialog.h"
|
||||||
|
#include "ui_SSH_dialog.h"
|
||||||
#include "Show_point_dialog.h"
|
#include "Show_point_dialog.h"
|
||||||
#include "File_loader_dialog.h"
|
#include "File_loader_dialog.h"
|
||||||
#include "Viewer.h"
|
#include "Viewer.h"
|
||||||
|
|
@ -70,6 +71,11 @@
|
||||||
# include <QScriptEngine>
|
# include <QScriptEngine>
|
||||||
# include <QScriptValue>
|
# include <QScriptValue>
|
||||||
#include "Color_map.h"
|
#include "Color_map.h"
|
||||||
|
|
||||||
|
#ifdef CGAL_USE_SSH
|
||||||
|
# include "CGAL/Use_ssh.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace CGAL::Three;
|
using namespace CGAL::Three;
|
||||||
QScriptValue
|
QScriptValue
|
||||||
myScene_itemToScriptValue(QScriptEngine *engine,
|
myScene_itemToScriptValue(QScriptEngine *engine,
|
||||||
|
|
@ -151,6 +157,7 @@ MainWindow::MainWindow(const QStringList &keywords, bool verbose, QWidget* paren
|
||||||
// remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB
|
// remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB
|
||||||
#if !defined(QT_SCRIPT_LIB)
|
#if !defined(QT_SCRIPT_LIB)
|
||||||
ui->menuBar->removeAction(ui->actionLoadScript);
|
ui->menuBar->removeAction(ui->actionLoadScript);
|
||||||
|
ui->menuBar->removeAction(ui->on_actionLoad_a_Scene_from_a_Script_File);
|
||||||
#endif
|
#endif
|
||||||
// Save some pointers from ui, for latter use.
|
// Save some pointers from ui, for latter use.
|
||||||
sceneView = ui->sceneView;
|
sceneView = ui->sceneView;
|
||||||
|
|
@ -1891,14 +1898,7 @@ void MainWindow::throw_exception() {
|
||||||
void MainWindow::on_actionLoadScript_triggered()
|
void MainWindow::on_actionLoadScript_triggered()
|
||||||
{
|
{
|
||||||
#if defined(QT_SCRIPT_LIB)
|
#if defined(QT_SCRIPT_LIB)
|
||||||
QString filename = QFileDialog::getOpenFileName(
|
|
||||||
this,
|
|
||||||
tr("Select a script to run..."),
|
|
||||||
".",
|
|
||||||
"QTScripts (*.js);;All Files (*)");
|
|
||||||
if(filename.isEmpty())
|
|
||||||
return;
|
|
||||||
loadScript(QFileInfo(filename));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2198,7 +2198,10 @@ void MainWindow::on_actionPreferences_triggered()
|
||||||
QDialog dialog(this);
|
QDialog dialog(this);
|
||||||
Ui::PreferencesDialog prefdiag;
|
Ui::PreferencesDialog prefdiag;
|
||||||
prefdiag.setupUi(&dialog);
|
prefdiag.setupUi(&dialog);
|
||||||
|
#ifdef CGAL_USE_SSH
|
||||||
|
|
||||||
|
prefdiag.sshButton->setEnabled(true);
|
||||||
|
#endif
|
||||||
float lineWidth[2];
|
float lineWidth[2];
|
||||||
if(!viewer->isOpenGL_4_3())
|
if(!viewer->isOpenGL_4_3())
|
||||||
viewer->glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth);
|
viewer->glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth);
|
||||||
|
|
@ -2337,6 +2340,52 @@ void MainWindow::on_actionPreferences_triggered()
|
||||||
});
|
});
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
});
|
});
|
||||||
|
connect(prefdiag.sshButton, &QPushButton::clicked,
|
||||||
|
this, [this, prefdiag](){
|
||||||
|
QDialog dialog(this);
|
||||||
|
Ui::SSHDialog sshdiag;
|
||||||
|
sshdiag.setupUi(&dialog);
|
||||||
|
sshdiag.userEdit->setText(settings.value("ssh_user", QString()).toString());
|
||||||
|
sshdiag.serverEdit->setText(settings.value("ssh_server", QString()).toString());
|
||||||
|
sshdiag.publicEdit->setText(settings.value("ssh_public_key", QString()).toString());
|
||||||
|
sshdiag.privkEdit->setText(settings.value("ssh_priv_key", QString()).toString());
|
||||||
|
connect(sshdiag.pubButton, &QPushButton::clicked,
|
||||||
|
this, [this, sshdiag](){
|
||||||
|
QFileDialog diag(this,
|
||||||
|
"Public Key",
|
||||||
|
"",
|
||||||
|
"All Files (*)");
|
||||||
|
diag.setFilter(QDir::Hidden|QDir::Files|QDir::Dirs|QDir::NoDotAndDotDot);
|
||||||
|
if(!diag.exec())
|
||||||
|
return;
|
||||||
|
sshdiag.publicEdit->setText(diag.selectedFiles().front());
|
||||||
|
});
|
||||||
|
connect(sshdiag.privButton, &QPushButton::clicked,
|
||||||
|
this, [this, sshdiag](){
|
||||||
|
QFileDialog diag(this,
|
||||||
|
"Private Key",
|
||||||
|
"",
|
||||||
|
"All Files (*)");
|
||||||
|
diag.setFilter(QDir::Hidden|QDir::Files|QDir::Dirs|QDir::NoDotAndDotDot);
|
||||||
|
if(!diag.exec())
|
||||||
|
return;
|
||||||
|
sshdiag.privkEdit->setText(diag.selectedFiles().front());
|
||||||
|
});
|
||||||
|
connect(prefdiag.sshButton, &QPushButton::clicked,
|
||||||
|
this, [this, prefdiag](){});
|
||||||
|
dialog.exec();
|
||||||
|
if ( dialog.result() )
|
||||||
|
{
|
||||||
|
settings.setValue("ssh_user",
|
||||||
|
sshdiag.userEdit->text());
|
||||||
|
settings.setValue("ssh_server",
|
||||||
|
sshdiag.serverEdit->text());
|
||||||
|
settings.setValue("ssh_public_key",
|
||||||
|
sshdiag.publicEdit->text());
|
||||||
|
settings.setValue("ssh_priv_key",
|
||||||
|
sshdiag.privkEdit->text());
|
||||||
|
}
|
||||||
|
});
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
|
|
||||||
if ( dialog.result() )
|
if ( dialog.result() )
|
||||||
|
|
@ -2842,11 +2891,41 @@ void MainWindow::on_actionSa_ve_Scene_as_Script_triggered()
|
||||||
{
|
{
|
||||||
if(scene->numberOfEntries() == 0)
|
if(scene->numberOfEntries() == 0)
|
||||||
return;
|
return;
|
||||||
QString filename =
|
bool do_upload = false;
|
||||||
QFileDialog::getSaveFileName(this,
|
#ifdef CGAL_USE_SSH
|
||||||
"Save the Scene as a Script File",
|
QString user = settings.value("ssh_user", QString()).toString();
|
||||||
last_saved_dir,
|
QString pass;
|
||||||
"Qt Script files (*.js)");
|
if(!user.isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton doyou =
|
||||||
|
QMessageBox::question(this, tr("Upload ?"), tr("Do you wish to upload the scene"
|
||||||
|
" using the SSH preferences ?"));
|
||||||
|
bool ok;
|
||||||
|
do_upload = (doyou == QMessageBox::Yes);
|
||||||
|
if(do_upload)
|
||||||
|
{
|
||||||
|
pass = QInputDialog::getText(this, "SSH Password",
|
||||||
|
"Enter ssh key password:",
|
||||||
|
QLineEdit::Password,
|
||||||
|
tr(""),
|
||||||
|
&ok);
|
||||||
|
if(!ok)
|
||||||
|
return;
|
||||||
|
pass = pass.trimmed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QString filename;
|
||||||
|
|
||||||
|
if(do_upload){
|
||||||
|
filename = QString("%1/save_scene.js").arg(QDir::tempPath());
|
||||||
|
}else{
|
||||||
|
filename = QFileDialog::getSaveFileName(this,
|
||||||
|
"Save the Scene as a Script File",
|
||||||
|
last_saved_dir,
|
||||||
|
"Qt Script files (*.js)");
|
||||||
|
}
|
||||||
CGAL::Three::Three::CursorScopeGuard cs(Qt::WaitCursor);
|
CGAL::Three::Three::CursorScopeGuard cs(Qt::WaitCursor);
|
||||||
std::ofstream os(filename.toUtf8(), std::ofstream::binary);
|
std::ofstream os(filename.toUtf8(), std::ofstream::binary);
|
||||||
if(!os)
|
if(!os)
|
||||||
|
|
@ -2961,6 +3040,58 @@ void MainWindow::on_actionSa_ve_Scene_as_Script_triggered()
|
||||||
"Items Not Saved",
|
"Items Not Saved",
|
||||||
QString("The following items could not be saved: %1").arg(
|
QString("The following items could not be saved: %1").arg(
|
||||||
not_saved.join(", ")));
|
not_saved.join(", ")));
|
||||||
|
#ifdef CGAL_USE_SSH
|
||||||
|
using namespace CGAL::ssh_internal;
|
||||||
|
if(do_upload)
|
||||||
|
{
|
||||||
|
QString server = settings.value("ssh_server", QString()).toString();
|
||||||
|
QString pk = settings.value("ssh_public_key", QString()).toString();
|
||||||
|
QString privK = settings.value("ssh_priv_key", QString()).toString();
|
||||||
|
user = user.trimmed();
|
||||||
|
server = server.trimmed();
|
||||||
|
pk = pk.trimmed();
|
||||||
|
privK=privK.trimmed();
|
||||||
|
if(user.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString path;
|
||||||
|
path = QInputDialog::getText(this,
|
||||||
|
"",
|
||||||
|
tr("Enter the destination path for your file."));
|
||||||
|
if(path.isEmpty())
|
||||||
|
return;
|
||||||
|
try{
|
||||||
|
ssh_session session;
|
||||||
|
bool res = establish_ssh_session(session,
|
||||||
|
user.toStdString().c_str(),
|
||||||
|
server.toStdString().c_str(),
|
||||||
|
pk.toStdString().c_str(),
|
||||||
|
privK.toStdString().c_str(),
|
||||||
|
pass.toStdString().c_str());
|
||||||
|
if(!res)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,
|
||||||
|
"Error",
|
||||||
|
"The SSH session could not be started.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res = push_file(session,path.toStdString().c_str(), filename.toStdString().c_str());
|
||||||
|
if(!res)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,
|
||||||
|
"Error",
|
||||||
|
"The file could not be uploaded. Check your console for more information.");
|
||||||
|
close_connection(session);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
close_connection(session);
|
||||||
|
} catch( ssh::SshException e )
|
||||||
|
{
|
||||||
|
std::cout << "Error during connection : ";
|
||||||
|
std::cout << e.getError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void MainWindow::setTransparencyPasses(int val)
|
void MainWindow::setTransparencyPasses(int val)
|
||||||
{
|
{
|
||||||
|
|
@ -3358,3 +3489,100 @@ void MainWindow::on_action_Save_triggered()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionLoad_a_Scene_from_a_Script_File_triggered()
|
||||||
|
{
|
||||||
|
bool do_download = false;
|
||||||
|
QString filename;
|
||||||
|
|
||||||
|
#ifdef CGAL_USE_SSH
|
||||||
|
QString user = settings.value("ssh_user", QString()).toString();
|
||||||
|
QString pass;
|
||||||
|
if(!user.isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton doyou =
|
||||||
|
QMessageBox::question(this, tr("Download ?"), tr("Do you wish to download the scene"
|
||||||
|
" using the SSH preferences ?"));
|
||||||
|
bool ok;
|
||||||
|
do_download= (doyou == QMessageBox::Yes);
|
||||||
|
if(do_download)
|
||||||
|
{
|
||||||
|
pass = QInputDialog::getText(this, "SSH Password",
|
||||||
|
"Enter ssh key password:",
|
||||||
|
QLineEdit::Password,
|
||||||
|
tr(""),
|
||||||
|
&ok);
|
||||||
|
if(!ok)
|
||||||
|
return;
|
||||||
|
pass = pass.trimmed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(do_download)
|
||||||
|
{
|
||||||
|
using namespace CGAL::ssh_internal;
|
||||||
|
QString server = settings.value("ssh_server", QString()).toString();
|
||||||
|
QString pk = settings.value("ssh_public_key", QString()).toString();
|
||||||
|
QString privK = settings.value("ssh_priv_key", QString()).toString();
|
||||||
|
user = user.trimmed();
|
||||||
|
server = server.trimmed();
|
||||||
|
pk = pk.trimmed();
|
||||||
|
privK=privK.trimmed();
|
||||||
|
QString path;
|
||||||
|
path = QInputDialog::getText(this,
|
||||||
|
"",
|
||||||
|
tr("Enter the remote path for your file."));
|
||||||
|
if(path.isEmpty())
|
||||||
|
return;
|
||||||
|
try{
|
||||||
|
ssh_session session;
|
||||||
|
bool res = establish_ssh_session(session,
|
||||||
|
user.toStdString().c_str(),
|
||||||
|
server.toStdString().c_str(),
|
||||||
|
pk.toStdString().c_str(),
|
||||||
|
privK.toStdString().c_str(),
|
||||||
|
pass.toStdString().c_str());
|
||||||
|
if(!res)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,
|
||||||
|
"Error",
|
||||||
|
"The SSH session could not be started.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
filename = QString("%1/load_scene.js").arg(QDir::tempPath());
|
||||||
|
path = tr("%1/%2").arg(QDir::tempPath()).arg(path);
|
||||||
|
res = pull_file(session,path.toStdString().c_str(), filename.toStdString().c_str());
|
||||||
|
if(!res)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this,
|
||||||
|
"Error",
|
||||||
|
"The file could not be fetched. Check your console for more info.");
|
||||||
|
close_connection(session);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
close_connection(session);
|
||||||
|
} catch( ssh::SshException e )
|
||||||
|
{
|
||||||
|
std::cout << "Error during connection : ";
|
||||||
|
std::cout << e.getError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filename = QFileDialog::getOpenFileName(
|
||||||
|
this,
|
||||||
|
tr("Select a Whole Scene file..."),
|
||||||
|
".",
|
||||||
|
"Whole Scene files (*.js)");
|
||||||
|
if(filename.isEmpty())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
loadScript(QFileInfo(filename));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -449,6 +449,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void on_actionSa_ve_Scene_as_Script_triggered();
|
void on_actionSa_ve_Scene_as_Script_triggered();
|
||||||
|
void on_actionLoad_a_Scene_from_a_Script_File_triggered();
|
||||||
void toggleFullScreen();
|
void toggleFullScreen();
|
||||||
void setDefaultSaveDir();
|
void setDefaultSaveDir();
|
||||||
void invalidate_bbox(bool do_recenter);
|
void invalidate_bbox(bool do_recenter);
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
<addaction name="action_Save"/>
|
<addaction name="action_Save"/>
|
||||||
<addaction name="actionSaveAs"/>
|
<addaction name="actionSaveAs"/>
|
||||||
<addaction name="actionSa_ve_Scene_as_Script"/>
|
<addaction name="actionSa_ve_Scene_as_Script"/>
|
||||||
|
<addaction name="actionLoad_a_Scene_from_a_Script_File"/>
|
||||||
<addaction name="actionSaveSnapshot"/>
|
<addaction name="actionSaveSnapshot"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionLoadScript"/>
|
<addaction name="actionLoadScript"/>
|
||||||
|
|
@ -463,10 +464,14 @@
|
||||||
<string>&Save</string>
|
<string>&Save</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionLoad_a_Scene_from_a_Script_File">
|
||||||
|
<property name="text">
|
||||||
|
<string>Load a Scene &from a Script File...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="Polyhedron_3.qrc"/>
|
<include location="Polyhedron_3.qrc"/>
|
||||||
<include location="Polyhedron_3.qrc"/>
|
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>631</width>
|
<width>631</width>
|
||||||
<height>526</height>
|
<height>628</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
@ -59,8 +59,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>278</width>
|
<width>275</width>
|
||||||
<height>499</height>
|
<height>534</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
|
@ -285,6 +285,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="sshButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>SSH Settings</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SSHDialog</class>
|
||||||
|
<widget class="QDialog" name="SSHDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>466</width>
|
||||||
|
<height>399</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>SSH Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="userBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>User</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="userEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="serverBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Server</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="serverEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="pkBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Public Key </string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="publicEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pubButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Browse...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="privkBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Private Key</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="privkEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="privButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Browse...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>SSHDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>SSHDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
|
|
@ -0,0 +1,244 @@
|
||||||
|
#ifdef CGAL_USE_SSH
|
||||||
|
#include "CGAL/Use_ssh.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
bool test_result(int res)
|
||||||
|
{
|
||||||
|
switch(res){
|
||||||
|
|
||||||
|
case SSH_AUTH_ERROR:
|
||||||
|
{
|
||||||
|
std::cerr<<"Auth failed with error: "<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case SSH_AUTH_DENIED:
|
||||||
|
{
|
||||||
|
std::cerr<<"The server doesn't accept that public key as an authentication token. Try another key or another method."<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case SSH_AUTH_PARTIAL :
|
||||||
|
{
|
||||||
|
std::cerr<<"You've been partially authenticated, you still have to use another method."<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case SSH_OK:
|
||||||
|
return true;
|
||||||
|
case SSH_EOF:
|
||||||
|
std::cerr<<"key doesn't exist."<<std::endl;
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
namespace CGAL{
|
||||||
|
namespace ssh_internal{
|
||||||
|
|
||||||
|
bool establish_ssh_session(ssh_session &session,
|
||||||
|
const char* user,
|
||||||
|
const char* server,
|
||||||
|
const char* pub_key_path,
|
||||||
|
const char* priv_key_path,
|
||||||
|
const char* priv_key_password)
|
||||||
|
{
|
||||||
|
int port = 22;
|
||||||
|
|
||||||
|
//Can use SSH_LOG_PROTOCOL here for verbose output
|
||||||
|
int verbosity = SSH_LOG_NOLOG;
|
||||||
|
|
||||||
|
session = ssh_new();
|
||||||
|
ssh_options_set( session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity );
|
||||||
|
ssh_options_set( session, SSH_OPTIONS_PORT, &port );
|
||||||
|
ssh_options_set( session, SSH_OPTIONS_USER, user );
|
||||||
|
ssh_options_set( session, SSH_OPTIONS_HOST, server);
|
||||||
|
|
||||||
|
ssh_connect(session);
|
||||||
|
|
||||||
|
if( ssh_is_server_known(session) != SSH_SERVER_KNOWN_OK )
|
||||||
|
{
|
||||||
|
if( ssh_write_knownhost(session) != SSH_OK )
|
||||||
|
{
|
||||||
|
std::cerr << "writeKnownHost failed" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ssh_connect(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ssh_key pubkey = ssh_key_new();
|
||||||
|
ssh_pki_import_pubkey_file(pub_key_path, &pubkey);
|
||||||
|
int res = ssh_userauth_try_publickey(session, NULL, pubkey);
|
||||||
|
if(!test_result(res))
|
||||||
|
{
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_key privkey = ssh_key_new();
|
||||||
|
res = ssh_pki_import_privkey_file(priv_key_path, priv_key_password, NULL, NULL, &privkey);
|
||||||
|
if (!test_result(res))
|
||||||
|
{
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
res = ssh_userauth_publickey(session, NULL, privkey);
|
||||||
|
if(!test_result(res))
|
||||||
|
{
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close_connection(ssh_session &session)
|
||||||
|
{
|
||||||
|
ssh_disconnect(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool push_file(ssh_session &session,
|
||||||
|
const char* dest_path,
|
||||||
|
const char* filepath)
|
||||||
|
{
|
||||||
|
//copy a file
|
||||||
|
ssh_scp scp = ssh_scp_new(
|
||||||
|
session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, "/tmp");
|
||||||
|
if (scp == NULL)
|
||||||
|
{
|
||||||
|
std::cerr<<"Error allocating scp session: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
int res = ssh_scp_init(scp);
|
||||||
|
if(res != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<< "Error initializing scp session: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//read a file into a buffer
|
||||||
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||||
|
if(!file)
|
||||||
|
{
|
||||||
|
std::cerr<<"File not found."<<std::endl;
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::streamsize size = file.tellg();
|
||||||
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
|
std::vector<char> buffer(size);
|
||||||
|
if (!file.read(buffer.data(), size))
|
||||||
|
{
|
||||||
|
std::cerr<<"error while reading file."<<std::endl;
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//push a file to /tmp
|
||||||
|
res = ssh_scp_push_directory(scp, ".", S_IRWXU|S_IRWXO);
|
||||||
|
if (res != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<<"Can't create remote directory: %s\n"
|
||||||
|
<<ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
res = ssh_scp_push_file
|
||||||
|
(scp, dest_path, size, S_IRWXU|S_IRWXO);
|
||||||
|
if (res != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<< "Can't open remote file: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
res = ssh_scp_write(scp, buffer.data(), size);
|
||||||
|
if (res != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<< "Can't write to remote file: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pull_file(ssh_session &session,
|
||||||
|
const char* from_path,
|
||||||
|
const char* to_path)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
long unsigned int size;
|
||||||
|
long unsigned int processed = 0;
|
||||||
|
std::vector<char> buffer;
|
||||||
|
|
||||||
|
ssh_scp scp = ssh_scp_new(
|
||||||
|
session, SSH_SCP_READ | SSH_SCP_RECURSIVE, from_path);
|
||||||
|
if (scp == NULL)
|
||||||
|
{
|
||||||
|
std::cerr<<"Error allocating scp session: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
int res = ssh_scp_init(scp);
|
||||||
|
if(res != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<< "Error initializing scp session: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rc = ssh_scp_pull_request(scp);
|
||||||
|
if (rc != SSH_SCP_REQUEST_NEWFILE)
|
||||||
|
{
|
||||||
|
std::cerr<< "Error receiving information about file: %s\n"
|
||||||
|
<< ssh_get_error(session)<<std::endl;
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
size = ssh_scp_request_get_size64(scp);
|
||||||
|
buffer.resize(size);
|
||||||
|
if(ssh_scp_accept_request(scp) != SSH_OK)
|
||||||
|
{
|
||||||
|
std::cerr<< "Could not accept request."<<std::endl;
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
do{
|
||||||
|
rc = ssh_scp_read(scp, buffer.data() + processed, size-processed);
|
||||||
|
if (rc == SSH_ERROR)
|
||||||
|
{
|
||||||
|
std::cerr<< "Error receiving file data: %s\n"<< ssh_get_error(session)<<std::endl;
|
||||||
|
//free(buffer);
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
ssh_disconnect(session);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
processed += rc;
|
||||||
|
}while(processed != size);
|
||||||
|
std::ofstream file(to_path, std::ios::binary |std::ios::trunc);
|
||||||
|
if(!file.write(buffer.data(), size))
|
||||||
|
{
|
||||||
|
std::cerr<<"Error while writing file."<<std::endl;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
//free(buffer);
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef USE_SSH_H
|
||||||
|
#define USE_SSH_H
|
||||||
|
#include <libssh/libsshpp.hpp>
|
||||||
|
namespace CGAL{
|
||||||
|
namespace ssh_internal{
|
||||||
|
//should be used inside a try/catch(ssh::SshException e)
|
||||||
|
|
||||||
|
//give an unitialized session.
|
||||||
|
bool establish_ssh_session(ssh_session& session,
|
||||||
|
const char *user,
|
||||||
|
const char *server,
|
||||||
|
const char *pub_key_path,
|
||||||
|
const char *priv_key_path,
|
||||||
|
const char *priv_key_password);
|
||||||
|
void close_connection(ssh_session& session);
|
||||||
|
|
||||||
|
bool push_file(ssh_session& session,
|
||||||
|
const char* dest_path,
|
||||||
|
const char* filepath);
|
||||||
|
bool pull_file(ssh_session &session,
|
||||||
|
const char *from_path,
|
||||||
|
const char *to_path);
|
||||||
|
|
||||||
|
}}
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue