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.
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.
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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/04/14 09:01:29 $
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
39 #include "stg/common.h"
41 #include "settings_impl.h"
45 char messageText[256];
49 IA_CLIENT_PROT * clnp;
54 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
59 printf("sgauth <path_to_config>\n");
61 //-----------------------------------------------------------------------------
62 void SetDirName(const std::vector<std::string> & dn, void *)
64 for (int j = 0; j < DIR_NUM; j++)
69 KOIToWin(dn[j], &dir);
71 web->SetDirName(dir, j);
76 web->SetDirName(dn[j], j);
80 //-----------------------------------------------------------------------------
81 void StatUpdate(const LOADSTAT & ls, void *)
86 //-----------------------------------------------------------------------------
87 void StatusChanged(int, void *)
90 //-----------------------------------------------------------------------------
91 void ShowMessage(const std::string & message, int i, int, int, void *)
94 web->AddMessage(message, i);
96 //-----------------------------------------------------------------------------
97 void ShowError(const std::string & message, int, void *)
100 web->AddMessage(message, 0);
102 //-----------------------------------------------------------------------------
105 if (clnp->GetAuthorized())
107 std::cout << "Connect" << std::endl;
111 //-----------------------------------------------------------------------------
114 std::cout << "Disconnect" << std::endl;
117 //-----------------------------------------------------------------------------
120 std::cout << "Terminated" << std::endl;
125 //-----------------------------------------------------------------------------
126 static void SetSignalHandlers()
128 struct sigaction newsa, oldsa;
131 sigemptyset(&sigmask);
132 sigaddset(&sigmask, SIGTERM);
133 newsa.sa_handler = CatchTERM;
134 newsa.sa_mask = sigmask;
136 sigaction(SIGTERM, &newsa, &oldsa);
138 sigemptyset(&sigmask);
139 sigaddset(&sigmask, SIGINT);
140 newsa.sa_handler = CatchTERM;
141 newsa.sa_mask = sigmask;
143 sigaction(SIGINT, &newsa, &oldsa);
145 sigemptyset(&sigmask);
146 sigaddset(&sigmask, SIGUSR1);
147 newsa.sa_handler = CatchUSR1;
148 newsa.sa_mask = sigmask;
150 sigaction(SIGUSR1, &newsa, &oldsa);
152 sigemptyset(&sigmask);
153 sigaddset(&sigmask, SIGUSR2);
154 newsa.sa_handler = CatchUSR2;
155 newsa.sa_mask = sigmask;
157 sigaction(SIGUSR2, &newsa, &oldsa);
161 //-----------------------------------------------------------------------------
162 int main(int argc, char *argv[])
164 SETTINGS_IMPL settings;
168 settings.SetConfFile(argv[1]);
175 if (settings.ReadSettings())
177 printf("ReadSettingsError\n");
178 printf("%s\n", settings.GetStrError().c_str());
183 if (settings.GetDaemon())
201 clnp = new IA_CLIENT_PROT(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalName(), settings.GetLocalPort());
203 if (!settings.GetNoWeb())
206 web->SetRefreshPagePeriod(settings.GetRefreshPeriod());
207 web->SetListenAddr(settings.GetListenWebIP());
211 clnp->SetLogin(settings.GetLogin());
212 clnp->SetPassword(settings.GetPassword());
214 clnp->SetStatusChangedCb(StatusChanged, NULL);
215 clnp->SetInfoCb(ShowMessage, NULL);
216 clnp->SetErrorCb(ShowError, NULL);
217 clnp->SetDirNameCb(SetDirName, NULL);
218 clnp->SetStatChangedCb(StatUpdate, NULL);
219 clnp->SetReconnect(settings.GetReconnect());
226 for (int i = 1; i < argc; i++)
227 memset(argv[i], 0, strlen(argv[i]));
230 strcpy(argv[1], "Connecting...");
234 setproctitle("Connecting...");
240 struct timespec ts = {0, 200000000};
241 nanosleep(&ts, NULL);
245 if (clnp->GetAuthorized())
247 if (settings.GetShowPid())
248 sprintf(state, "On %d", getpid());
250 strcpy(state, "Online");
254 if (settings.GetShowPid())
255 sprintf(state, "Off %d", getpid());
257 strcpy(state, "Offline");
261 for (int i = 1; i < argc; i++)
262 memset(argv[i], 0, strlen(argv[i]));
264 strcpy(argv[1], state);
278 //-----------------------------------------------------------------------------