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;
56 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
61 printf("sgauth <path_to_config>\n");
63 //-----------------------------------------------------------------------------
64 void SetDirName(const vector<string> & dn, void *)
66 for (int j = 0; j < DIR_NUM; j++)
71 KOIToWin(dn[j], &dir);
73 web->SetDirName(dir, j);
78 web->SetDirName(dn[j], j);
82 //-----------------------------------------------------------------------------
83 void StatUpdate(const LOADSTAT & ls, void *)
88 //-----------------------------------------------------------------------------
89 void StatusChanged(int, void *)
92 //-----------------------------------------------------------------------------
93 void ShowMessage(const string & message, int i, int, int, void *)
96 web->AddMessage(message, i);
98 //-----------------------------------------------------------------------------
99 void ShowError(const string & message, int, void *)
102 web->AddMessage(message, 0);
104 //-----------------------------------------------------------------------------
107 if (clnp->GetAuthorized())
109 cout << "Connect" << endl;
113 //-----------------------------------------------------------------------------
116 cout << "Disconnect" << endl;
119 //-----------------------------------------------------------------------------
122 cout << "Terminated" << endl;
127 //-----------------------------------------------------------------------------
128 static void SetSignalHandlers()
130 struct sigaction newsa, oldsa;
133 sigemptyset(&sigmask);
134 sigaddset(&sigmask, SIGTERM);
135 newsa.sa_handler = CatchTERM;
136 newsa.sa_mask = sigmask;
138 sigaction(SIGTERM, &newsa, &oldsa);
140 sigemptyset(&sigmask);
141 sigaddset(&sigmask, SIGINT);
142 newsa.sa_handler = CatchTERM;
143 newsa.sa_mask = sigmask;
145 sigaction(SIGINT, &newsa, &oldsa);
147 sigemptyset(&sigmask);
148 sigaddset(&sigmask, SIGUSR1);
149 newsa.sa_handler = CatchUSR1;
150 newsa.sa_mask = sigmask;
152 sigaction(SIGUSR1, &newsa, &oldsa);
154 sigemptyset(&sigmask);
155 sigaddset(&sigmask, SIGUSR2);
156 newsa.sa_handler = CatchUSR2;
157 newsa.sa_mask = sigmask;
159 sigaction(SIGUSR2, &newsa, &oldsa);
163 //-----------------------------------------------------------------------------
164 int main(int argc, char *argv[])
166 SETTINGS_IMPL settings;
170 settings.SetConfFile(argv[1]);
177 if (settings.ReadSettings())
179 printf("ReadSettingsError\n");
180 printf("%s\n", settings.GetStrError().c_str());
185 if (settings.GetDaemon())
203 clnp = new IA_CLIENT_PROT(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalName(), settings.GetLocalPort());
205 if (!settings.GetNoWeb())
208 web->SetRefreshPagePeriod(settings.GetRefreshPeriod());
209 web->SetListenAddr(settings.GetListenWebIP());
213 clnp->SetLogin(settings.GetLogin());
214 clnp->SetPassword(settings.GetPassword());
216 clnp->SetStatusChangedCb(StatusChanged, NULL);
217 clnp->SetInfoCb(ShowMessage, NULL);
218 clnp->SetErrorCb(ShowError, NULL);
219 clnp->SetDirNameCb(SetDirName, NULL);
220 clnp->SetStatChangedCb(StatUpdate, NULL);
221 clnp->SetReconnect(settings.GetReconnect());
228 for (int i = 1; i < argc; i++)
229 memset(argv[i], 0, strlen(argv[i]));
232 strcpy(argv[1], "Connecting...");
236 setproctitle("Connecting...");
242 struct timespec ts = {0, 200000000};
243 nanosleep(&ts, NULL);
247 if (clnp->GetAuthorized())
249 if (settings.GetShowPid())
250 sprintf(state, "On %d", getpid());
252 strcpy(state, "Online");
256 if (settings.GetShowPid())
257 sprintf(state, "Off %d", getpid());
259 strcpy(state, "Offline");
263 for (int i = 1; i < argc; i++)
264 memset(argv[i], 0, strlen(argv[i]));
266 strcpy(argv[1], state);
280 //-----------------------------------------------------------------------------