]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/rscript/rscript.cpp
Use "connected" subscription for detecting connection and disconnection.
[stg.git] / projects / stargazer / plugins / other / rscript / rscript.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #include <sys/time.h>
23
24 #include <csignal>
25 #include <cassert>
26 #include <cstdlib>
27 #include <cerrno>
28 #include <cstring>
29 #include <algorithm>
30
31 #include "stg/common.h"
32 #include "stg/locker.h"
33 #include "stg/users.h"
34 #include "stg/user_property.h"
35 #include "stg/plugin_creator.h"
36 #include "stg/logger.h"
37 #include "rscript.h"
38 #include "ur_functor.h"
39 #include "send_functor.h"
40
41 extern volatile const time_t stgTime;
42
43 #define RS_MAX_ROUTERS  (100)
44
45 using RS::REMOTE_SCRIPT;
46
47 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 PLUGIN_CREATOR<REMOTE_SCRIPT> rsc;
51 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 PLUGIN * GetPlugin()
55 {
56 return rsc.GetPlugin();
57 }
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 RS::USER::USER(const std::vector<uint32_t> & r, USER_PTR it, REMOTE_SCRIPT & rs)
62     : lastSentTime(0),
63       user(it),
64       routers(r),
65       shortPacketsCount(0),
66       ip(user->GetCurrIP()),
67       notifier(rs, *this)
68 {
69     user->AddConnectedAfterNotifier(&notifier);
70 }
71 //-----------------------------------------------------------------------------
72 RS::USER::USER(const RS::USER & rhs)
73     : lastSentTime(rhs.lastSentTime),
74       user(rhs.user),
75       routers(rhs.routers),
76       shortPacketsCount(rhs.shortPacketsCount),
77       ip(rhs.ip),
78       notifier(rhs.notifier)
79 {
80     user->DelConnectedAfterNotifier(&rhs.notifier);
81     user->AddConnectedAfterNotifier(&notifier);
82 }
83 //-----------------------------------------------------------------------------
84 RS::USER::~USER()
85 {
86     user->DelConnectedAfterNotifier(&notifier);
87 }
88 //-----------------------------------------------------------------------------
89 RS::SETTINGS::SETTINGS()
90     : sendPeriod(0),
91       port(0),
92       errorStr(),
93       netRouters(),
94       userParams(),
95       password(),
96       subnetFile()
97 {
98 }
99 //-----------------------------------------------------------------------------
100 int RS::SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
101 {
102 int p;
103 PARAM_VALUE pv;
104 vector<PARAM_VALUE>::const_iterator pvi;
105 netRouters.clear();
106 ///////////////////////////
107 pv.param = "Port";
108 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
109 if (pvi == s.moduleParams.end())
110     {
111     errorStr = "Parameter \'Port\' not found.";
112     printfd(__FILE__, "Parameter 'Port' not found\n");
113     return -1;
114     }
115 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
116     {
117     errorStr = "Cannot parse parameter \'Port\': " + errorStr;
118     printfd(__FILE__, "Cannot parse parameter 'Port'\n");
119     return -1;
120     }
121 port = p;
122 ///////////////////////////
123 pv.param = "SendPeriod";
124 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
125 if (pvi == s.moduleParams.end())
126     {
127     errorStr = "Parameter \'SendPeriod\' not found.";
128     printfd(__FILE__, "Parameter 'SendPeriod' not found\n");
129     return -1;
130     }
131
132 if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod))
133     {
134     errorStr = "Cannot parse parameter \'SendPeriod\': " + errorStr;
135     printfd(__FILE__, "Cannot parse parameter 'SendPeriod'\n");
136     return -1;
137     }
138 ///////////////////////////
139 pv.param = "UserParams";
140 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
141 if (pvi == s.moduleParams.end())
142     {
143     errorStr = "Parameter \'UserParams\' not found.";
144     printfd(__FILE__, "Parameter 'UserParams' not found\n");
145     return -1;
146     }
147 userParams = pvi->value;
148 ///////////////////////////
149 pv.param = "Password";
150 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
151 if (pvi == s.moduleParams.end())
152     {
153     errorStr = "Parameter \'Password\' not found.";
154     printfd(__FILE__, "Parameter 'Password' not found\n");
155     return -1;
156     }
157 password = pvi->value[0];
158 ///////////////////////////
159 pv.param = "SubnetFile";
160 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
161 if (pvi == s.moduleParams.end())
162     {
163     errorStr = "Parameter \'SubnetFile\' not found.";
164     printfd(__FILE__, "Parameter 'SubnetFile' not found\n");
165     return -1;
166     }
167 subnetFile = pvi->value[0];
168
169 NRMapParser nrMapParser;
170
171 if (!nrMapParser.ReadFile(subnetFile))
172     {
173     netRouters = nrMapParser.GetMap();
174     }
175 else
176     {
177     GetStgLogger()("mod_rscript: error opening subnets file '%s'", subnetFile.c_str());
178     }
179
180 return 0;
181 }
182 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
185 REMOTE_SCRIPT::REMOTE_SCRIPT()
186     : ctx(),
187       ipNotifierList(),
188       authorizedUsers(),
189       errorStr(),
190       rsSettings(),
191       settings(),
192       sendPeriod(15),
193       halfPeriod(8),
194       nonstop(false),
195       isRunning(false),
196       users(NULL),
197       netRouters(),
198       thread(),
199       mutex(),
200       sock(0),
201       onAddUserNotifier(*this),
202       onDelUserNotifier(*this),
203       logger(GetPluginLogger(GetStgLogger(), "rscript"))
204 {
205 pthread_mutex_init(&mutex, NULL);
206 }
207 //-----------------------------------------------------------------------------
208 REMOTE_SCRIPT::~REMOTE_SCRIPT()
209 {
210 pthread_mutex_destroy(&mutex);
211 }
212 //-----------------------------------------------------------------------------
213 void * REMOTE_SCRIPT::Run(void * d)
214 {
215 sigset_t signalSet;
216 sigfillset(&signalSet);
217 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
218
219 REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
220
221 rs->isRunning = true;
222
223 while (rs->nonstop)
224     {
225     rs->PeriodicSend();
226     sleep(2);
227     }
228
229 rs->isRunning = false;
230 return NULL;
231 }
232 //-----------------------------------------------------------------------------
233 int REMOTE_SCRIPT::ParseSettings()
234 {
235 int ret = rsSettings.ParseSettings(settings);
236 if (ret)
237     errorStr = rsSettings.GetStrError();
238
239 sendPeriod = rsSettings.GetSendPeriod();
240 halfPeriod = sendPeriod / 2;
241
242 return ret;
243 }
244 //-----------------------------------------------------------------------------
245 int REMOTE_SCRIPT::Start()
246 {
247 netRouters = rsSettings.GetSubnetsMap();
248
249 InitEncrypt(&ctx, rsSettings.GetPassword());
250
251 users->AddNotifierUserAdd(&onAddUserNotifier);
252 users->AddNotifierUserDel(&onDelUserNotifier);
253
254 nonstop = true;
255
256 if (GetUsers())
257     {
258     return -1;
259     }
260
261 if (PrepareNet())
262     {
263     return -1;
264     }
265
266 if (!isRunning)
267     {
268     if (pthread_create(&thread, NULL, Run, this))
269         {
270         errorStr = "Cannot create thread.";
271         logger("Cannot create thread.");
272         printfd(__FILE__, "Cannot create thread\n");
273         return -1;
274         }
275     }
276
277 errorStr = "";
278 return 0;
279 }
280 //-----------------------------------------------------------------------------
281 int REMOTE_SCRIPT::Stop()
282 {
283 if (!IsRunning())
284     return 0;
285
286 nonstop = false;
287
288 std::for_each(
289         authorizedUsers.begin(),
290         authorizedUsers.end(),
291         DisconnectUser(*this)
292         );
293
294 FinalizeNet();
295
296 if (isRunning)
297     {
298     //5 seconds to thread stops itself
299     for (int i = 0; i < 25 && isRunning; i++)
300         {
301         struct timespec ts = {0, 200000000};
302         nanosleep(&ts, NULL);
303         }
304     }
305
306 users->DelNotifierUserDel(&onDelUserNotifier);
307 users->DelNotifierUserAdd(&onAddUserNotifier);
308
309 if (isRunning)
310     {
311     logger("Cannot stop thread.");
312     return -1;
313     }
314
315 return 0;
316 }
317 //-----------------------------------------------------------------------------
318 int REMOTE_SCRIPT::Reload()
319 {
320 NRMapParser nrMapParser;
321
322 if (nrMapParser.ReadFile(rsSettings.GetMapFileName()))
323     {
324     errorStr = nrMapParser.GetErrorStr();
325     logger("Map file reading error: %s", errorStr.c_str());
326     return -1;
327     }
328
329     {
330     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
331
332     printfd(__FILE__, "REMOTE_SCRIPT::Reload()\n");
333
334     netRouters = nrMapParser.GetMap();
335     }
336
337 std::for_each(authorizedUsers.begin(),
338               authorizedUsers.end(),
339               UpdateRouter(*this));
340
341 return 0;
342 }
343 //-----------------------------------------------------------------------------
344 bool REMOTE_SCRIPT::PrepareNet()
345 {
346 sock = socket(AF_INET, SOCK_DGRAM, 0);
347
348 if (sock < 0)
349     {
350     errorStr = "Cannot create socket.";
351     logger("Canot create a socket: %s", strerror(errno));
352     printfd(__FILE__, "Cannot create socket\n");
353     return true;
354     }
355
356 return false;
357 }
358 //-----------------------------------------------------------------------------
359 bool REMOTE_SCRIPT::FinalizeNet()
360 {
361 close(sock);
362 return false;
363 }
364 //-----------------------------------------------------------------------------
365 void REMOTE_SCRIPT::PeriodicSend()
366 {
367 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
368
369 map<uint32_t, RS::USER>::iterator it(authorizedUsers.begin());
370 while (it != authorizedUsers.end())
371     {
372     if (difftime(stgTime, it->second.lastSentTime) - (rand() % halfPeriod) > sendPeriod)
373         {
374         Send(it->first, it->second);
375         }
376     ++it;
377     }
378 }
379 //-----------------------------------------------------------------------------
380 #ifdef NDEBUG
381 bool REMOTE_SCRIPT::PreparePacket(char * buf, size_t, uint32_t ip, RS::USER & rsu, bool forceDisconnect) const
382 #else
383 bool REMOTE_SCRIPT::PreparePacket(char * buf, size_t bufSize, uint32_t ip, RS::USER & rsu, bool forceDisconnect) const
384 #endif
385 {
386 RS::PACKET_HEADER packetHead;
387
388 memset(packetHead.padding, 0, sizeof(packetHead.padding));
389 strcpy((char*)packetHead.magic, RS_ID);
390 packetHead.protoVer[0] = '0';
391 packetHead.protoVer[1] = '2';
392 if (forceDisconnect)
393     {
394     packetHead.packetType = RS_DISCONNECT_PACKET;
395     }
396 else
397     {
398     if (rsu.shortPacketsCount % MAX_SHORT_PCKT == 0)
399         {
400         //SendLong
401         packetHead.packetType = rsu.user->IsInetable() ? RS_CONNECT_PACKET : RS_DISCONNECT_PACKET;
402         }
403     else
404         {
405         //SendShort
406         packetHead.packetType = rsu.user->IsInetable() ? RS_ALIVE_PACKET : RS_DISCONNECT_PACKET;
407         }
408     }
409 rsu.shortPacketsCount++;
410 rsu.lastSentTime = stgTime;
411
412 packetHead.ip = htonl(ip);
413 packetHead.id = htonl(rsu.user->GetID());
414 strncpy((char*)packetHead.login, rsu.user->GetLogin().c_str(), RS_LOGIN_LEN);
415 packetHead.login[RS_LOGIN_LEN - 1] = 0;
416
417 memcpy(buf, &packetHead, sizeof(packetHead));
418
419 if (packetHead.packetType == RS_ALIVE_PACKET)
420     {
421     return false;
422     }
423
424 RS::PACKET_TAIL packetTail;
425
426 memset(packetTail.padding, 0, sizeof(packetTail.padding));
427 strcpy((char*)packetTail.magic, RS_ID);
428 vector<string>::const_iterator it;
429 std::string params;
430 for(it = rsSettings.GetUserParams().begin();
431     it != rsSettings.GetUserParams().end();
432     ++it)
433     {
434     std::string parameter(GetUserParam(rsu.user, *it));
435     if (params.length() + parameter.length() > RS_PARAMS_LEN - 1)
436         break;
437     params += parameter + " ";
438     }
439 strncpy((char *)packetTail.params, params.c_str(), RS_PARAMS_LEN);
440 packetTail.params[RS_PARAMS_LEN - 1] = 0;
441
442 assert(sizeof(packetHead) + sizeof(packetTail) <= bufSize && "Insufficient buffer space");
443
444 Encrypt(&ctx, buf + sizeof(packetHead), (char *)&packetTail, sizeof(packetTail) / 8);
445
446 return false;
447 }
448 //-----------------------------------------------------------------------------
449 bool REMOTE_SCRIPT::Send(uint32_t ip, RS::USER & rsu, bool forceDisconnect) const
450 {
451 char buffer[RS_MAX_PACKET_LEN];
452
453 memset(buffer, 0, sizeof(buffer));
454
455 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
456     {
457     printfd(__FILE__, "REMOTE_SCRIPT::Send() - Invalid packet length!\n");
458     return true;
459     }
460
461 std::for_each(
462         rsu.routers.begin(),
463         rsu.routers.end(),
464         PacketSender(sock, buffer, sizeof(buffer), htons(rsSettings.GetPort()))
465         );
466
467 return false;
468 }
469 //-----------------------------------------------------------------------------
470 bool REMOTE_SCRIPT::SendDirect(uint32_t ip, RS::USER & rsu, uint32_t routerIP, bool forceDisconnect) const
471 {
472 char buffer[RS_MAX_PACKET_LEN];
473
474 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
475     {
476     printfd(__FILE__, "REMOTE_SCRIPT::SendDirect() - Invalid packet length!\n");
477     return true;
478     }
479
480 struct sockaddr_in sendAddr;
481
482 sendAddr.sin_family = AF_INET;
483 sendAddr.sin_port = htons(rsSettings.GetPort());
484 sendAddr.sin_addr.s_addr = routerIP;
485
486 int res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr));
487
488 if (res < 0)
489     logger("sendto error: %s", strerror(errno));
490
491 return (res != sizeof(buffer));
492 }
493 //-----------------------------------------------------------------------------
494 bool REMOTE_SCRIPT::GetUsers()
495 {
496 USER_PTR u;
497
498 int h = users->OpenSearch();
499 assert(h && "USERS::OpenSearch is always correct");
500
501 while (!users->SearchNext(h, &u))
502     {
503     SetUserNotifier(u);
504     }
505
506 users->CloseSearch(h);
507 return false;
508 }
509 //-----------------------------------------------------------------------------
510 void REMOTE_SCRIPT::ChangedIP(USER_PTR u, uint32_t oldIP, uint32_t newIP)
511 {
512 /*
513  * When ip changes process looks like:
514  * old => 0, 0 => new
515  *
516  */
517 if (newIP)
518     {
519     RS::USER rsu(IP2Routers(newIP), u, *this);
520     Send(newIP, rsu);
521
522     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
523     authorizedUsers.insert(std::make_pair(newIP, rsu));
524     }
525 else
526     {
527     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
528     const map<uint32_t, RS::USER>::iterator it(
529             authorizedUsers.find(oldIP)
530             );
531     if (it != authorizedUsers.end())
532         {
533         Send(oldIP, it->second, true);
534         authorizedUsers.erase(it);
535         }
536     }
537 }
538 //-----------------------------------------------------------------------------
539 std::vector<uint32_t> REMOTE_SCRIPT::IP2Routers(uint32_t ip)
540 {
541 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
542 for (size_t i = 0; i < netRouters.size(); ++i)
543     {
544     if ((ip & netRouters[i].subnetMask) == (netRouters[i].subnetIP & netRouters[i].subnetMask))
545         {
546         return netRouters[i].routers;
547         }
548     }
549 return std::vector<uint32_t>();
550 }
551 //-----------------------------------------------------------------------------
552 string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const string & paramName) const
553 {
554 string value = "";
555 if (strcasecmp(paramName.c_str(), "cash") == 0)
556     strprintf(&value, "%f", u->GetProperty().cash.Get());
557 else
558 if (strcasecmp(paramName.c_str(), "freeMb") == 0)
559     strprintf(&value, "%f", u->GetProperty().freeMb.Get());
560 else
561 if (strcasecmp(paramName.c_str(), "passive") == 0)
562     strprintf(&value, "%d", u->GetProperty().passive.Get());
563 else
564 if (strcasecmp(paramName.c_str(), "disabled") == 0)
565     strprintf(&value, "%d", u->GetProperty().disabled.Get());
566 else
567 if (strcasecmp(paramName.c_str(), "alwaysOnline") == 0)
568     strprintf(&value, "%d", u->GetProperty().alwaysOnline.Get());
569 else
570 if (strcasecmp(paramName.c_str(), "tariffName") == 0 ||
571     strcasecmp(paramName.c_str(), "tariff") == 0)
572     value = "\"" + u->GetProperty().tariffName.Get() + "\"";
573 else
574 if (strcasecmp(paramName.c_str(), "nextTariff") == 0)
575     value = "\"" + u->GetProperty().nextTariff.Get() + "\"";
576 else
577 if (strcasecmp(paramName.c_str(), "address") == 0)
578     value = "\"" + u->GetProperty().address.Get() + "\"";
579 else
580 if (strcasecmp(paramName.c_str(), "note") == 0)
581     value = "\"" + u->GetProperty().note.Get() + "\"";
582 else
583 if (strcasecmp(paramName.c_str(), "group") == 0)
584     value = "\"" + u->GetProperty().group.Get() + "\"";
585 else
586 if (strcasecmp(paramName.c_str(), "email") == 0)
587     value = "\"" + u->GetProperty().email.Get() + "\"";
588 else
589 if (strcasecmp(paramName.c_str(), "realName") == 0)
590     value = "\"" + u->GetProperty().realName.Get() + "\"";
591 else
592 if (strcasecmp(paramName.c_str(), "credit") == 0)
593     strprintf(&value, "%f", u->GetProperty().credit.Get());
594 else
595 if (strcasecmp(paramName.c_str(), "userdata0") == 0)
596     value = "\"" + u->GetProperty().userdata0.Get() + "\"";
597 else
598 if (strcasecmp(paramName.c_str(), "userdata1") == 0)
599     value = "\"" + u->GetProperty().userdata1.Get() + "\"";
600 else
601 if (strcasecmp(paramName.c_str(), "userdata2") == 0)
602     value = "\"" + u->GetProperty().userdata2.Get() + "\"";
603 else
604 if (strcasecmp(paramName.c_str(), "userdata3") == 0)
605     value = "\"" + u->GetProperty().userdata3.Get() + "\"";
606 else
607 if (strcasecmp(paramName.c_str(), "userdata4") == 0)
608     value = "\"" + u->GetProperty().userdata4.Get() + "\"";
609 else
610 if (strcasecmp(paramName.c_str(), "userdata5") == 0)
611     value = "\"" + u->GetProperty().userdata5.Get() + "\"";
612 else
613 if (strcasecmp(paramName.c_str(), "userdata6") == 0)
614     value = "\"" + u->GetProperty().userdata6.Get() + "\"";
615 else
616 if (strcasecmp(paramName.c_str(), "userdata7") == 0)
617     value = "\"" + u->GetProperty().userdata7.Get() + "\"";
618 else
619 if (strcasecmp(paramName.c_str(), "userdata8") == 0)
620     value = "\"" + u->GetProperty().userdata8.Get() + "\"";
621 else
622 if (strcasecmp(paramName.c_str(), "userdata9") == 0)
623     value = "\"" + u->GetProperty().userdata9.Get() + "\"";
624 else
625 if (strcasecmp(paramName.c_str(), "enabledDirs") == 0)
626     value = u->GetEnabledDirs();
627 else
628     printfd(__FILE__, "Unknown value name: %s\n", paramName.c_str());
629 return value;
630 }
631 //-----------------------------------------------------------------------------
632 void REMOTE_SCRIPT::SetUserNotifier(USER_PTR u)
633 {
634 ipNotifierList.push_front(RS::IP_NOTIFIER(*this, u));
635
636 u->AddCurrIPAfterNotifier(&(*ipNotifierList.begin()));
637 }
638 //-----------------------------------------------------------------------------
639 void REMOTE_SCRIPT::UnSetUserNotifier(USER_PTR u)
640 {
641 list<RS::IP_NOTIFIER>::iterator  ipAIter;
642 std::list<list<RS::IP_NOTIFIER>::iterator> toErase;
643
644 for (ipAIter = ipNotifierList.begin(); ipAIter != ipNotifierList.end(); ++ipAIter)
645     {
646     if (ipAIter->GetUser() == u)
647         {
648         u->DelCurrIPAfterNotifier(&(*ipAIter));
649         toErase.push_back(ipAIter);
650         }
651     }
652
653 std::list<list<RS::IP_NOTIFIER>::iterator>::iterator eIter;
654
655 for (eIter = toErase.begin(); eIter != toErase.end(); ++eIter)
656     {
657     ipNotifierList.erase(*eIter);
658     }
659 }
660 //-----------------------------------------------------------------------------
661 void RS::IP_NOTIFIER::Notify(const uint32_t & oldValue, const uint32_t & newValue)
662 {
663 rs.ChangedIP(user, oldValue, newValue);
664 }
665 //-----------------------------------------------------------------------------
666 void RS::CONNECTED_NOTIFIER::Notify(const bool & /*oldValue*/, const bool & newValue)
667 {
668 if (!newValue)
669     rs.Send(user.ip, user, true);
670 }
671 //-----------------------------------------------------------------------------
672 void REMOTE_SCRIPT::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const
673 {
674 unsigned char keyL[PASSWD_LEN];  // Пароль для шифровки
675 memset(keyL, 0, PASSWD_LEN);
676 strncpy((char *)keyL, password.c_str(), PASSWD_LEN);
677 Blowfish_Init(ctx, keyL, PASSWD_LEN);
678 }
679 //-----------------------------------------------------------------------------
680 void REMOTE_SCRIPT::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const
681 {
682 if (dst != src)
683     memcpy(dst, src, len8 * 8);
684 for (size_t i = 0; i < len8; ++i)
685     Blowfish_Encrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4));
686 }
687 //-----------------------------------------------------------------------------