Skip to content

Commit a0d1f2c

Browse files
committed
Added variable support at library and API level
1 parent 12e2635 commit a0d1f2c

File tree

7 files changed

+178
-10
lines changed

7 files changed

+178
-10
lines changed

backend/api/index.js

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = ((router, database, config) => {
9797

9898
if(result.length >= 1)
9999
{
100-
var license = result[0];
100+
const license = result[0];
101101

102102
if(!license.hwid || license.hwid == "")
103103
{
@@ -173,7 +173,7 @@ module.exports = ((router, database, config) => {
173173
}
174174
else
175175
{
176-
res.status(400).json({
176+
res.status(401).json({
177177
status: "failure",
178178
message: "That license has been expired."
179179
});
@@ -182,7 +182,7 @@ module.exports = ((router, database, config) => {
182182
}
183183
else
184184
{
185-
res.status(404).json({
185+
res.status(401).json({
186186
status: "failure",
187187
message: "The hardware id doesn't match."
188188
});
@@ -204,5 +204,65 @@ module.exports = ((router, database, config) => {
204204
message: "Internal client error"
205205
});
206206
}
207-
})
207+
});
208+
209+
router.get('/variables/:id', (req, res) => {
210+
if(req.query.license)
211+
{
212+
database.query("SELECT * FROM licenses WHERE license = ?", [req.query.license], (error, result, fields) => {
213+
if(error) throw error;
214+
215+
if(result.length >= 1)
216+
{
217+
const license = result[0];
218+
const current_date = new Date();
219+
if(current_date <= new Date(license.expiry))
220+
{
221+
database.query("SELECT * FROM variables WHERE id = ? AND app = ?", [req.params.id, license.app], (error, result, fields) => {
222+
if(error) throw error;
223+
224+
if(result.length >= 1)
225+
{
226+
res.status(200).json({
227+
status: "success",
228+
variable: {
229+
name: result[0].name,
230+
content: result[0].content
231+
}
232+
});
233+
}
234+
else
235+
{
236+
res.status(404).json({
237+
status: "failure",
238+
message: "Variable doesn't seem to exist"
239+
});
240+
}
241+
});
242+
}
243+
else
244+
{
245+
res.status(401).json({
246+
status: "failure",
247+
message: "This license has expired."
248+
})
249+
}
250+
}
251+
else
252+
{
253+
res.status(404).json({
254+
status: "failure",
255+
message: "That license doesn't seem exist"
256+
})
257+
}
258+
});
259+
}
260+
else
261+
{
262+
res.status(400).json({
263+
status: "failure",
264+
message: "Internal client error"
265+
});
266+
}
267+
});
208268
});

dashboard/src/views/dashboard/ViewApp.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<th> Action </th>
2424
</tr>
2525
<tr v-for="license in this.licenses" :key="license.id">
26-
<td> {{ license.license }} </td>
26+
<td @click="copy(license.license)"> {{ license.license }} </td>
2727
<td v-if="license.expiry"> {{ license.expiry }} </td>
2828
<td v-else> Not set </td>
2929
<td> {{ license.duration }} </td>
@@ -48,15 +48,15 @@
4848
<VariableForm :app="this.app"/>
4949
<table>
5050
<tr>
51+
<th> Id </th>
5152
<th> Name </th>
5253
<th> Content </th>
53-
<th> Created on </th>
5454
<th> Action </th>
5555
</tr>
5656
<tr v-for="variable in this.variables" :key="variable.id">
57+
<td @click="copy(variable.id)"> {{ variable.id }} </td>
5758
<td> {{ variable.name }} </td>
5859
<td> {{ variable.content }} </td>
59-
<td> {{ variable.created_on }} </td>
6060
<td> <button @click="deleteVariable(variable.id)" class="btn danger"> Delete </button> </td>
6161
</tr>
6262
</table>
@@ -140,6 +140,10 @@ export default {
140140
const selectedFile = e.target.files[0]; // accessing file
141141
this.selectedFile = selectedFile;
142142
},
143+
copy(text) {
144+
navigator.clipboard.writeText(text);
145+
this.$toast.success("Copied to clipboard")
146+
},
143147
async onUploadFile() {
144148
await apps.updateFile(this, this.$route.params.id, this.selectedFile);
145149
},

example/auth.hpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <Windows.h>
22
#include <iostream>
33
#include <vector>
4-
54
#define ENDPOINT "http://localhost:4000"
65
#define CURL_STATICLIB
76

@@ -54,7 +53,7 @@ namespace auth
5453
std::string m_created_on;
5554
std::uint32_t m_duration;
5655
public:
57-
license_ctx(std::string id, std::string license, std::string hwid, std::string created_on, std::uint32_t duration);
56+
license_ctx(std::string id, std::string license, std::string hwid, std::string expiry, std::string created_on, std::uint32_t duration);
5857
license_ctx() {}
5958

6059
std::uint32_t deriveKey();
@@ -72,12 +71,30 @@ namespace auth
7271
std::string created_on();
7372
};
7473

74+
class variable_ctx
75+
{
76+
private:
77+
std::string m_id;
78+
std::string m_name;
79+
std::string m_content;
80+
public:
81+
variable_ctx(std::string id, std::string name, std::string content);
82+
variable_ctx() {}
83+
~variable_ctx();
84+
85+
std::string id();
86+
87+
std::string name();
88+
89+
std::string content();
90+
};
91+
7592
class app_ctx
7693
{
7794
private:
7895
std::string m_id;
7996
std::string m_name;
80-
std::string m_version;
97+
std::string m_version;
8198
std::string m_created_on;
8299
auth::status_e m_status;
83100
public:
@@ -108,6 +125,8 @@ namespace auth
108125
response_ctx(auth::license_ctx license, auth::session_ctx session, auth::app_ctx app, bool success);
109126
response_ctx() {}
110127

128+
auth::variable_ctx get_variable(std::string id);
129+
111130
auth::license_ctx license();
112131
auth::session_ctx session();
113132
auth::app_ctx app();

example/library_x64.lib

9.67 KB
Binary file not shown.

example/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ std::uint32_t main()
1313
{
1414
std::printf("welcome back!\nlicenses expiry: %s\n", response.license().expiry().c_str());
1515

16+
auth::variable_ctx variable = response.get_variable("5a6d6f87-e5d6-4dbc-bff9-404d3f8edf3b");
17+
std::printf("variable: %s = %s\n", variable.name().c_str(), variable.content().c_str());
18+
1619
std::printf("preparing streaming procedure\n");
1720
auth::session_ctx session = response.session();
1821
std::printf("streaming image..\n");

library/auth.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,39 @@ auth::app_ctx::~app_ctx()
1919
this->m_created_on.clear();
2020
}
2121

22+
auth::variable_ctx auth::response_ctx::get_variable(std::string id)
23+
{
24+
std::string response;
25+
26+
CURL* curl = curl_easy_init();
27+
28+
if (curl)
29+
{
30+
31+
char* url = reinterpret_cast<char*>(malloc(255));
32+
sprintf(url, "%s/backend/client/api/v1/variables/%s?license=%s", ENDPOINT, id.c_str(), this->m_license.license().c_str());
33+
34+
curl_easy_setopt(curl, CURLOPT_URL, url);
35+
36+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
37+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
38+
39+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
40+
41+
CURLcode res = curl_easy_perform(curl);
42+
curl_easy_cleanup(curl);
43+
}
44+
45+
nlohmann::json data = nlohmann::json::parse(response);
46+
47+
if (data["status"] == "success")
48+
{
49+
return auth::variable_ctx(id, data["variable"]["name"], data["variable"]["content"]);
50+
}
51+
52+
return auth::variable_ctx();
53+
}
54+
2255
auth::status_e auth::app_ctx::status()
2356
{
2457
return this->m_status;
@@ -270,3 +303,32 @@ bool auth::response_ctx::succeeded()
270303
{
271304
return this->m_success;
272305
}
306+
307+
auth::variable_ctx::variable_ctx(std::string id, std::string name, std::string content)
308+
{
309+
this->m_id = id;
310+
this->m_name = name;
311+
this->m_content = content;
312+
}
313+
314+
auth::variable_ctx::~variable_ctx()
315+
{
316+
this->m_id.clear();
317+
this->m_name.clear();
318+
this->m_content.clear();
319+
}
320+
321+
std::string auth::variable_ctx::id()
322+
{
323+
return this->m_id;
324+
}
325+
326+
std::string auth::variable_ctx::name()
327+
{
328+
return this->m_name;
329+
}
330+
331+
std::string auth::variable_ctx::content()
332+
{
333+
return this->m_content;
334+
}

library/auth.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ namespace auth
7272
std::string created_on();
7373
};
7474

75+
class variable_ctx
76+
{
77+
private:
78+
std::string m_id;
79+
std::string m_name;
80+
std::string m_content;
81+
public:
82+
variable_ctx(std::string id, std::string name, std::string content);
83+
variable_ctx() {}
84+
~variable_ctx();
85+
86+
std::string id();
87+
88+
std::string name();
89+
90+
std::string content();
91+
};
92+
7593
class app_ctx
7694
{
7795
private:
@@ -108,6 +126,8 @@ namespace auth
108126
response_ctx(auth::license_ctx license, auth::session_ctx session, auth::app_ctx app, bool success);
109127
response_ctx() {}
110128

129+
auth::variable_ctx get_variable(std::string id);
130+
111131
auth::license_ctx license();
112132
auth::session_ctx session();
113133
auth::app_ctx app();

0 commit comments

Comments
 (0)