forked from multiOTP/multiotp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.cpp
122 lines (106 loc) · 4.16 KB
/
launcher.cpp
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
/**
* @file launcher.cpp
* @brief Launcher for the multiOTP open source embedded CLI package
*
* multiOTP C++ launcher - Strong two-factor authentication solution
* https://www\.multiOTP.net
*
* Visit http://forum.multiotp.net/ for additional support.
*
* Donation are always welcome! Please check https://www\.multiOTP.net
* and you will find the magic button ;-)
*
* The multiOTP C++ launcher is simply used to launch PHP
* and run multiotp.windows.php with the provided arguments.
*
* @author Andre Liechti, SysCo systemes de communication sa, <[email protected]>
* @version 5.9.8.0
* @date 2024-08-26
* @since 2016-12-08
* @copyright (c) 2010-2024 SysCo systemes de communication sa
* @copyright GNU Lesser General Public License
*
*//*
*
* LICENCE
*
* Copyright (c) 2010-2024 SysCo systemes de communication sa
* SysCo (tm) is a trademark of SysCo systemes de communication sa
* (http://www.sysco.ch)
* All rights reserved.
*
* This file is part of the multiOTP open source project.
*
* multiOTP open source project is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* multiOTP open source project 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with multiOTP open source project.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Change Log
*
* 2018-03-05 5.1.0.8 SysCo/al Adapt the php.exe path automatically
* 2018-02-19 5.1.0.6 SysCo/al Quotes tested and debugged with Credential Provider
* 2018-02-19 5.1.0.3 SysCo/al Comments cleaning
* 2017-05-29 5.0.4.5 SysCo/al Quotes must by around the launch string
* 2016-12-29 5.0.3.4 SysCo/al Initial implementation and distribution
*
*********************************************************************/
#include "stdafx.h"
#define WIN32_LEAN_AND_MEAN
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#include <windows.h>
#include <string>
#include <iostream>
#define SOFTWARE "LAUNCHPHPMULTIOTP"
#define VER_NUMBER "5.9.8.0"
#define VER_DATE "2024-08-26"
void replaceAll(std::string& str, const std::string& from, const std::string& to) {
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
int _tmain(int argc, _TCHAR* argv[])
{
std::string cli_arg = argv[0];
cli_arg = cli_arg + "\\..\\";
const char* cli_arg_char = cli_arg.c_str();
char basePath[4096] = "";
_fullpath(basePath, cli_arg_char, sizeof(basePath));
std::string quote = "\"";
std::string pathToPhp = quote + basePath + "php\\php.exe" + quote;
std::string pathToMultiotp = quote + basePath + "php\\multiotp.windows.php" + quote;
// std::string defaultPath = basePath + "php";
// char defaultPath[4096] = "";
// strcpy_s(defaultPath, basePath);
// strcat_s(defaultPath, "php");
std::string run_software = pathToPhp + " " + pathToMultiotp + " -base-dir=" + quote + basePath + "." + quote;
std::string escapedArgv;
for (int i = 1; i < argc; i = i + 1) {
escapedArgv = argv[i];
replaceAll(escapedArgv, "\"", "\\\"");
replaceAll(escapedArgv, "&", "^&");
run_software = run_software + " " + quote + escapedArgv + quote;
}
// Put the run software between quotes, because system use CMD /K
run_software = quote + run_software + quote;
const char* run_software_char = run_software.c_str();
// std::cout << "Full RUN: " << run_software_char << std::endl;
_chdir(basePath);
return system(run_software_char);
}