00001
00002
00003
00004
00005 #include <string.h>
00006 #include <stdio.h>
00007 #include "mysql_interface.h"
00008 #include "strings_utils.h"
00009 #include "conversion.h"
00010 #include "modem.h"
00011 #include "logging.h"
00012
00013
00014 #ifndef TESTS_UNITAIRES
00015
00016 static int load_abonnes (struct smysql *mysql_info,
00017 struct mysql_tables *mysql_tables,
00018 struct global_config *config);
00019 static int load_vlan (struct smysql *mysql_info,
00020 struct smysql *mysql_info_pool,
00021 struct mysql_tables *mysql_tables,
00022 struct global_config *config);
00023 static int load_ip_lease (struct smysql *mysql_info,
00024 struct mysql_tables *mysql_tables,
00025 struct global_config *config);
00026 static int load_pool (struct smysql *mysql_info,
00027 struct mysql_tables *mysql_tables,
00028 struct global_config *config);
00029 static int try_reserve_ip_from_pool (struct smysql *mysql_info,
00030 struct mysql_tables *mysql_tables,
00031 struct global_config *config,
00032 unsigned long int timeout);
00033 static int try_find_and_reserve_ip_from_pool (struct smysql *mysql_info,
00034 struct mysql_tables *mysql_tables,
00035 struct global_config *config,
00036 unsigned long int timeout);
00037
00038 #ifdef NOT_USED
00039
00040 static int select_login_modem_from_logistic (struct smysql *mysql_info,
00041 char *login_modem,
00042 struct global_config *config);
00043 static int delete_mac_address_from_logistic (struct smysql *mysql_info,
00044 char *mac_address,
00045 struct global_config *config);
00046
00047 #endif
00048
00049 #endif
00050
00051
00052
00053
00054
00055 static unsigned int mydns_id;
00056
00057
00058
00059
00060
00061
00062 void clear_tables (struct mysql_tables *mysql_tables)
00063 { memset ((void*)(mysql_tables), 0, sizeof(struct mysql_tables)); }
00064
00065
00066
00067
00068
00069 static int my_fake_syslog (const char *file, const char * fmt,...) { return 0; }
00070
00071
00072
00073
00074 #define SQL_REQUEST_SIZE 2048
00075
00076
00077
00078
00079
00080
00081
00082 #define NASPORT_SIZE 512
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 int load_abonnes (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
00112 {
00113 static char sql[SQL_REQUEST_SIZE], integer1[32], integer2[32], integer3[32];
00114 int (*pk_syslog)(const char *file, const char * fmt,...);
00115 int n, e;
00116 MYSQL_ROW row;
00117 unsigned long int *length;
00118
00119
00120
00121 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
00122 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
00123
00124
00125
00126
00127
00128 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00129
00130 snprintf (sql,
00131 SQL_REQUEST_SIZE,
00132 "SELECT abonnes_id, node_id, shelf, numero_port, numero_slot, login_radius, first_connection, profile, nack_flag FROM abonnes WHERE node_id='%s' AND shelf='%u' AND numero_port='%u' AND numero_slot='%u'",
00133 mysql_tables->abonnes.node_id,
00134 mysql_tables->abonnes.shelf,
00135 mysql_tables->abonnes.numero_port,
00136 mysql_tables->abonnes.numero_slot);
00137
00138 if (mysql_info->debug > 0)
00139 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
00140
00141
00142
00143
00144
00145 n = sql_select (mysql_info, sql);
00146
00147 switch (n)
00148 {
00149 case MYSQL_REQUEST_SKIPED:
00150 pk_syslog (mysql_info->log_file,
00151 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00152 return MYSQL_INTERFACE_REQUEST_SKIPED;
00153 case MYSQL_CONNECTION_LOST:
00154 pk_syslog (mysql_info->log_file,
00155 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00156 return MYSQL_INTERFACE_CONNECTION_LOST;
00157 case MYSQL_RECONNECTION_FAILED:
00158 pk_syslog (mysql_info->log_file,
00159 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00160 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00161 case MYSQL_SQL_PROBLEM:
00162 pk_syslog (mysql_info->log_file,
00163 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00164 return MYSQL_INTERFACE_SQL_PROBLEM;
00165 case MYSQL_UNEXPECTED_ERROR:
00166 pk_syslog (mysql_info->log_file,
00167 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00168 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00169 case 0:
00170 pk_syslog (mysql_info->log_file,
00171 "[WARNING] [%s,%d] Can not find user (node_id=%s,shelf=%u,port=%u,slot=%u)",
00172 __FILE__, __LINE__,
00173 mysql_tables->abonnes.node_id,
00174 mysql_tables->abonnes.shelf,
00175 mysql_tables->abonnes.numero_port,
00176 mysql_tables->abonnes.numero_slot);
00177
00178 mysql_free_result(mysql_info->result);
00179 return MYSQL_INTERFACE_NOT_FOUND;
00180 }
00181
00182 if (n != 1)
00183 {
00184 pk_syslog (mysql_info->log_file,
00185 "[ERROR] [%s,%d] Found more than one user with (node_id=%s,shelf=%u,port=%u,slot=%u)",
00186 __FILE__, __LINE__,
00187 mysql_tables->abonnes.node_id,
00188 mysql_tables->abonnes.shelf,
00189 mysql_tables->abonnes.numero_port,
00190 mysql_tables->abonnes.numero_slot);
00191
00192 mysql_free_result(mysql_info->result);
00193 return MYSQL_INTERFACE_MORE_THAN_ONE;
00194 }
00195
00196
00197
00198
00199
00200 row = mysql_fetch_row (mysql_info->result);
00201 length = mysql_fetch_lengths (mysql_info->result);
00202
00203 if (mysql_info->debug > 1)
00204 {
00205 pk_syslog (mysql_info->log_file,
00206 "[DEBUG] [%s,%d] abonnes_id[%d], login_radius[%d], first_connection[%d], profile[%d], nack_flag[%d]",
00207 __FILE__, __LINE__,
00208 length[0],
00209 length[5],
00210 length[6],
00211 length[7],
00212 length[8]);
00213 }
00214
00215 memset ((void*)integer1, 0, 32);
00216 memset ((void*)integer2, 0, 32);
00217 memset ((void*)integer3, 0, 32);
00218 memset ((void*)mysql_tables->abonnes.login_radius, 0, LOGIN_RADIUS_SIZE);
00219 memset ((void*)mysql_tables->abonnes.profile, 0, OPTIONNAL_PROFILE_SIZE);
00220
00221 memcpy ((void*)integer1, (void*)row[0],
00222 (length[0] < 32) ? length[0] : 31);
00223
00224 memcpy ((void*)mysql_tables->abonnes.login_radius, (void*)row[5],
00225 (length[5] < LOGIN_RADIUS_SIZE) ? length[5] : LOGIN_RADIUS_SIZE-1);
00226
00227 memcpy ((void*)integer2, (void*)row[6],
00228 (length[6] < 32) ? length[6] : 31);
00229
00230 memcpy ((void*)mysql_tables->abonnes.profile, (void*)row[7],
00231 (length[7] < OPTIONNAL_PROFILE_SIZE) ? length[7] : OPTIONNAL_PROFILE_SIZE-1);
00232
00233 memcpy ((void*)integer3, (void*)row[8],
00234 (length[8] < 32) ? length[8] : 32);
00235
00236
00237 mysql_tables->abonnes.abonnes_id = string2unsigned_int (integer1, &e);
00238 mysql_tables->abonnes.first_connection = string2unsigned_int (integer2, &e);
00239 mysql_tables->abonnes.nack_flag = string2unsigned_int (integer3, &e);
00240
00241 if (mysql_info->debug > 0)
00242 {
00243 pk_syslog (mysql_info->log_file,
00244 "[SQL RESULT] [%s,%d] [%s] => abonnes_id='%lu', login_radius='%s' and first_connection='%u'",
00245 __FILE__, __LINE__, sql,
00246 mysql_tables->abonnes.abonnes_id,
00247 mysql_tables->abonnes.login_radius,
00248 mysql_tables->abonnes.first_connection);
00249 }
00250
00251 mysql_free_result(mysql_info->result);
00252
00253 return 0;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 int load_vlan (struct smysql *mysql_info, struct smysql *mysql_info_pool, struct mysql_tables *mysql_tables, struct global_config *config)
00298 {
00299 static char sql[SQL_REQUEST_SIZE], integer1[32], integer2[32];
00300 int (*pk_syslog)(const char *file, const char * fmt,...);
00301 int n, e;
00302 MYSQL_ROW row;
00303 unsigned long int *length, now, delay;
00304
00305
00306
00307 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
00308 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
00309
00310
00311
00312
00313
00314
00315 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00316
00317 snprintf (sql,
00318 SQL_REQUEST_SIZE,
00319 "SELECT vlan_id, profile_optionnel, vlan_tag, vlan_gateway, radius_identifiant, libelle, comment, offer_timeout FROM vlan WHERE vlan_gateway='%s'",
00320 mysql_tables->vlan.vlan_gateway);
00321
00322 if (mysql_info->debug > 0)
00323 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
00324
00325 n = sql_select (mysql_info, sql);
00326
00327 switch (n)
00328 {
00329 case MYSQL_REQUEST_SKIPED:
00330 pk_syslog (mysql_info->log_file,
00331 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00332 return MYSQL_INTERFACE_REQUEST_SKIPED;
00333 case MYSQL_CONNECTION_LOST:
00334 pk_syslog (mysql_info->log_file,
00335 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00336 return MYSQL_INTERFACE_CONNECTION_LOST;
00337 case MYSQL_RECONNECTION_FAILED:
00338 pk_syslog (mysql_info->log_file,
00339 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00340 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00341 case MYSQL_SQL_PROBLEM:
00342 pk_syslog (mysql_info->log_file,
00343 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00344 return MYSQL_INTERFACE_SQL_PROBLEM;
00345 case MYSQL_UNEXPECTED_ERROR:
00346 pk_syslog (mysql_info->log_file,
00347 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00348 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00349 case 0:
00350 pk_syslog (mysql_info->log_file,
00351 "[INFO] [%s,%d] Can not find vlan ID (%lu,%s) in database (may be an UNICAST?)",
00352 __FILE__, __LINE__,
00353 mysql_tables->vlan.vlan_tag,
00354 mysql_tables->vlan.vlan_gateway);
00355 mysql_free_result(mysql_info->result);
00356 }
00357
00358 if (n > 1)
00359 {
00360 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one vlan ID (%u,%s)",
00361 __FILE__, __LINE__,
00362 mysql_tables->vlan.vlan_tag,
00363 mysql_tables->vlan.vlan_gateway);
00364
00365 mysql_free_result(mysql_info->result);
00366 return MYSQL_INTERFACE_MORE_THAN_ONE;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 if (n == 0)
00379 {
00380 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00381
00382 snprintf (sql,
00383 SQL_REQUEST_SIZE,
00384 "SELECT vlan.vlan_id, vlan.profile_optionnel, vlan.vlan_tag, vlan.vlan_gateway, vlan.radius_identifiant, vlan.libelle, vlan.comment, vlan.offer_timeout FROM vlan, abonne_ip WHERE vlan.vlan_id=abonne_ip.vlan_id AND abonne_ip.ip='%s'",
00385 mysql_tables->vlan.vlan_gateway);
00386
00387 if (mysql_info->debug > 0)
00388 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] %s", __FILE__, __LINE__, sql); }
00389
00390 n = sql_select (mysql_info, sql);
00391
00392 switch (n)
00393 {
00394 case MYSQL_REQUEST_SKIPED:
00395 pk_syslog (mysql_info->log_file,
00396 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00397 return MYSQL_INTERFACE_REQUEST_SKIPED;
00398 case MYSQL_CONNECTION_LOST:
00399 pk_syslog (mysql_info->log_file,
00400 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00401 return MYSQL_INTERFACE_CONNECTION_LOST;
00402 case MYSQL_RECONNECTION_FAILED:
00403 pk_syslog (mysql_info->log_file,
00404 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00405 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00406 case MYSQL_SQL_PROBLEM:
00407 pk_syslog (mysql_info->log_file,
00408 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00409 return MYSQL_INTERFACE_SQL_PROBLEM;
00410 case MYSQL_UNEXPECTED_ERROR:
00411 pk_syslog (mysql_info->log_file,
00412 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00413 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00414 case 0:
00415 pk_syslog (mysql_info->log_file,
00416 "[INFO] [%s,%d] Can not find STATIC IP (%s) in database (may be an DYNAMIC?)",
00417 __FILE__, __LINE__,
00418 mysql_tables->vlan.vlan_gateway);
00419 mysql_free_result(mysql_info->result);
00420 }
00421
00422 if (n > 1)
00423 {
00424 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one STATIC IP (%s)",
00425 __FILE__, __LINE__,
00426 mysql_tables->vlan.vlan_gateway);
00427 mysql_free_result(mysql_info->result);
00428 return MYSQL_INTERFACE_MORE_THAN_ONE;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437 if (n == 0)
00438 {
00439
00440
00441
00442
00443 now = get_unix_timestamp (mysql_info_pool, &e);
00444
00445 switch (e)
00446 {
00447 case MYSQL_REQUEST_SKIPED:
00448 pk_syslog (mysql_info_pool->log_file,
00449 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_REQUEST_SKIPED)",
00450 __FILE__, __LINE__);
00451 return MYSQL_INTERFACE_NO_TIMESTAMP;
00452 case MYSQL_CONNECTION_LOST:
00453 pk_syslog (mysql_info_pool->log_file,
00454 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_CONNECTION_LOST)",
00455 __FILE__, __LINE__);
00456 return MYSQL_INTERFACE_NO_TIMESTAMP;
00457 case MYSQL_RECONNECTION_FAILED:
00458 pk_syslog (mysql_info_pool->log_file,
00459 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_RECONNECTION_FAILED)",
00460 __FILE__, __LINE__);
00461 return MYSQL_INTERFACE_NO_TIMESTAMP;
00462 case MYSQL_SQL_PROBLEM:
00463 pk_syslog (mysql_info_pool->log_file,
00464 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_SQL_PROBLEM)",
00465 __FILE__, __LINE__);
00466 return MYSQL_INTERFACE_NO_TIMESTAMP;
00467 case MYSQL_UNEXPECTED_ERROR:
00468 pk_syslog (mysql_info_pool->log_file,
00469 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_UNEXPECTED_ERROR)",
00470 __FILE__, __LINE__);
00471 return MYSQL_INTERFACE_NO_TIMESTAMP;
00472 case MYSQL_NO_TIMESTAMP:
00473 pk_syslog (mysql_info_pool->log_file,
00474 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_NO_TIMESTAMP)",
00475 __FILE__, __LINE__);
00476 return MYSQL_INTERFACE_NO_TIMESTAMP;
00477 case 0:
00478 if (mysql_info_pool->debug > 1)
00479 {
00480 pk_syslog (mysql_info_pool->log_file,
00481 "[SQL RESULT] [%s,%d] Timestamp is %lu", __FILE__, __LINE__, now);
00482 }; break;
00483 }
00484
00485 delay = config->sql_expiration_security_delay;
00486
00487 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00488
00489 snprintf (sql,
00490 SQL_REQUEST_SIZE,
00491 "SELECT ip_lease.vlan_id FROM ip_lease, pool WHERE pool.ip='%s' AND ip_lease.ip_lease_id=pool.ip_lease_id AND expiration>%lu LIMIT 1",
00492 mysql_tables->vlan.vlan_gateway,
00493 now+delay);
00494
00495 if (mysql_info->debug > 0)
00496 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] %s", __FILE__, __LINE__, sql); }
00497
00498 n = sql_select (mysql_info_pool, sql);
00499
00500 switch (n)
00501 {
00502 case MYSQL_REQUEST_SKIPED:
00503 pk_syslog (mysql_info_pool->log_file,
00504 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00505 return MYSQL_INTERFACE_REQUEST_SKIPED;
00506 case MYSQL_CONNECTION_LOST:
00507 pk_syslog (mysql_info_pool->log_file,
00508 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00509 return MYSQL_INTERFACE_CONNECTION_LOST;
00510 case MYSQL_RECONNECTION_FAILED:
00511 pk_syslog (mysql_info_pool->log_file,
00512 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00513 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00514 case MYSQL_SQL_PROBLEM:
00515 pk_syslog (mysql_info_pool->log_file,
00516 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00517 return MYSQL_INTERFACE_SQL_PROBLEM;
00518 case MYSQL_UNEXPECTED_ERROR:
00519 pk_syslog (mysql_info_pool->log_file,
00520 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00521 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00522 case 0:
00523 pk_syslog (mysql_info_pool->log_file,
00524 "[INFO] [%s,%d] Can not find DYNAMIC IP (%s) in database",
00525 __FILE__, __LINE__,
00526 mysql_tables->vlan.vlan_gateway);
00527 mysql_free_result(mysql_info_pool->result);
00528 return MYSQL_INTERFACE_NOT_FOUND;
00529 }
00530
00531 if (n != 1)
00532 {
00533 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one DYNAMIC IP (%s)",
00534 __FILE__, __LINE__,
00535 mysql_tables->vlan.vlan_gateway);
00536 mysql_free_result(mysql_info_pool->result);
00537 return MYSQL_INTERFACE_MORE_THAN_ONE;
00538 }
00539
00540
00541
00542
00543
00544 row = mysql_fetch_row (mysql_info_pool->result);
00545 length = mysql_fetch_lengths (mysql_info_pool->result);
00546
00547 if (mysql_info->debug > 1)
00548 {
00549 pk_syslog (mysql_info_pool->log_file,
00550 "[DEBUG] [%s,%d] vlan_id[%d]",
00551 __FILE__, __LINE__,
00552 length[0]);
00553 }
00554
00555 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00556
00557 snprintf (sql,
00558 SQL_REQUEST_SIZE,
00559 "SELECT vlan_id, profile_optionnel, vlan_tag, vlan_gateway, radius_identifiant, libelle, comment, offer_timeout FROM vlan WHERE vlan_id='%s'",
00560 (char*)row[0]);
00561
00562 mysql_free_result(mysql_info_pool->result);
00563
00564 if (mysql_info->debug > 0)
00565 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
00566
00567 n = sql_select (mysql_info, sql);
00568
00569 switch (n)
00570 {
00571 case MYSQL_REQUEST_SKIPED:
00572 pk_syslog (mysql_info->log_file,
00573 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00574 return MYSQL_INTERFACE_REQUEST_SKIPED;
00575 case MYSQL_CONNECTION_LOST:
00576 pk_syslog (mysql_info->log_file,
00577 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00578 return MYSQL_INTERFACE_CONNECTION_LOST;
00579 case MYSQL_RECONNECTION_FAILED:
00580 pk_syslog (mysql_info->log_file,
00581 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00582 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00583 case MYSQL_SQL_PROBLEM:
00584 pk_syslog (mysql_info->log_file,
00585 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00586 return MYSQL_INTERFACE_SQL_PROBLEM;
00587 case MYSQL_UNEXPECTED_ERROR:
00588 pk_syslog (mysql_info->log_file,
00589 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00590 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00591 case 0:
00592 pk_syslog (mysql_info->log_file,
00593 "[INFO] [%s,%d] Can not find vlan ID in database", __FILE__, __LINE__);
00594 mysql_free_result(mysql_info->result);
00595 }
00596
00597 if (n > 1)
00598 {
00599 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one vlan ID",
00600 __FILE__, __LINE__);
00601
00602 mysql_free_result(mysql_info->result);
00603 return MYSQL_INTERFACE_MORE_THAN_ONE;
00604 }
00605 }
00606 }
00607
00608
00609
00610
00611
00612
00613 row = mysql_fetch_row (mysql_info->result);
00614 length = mysql_fetch_lengths (mysql_info->result);
00615
00616 if (mysql_info->debug > 1)
00617 {
00618 pk_syslog (mysql_info->log_file,
00619 "[DEBUG] [%s,%d] vlan_id[%d], profile_optionnel[%d], radius_identifiant[%d], libelle[%d], commentaire[%d], offer_timeout[%d]",
00620 __FILE__, __LINE__,
00621 length[0],
00622 length[1],
00623 length[4],
00624 length[5],
00625 length[6],
00626 length[7]);
00627 }
00628
00629 memset ((void*)integer1, 0, 32);
00630 memset ((void*)integer2, 0, 32);
00631 memset ((void*)mysql_tables->vlan.profile_optionnel, 0, OPTIONNAL_PROFILE_SIZE);
00632 memset ((void*)mysql_tables->vlan.radius_identifiant, 0, ACCT_IDENTIFIER_SIZE);
00633 memset ((void*)mysql_tables->vlan.libelle, 0, LABEL_SIZE);
00634 memset ((void*)mysql_tables->vlan.comment, 0, COMMENT_SIZE);
00635
00636 memcpy ((void*)integer1, (void*)row[0],
00637 (length[0] < 32) ? length[0] : 31);
00638
00639 memcpy ((void*)mysql_tables->vlan.profile_optionnel, (void*)row[1], (length[1] < OPTIONNAL_PROFILE_SIZE) ?
00640 length[1] : OPTIONNAL_PROFILE_SIZE-1);
00641
00642 memcpy ((void*)mysql_tables->vlan.radius_identifiant, (void*)row[4], (length[4] < ACCT_IDENTIFIER_SIZE) ?
00643 length[4] : ACCT_IDENTIFIER_SIZE-1);
00644
00645 memcpy ((void*)mysql_tables->vlan.libelle, (void*)row[5], (length[5] < LABEL_SIZE) ?
00646 length[5] : LABEL_SIZE-1);
00647
00648 memcpy ((void*)mysql_tables->vlan.comment, (void*)row[6], (length[6] < COMMENT_SIZE) ?
00649 length[6] : COMMENT_SIZE-1);
00650
00651 memcpy ((void*)integer2, (void*)row[7],
00652 (length[7] < 32) ? length[7] : 31);
00653
00654 mysql_tables->vlan.vlan_id = string2unsigned_int (integer1, &e);
00655 mysql_tables->vlan.offer_timeout = string2unsigned_int (integer2, &e);
00656
00657 if (mysql_info->debug > 0)
00658 {
00659 pk_syslog (mysql_info->log_file,
00660 "[SQL RESULT] [%s,%d] [%s] => vlan_id='%lu', profile_optionnel='%s', radius_identifiant='%s', libelle='%s', comment='%s', offer_timeout='%lu'",
00661 __FILE__, __LINE__, sql,
00662 mysql_tables->vlan.vlan_id,
00663 mysql_tables->vlan.profile_optionnel,
00664 mysql_tables->vlan.radius_identifiant,
00665 mysql_tables->vlan.libelle,
00666 mysql_tables->vlan.comment,
00667 mysql_tables->vlan.offer_timeout);
00668 }
00669
00670 mysql_free_result(mysql_info->result);
00671
00672 return 0;
00673 }
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 int load_abonne_ip (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
00700 {
00701 static char sql[SQL_REQUEST_SIZE], integer1[32];
00702 int (*pk_syslog)(const char *file, const char * fmt,...);
00703 int n, e;
00704 MYSQL_ROW row;
00705 unsigned long int *length;
00706
00707
00708
00709 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
00710 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
00711
00712
00713
00714
00715
00716 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00717
00718 snprintf (sql,
00719 SQL_REQUEST_SIZE,
00720 "SELECT abonne_ip_id, abonnes_id, vlan_id, ip, gateway, subnet FROM abonne_ip WHERE abonnes_id='%lu' AND vlan_id='%lu'",
00721 mysql_tables->abonne_ip.abonnes_id,
00722 mysql_tables->abonne_ip.vlan_id);
00723
00724 if (mysql_info->debug > 0)
00725 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
00726
00727
00728
00729
00730
00731 n = sql_select (mysql_info, sql);
00732
00733 switch (n)
00734 {
00735 case MYSQL_REQUEST_SKIPED:
00736 pk_syslog (mysql_info->log_file,
00737 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00738 return MYSQL_INTERFACE_REQUEST_SKIPED;
00739 case MYSQL_CONNECTION_LOST:
00740 pk_syslog (mysql_info->log_file,
00741 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00742 return MYSQL_INTERFACE_CONNECTION_LOST;
00743 case MYSQL_RECONNECTION_FAILED:
00744 pk_syslog (mysql_info->log_file,
00745 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00746 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00747 case MYSQL_SQL_PROBLEM:
00748 pk_syslog (mysql_info->log_file,
00749 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00750 return MYSQL_INTERFACE_SQL_PROBLEM;
00751 case MYSQL_UNEXPECTED_ERROR:
00752 pk_syslog (mysql_info->log_file,
00753 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00754 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00755 case 0:
00756 pk_syslog (mysql_info->log_file,
00757 "[WARNING] [%s,%d] Can not find static ip (abonnes_id=%lu, vlan_id=%lu)",
00758 __FILE__, __LINE__,
00759 mysql_tables->abonne_ip.abonnes_id,
00760 mysql_tables->abonne_ip.vlan_id);
00761
00762 mysql_free_result(mysql_info->result);
00763 return MYSQL_INTERFACE_NOT_FOUND;
00764 }
00765
00766 if (n != 1)
00767 {
00768 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one user with (%lu,%lu)",
00769 __FILE__, __LINE__,
00770 mysql_tables->abonne_ip.abonnes_id,
00771 mysql_tables->abonne_ip.vlan_id);
00772
00773 mysql_free_result(mysql_info->result);
00774 return MYSQL_INTERFACE_MORE_THAN_ONE;
00775 }
00776
00777
00778
00779
00780
00781 row = mysql_fetch_row (mysql_info->result);
00782 length = mysql_fetch_lengths (mysql_info->result);
00783
00784 if (mysql_info->debug > 1)
00785 {
00786 pk_syslog (mysql_info->log_file,
00787 "[DEBUG] [%s,%d] abonne_ip_id[%d], ip[%d], gateway[%d], subnet[%d]",
00788 __FILE__, __LINE__,
00789 length[0],
00790 length[3],
00791 length[4],
00792 length[5]);
00793
00794 }
00795
00796 memset ((void*)integer1, 0, 32);
00797 memset ((void*)mysql_tables->abonne_ip.ip, 0, IP_ADDRESS_STR_SIZE);
00798 memset ((void*)mysql_tables->abonne_ip.gateway, 0, IP_ADDRESS_STR_SIZE);
00799 memset ((void*)mysql_tables->abonne_ip.subnet, 0, IP_ADDRESS_STR_SIZE);
00800
00801 memcpy ((void*)integer1, (void*)row[0],
00802 (length[0] < 32) ? length[0] : 31);
00803
00804 memcpy ((void*)mysql_tables->abonne_ip.ip, (void*)row[3],
00805 (length[3] < IP_ADDRESS_STR_SIZE) ? length[3] : IP_ADDRESS_STR_SIZE-1);
00806
00807 memcpy ((void*)mysql_tables->abonne_ip.gateway, (void*)row[4],
00808 (length[4] < IP_ADDRESS_STR_SIZE) ? length[4] : IP_ADDRESS_STR_SIZE-1);
00809
00810 memcpy ((void*)mysql_tables->abonne_ip.subnet, (void*)row[5],
00811 (length[5] < IP_ADDRESS_STR_SIZE) ? length[5] : IP_ADDRESS_STR_SIZE-1);
00812
00813 mysql_tables->abonne_ip.abonne_ip_id = string2unsigned_int (integer1, &e);
00814
00815 if (mysql_info->debug > 0)
00816 {
00817 pk_syslog (mysql_info->log_file,
00818 "[SQL RESULT] [%s,%d] [%s] => abonne_ip_id='%lu', ip='%s', gateway='%s' and subnet='%s'",
00819 __FILE__, __LINE__, sql,
00820 mysql_tables->abonne_ip.abonne_ip_id,
00821 mysql_tables->abonne_ip.ip,
00822 mysql_tables->abonne_ip.gateway,
00823 mysql_tables->abonne_ip.subnet);
00824
00825 }
00826
00827 mysql_free_result(mysql_info->result);
00828
00829 return 0;
00830 }
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856 int load_options (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
00857 {
00858 static char sql[SQL_REQUEST_SIZE], integer1[32], integer2[32];
00859 int (*pk_syslog)(const char *file, const char * fmt,...);
00860 int n, e, i;
00861 MYSQL_ROW row;
00862 unsigned long int *length;
00863
00864
00865 mysql_tables->option_number = 0;
00866
00867 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
00868 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
00869
00870
00871
00872
00873
00874 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
00875
00876 snprintf (sql,
00877 SQL_REQUEST_SIZE,
00878 "SELECT options_id, profile_optionnel, option_code, option_type, option_value, comment FROM options WHERE profile_optionnel='%s'",
00879 ((mysql_tables->options)[0]).profile_optionnel);
00880
00881 if (mysql_info->debug > 0)
00882 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
00883
00884
00885
00886
00887
00888 n = sql_select (mysql_info, sql);
00889
00890 switch (n)
00891 {
00892 case MYSQL_REQUEST_SKIPED:
00893 pk_syslog (mysql_info->log_file,
00894 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00895 return MYSQL_INTERFACE_REQUEST_SKIPED;
00896 case MYSQL_CONNECTION_LOST:
00897 pk_syslog (mysql_info->log_file,
00898 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00899 return MYSQL_INTERFACE_CONNECTION_LOST;
00900 case MYSQL_RECONNECTION_FAILED:
00901 pk_syslog (mysql_info->log_file,
00902 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00903 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00904 case MYSQL_SQL_PROBLEM:
00905 pk_syslog (mysql_info->log_file,
00906 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00907 return MYSQL_INTERFACE_SQL_PROBLEM;
00908 case MYSQL_UNEXPECTED_ERROR:
00909 pk_syslog (mysql_info->log_file,
00910 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00911 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00912 case 0:
00913 pk_syslog (mysql_info->log_file,
00914 "[ERROR] [%s,%d] Can not find option (%s) in database",
00915 __FILE__, __LINE__,
00916 ((mysql_tables->options)[0]).profile_optionnel);
00917
00918 mysql_free_result(mysql_info->result);
00919 return MYSQL_INTERFACE_NOT_FOUND;
00920 }
00921
00922 if (n > MAX_PROFILE_OPTIONS)
00923 {
00924 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Too many items (%s) found in database",
00925 __FILE__, __LINE__,
00926 ((mysql_tables->options)[0]).profile_optionnel);
00927
00928 mysql_free_result(mysql_info->result);
00929 return MYSQL_INTERFACE_TOO_MANY_ITEMS;
00930 }
00931
00932 if (mysql_info->debug > 1)
00933 {
00934 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Got %d options",
00935 __FILE__, __LINE__,
00936 n);
00937 }
00938
00939
00940
00941
00942
00943 mysql_tables->option_number = n;
00944
00945 for (i=0; i<n; i++)
00946 {
00947 row = mysql_fetch_row (mysql_info->result);
00948 length = mysql_fetch_lengths (mysql_info->result);
00949
00950 if (mysql_info->debug > 1)
00951 {
00952 pk_syslog (mysql_info->log_file,
00953 "[DEBUG] [%s,%d] options_id[%d], profile_optionnel[%d], option_code[%d], option_type[%d], option_value[%d], comment[%d]",
00954 __FILE__, __LINE__,
00955 length[0],
00956 length[1],
00957 length[2],
00958 length[3],
00959 length[4],
00960 length[5]);
00961 }
00962
00963 memset ((void*)integer1, 0, 32);
00964 memset ((void*)integer2, 0, 32);
00965 memset ((void*)((mysql_tables->options)[i]).profile_optionnel, 0, OPTIONNAL_PROFILE_SIZE);
00966 memset ((void*)((mysql_tables->options)[i]).option_type, 0, OPTION_TYPE_SIZE);
00967 memset ((void*)((mysql_tables->options)[i]).option_value, 0, OPTION_VALUE_SIZE);
00968 memset ((void*)((mysql_tables->options)[i]).comment, 0, COMMENT_SIZE);
00969
00970 memcpy ((void*)integer1, (void*)row[0],
00971 (length[0] < 32) ? length[0] : 31);
00972
00973 memcpy ((void*)((mysql_tables->options)[i]).profile_optionnel, (void*)row[1],
00974 (length[1] < OPTIONNAL_PROFILE_SIZE) ? length[1] : OPTIONNAL_PROFILE_SIZE-1);
00975
00976 memcpy ((void*)integer2, (void*)row[2],
00977 (length[2] < 32) ? length[2] : 31);
00978
00979 memcpy ((void*)((mysql_tables->options)[i]).option_type, (void*)row[3],
00980 (length[3] < OPTION_TYPE_SIZE) ? length[3] : OPTION_TYPE_SIZE-1);
00981
00982 memcpy ((void*)((mysql_tables->options)[i]).option_value, (void*)row[4],
00983 (length[4] < OPTION_VALUE_SIZE) ? length[4] : OPTION_VALUE_SIZE-1);
00984
00985 memcpy ((void*)((mysql_tables->options)[i]).comment, (void*)row[5],
00986 (length[5] < COMMENT_SIZE) ? length[5] : COMMENT_SIZE-1);
00987
00988 ((mysql_tables->options)[i]).options_id = string2unsigned_int (integer1, &e);
00989 ((mysql_tables->options)[i]).option_code = (unsigned char) string2unsigned_int (integer2, &e);
00990
00991 if (mysql_info->debug > 0)
00992 {
00993 pk_syslog (mysql_info->log_file,
00994 "[SQL RESULT] [%s,%d] OPTION %d: [%s] => options_id='%lu', profile_optionnel='%s', option_code='%u', option_type='%s', option_value='%s', comment='%s'",
00995 __FILE__, __LINE__,
00996 i, sql,
00997 ((mysql_tables->options)[i]).options_id,
00998 ((mysql_tables->options)[i]).profile_optionnel,
00999 ((mysql_tables->options)[i]).option_code,
01000 ((mysql_tables->options)[i]).option_type,
01001 ((mysql_tables->options)[i]).option_value,
01002 ((mysql_tables->options)[i]).comment);
01003 }
01004 }
01005
01006 mysql_free_result(mysql_info->result);
01007 return 0;
01008 }
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033 int load_ip_lease (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
01034 {
01035 static char sql[SQL_REQUEST_SIZE], integer1[32];
01036 int (*pk_syslog)(const char *file, const char * fmt,...);
01037 int n, e;
01038 MYSQL_ROW row;
01039 unsigned long int *length;
01040
01041
01042
01043 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01044 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01045
01046
01047
01048
01049
01050 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
01051
01052 snprintf (sql,
01053 SQL_REQUEST_SIZE,
01054 "SELECT ip_lease_id, vlan_id, cidr, subnet, gateway FROM ip_lease WHERE vlan_id='%lu'",
01055 mysql_tables->ip_lease.vlan_id);
01056
01057 if (mysql_info->debug > 0)
01058 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
01059
01060
01061
01062
01063
01064 n = sql_select (mysql_info, sql);
01065
01066 switch (n)
01067 {
01068 case MYSQL_REQUEST_SKIPED:
01069 pk_syslog (mysql_info->log_file,
01070 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
01071 return MYSQL_INTERFACE_REQUEST_SKIPED;
01072 case MYSQL_CONNECTION_LOST:
01073 pk_syslog (mysql_info->log_file,
01074 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
01075 return MYSQL_INTERFACE_CONNECTION_LOST;
01076 case MYSQL_RECONNECTION_FAILED:
01077 pk_syslog (mysql_info->log_file,
01078 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
01079 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01080 case MYSQL_SQL_PROBLEM:
01081 pk_syslog (mysql_info->log_file,
01082 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
01083 return MYSQL_INTERFACE_SQL_PROBLEM;
01084 case MYSQL_UNEXPECTED_ERROR:
01085 pk_syslog (mysql_info->log_file,
01086 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
01087 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01088 case 0:
01089 pk_syslog (mysql_info->log_file,
01090 "[WARNING] [%s,%d] Can not find ip_lease (%lu) in database",
01091 __FILE__, __LINE__,
01092 mysql_tables->ip_lease.vlan_id);
01093
01094 mysql_free_result(mysql_info->result);
01095 return MYSQL_INTERFACE_NOT_FOUND;
01096 }
01097
01098 if (n != 1)
01099 {
01100 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one ip_lease with (%lu)",
01101 __FILE__, __LINE__,
01102 mysql_tables->ip_lease.vlan_id);
01103
01104 mysql_free_result(mysql_info->result);
01105 return MYSQL_INTERFACE_MORE_THAN_ONE;
01106 }
01107
01108
01109
01110
01111
01112 row = mysql_fetch_row (mysql_info->result);
01113 length = mysql_fetch_lengths (mysql_info->result);
01114
01115 if (mysql_info->debug > 1)
01116 {
01117 pk_syslog (mysql_info->log_file,
01118 "[DEBUG] [%s,%d] ip_lease_id[%d], cidr[%d], subnet[%d], gateway[%d]",
01119 __FILE__, __LINE__,
01120 length[0],
01121 length[2],
01122 length[3],
01123 length[4]);
01124 }
01125
01126 memset ((void*)integer1, 0, 32);
01127 memset ((void*)mysql_tables->ip_lease.cidr, 0, CIDR_SIZE);
01128 memset ((void*)mysql_tables->ip_lease.subnet, 0, IP_ADDRESS_STR_SIZE);
01129 memset ((void*)mysql_tables->ip_lease.gateway, 0, IP_ADDRESS_STR_SIZE);
01130
01131 memcpy ((void*)integer1, (void*)row[0],
01132 (length[0] < 32) ? length[0] : 31);
01133
01134 memcpy ((void*)mysql_tables->ip_lease.cidr, (void*)row[2],
01135 (length[2] < CIDR_SIZE) ? length[2] : CIDR_SIZE-1);
01136
01137 memcpy ((void*)mysql_tables->ip_lease.subnet, (void*)row[3],
01138 (length[3] < IP_ADDRESS_STR_SIZE) ? length[3] : IP_ADDRESS_STR_SIZE-1);
01139
01140 memcpy ((void*)mysql_tables->ip_lease.gateway, (void*)row[4],
01141 (length[4] < IP_ADDRESS_STR_SIZE) ? length[4] : IP_ADDRESS_STR_SIZE-1);
01142
01143 mysql_tables->ip_lease.ip_lease_id = string2unsigned_int (integer1, &e);
01144
01145 if (mysql_info->debug > 0)
01146 {
01147 pk_syslog (mysql_info->log_file,
01148 "[SQL RESULT] [%s,%d] [%s] => ip_lease_id='%lu', cidr='%s', subnet='%s', gateway='%s'",
01149 __FILE__, __LINE__, sql,
01150 mysql_tables->ip_lease.ip_lease_id,
01151 mysql_tables->ip_lease.cidr,
01152 mysql_tables->ip_lease.subnet,
01153 mysql_tables->ip_lease.gateway);
01154 }
01155
01156 mysql_free_result(mysql_info->result);
01157
01158 return 0;
01159 }
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 int load_pool (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
01187 {
01188 static char sql[SQL_REQUEST_SIZE], integer1[32], integer2[32];
01189 int (*pk_syslog)(const char *file, const char * fmt,...);
01190 int n, e;
01191 MYSQL_ROW row;
01192 unsigned long int *length, now, delay;
01193
01194 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01195 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01196
01197
01198
01199
01200
01201 now = get_unix_timestamp (mysql_info, &e);
01202
01203 switch (e)
01204 {
01205 case MYSQL_REQUEST_SKIPED:
01206 pk_syslog (mysql_info->log_file,
01207 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_REQUEST_SKIPED)",
01208 __FILE__, __LINE__);
01209 return MYSQL_INTERFACE_NO_TIMESTAMP;
01210 case MYSQL_CONNECTION_LOST:
01211 pk_syslog (mysql_info->log_file,
01212 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_CONNECTION_LOST)",
01213 __FILE__, __LINE__);
01214 return MYSQL_INTERFACE_NO_TIMESTAMP;
01215 case MYSQL_RECONNECTION_FAILED:
01216 pk_syslog (mysql_info->log_file,
01217 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_RECONNECTION_FAILED)",
01218 __FILE__, __LINE__);
01219 return MYSQL_INTERFACE_NO_TIMESTAMP;
01220 case MYSQL_SQL_PROBLEM:
01221 pk_syslog (mysql_info->log_file,
01222 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_SQL_PROBLEM)",
01223 __FILE__, __LINE__);
01224 return MYSQL_INTERFACE_NO_TIMESTAMP;
01225 case MYSQL_UNEXPECTED_ERROR:
01226 pk_syslog (mysql_info->log_file,
01227 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_UNEXPECTED_ERROR)",
01228 __FILE__, __LINE__);
01229 return MYSQL_INTERFACE_NO_TIMESTAMP;
01230 case MYSQL_NO_TIMESTAMP:
01231 pk_syslog (mysql_info->log_file,
01232 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_NO_TIMESTAMP)",
01233 __FILE__, __LINE__);
01234 return MYSQL_INTERFACE_NO_TIMESTAMP;
01235 case 0:
01236 if (mysql_info->debug > 1)
01237 {
01238 pk_syslog (mysql_info->log_file,
01239 "[SQL RESULT] [%s,%d] Timestamp is %lu", __FILE__, __LINE__, now);
01240 }; break;
01241 }
01242
01243 delay = config->sql_expiration_security_delay;
01244
01245
01246
01247
01248
01249 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
01250
01251 snprintf (sql,
01252 SQL_REQUEST_SIZE,
01253 "SELECT pool_id, ip_lease_id, abonnes_id, ip, expiration FROM pool WHERE ip_lease_id='%lu' AND abonnes_id='%lu' AND expiration>%lu ORDER BY expiration DESC LIMIT 1",
01254 mysql_tables->pool.ip_lease_id,
01255 mysql_tables->pool.abonnes_id,
01256 now+delay);
01257
01258 if (mysql_info->debug > 0)
01259 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
01260
01261
01262
01263
01264
01265 n = sql_select (mysql_info, sql);
01266
01267 switch (n)
01268 {
01269 case MYSQL_REQUEST_SKIPED:
01270 pk_syslog (mysql_info->log_file,
01271 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
01272 return MYSQL_INTERFACE_REQUEST_SKIPED;
01273 case MYSQL_CONNECTION_LOST:
01274 pk_syslog (mysql_info->log_file,
01275 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
01276 return MYSQL_INTERFACE_CONNECTION_LOST;
01277 case MYSQL_RECONNECTION_FAILED:
01278 pk_syslog (mysql_info->log_file,
01279 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
01280 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01281 case MYSQL_SQL_PROBLEM:
01282 pk_syslog (mysql_info->log_file,
01283 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
01284 return MYSQL_INTERFACE_SQL_PROBLEM;
01285 case MYSQL_UNEXPECTED_ERROR:
01286 pk_syslog (mysql_info->log_file,
01287 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
01288 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01289 case 0:
01290 pk_syslog (mysql_info->log_file,
01291 "[INFO] [%s,%d] No dyamic IP (ip_lease_id=%lu, abonnes_id=%lu) in database",
01292 __FILE__, __LINE__,
01293 mysql_tables->pool.ip_lease_id,
01294 mysql_tables->pool.abonnes_id);
01295
01296 mysql_free_result(mysql_info->result);
01297 return MYSQL_INTERFACE_NOT_FOUND;
01298 }
01299
01300 if (n != 1)
01301 {
01302 pk_syslog (mysql_info->log_file,
01303 "[ERROR] [%s,%d] Found more than one dyamic IP with (%lu, %lu)",
01304 __FILE__, __LINE__,
01305 mysql_tables->pool.ip_lease_id,
01306 mysql_tables->pool.abonnes_id);
01307
01308 mysql_free_result(mysql_info->result);
01309 return MYSQL_INTERFACE_MORE_THAN_ONE;
01310 }
01311
01312
01313
01314
01315
01316 row = mysql_fetch_row (mysql_info->result);
01317 length = mysql_fetch_lengths (mysql_info->result);
01318
01319 if (mysql_info->debug > 1)
01320 {
01321 pk_syslog (mysql_info->log_file,
01322 "[DEBUG] [%s,%d] pool_id[%d], ip[%d], expiration[%d]",
01323 __FILE__, __LINE__,
01324 length[0],
01325 length[3],
01326 length[4]);
01327 }
01328
01329 memset ((void*)integer1, 0, 32);
01330 memset ((void*)integer2, 0, 32);
01331 memset ((void*)mysql_tables->pool.ip, 0, IP_ADDRESS_STR_SIZE);
01332
01333 memcpy ((void*)integer1, (void*)row[0],
01334 (length[0] < 32) ? length[0] : 31);
01335
01336 memcpy ((void*)mysql_tables->pool.ip, (void*)row[3],
01337 (length[3] < IP_ADDRESS_STR_SIZE) ? length[3] : IP_ADDRESS_STR_SIZE-1);
01338
01339 memcpy ((void*)integer2, (void*)row[4],
01340 (length[4] < 32) ? length[4] : 31);
01341
01342 mysql_tables->pool.pool_id = string2unsigned_int (integer1, &e);
01343 mysql_tables->pool.expiration = string2unsigned_int (integer2, &e);
01344
01345 if (mysql_info->debug > 0)
01346 {
01347 pk_syslog (mysql_info->log_file,
01348 "[SQL RESULT] [%s,%d] [%s] => pool_id='%lu', ip='%s' and expiration='%lu'",
01349 __FILE__, __LINE__, sql,
01350 mysql_tables->pool.pool_id,
01351 mysql_tables->pool.ip,
01352 mysql_tables->pool.expiration);
01353 }
01354
01355 mysql_free_result(mysql_info->result);
01356 return 0;
01357 }
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386 int try_reserve_ip_from_pool (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config, unsigned long int timeout)
01387 {
01388 static char sql[SQL_REQUEST_SIZE];
01389 int (*pk_syslog)(const char *file, const char * fmt,...);
01390 int rc, e;
01391 time_t now;
01392
01393
01394
01395 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01396 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01397
01398
01399
01400
01401
01402
01403 now = get_unix_timestamp (mysql_info, &e);
01404
01405 switch (e)
01406 {
01407 case MYSQL_REQUEST_SKIPED:
01408 pk_syslog (mysql_info->log_file,
01409 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_REQUEST_SKIPED)",
01410 __FILE__, __LINE__);
01411 return MYSQL_INTERFACE_NO_TIMESTAMP;
01412 case MYSQL_CONNECTION_LOST:
01413 pk_syslog (mysql_info->log_file,
01414 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_CONNECTION_LOST)",
01415 __FILE__, __LINE__);
01416 return MYSQL_INTERFACE_NO_TIMESTAMP;
01417 case MYSQL_RECONNECTION_FAILED:
01418 pk_syslog (mysql_info->log_file,
01419 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_RECONNECTION_FAILED)",
01420 __FILE__, __LINE__);
01421 return MYSQL_INTERFACE_NO_TIMESTAMP;
01422 case MYSQL_SQL_PROBLEM:
01423 pk_syslog (mysql_info->log_file,
01424 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_SQL_PROBLEM)",
01425 __FILE__, __LINE__);
01426 return MYSQL_INTERFACE_NO_TIMESTAMP;
01427 case MYSQL_UNEXPECTED_ERROR:
01428 pk_syslog (mysql_info->log_file,
01429 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_UNEXPECTED_ERROR)",
01430 __FILE__, __LINE__);
01431 return MYSQL_INTERFACE_NO_TIMESTAMP;
01432 case MYSQL_NO_TIMESTAMP:
01433 pk_syslog (mysql_info->log_file,
01434 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_NO_TIMESTAMP)",
01435 __FILE__, __LINE__);
01436 return MYSQL_INTERFACE_NO_TIMESTAMP;
01437 case 0:
01438 if (mysql_info->debug > 1)
01439 {
01440 pk_syslog (mysql_info->log_file,
01441 "[SQL RESULT] [%s,%d] Timestamp is %lu", __FILE__, __LINE__, now);
01442 }; break;
01443 }
01444
01445
01446
01447
01448
01449 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
01450
01451 snprintf (sql,
01452 SQL_REQUEST_SIZE,
01453 "UPDATE pool SET expiration='%lu' WHERE pool_id='%lu' AND abonnes_id='%lu' AND expiration>%lu LIMIT 1",
01454 now + timeout,
01455 mysql_tables->pool.pool_id,
01456 mysql_tables->pool.abonnes_id,
01457 now + config->sql_expiration_security_delay + 2);
01458
01459 if (mysql_info->debug > 0)
01460 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
01461
01462
01463
01464
01465
01466 rc = sql_update (mysql_info, sql);
01467
01468 if (rc != 0)
01469 {
01470 switch (rc)
01471 {
01472 case MYSQL_REQUEST_SKIPED:
01473 pk_syslog (mysql_info->log_file,
01474 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
01475 return MYSQL_INTERFACE_REQUEST_SKIPED;
01476 case MYSQL_CONNECTION_LOST:
01477 pk_syslog (mysql_info->log_file,
01478 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
01479 return MYSQL_INTERFACE_CONNECTION_LOST;
01480 case MYSQL_RECONNECTION_FAILED:
01481 pk_syslog (mysql_info->log_file,
01482 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
01483 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01484 case MYSQL_SQL_PROBLEM:
01485 pk_syslog (mysql_info->log_file,
01486 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
01487 return MYSQL_INTERFACE_SQL_PROBLEM;
01488 case MYSQL_UNEXPECTED_ERROR:
01489 pk_syslog (mysql_info->log_file,
01490 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
01491 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01492 }
01493 }
01494
01495 return 0;
01496 }
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521 int try_find_and_reserve_ip_from_pool (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config, unsigned long int timeout)
01522 {
01523 static char sql[SQL_REQUEST_SIZE];
01524 int (*pk_syslog)(const char *file, const char * fmt,...);
01525 int rc, e;
01526 time_t now;
01527
01528 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01529 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01530
01531
01532
01533
01534
01535 now = get_unix_timestamp (mysql_info, &e);
01536
01537 switch (e)
01538 {
01539 case MYSQL_REQUEST_SKIPED:
01540 pk_syslog (mysql_info->log_file,
01541 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_REQUEST_SKIPED)",
01542 __FILE__, __LINE__);
01543 return MYSQL_INTERFACE_NO_TIMESTAMP;
01544 case MYSQL_CONNECTION_LOST:
01545 pk_syslog (mysql_info->log_file,
01546 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_CONNECTION_LOST)",
01547 __FILE__, __LINE__);
01548 return MYSQL_INTERFACE_NO_TIMESTAMP;
01549 case MYSQL_RECONNECTION_FAILED:
01550 pk_syslog (mysql_info->log_file,
01551 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_RECONNECTION_FAILED)",
01552 __FILE__, __LINE__);
01553 return MYSQL_INTERFACE_NO_TIMESTAMP;
01554 case MYSQL_SQL_PROBLEM:
01555 pk_syslog (mysql_info->log_file,
01556 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_SQL_PROBLEM)",
01557 __FILE__, __LINE__);
01558 return MYSQL_INTERFACE_NO_TIMESTAMP;
01559 case MYSQL_UNEXPECTED_ERROR:
01560 pk_syslog (mysql_info->log_file,
01561 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_UNEXPECTED_ERROR)",
01562 __FILE__, __LINE__);
01563 return MYSQL_INTERFACE_NO_TIMESTAMP;
01564 case MYSQL_NO_TIMESTAMP:
01565 pk_syslog (mysql_info->log_file,
01566 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_NO_TIMESTAMP)",
01567 __FILE__, __LINE__);
01568 return MYSQL_INTERFACE_NO_TIMESTAMP;
01569 case 0:
01570 if (mysql_info->debug > 1)
01571 {
01572 pk_syslog (mysql_info->log_file,
01573 "[SQL RESULT] [%s,%d] Timestamp is %lu", __FILE__, __LINE__, now);
01574 }; break;
01575 }
01576
01577
01578
01579
01580
01581 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
01582
01583 #ifdef RECENT_MYSQL_VERSION
01584
01585 snprintf (sql,
01586 SQL_REQUEST_SIZE,
01587 "UPDATE pool SET abonnes_id='%lu', expiration='%lu' WHERE ip_lease_id='%lu' AND expiration<%lu ORDER BY expiration DESC LIMIT 1",
01588 mysql_tables->pool.abonnes_id,
01589 now + timeout,
01590 mysql_tables->pool.ip_lease_id,
01591 now);
01592
01593 #else
01594
01595 snprintf (sql,
01596 SQL_REQUEST_SIZE,
01597 "UPDATE pool SET abonnes_id='%lu', expiration='%lu' WHERE ip_lease_id='%lu' AND expiration<%lu LIMIT 1",
01598 mysql_tables->pool.abonnes_id,
01599 now + timeout,
01600 mysql_tables->pool.ip_lease_id,
01601 now);
01602
01603 #endif
01604
01605 if (mysql_info->debug > 0)
01606 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
01607
01608
01609
01610
01611
01612 rc = sql_update (mysql_info, sql);
01613
01614 if (rc != 0)
01615 {
01616 switch (rc)
01617 {
01618 case MYSQL_REQUEST_SKIPED:
01619 pk_syslog (mysql_info->log_file,
01620 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
01621 return MYSQL_INTERFACE_REQUEST_SKIPED;
01622 case MYSQL_CONNECTION_LOST:
01623 pk_syslog (mysql_info->log_file,
01624 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
01625 return MYSQL_INTERFACE_CONNECTION_LOST;
01626 case MYSQL_RECONNECTION_FAILED:
01627 pk_syslog (mysql_info->log_file,
01628 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
01629 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01630 case MYSQL_SQL_PROBLEM:
01631 pk_syslog (mysql_info->log_file,
01632 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
01633 return MYSQL_INTERFACE_SQL_PROBLEM;
01634 case MYSQL_UNEXPECTED_ERROR:
01635 pk_syslog (mysql_info->log_file,
01636 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
01637 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01638 }
01639 }
01640
01641 return 0;
01642 }
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666 int release_ip_from_pool (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
01667 {
01668 static char sql[SQL_REQUEST_SIZE];
01669 int (*pk_syslog)(const char *file, const char * fmt,...);
01670 int rc, e;
01671 time_t now;
01672
01673
01674 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01675 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01676
01677
01678
01679
01680
01681 now = get_unix_timestamp (mysql_info, &e);
01682
01683 switch (e)
01684 {
01685 case MYSQL_REQUEST_SKIPED:
01686 pk_syslog (mysql_info->log_file,
01687 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_REQUEST_SKIPED)",
01688 __FILE__, __LINE__);
01689 return MYSQL_INTERFACE_NO_TIMESTAMP;
01690 case MYSQL_CONNECTION_LOST:
01691 pk_syslog (mysql_info->log_file,
01692 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_CONNECTION_LOST)",
01693 __FILE__, __LINE__);
01694 return MYSQL_INTERFACE_NO_TIMESTAMP;
01695 case MYSQL_RECONNECTION_FAILED:
01696 pk_syslog (mysql_info->log_file,
01697 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_RECONNECTION_FAILED)",
01698 __FILE__, __LINE__);
01699 return MYSQL_INTERFACE_NO_TIMESTAMP;
01700 case MYSQL_SQL_PROBLEM:
01701 pk_syslog (mysql_info->log_file,
01702 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_SQL_PROBLEM)",
01703 __FILE__, __LINE__);
01704 return MYSQL_INTERFACE_NO_TIMESTAMP;
01705 case MYSQL_UNEXPECTED_ERROR:
01706 pk_syslog (mysql_info->log_file,
01707 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_UNEXPECTED_ERROR)",
01708 __FILE__, __LINE__);
01709 return MYSQL_INTERFACE_NO_TIMESTAMP;
01710 case MYSQL_NO_TIMESTAMP:
01711 pk_syslog (mysql_info->log_file,
01712 "[WARNING] [%s,%d] Error while getting UNIX timestamp (MYSQL_NO_TIMESTAMP)",
01713 __FILE__, __LINE__);
01714 return MYSQL_INTERFACE_NO_TIMESTAMP;
01715 case 0:
01716 if (mysql_info->debug > 1)
01717 {
01718 pk_syslog (mysql_info->log_file,
01719 "[SQL RESULT] [%s,%d] Timestamp is %lu", __FILE__, __LINE__, now);
01720 }; break;
01721 }
01722
01723
01724
01725
01726
01727 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
01728
01729 snprintf (sql,
01730 SQL_REQUEST_SIZE,
01731 "UPDATE pool SET abonnes_id=NULL, expiration='0' WHERE abonnes_id='%lu' AND ip_lease_id='%lu'",
01732 mysql_tables->pool.abonnes_id,
01733 mysql_tables->pool.ip_lease_id);
01734
01735 if (mysql_info->debug > 0)
01736 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
01737
01738
01739
01740
01741
01742 rc = sql_update (mysql_info, sql);
01743
01744 if (rc != 0)
01745 {
01746 switch (rc)
01747 {
01748 case MYSQL_REQUEST_SKIPED:
01749 pk_syslog (mysql_info->log_file,
01750 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
01751 return MYSQL_INTERFACE_REQUEST_SKIPED;
01752 case MYSQL_CONNECTION_LOST:
01753 pk_syslog (mysql_info->log_file,
01754 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
01755 return MYSQL_INTERFACE_CONNECTION_LOST;
01756 case MYSQL_RECONNECTION_FAILED:
01757 pk_syslog (mysql_info->log_file,
01758 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
01759 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01760 case MYSQL_SQL_PROBLEM:
01761 pk_syslog (mysql_info->log_file,
01762 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
01763 return MYSQL_INTERFACE_SQL_PROBLEM;
01764 case MYSQL_UNEXPECTED_ERROR:
01765 pk_syslog (mysql_info->log_file,
01766 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
01767 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01768 }
01769 }
01770
01771 return 0;
01772 }
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818 int load_context (struct smysql *mysql_info, struct smysql *mysql_info_write, struct mysql_tables *mysql_tables, struct global_config *config)
01819 {
01820 int rc;
01821 int (*pk_syslog)(const char *file, const char * fmt,...);
01822
01823
01824
01825 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
01826 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
01827
01828
01829
01830
01831
01832 rc = load_abonnes (mysql_info, mysql_tables, config);
01833
01834 if (rc != 0)
01835 {
01836 switch (rc)
01837 {
01838 case MYSQL_INTERFACE_REQUEST_SKIPED:
01839 pk_syslog (mysql_info->log_file,
01840 "[WARNING] [%s,%d] Could not load 'abonnes' - Request skiped",
01841 __FILE__, __LINE__);
01842 break;
01843 case MYSQL_INTERFACE_CONNECTION_LOST:
01844 pk_syslog (mysql_info->log_file,
01845 "[WARNING] [%s,%d] Could not load 'abonnes' - Connection lost",
01846 __FILE__, __LINE__);
01847 break;
01848 case MYSQL_INTERFACE_RECONNECTION_FAILED:
01849 pk_syslog (mysql_info->log_file,
01850 "[WARNING] [%s,%d] Could not load 'abonnes' - Could not reconnect",
01851 __FILE__, __LINE__);
01852 break;
01853 case MYSQL_INTERFACE_SQL_PROBLEM:
01854 pk_syslog (mysql_info->log_file,
01855 "[ERROR] [%s,%d] Could not load 'abonnes' - Some SQL problem",
01856 __FILE__, __LINE__);
01857 break;
01858 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01859 pk_syslog (mysql_info->log_file,
01860 "[ERROR] [%s,%d] Could not load 'abonnes' - Unexpected error",
01861 __FILE__, __LINE__);
01862 break;
01863 case MYSQL_INTERFACE_NOT_FOUND:
01864 pk_syslog (mysql_info->log_file,
01865 "[WARNING] [%s,%d] Could not load 'abonnes' - Data not found",
01866 __FILE__, __LINE__);
01867 break;
01868 case MYSQL_INTERFACE_MORE_THAN_ONE:
01869 pk_syslog (mysql_info->log_file,
01870 "[ERROR] [%s,%d] Could not load 'abonnes' - More than one",
01871 __FILE__, __LINE__);
01872 break;
01873 }
01874
01875 return rc;
01876 }
01877
01878
01879
01880
01881
01882 rc = load_vlan (mysql_info, mysql_info_write, mysql_tables, config);
01883
01884 if (rc != 0)
01885 {
01886 switch (rc)
01887 {
01888 case MYSQL_INTERFACE_REQUEST_SKIPED:
01889 pk_syslog (mysql_info->log_file,
01890 "[WARNING] [%s,%d] Could not load 'vlan' - Request skiped",
01891 __FILE__, __LINE__);
01892 break;
01893 case MYSQL_INTERFACE_CONNECTION_LOST:
01894 pk_syslog (mysql_info->log_file,
01895 "[WARNING] [%s,%d] Could not load 'vlan' - Connection lost",
01896 __FILE__, __LINE__);
01897 break;
01898 case MYSQL_INTERFACE_RECONNECTION_FAILED:
01899 pk_syslog (mysql_info->log_file,
01900 "[WARNING] [%s,%d] Could not load 'vlan' - Could not reconnect",
01901 __FILE__, __LINE__);
01902 break;
01903 case MYSQL_INTERFACE_SQL_PROBLEM:
01904 pk_syslog (mysql_info->log_file,
01905 "[ERROR] [%s,%d] Could not load 'vlan' - Some SQL problem",
01906 __FILE__, __LINE__);
01907 break;
01908 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01909 pk_syslog (mysql_info->log_file,
01910 "[ERROR] [%s,%d] Could not load 'vlan' - Unexpected error",
01911 __FILE__, __LINE__);
01912 break;
01913 case MYSQL_INTERFACE_NOT_FOUND:
01914 pk_syslog (mysql_info->log_file,
01915 "[WARNING] [%s,%d] Could not load 'vlan' - Data not found",
01916 __FILE__, __LINE__);
01917 break;
01918 case MYSQL_INTERFACE_MORE_THAN_ONE:
01919 pk_syslog (mysql_info->log_file,
01920 "[ERROR] [%s,%d] Could not load 'vlan' - More than one",
01921 __FILE__, __LINE__);
01922 break;
01923 }
01924
01925 return rc;
01926 }
01927
01928
01929
01930
01931
01932 snprintf ((mysql_tables->options[0]).profile_optionnel,
01933 OPTIONNAL_PROFILE_SIZE,
01934 "%s",
01935 (mysql_tables->vlan).profile_optionnel);
01936
01937
01938
01939
01940
01941 rc = load_options (mysql_info, mysql_tables, config);
01942
01943 if (rc != 0)
01944 {
01945 switch (rc)
01946 {
01947 case MYSQL_INTERFACE_REQUEST_SKIPED:
01948 pk_syslog (mysql_info->log_file,
01949 "[WARNING] [%s,%d] Could not load 'options' - Request skiped",
01950 __FILE__, __LINE__);
01951 break;
01952 case MYSQL_INTERFACE_CONNECTION_LOST:
01953 pk_syslog (mysql_info->log_file,
01954 "[WARNING] [%s,%d] Could not load 'options' - Connection lost",
01955 __FILE__, __LINE__);
01956 break;
01957 case MYSQL_INTERFACE_RECONNECTION_FAILED:
01958 pk_syslog (mysql_info->log_file,
01959 "[WARNING] [%s,%d] Could not load 'options' - Could not reconnect",
01960 __FILE__, __LINE__);
01961 break;
01962 case MYSQL_INTERFACE_SQL_PROBLEM:
01963 pk_syslog (mysql_info->log_file,
01964 "[ERROR] [%s,%d] Could not load 'options' - Some SQL problem",
01965 __FILE__, __LINE__);
01966 break;
01967 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01968 pk_syslog (mysql_info->log_file,
01969 "[ERROR] [%s,%d] Could not load 'options' - Unexpected error",
01970 __FILE__, __LINE__);
01971 break;
01972 case MYSQL_INTERFACE_NOT_FOUND:
01973 pk_syslog (mysql_info->log_file,
01974 "[WARNING] [%s,%d] Could not load 'options' - Data not found",
01975 __FILE__, __LINE__);
01976 break;
01977 case MYSQL_INTERFACE_TOO_MANY_ITEMS:
01978 pk_syslog (mysql_info->log_file,
01979 "[ERROR] [%s,%d] Could not load 'options' - Too many options",
01980 __FILE__, __LINE__); break;
01981 }
01982
01983 return rc;
01984 }
01985
01986
01987
01988
01989
01990
01991 if (strncasecmp ((mysql_tables->abonnes).profile, "STANDARD", OPTIONNAL_PROFILE_SIZE) != 0)
01992 {
01993 if (mysql_info->debug > 0)
01994 { pk_syslog (mysql_info->log_file, "[INFO] [%s,%d] User profile is not STANDARD (%s)",
01995 __FILE__, __LINE__, (mysql_tables->abonnes).profile); }
01996
01997
01998
01999
02000
02001 snprintf ((mysql_tables->options[0]).profile_optionnel,
02002 OPTIONNAL_PROFILE_SIZE,
02003 "%s",
02004 (mysql_tables->abonnes).profile);
02005
02006
02007 rc = load_options (mysql_info, mysql_tables, config);
02008
02009 if (rc != 0)
02010 {
02011 switch (rc)
02012 {
02013 case MYSQL_INTERFACE_REQUEST_SKIPED:
02014 pk_syslog (mysql_info->log_file,
02015 "[WARNING] [%s,%d] Could not load profile 'options' - Request skiped",
02016 __FILE__, __LINE__);
02017 break;
02018 case MYSQL_INTERFACE_CONNECTION_LOST:
02019 pk_syslog (mysql_info->log_file,
02020 "[WARNING] [%s,%d] Could not load profile 'options' - Connection lost",
02021 __FILE__, __LINE__);
02022 break;
02023 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02024 pk_syslog (mysql_info->log_file,
02025 "[WARNING] [%s,%d] Could not load profile 'options' - Could not reconnect",
02026 __FILE__, __LINE__);
02027 break;
02028 case MYSQL_INTERFACE_SQL_PROBLEM:
02029 pk_syslog (mysql_info->log_file,
02030 "[ERROR] [%s,%d] Could not load profile 'options' - Some SQL problem",
02031 __FILE__, __LINE__);
02032 break;
02033 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02034 pk_syslog (mysql_info->log_file,
02035 "[ERROR] [%s,%d] Could not load profile 'options' - Unexpected error",
02036 __FILE__, __LINE__);
02037 break;
02038 case MYSQL_INTERFACE_NOT_FOUND:
02039 pk_syslog (mysql_info->log_file,
02040 "[WARNING] [%s,%d] Could not load profile 'options' - Data not found",
02041 __FILE__, __LINE__);
02042 break;
02043 case MYSQL_INTERFACE_TOO_MANY_ITEMS:
02044 pk_syslog (mysql_info->log_file,
02045 "[ERROR] [%s,%d] Could not load profile 'options' - Too many options",
02046 __FILE__, __LINE__);
02047 break;
02048 }
02049
02050 return rc;
02051 }
02052 }
02053
02054 return 0;
02055 }
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090 int find_ip_in_vlan_pool (struct smysql *mysql_info,
02091 struct mysql_tables *mysql_tables,
02092 struct global_config *config)
02093 {
02094 int cr;
02095 int (*pk_syslog)(const char *file, const char * fmt,...);
02096
02097
02098
02099 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
02100 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
02101
02102
02103
02104
02105
02106 (mysql_tables->ip_lease).vlan_id = (mysql_tables->vlan).vlan_id;
02107
02108 cr = load_ip_lease (mysql_info, mysql_tables, config);
02109
02110 if (cr != 0)
02111 {
02112 switch (cr)
02113 {
02114 case MYSQL_INTERFACE_REQUEST_SKIPED:
02115 pk_syslog (mysql_info->log_file,
02116 "[WARNING] [%s,%d] Could not load 'ip_lease' - Request skiped",
02117 __FILE__, __LINE__);
02118 break;
02119 case MYSQL_INTERFACE_CONNECTION_LOST:
02120 pk_syslog (mysql_info->log_file,
02121 "[WARNING] [%s,%d] Could not load 'ip_lease' - Connection loast",
02122 __FILE__, __LINE__);
02123 break;
02124 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02125 pk_syslog (mysql_info->log_file,
02126 "[WARNING] [%s,%d] Could not load 'ip_lease' - Could not reconnect to MySql server",
02127 __FILE__, __LINE__);
02128 break;
02129 case MYSQL_INTERFACE_SQL_PROBLEM:
02130 pk_syslog (mysql_info->log_file,
02131 "[ERROR] [%s,%d] Could not load 'ip_lease' - Some SQL problem occured",
02132 __FILE__, __LINE__);
02133 break;
02134 case MYSQL_INTERFACE_MORE_THAN_ONE:
02135 pk_syslog (mysql_info->log_file,
02136 "[INFO] [%s,%d] Could not load 'ip_lease' - More than one item found (this should not happen)",
02137 __FILE__, __LINE__);
02138 break;
02139 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02140 pk_syslog (mysql_info->log_file,
02141 "[INFO] [%s,%d] Could not load 'ip_lease' - Unexpected error",
02142 __FILE__, __LINE__);
02143 break;
02144
02145
02146
02147 case MYSQL_INTERFACE_NOT_FOUND:
02148 pk_syslog (mysql_info->log_file,
02149 "[INFO] [%s,%d] Could not load 'ip_lease' - Data not found",
02150 __FILE__, __LINE__);
02151 return MYSQL_INTERFACE_NO_LEASE_ID;
02152 }
02153
02154 return cr;
02155 }
02156
02157
02158
02159
02160
02161 (mysql_tables->pool).ip_lease_id = (mysql_tables->ip_lease).ip_lease_id;
02162 (mysql_tables->pool).abonnes_id = (mysql_tables->abonnes).abonnes_id;
02163
02164 cr = load_pool (mysql_info, mysql_tables, config);
02165
02166 if (cr != 0)
02167 {
02168 switch (cr)
02169 {
02170 case MYSQL_INTERFACE_REQUEST_SKIPED:
02171 pk_syslog (mysql_info->log_file,
02172 "[WARNING] [%s,%d] Could not load 'pool' - Request skiped",
02173 __FILE__, __LINE__);
02174 break;
02175 case MYSQL_INTERFACE_CONNECTION_LOST:
02176 pk_syslog (mysql_info->log_file,
02177 "[WARNING] [%s,%d] Could not load 'pool' - Connection loast",
02178 __FILE__, __LINE__);
02179 break;
02180 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02181 pk_syslog (mysql_info->log_file,
02182 "[WARNING] [%s,%d] Could not load 'pool' - Could not reconnect to MySql server",
02183 __FILE__, __LINE__);
02184 break;
02185 case MYSQL_INTERFACE_SQL_PROBLEM:
02186 pk_syslog (mysql_info->log_file,
02187 "[ERROR] [%s,%d] Could not load 'pool' - Some SQL problem occured",
02188 __FILE__, __LINE__);
02189 break;
02190 case MYSQL_INTERFACE_MORE_THAN_ONE:
02191 pk_syslog (mysql_info->log_file,
02192 "[ERROR] [%s,%d] Could not load 'pool' - More than one item found (this should not happen)",
02193 __FILE__, __LINE__);
02194 break;
02195 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02196 pk_syslog (mysql_info->log_file,
02197 "[ERROR] [%s,%d] Could not load 'pool' - Unexpected error",
02198 __FILE__, __LINE__);
02199 break;
02200 case MYSQL_INTERFACE_NO_TIMESTAMP:
02201 pk_syslog (mysql_info->log_file,
02202 "[ERROR] [%s,%d] Could not load 'pool' - Error while retrieving timestamp",
02203 __FILE__, __LINE__);
02204 break;
02205
02206
02207
02208 case MYSQL_INTERFACE_NOT_FOUND:
02209 pk_syslog (mysql_info->log_file,
02210 "[INFO] [%s,%d] Could not load 'pool' - Data not found",
02211 __FILE__, __LINE__);
02212 return MYSQL_INTERFACE_NO_IP_FOUND;
02213 }
02214
02215 return cr;
02216 }
02217
02218 return 0;
02219 }
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272 int get_ip_from_pool (struct smysql *mysql_info,
02273 struct mysql_tables *mysql_tables,
02274 struct global_config *config,
02275 unsigned int timeout,
02276 int reserve_ip)
02277 {
02278 int cr;
02279 int (*pk_syslog)(const char *file, const char * fmt,...);
02280
02281 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
02282 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
02283
02284
02285
02286
02287
02288 cr = find_ip_in_vlan_pool (mysql_info, mysql_tables, config);
02289
02290 if (mysql_info->debug > 1)
02291 {
02292 pk_syslog (mysql_info->log_file,
02293 "[DEBUG] [%s,%d] find_ip_in_vlan_pool() returned the value %d",
02294 __FILE__, __LINE__, cr);
02295 }
02296
02297 if ((cr != 0) && (cr != MYSQL_INTERFACE_NO_IP_FOUND))
02298 {
02299 switch (cr)
02300 {
02301 case MYSQL_INTERFACE_REQUEST_SKIPED:
02302 pk_syslog (mysql_info->log_file,
02303 "[WARNING] [%s,%d] Could not look up pool - Request skiped",
02304 __FILE__, __LINE__);
02305 break;
02306 case MYSQL_INTERFACE_CONNECTION_LOST:
02307 pk_syslog (mysql_info->log_file,
02308 "[WARNING] [%s,%d] Could not look up pool - Connection lost",
02309 __FILE__, __LINE__);
02310 break;
02311 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02312 pk_syslog (mysql_info->log_file,
02313 "[WARNING] [%s,%d] Could not look up pool - Could not reconnect to the MySql server",
02314 __FILE__, __LINE__);
02315 break;
02316 case MYSQL_INTERFACE_SQL_PROBLEM:
02317 pk_syslog (mysql_info->log_file,
02318 "[ERROR] [%s,%d] Could not look up pool - Some SQL problem occured",
02319 __FILE__, __LINE__);
02320 break;
02321 case MYSQL_INTERFACE_MORE_THAN_ONE:
02322 pk_syslog (mysql_info->log_file,
02323 "[ERROR] [%s,%d] Could not look up pool - More than one lease ID foud",
02324 __FILE__, __LINE__);
02325 break;
02326 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02327 pk_syslog (mysql_info->log_file,
02328 "[ERROR] [%s,%d] Could not look up pool - Unexpected error",
02329 __FILE__, __LINE__);
02330 break;
02331 case MYSQL_INTERFACE_NO_TIMESTAMP:
02332 pk_syslog (mysql_info->log_file,
02333 "[ERROR] [%s,%d] Could not look up pool - Could not retrieve MySql server timestamp",
02334 __FILE__, __LINE__);
02335 break;
02336 case MYSQL_INTERFACE_NO_LEASE_ID:
02337 pk_syslog (mysql_info->log_file,
02338 "[WARNING] [%s,%d] Could not look up pool - Could not find requested lease ID",
02339 __FILE__, __LINE__);
02340 break;
02341 }
02342
02343 return cr;
02344 }
02345
02346
02347 mysql_tables->pool.ip_lease_id = mysql_tables->ip_lease.ip_lease_id;
02348
02349
02350
02351
02352
02353
02354 if (cr == MYSQL_INTERFACE_NO_IP_FOUND)
02355 {
02356 if (reserve_ip == 0)
02357 {
02358 pk_syslog (mysql_info->log_file,
02359 "[DEBUG] [%s,%d] No IP already reserved for the user '%lu'. Do not try to reserve IP address from pool.",
02360 __FILE__, __LINE__, mysql_tables->pool.abonnes_id);
02361
02362 return 0;
02363 }
02364
02365
02366
02367
02368
02369
02370
02371 if (mysql_info->debug > 1)
02372 {
02373 pk_syslog (mysql_info->log_file,
02374 "[DEBUG] [%s,%d] No IP already reserved for the user '%lu', try to reserve one",
02375 __FILE__, __LINE__, mysql_tables->pool.abonnes_id);
02376 }
02377
02378 cr = try_find_and_reserve_ip_from_pool (mysql_info, mysql_tables, config, timeout);
02379
02380 if (cr != 0)
02381 {
02382 switch (cr)
02383 {
02384 case MYSQL_INTERFACE_REQUEST_SKIPED:
02385 pk_syslog (mysql_info->log_file,
02386 "[WARNING] [%s,%d] Could not find and reserve IP - Request skiped",
02387 __FILE__, __LINE__);
02388 break;
02389 case MYSQL_INTERFACE_CONNECTION_LOST:
02390 pk_syslog (mysql_info->log_file,
02391 "[WARNING] [%s,%d] Could not find and reserve IP - Connection lost",
02392 __FILE__, __LINE__);
02393 break;
02394 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02395 pk_syslog (mysql_info->log_file,
02396 "[WARNING] [%s,%d] Could not find and reserve IP - Could not reconnection to MySql server",
02397 __FILE__, __LINE__);
02398 break;
02399 case MYSQL_INTERFACE_SQL_PROBLEM:
02400 pk_syslog (mysql_info->log_file,
02401 "[ERROR] [%s,%d] Could not find and reserve IP - Some SQL problem occured.",
02402 __FILE__, __LINE__);
02403 break;
02404 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02405 pk_syslog (mysql_info->log_file,
02406 "[ERROR] [%s,%d] Could not find and reserve IP - Unexpected error",
02407 __FILE__, __LINE__);
02408 break;
02409 case MYSQL_INTERFACE_NO_TIMESTAMP:
02410 pk_syslog (mysql_info->log_file,
02411 "[WARNING] [%s,%d] Could not find and reserve IP - Could not retrieve the MySql server timestamp",
02412 __FILE__, __LINE__);
02413 break;
02414 }
02415
02416 return cr;
02417 }
02418 }
02419 else
02420 {
02421
02422
02423
02424
02425
02426
02427 if (mysql_info->debug > 1)
02428 {
02429 pk_syslog (mysql_info->log_file,
02430 "[DEBUG] [%s,%d] Found IP already reserved for the user, extend expiration date for pool_id='%lu' by %lu seconds",
02431 __FILE__, __LINE__,
02432 mysql_tables->pool.pool_id,
02433 timeout);
02434 }
02435
02436 cr = try_reserve_ip_from_pool (mysql_info, mysql_tables, config, timeout);
02437
02438 if (cr != 0)
02439 {
02440 switch (cr)
02441 {
02442 case MYSQL_INTERFACE_REQUEST_SKIPED:
02443 pk_syslog (mysql_info->log_file,
02444 "[WARNING] [%s,%d] Could not reserve IP - Request skiped",
02445 __FILE__, __LINE__);
02446 break;
02447 case MYSQL_INTERFACE_CONNECTION_LOST:
02448 pk_syslog (mysql_info->log_file,
02449 "[WARNING] [%s,%d] Could not reserve IP - Connection lost",
02450 __FILE__, __LINE__);
02451 break;
02452 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02453 pk_syslog (mysql_info->log_file,
02454 "[WARNING] [%s,%d] Could not reserve IP - Could not reconnect to MySql server",
02455 __FILE__, __LINE__);
02456 break;
02457 case MYSQL_INTERFACE_SQL_PROBLEM:
02458 pk_syslog (mysql_info->log_file,
02459 "[WARNING] [%s,%d] Could not reserve IP - Some SQL problem occured",
02460 __FILE__, __LINE__);
02461 break;
02462 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02463 pk_syslog (mysql_info->log_file,
02464 "[WARNING] [%s,%d] Could not reserve IP - Unexpected error",
02465 __FILE__, __LINE__);
02466 break;
02467 case MYSQL_INTERFACE_NO_TIMESTAMP:
02468 pk_syslog (mysql_info->log_file,
02469 "[WARNING] [%s,%d] Could not reserve IP - Could not retrieve the MySql server timestamp",
02470 __FILE__, __LINE__);
02471 break;
02472 }
02473
02474 return cr;
02475 }
02476 }
02477
02478
02479
02480
02481
02482 if (mysql_info->debug > 1)
02483 {
02484 pk_syslog (mysql_info->log_file,
02485 "[DEBUG] [%s,%d] OK, make sure that we have a reserved IP address in the pool",
02486 __FILE__, __LINE__);
02487 }
02488
02489 cr = load_pool (mysql_info, mysql_tables, config);
02490
02491 if (cr != 0)
02492 {
02493 switch (cr)
02494 {
02495 case MYSQL_INTERFACE_REQUEST_SKIPED:
02496 pk_syslog (mysql_info->log_file,
02497 "[WARNING] [%s,%d] IP pool reservation failed - Request skiped",
02498 __FILE__, __LINE__);
02499 break;
02500 case MYSQL_INTERFACE_CONNECTION_LOST:
02501 pk_syslog (mysql_info->log_file,
02502 "[WARNING] [%s,%d] IP pool reservation failed - Connection lost",
02503 __FILE__, __LINE__);
02504 break;
02505 case MYSQL_INTERFACE_RECONNECTION_FAILED:
02506 pk_syslog (mysql_info->log_file,
02507 "[WARNING] [%s,%d] IP pool reservation failed - Could not reconnect to the MySql server",
02508 __FILE__, __LINE__);
02509 break;
02510 case MYSQL_INTERFACE_SQL_PROBLEM:
02511 pk_syslog (mysql_info->log_file,
02512 "[WARNING] [%s,%d] IP pool reservation failed - Some SQL problem occured",
02513 __FILE__, __LINE__);
02514 break;
02515 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
02516 pk_syslog (mysql_info->log_file,
02517 "[WARNING] [%s,%d] IP pool reservation failed - Unexpected error",
02518 __FILE__, __LINE__);
02519 break;
02520 case MYSQL_INTERFACE_MORE_THAN_ONE:
02521 pk_syslog (mysql_info->log_file,
02522 "[WARNING] [%s,%d] IP pool reservation failed - More than one IP address (this should never happen)",
02523 __FILE__, __LINE__);
02524 break;
02525 case MYSQL_INTERFACE_NO_TIMESTAMP:
02526 pk_syslog (mysql_info->log_file,
02527 "[ERROR] [%s,%d] IP pool reservation failed - Error while retrieving timestamp",
02528 __FILE__, __LINE__);
02529 break;
02530
02531
02532
02533 case MYSQL_INTERFACE_NOT_FOUND:
02534 pk_syslog (mysql_info->log_file,
02535 "[WARNING] [%s,%d] IP pool reservation failed - No free IP address were available",
02536 __FILE__, __LINE__);
02537 return 0;
02538 }
02539
02540 return cr;
02541 }
02542
02543 if (mysql_info->debug > 1)
02544 {
02545 pk_syslog (mysql_info->log_file,
02546 "[DEBUG] [%s,%d] OK, IP='%s' reserved from user id='%lu'",
02547 __FILE__, __LINE__,
02548 mysql_tables->pool.ip,
02549 mysql_tables->pool.abonnes_id);
02550 }
02551
02552
02553 return 1;
02554 }
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586 int send_to_radonline (
02587 struct smysql *mysql_info,
02588 struct mysql_tables *mysql_tables,
02589 char *ip,
02590 int action,
02591 struct global_config *config)
02592 {
02593 static char sql[SQL_REQUEST_SIZE], dslamid[NASPORT_SIZE];
02594 int (*pk_syslog)(const char *file, const char * fmt,...), i;
02595
02596
02597 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
02598 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
02599
02600
02601 if (mysql_info->debug > 1)
02602 {
02603 if (action == RADONLINE_START)
02604 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Inserting START ticket into Radonline",
02605 __FILE__, __LINE__); }
02606
02607 if (action == RADONLINE_STOP)
02608 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Inserting STOP ticket into Radonline",
02609 __FILE__, __LINE__); }
02610 }
02611
02612
02613
02614
02615
02616
02617
02618 memset ((void*)dslamid, 0, NASPORT_SIZE);
02619
02620 snprintf (dslamid,
02621 NASPORT_SIZE,
02622 "%3u%3u%3u%5u",
02623 (mysql_tables->abonnes).shelf,
02624 (mysql_tables->abonnes).numero_port,
02625 (mysql_tables->abonnes).numero_slot,
02626 (unsigned int)(mysql_tables->vlan).vlan_tag);
02627
02628 for (i=0; i<strlen(dslamid); i++) { if (dslamid[i] == ' ') { dslamid[i] = '0'; } }
02629
02630
02631
02632
02633
02634
02635
02636 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
02637
02638 #ifdef USE_TRIPLET
02639 snprintf (sql,
02640 SQL_REQUEST_SIZE,
02641 "DELETE FROM RADONLINE WHERE USERNAME='%s' AND NASIDENTIFIER='%s' AND NASPORT='%s'",
02642 (mysql_tables->abonnes).login_radius,
02643 (mysql_tables->vlan).vlan_gateway,
02644 dslamid);
02645 #else
02646 snprintf (sql,
02647 SQL_REQUEST_SIZE,
02648 "DELETE FROM RADONLINE WHERE NASIDENTIFIER='%s' AND NASPORT='%s'",
02649 (mysql_tables->vlan).vlan_gateway,
02650 dslamid);
02651 #endif
02652
02653 if (mysql_info->debug > 1)
02654 {
02655 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] dslamid = [%s]",
02656 __FILE__, __LINE__, dslamid);
02657 }
02658
02659 if (mysql_info->debug > 0)
02660 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
02661
02662 switch (sql_delete (mysql_info, sql))
02663 {
02664 case MYSQL_REQUEST_SKIPED:
02665 {
02666 if (mysql_info->debug > 1)
02667 { pk_syslog (mysql_info->log_file,
02668 "[DEBUG] [%s,%d] SQL '%s' skiped", __FILE__, __LINE__, sql); }
02669 return MYSQL_REQUEST_SKIPED;
02670 };
02671
02672 case MYSQL_CONNECTION_LOST:
02673 {
02674 if (mysql_info->debug > 1)
02675 {
02676 pk_syslog (mysql_info->log_file,
02677 "[DEBUG] [%s,%d] SQL '%s' connection lost",
02678 __FILE__, __LINE__, sql);
02679 }
02680 return MYSQL_CONNECTION_LOST;
02681 };
02682
02683 case MYSQL_RECONNECTION_FAILED:
02684 {
02685 if (mysql_info->debug > 1)
02686 {
02687 pk_syslog (mysql_info->log_file,
02688 "[DEBUG] [%s,%d] SQL '%s' reconnection failed",
02689 __FILE__, __LINE__, sql);
02690 }
02691 return MYSQL_RECONNECTION_FAILED;
02692 };
02693
02694 case MYSQL_SQL_PROBLEM:
02695 {
02696 if (mysql_info->debug > 1)
02697 {
02698 pk_syslog (mysql_info->log_file,
02699 "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
02700 __FILE__, __LINE__, sql);
02701 }
02702 return MYSQL_SQL_PROBLEM;
02703 };
02704
02705 case MYSQL_UNEXPECTED_ERROR:
02706 {
02707 if (mysql_info->debug > 1)
02708 {
02709 pk_syslog (mysql_info->log_file,
02710 "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
02711 __FILE__, __LINE__, sql);
02712 }
02713 return MYSQL_UNEXPECTED_ERROR;
02714 };
02715
02716 default:
02717 {
02718 if (mysql_info->debug > 1)
02719 {
02720 pk_syslog (mysql_info->log_file,
02721 "[DEBUG] [%s,%d] SQL '%s' OK",
02722 __FILE__, __LINE__, sql);
02723 }
02724 };
02725 }
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735 if (action == RADONLINE_START)
02736 {
02737 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
02738
02739 if ((mysql_tables->logistic).radonline_acct_identifier[0] == 0)
02740 {
02741
02742
02743
02744
02745 if (mysql_info->debug > 1)
02746 {
02747 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] radonline_acct_identifier is empty",
02748 __FILE__, __LINE__);
02749 }
02750
02751 snprintf (sql,
02752 SQL_REQUEST_SIZE,
02753 "INSERT INTO RADONLINE (USERNAME, NASIDENTIFIER, NASPORT, ACCTSESSIONID, TIME_STAMP, FRAMEDIPADDRESS, NASPORTTYPE, SERVICETYPE, CALLERID, CALLEDID, ACCT_IDENTIFIER) VALUES ('%s', '%s', '%s', '%s', '%lu', '%s', '%s', '%s', NULL, NULL, '%s')",
02754
02755 (mysql_tables->abonnes).login_radius,
02756 (mysql_tables->vlan).vlan_gateway,
02757 dslamid,
02758 "adsl",
02759 (unsigned long int)(time(NULL)),
02760 ip,
02761 "adsl",
02762 "adsl",
02763 (mysql_tables->vlan).radius_identifiant);
02764
02765 if (mysql_info->debug > 0)
02766 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
02767 }
02768 else
02769 {
02770
02771
02772
02773
02774 if (mysql_info->debug > 1)
02775 {
02776 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] radonline_acct_identifier is not empty",
02777 __FILE__, __LINE__);
02778 }
02779
02780 snprintf (sql,
02781 SQL_REQUEST_SIZE,
02782 "INSERT INTO RADONLINE (USERNAME, NASIDENTIFIER, NASPORT, ACCTSESSIONID, TIME_STAMP, FRAMEDIPADDRESS, NASPORTTYPE, SERVICETYPE, CALLERID, CALLEDID, ACCT_IDENTIFIER, LOGIN_MODEM) VALUES ('%s', '%s', '%s', '%s', '%lu', '%s', '%s', '%s', NULL, NULL, '%s', '%s')",
02783
02784 (mysql_tables->logistic).radonline_user_name,
02785 (mysql_tables->vlan).vlan_gateway,
02786 dslamid,
02787 "adsl",
02788 (unsigned long int)(time(NULL)),
02789 ip,
02790 "adsl",
02791 "adsl",
02792 (mysql_tables->logistic).radonline_acct_identifier,
02793 (mysql_tables->logistic).login_modem);
02794
02795 if (mysql_info->debug > 0)
02796 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
02797 }
02798
02799
02800 switch (sql_insert (mysql_info, sql))
02801 {
02802 case MYSQL_REQUEST_SKIPED:
02803 {
02804 if (mysql_info->debug > 1)
02805 { pk_syslog (mysql_info->log_file,
02806 "[DEBUG] [%s,%d] SQL '%s' skiped", __FILE__, __LINE__, sql); }
02807 return MYSQL_REQUEST_SKIPED;
02808 };
02809
02810 case MYSQL_CONNECTION_LOST:
02811 {
02812 if (mysql_info->debug > 1)
02813 {
02814 pk_syslog (mysql_info->log_file,
02815 "[DEBUG] [%s,%d] SQL '%s' connection lost",
02816 __FILE__, __LINE__, sql);
02817 }
02818 return MYSQL_CONNECTION_LOST;
02819 };
02820
02821 case MYSQL_RECONNECTION_FAILED:
02822 {
02823 if (mysql_info->debug > 1)
02824 {
02825 pk_syslog (mysql_info->log_file,
02826 "[DEBUG] [%s,%d] SQL '%s' reconnection failed",
02827 __FILE__, __LINE__, sql);
02828 }
02829 return MYSQL_RECONNECTION_FAILED;
02830 };
02831
02832 case MYSQL_SQL_PROBLEM:
02833 {
02834 if (mysql_info->debug > 1)
02835 {
02836 pk_syslog (mysql_info->log_file,
02837 "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
02838 __FILE__, __LINE__, sql);
02839 }
02840 return MYSQL_SQL_PROBLEM;
02841 };
02842
02843 case MYSQL_UNEXPECTED_ERROR:
02844 {
02845 if (mysql_info->debug > 1)
02846 {
02847 pk_syslog (mysql_info->log_file,
02848 "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
02849 __FILE__, __LINE__, sql);
02850 }
02851 return MYSQL_UNEXPECTED_ERROR;
02852 };
02853
02854 default:
02855 {
02856 if (mysql_info->debug > 1)
02857 {
02858 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' OK",
02859 __FILE__, __LINE__, sql);
02860 }
02861 };
02862 }
02863 }
02864
02865 if (mysql_info->debug > 1)
02866 {
02867 pk_syslog (mysql_info->log_file,
02868 "[DEBUG] [%s,%d] Ticket successfully sent to Radonline database",
02869 __FILE__, __LINE__);
02870 }
02871
02872
02873 return 0;
02874 }
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884 int mydns_init (struct smysql *mysql_info)
02885 {
02886 static char sql[SQL_REQUEST_SIZE], integer[32];
02887 int (*pk_syslog)(const char *file, const char * fmt,...);
02888 MYSQL_ROW row;
02889 unsigned long int *length;
02890 int n, e;
02891
02892
02893 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
02894 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
02895
02896 memset((void*)sql, 0, SQL_REQUEST_SIZE);
02897
02898 snprintf (sql, SQL_REQUEST_SIZE, "SELECT id FROM soa WHERE origin='user.'");
02899
02900 if (mysql_info->debug > 0)
02901 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
02902
02903
02904
02905
02906
02907 n = sql_select (mysql_info, sql);
02908
02909 switch (n)
02910 {
02911 case MYSQL_REQUEST_SKIPED:
02912 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped '%s'", __FILE__, __LINE__, sql);
02913 return 1;
02914 case MYSQL_CONNECTION_LOST:
02915 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Connection lost '%s'", __FILE__, __LINE__, sql);
02916 return 1;
02917 case MYSQL_RECONNECTION_FAILED:
02918 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect '%s'", __FILE__, __LINE__, sql);
02919 return 1;
02920 case MYSQL_SQL_PROBLEM:
02921 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error '%s'", __FILE__, __LINE__, sql);
02922 return 1;
02923 case MYSQL_UNEXPECTED_ERROR:
02924 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error '%s'", __FILE__, __LINE__, sql);
02925 return 1;
02926 case 0:
02927 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] '%s' => no result", __FILE__, __LINE__, sql);
02928 mysql_free_result(mysql_info->result);
02929 return 1;
02930 }
02931
02932 if (n != 1)
02933 {
02934 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one id from '%s'",
02935 __FILE__, __LINE__, sql);
02936 mysql_free_result(mysql_info->result);
02937 return 1;
02938 }
02939
02940
02941
02942
02943
02944 row = mysql_fetch_row (mysql_info->result);
02945 length = mysql_fetch_lengths (mysql_info->result);
02946
02947 if (mysql_info->debug > 1)
02948 { pk_syslog (mysql_info->log_file,
02949 "[DEBUG] [%s,%d] id[%d]",
02950 __FILE__, __LINE__, length[0]); }
02951
02952 memset ((void*)integer, 0, 32);
02953 memcpy ((void*)integer, (void*)row[0], (length[0] < 32) ? length[0] : 31);
02954 mydns_id = string2unsigned_int (integer, &e);
02955
02956 if (mysql_info->debug > 0)
02957 {
02958 pk_syslog (mysql_info->log_file, "[SQL RESULT] [%s,%d] [%s] => id=%u",
02959 __FILE__, __LINE__, sql, mydns_id);
02960 }
02961
02962 mysql_free_result(mysql_info->result);
02963 return 0;
02964 }
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992 int send_to_mydns (
02993 struct smysql *mysql_info,
02994 struct mysql_tables *mysql_tables,
02995 char *ip,
02996 int action,
02997 struct global_config *config)
02998 {
02999 static char sql[SQL_REQUEST_SIZE], mydns_login[MYDNS_LOGIN_SIZE];
03000 int (*pk_syslog)(const char *file, const char * fmt,...);
03001
03002
03003 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03004 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03005
03006 radius2mydns ((mysql_tables->abonnes).login_radius, mydns_login, MYDNS_LOGIN_SIZE);
03007
03008 if (mysql_info->debug > 1)
03009 {
03010 pk_syslog (mysql_info->log_file,
03011 "[DEBUG] [%s,%d] MYDNS UPDATE Radius login = '%s', MyDns login = '%s'",
03012 __FILE__, __LINE__, (mysql_tables->abonnes).login_radius, mydns_login);
03013 }
03014
03015 if (mysql_info->debug > 1)
03016 {
03017 if (action == MYDNS_START)
03018 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Inserting START ticket into MyDns %s -> %s",
03019 __FILE__, __LINE__, (mysql_tables->abonnes).login_radius, mydns_login); }
03020
03021 if (action == MYDNS_STOP)
03022 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Inserting STOP ticket into MyDns %s -> %s",
03023 __FILE__, __LINE__, (mysql_tables->abonnes).login_radius, mydns_login); }
03024 }
03025
03026
03027
03028
03029
03030 if (action == MYDNS_STOP)
03031 {
03032 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03033
03034 snprintf (sql,
03035 SQL_REQUEST_SIZE,
03036 "DELETE FROM rr_%u WHERE name='%s' AND zone='%u'",
03037 mydns_id,
03038 mydns_login,
03039 mydns_id);
03040
03041 if (mysql_info->debug > 0)
03042 {
03043 pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s",
03044 __FILE__, __LINE__, sql);
03045 }
03046
03047 switch (sql_delete (mysql_info, sql))
03048 {
03049 case MYSQL_REQUEST_SKIPED:
03050 {
03051 if (mysql_info->debug > 1)
03052 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' skiped", __FILE__, __LINE__, sql); }
03053 return MYSQL_REQUEST_SKIPED;
03054 };
03055
03056 case MYSQL_CONNECTION_LOST:
03057 {
03058 if (mysql_info->debug > 1)
03059 {
03060 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' connection lost",
03061 __FILE__, __LINE__, sql);
03062 }
03063 return MYSQL_CONNECTION_LOST;
03064 };
03065
03066 case MYSQL_RECONNECTION_FAILED:
03067 {
03068 if (mysql_info->debug > 1)
03069 {
03070 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' reconnection failed",
03071 __FILE__, __LINE__, sql);
03072 }
03073 return MYSQL_RECONNECTION_FAILED;
03074 };
03075
03076 case MYSQL_SQL_PROBLEM:
03077 {
03078 if (mysql_info->debug > 1)
03079 {
03080 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03081 __FILE__, __LINE__, sql);
03082 }
03083 return MYSQL_SQL_PROBLEM;
03084 };
03085
03086 case MYSQL_UNEXPECTED_ERROR:
03087 {
03088 if (mysql_info->debug > 1)
03089 {
03090 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03091 __FILE__, __LINE__, sql);
03092 }
03093 return MYSQL_UNEXPECTED_ERROR;
03094 };
03095
03096 default:
03097 {
03098 if (mysql_info->debug > 1)
03099 {
03100 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' OK",
03101 __FILE__, __LINE__, sql);
03102 }
03103 };
03104 }
03105 }
03106
03107
03108
03109
03110
03111
03112 if (action == MYDNS_START)
03113 {
03114 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03115
03116 snprintf (sql,
03117 SQL_REQUEST_SIZE,
03118 "REPLACE INTO rr_%u (zone, name, type, data) VALUES ('%u', '%s', 'A', '%s')",
03119 mydns_id,
03120 mydns_id,
03121 mydns_login,
03122 ip);
03123
03124 if (mysql_info->debug > 0)
03125 {
03126 pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s",
03127 __FILE__, __LINE__, sql);
03128 }
03129
03130 switch (sql_insert (mysql_info, sql))
03131 {
03132 case MYSQL_REQUEST_SKIPED:
03133 {
03134 if (mysql_info->debug > 1)
03135 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' skiped", __FILE__, __LINE__, sql); }
03136 return MYSQL_REQUEST_SKIPED;
03137 };
03138
03139 case MYSQL_CONNECTION_LOST:
03140 {
03141 if (mysql_info->debug > 1)
03142 {
03143 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' connection lost",
03144 __FILE__, __LINE__, sql);
03145 }
03146 return MYSQL_CONNECTION_LOST;
03147 };
03148
03149 case MYSQL_RECONNECTION_FAILED:
03150 {
03151 if (mysql_info->debug > 1)
03152 {
03153 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' reconnection failed",
03154 __FILE__, __LINE__, sql);
03155 }
03156 return MYSQL_RECONNECTION_FAILED;
03157 };
03158
03159 case MYSQL_SQL_PROBLEM:
03160 {
03161 if (mysql_info->debug > 1)
03162 {
03163 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03164 __FILE__, __LINE__, sql);
03165 }
03166 return MYSQL_SQL_PROBLEM;
03167 };
03168
03169 case MYSQL_UNEXPECTED_ERROR:
03170 {
03171 if (mysql_info->debug > 1)
03172 {
03173 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03174 __FILE__, __LINE__, sql);
03175 }
03176 return MYSQL_UNEXPECTED_ERROR;
03177 };
03178
03179 default:
03180 {
03181 if (mysql_info->debug > 1)
03182 {
03183 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' OK",
03184 __FILE__, __LINE__, sql);
03185 }
03186 };
03187 }
03188 }
03189
03190 if (mysql_info->debug > 1)
03191 {
03192 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Ticket successfully sent to MyDns database",
03193 __FILE__, __LINE__);
03194 }
03195
03196 return 0;
03197 }
03198
03199
03200
03201
03202
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219
03220
03221
03222
03223
03224
03225
03226
03227 int load_logistic (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
03228 {
03229 static char sql[SQL_REQUEST_SIZE], integer1[32];
03230 int (*pk_syslog)(const char *file, const char * fmt,...);
03231 int n, e;
03232 MYSQL_ROW row;
03233 unsigned long int *length;
03234
03235
03236
03237 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03238 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03239
03240
03241
03242
03243
03244 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03245
03246 snprintf (sql,
03247 SQL_REQUEST_SIZE,
03248 "SELECT RADIUS_LOGIN, FLAG_CHECK_RADIUS FROM LOGISTIC_RADIUS WHERE LOGIN_MODEM='%s'",
03249 mysql_tables->logistic.LOGIN_MODEM);
03250
03251 if (mysql_info->debug > 0)
03252 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03253
03254
03255
03256
03257
03258 n = sql_select (mysql_info, sql);
03259
03260 switch (n)
03261 {
03262 case MYSQL_REQUEST_SKIPED:
03263 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03264 return MYSQL_INTERFACE_REQUEST_SKIPED;
03265 case MYSQL_CONNECTION_LOST:
03266 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03267 return MYSQL_INTERFACE_CONNECTION_LOST;
03268 case MYSQL_RECONNECTION_FAILED:
03269 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03270 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03271 case MYSQL_SQL_PROBLEM:
03272 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03273 return MYSQL_INTERFACE_SQL_PROBLEM;
03274 case MYSQL_UNEXPECTED_ERROR:
03275 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03276 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03277 case 0:
03278 pk_syslog (mysql_info->log_file, "[INFO] [%s,%d] Can not find LOGIN_MODEM (%s) in database",
03279 __FILE__, __LINE__,
03280 mysql_tables->logistic.LOGIN_MODEM);
03281
03282 mysql_free_result(mysql_info->result);
03283 return MYSQL_INTERFACE_NOT_FOUND;
03284 }
03285
03286 if (n != 1)
03287 {
03288 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one record with LOGIN_MODEM (%s)",
03289 __FILE__, __LINE__,
03290 mysql_tables->logistic.LOGIN_MODEM);
03291
03292 mysql_free_result(mysql_info->result);
03293 return MYSQL_INTERFACE_MORE_THAN_ONE;
03294 }
03295
03296
03297
03298
03299
03300 row = mysql_fetch_row (mysql_info->result);
03301 length = mysql_fetch_lengths (mysql_info->result);
03302
03303 if (mysql_info->debug > 1)
03304 {
03305 pk_syslog (mysql_info->log_file,
03306 "[DEBUG] [%s,%d] RADIUS_LOGIN[%d], FLAG_CHECK_RADIUS[%d]",
03307 __FILE__, __LINE__,
03308 length[0],
03309 length[1]);
03310 }
03311
03312 memset ((void*)mysql_tables->logistic.RADIUS_LOGIN, 0, LOGISTIC_RADIUS_LOGIN_SIZE);
03313 memset ((void*)integer1, 0, 32);
03314
03315 memcpy ((void*)mysql_tables->logistic.RADIUS_LOGIN,
03316 (void*)row[0],
03317 (length[0] < LOGISTIC_RADIUS_LOGIN_SIZE) ? length[0] : LOGISTIC_RADIUS_LOGIN_SIZE-1);
03318
03319 memcpy ((void*)integer1, (void*)row[1],
03320 (length[1] < 32) ? length[1] : 31);
03321
03322 mysql_tables->logistic.FLAG_CHECK_RADIUS = string2unsigned_int (integer1, &e);
03323
03324 if (mysql_info->debug > 0)
03325 {
03326 pk_syslog (mysql_info->log_file,
03327 "[SQL RESULT] [%s,%d] [%s] => RADIUS_LOGIN='%s', FLAG_CHECK_RADIUS='%u'",
03328 __FILE__, __LINE__, sql,
03329 mysql_tables->logistic.RADIUS_LOGIN,
03330 mysql_tables->logistic.FLAG_CHECK_RADIUS);
03331 }
03332
03333 mysql_free_result(mysql_info->result);
03334
03335 return 0;
03336 }
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360 int blackhole_abonne (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
03361 {
03362 static char sql[SQL_REQUEST_SIZE];
03363 int (*pk_syslog)(const char *file, const char * fmt,...);
03364 int n;
03365
03366
03367
03368 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03369 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03370
03371
03372
03373
03374
03375 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03376
03377 snprintf (sql,
03378 SQL_REQUEST_SIZE,
03379 "UPDATE abonnes SET profile='autoconfblackhole', nack_flag='1' WHERE abonnes_id='%lu'",
03380 mysql_tables->abonnes.abonnes_id);
03381
03382 if (mysql_info->debug > 0)
03383 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03384
03385
03386
03387
03388
03389 n = sql_update (mysql_info, sql);
03390
03391 switch (n)
03392 {
03393 case MYSQL_REQUEST_SKIPED:
03394 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03395 return MYSQL_INTERFACE_REQUEST_SKIPED;
03396 case MYSQL_CONNECTION_LOST:
03397 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03398 return MYSQL_INTERFACE_CONNECTION_LOST;
03399 case MYSQL_RECONNECTION_FAILED:
03400 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03401 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03402 case MYSQL_SQL_PROBLEM:
03403 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03404 return MYSQL_INTERFACE_SQL_PROBLEM;
03405 case MYSQL_UNEXPECTED_ERROR:
03406 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03407 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03408 case 0:
03409 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found no record with abonnes_id='%lu'",
03410 __FILE__, __LINE__,
03411 mysql_tables->abonnes.abonnes_id);
03412
03413 return MYSQL_INTERFACE_NOT_FOUND;
03414 }
03415
03416 if (n > 1)
03417 {
03418 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one record with abonnes_id='%lu'",
03419 __FILE__, __LINE__,
03420 mysql_tables->abonnes.abonnes_id);
03421
03422 return MYSQL_INTERFACE_MORE_THAN_ONE;
03423 }
03424
03425 return 0;
03426 }
03427
03428
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448
03449 int remove_autoconf_bh (struct smysql *mysql_info, struct mysql_tables *mysql_tables, struct global_config *config)
03450 {
03451 static char sql[SQL_REQUEST_SIZE];
03452 int (*pk_syslog)(const char *file, const char * fmt,...);
03453 int n;
03454
03455
03456
03457 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03458 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03459
03460
03461
03462
03463
03464 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03465
03466 snprintf (sql,
03467 SQL_REQUEST_SIZE,
03468 "UPDATE abonnes SET profile='STANDARD', nack_flag='1' WHERE abonnes_id='%lu' AND profile='autoconfblackhole'",
03469 mysql_tables->abonnes.abonnes_id);
03470
03471 if (mysql_info->debug > 0)
03472 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03473
03474
03475
03476
03477
03478 n = sql_update (mysql_info, sql);
03479
03480 switch (n)
03481 {
03482 case MYSQL_REQUEST_SKIPED:
03483 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03484 return MYSQL_INTERFACE_REQUEST_SKIPED;
03485 case MYSQL_CONNECTION_LOST:
03486 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03487 return MYSQL_INTERFACE_CONNECTION_LOST;
03488 case MYSQL_RECONNECTION_FAILED:
03489 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03490 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03491 case MYSQL_SQL_PROBLEM:
03492 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03493 return MYSQL_INTERFACE_SQL_PROBLEM;
03494 case MYSQL_UNEXPECTED_ERROR:
03495 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03496 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03497 case 0:
03498 pk_syslog (mysql_info->log_file, "[INFO] [%s,%d] Found no record with abonnes_id='%lu' and profile='autoconfblackhole'",
03499 __FILE__, __LINE__,
03500 mysql_tables->abonnes.abonnes_id);
03501 break;
03502 }
03503
03504 if (n > 1)
03505 {
03506 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one record with abonnes_id='%lu' and profile='autoconfblackhole'",
03507 __FILE__, __LINE__,
03508 mysql_tables->abonnes.abonnes_id);
03509
03510 return MYSQL_INTERFACE_MORE_THAN_ONE;
03511 }
03512
03513 return 0;
03514 }
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538 int set_flag_check_radius (struct smysql *mysql_info,
03539 struct mysql_tables *mysql_tables,
03540 struct global_config *config)
03541 {
03542 static char sql[SQL_REQUEST_SIZE];
03543 int (*pk_syslog)(const char *file, const char * fmt,...);
03544 int n;
03545
03546
03547
03548 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03549 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03550
03551
03552
03553
03554
03555 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03556
03557 snprintf (sql,
03558 SQL_REQUEST_SIZE,
03559 "UPDATE LOGISTIC_RADIUS SET FLAG_CHECK_RADIUS='1' WHERE LOGIN_MODEM='%s'",
03560 mysql_tables->logistic.LOGIN_MODEM);
03561
03562 if (mysql_info->debug > 0)
03563 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03564
03565
03566
03567
03568
03569 n = sql_update (mysql_info, sql);
03570
03571 switch (n)
03572 {
03573 case MYSQL_REQUEST_SKIPED:
03574 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03575 return MYSQL_INTERFACE_REQUEST_SKIPED;
03576 case MYSQL_CONNECTION_LOST:
03577 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03578 return MYSQL_INTERFACE_CONNECTION_LOST;
03579 case MYSQL_RECONNECTION_FAILED:
03580 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03581 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03582 case MYSQL_SQL_PROBLEM:
03583 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03584 return MYSQL_INTERFACE_SQL_PROBLEM;
03585 case MYSQL_UNEXPECTED_ERROR:
03586 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03587 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03588 case 0:
03589 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found no record with LOGIN_MODEM='%s'",
03590 __FILE__, __LINE__,
03591 mysql_tables->logistic.LOGIN_MODEM);
03592
03593 return MYSQL_INTERFACE_NOT_FOUND;
03594 }
03595
03596 if (n > 1)
03597 {
03598 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one record with LOGIN_MODEM='%s'",
03599 __FILE__, __LINE__,
03600 mysql_tables->logistic.LOGIN_MODEM);
03601
03602 return MYSQL_INTERFACE_MORE_THAN_ONE;
03603 }
03604
03605 return 0;
03606 }
03607
03608
03609
03610
03611
03612
03613
03614
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625
03626
03627
03628
03629 int signal_unknown_mac_address (struct smysql *mysql_info,
03630 struct mysql_tables *mysql_tables,
03631 struct global_config *config)
03632 {
03633 static char sql[SQL_REQUEST_SIZE];
03634 int (*pk_syslog)(const char *file, const char * fmt,...);
03635 int n;
03636
03637
03638
03639 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03640 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650 #ifdef NOT_USED
03651
03652
03653
03654
03655
03656 if (mysql_info->debug > 1)
03657 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] Select from SQL_REQUEST_SIZE login modem '%s'",
03658 __FILE__, __LINE__, mysql_tables->logistic.LOGIN_MODEM); }
03659
03660 #ifdef USE_MAC_ADDRESS
03661 n = delete_mac_address_from_logistic (mysql_info,
03662 mysql_tables->logistic.MAC_ADDRESS,
03663 config);
03664 #else
03665 n = select_login_modem_from_logistic (mysql_info,
03666 mysql_tables->logistic.LOGIN_MODEM,
03667 config);
03668 #endif
03669
03670 switch (n)
03671 {
03672 case MYSQL_REQUEST_SKIPED:
03673 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03674 return MYSQL_INTERFACE_REQUEST_SKIPED;
03675 case MYSQL_CONNECTION_LOST:
03676 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03677 return MYSQL_INTERFACE_CONNECTION_LOST;
03678 case MYSQL_RECONNECTION_FAILED:
03679 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03680 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03681 case MYSQL_SQL_PROBLEM:
03682 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03683 return MYSQL_INTERFACE_SQL_PROBLEM;
03684 case MYSQL_UNEXPECTED_ERROR:
03685 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03686 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03687 }
03688
03689 #endif
03690
03691
03692
03693
03694
03695
03696 n = 0;
03697 if (!n)
03698 {
03699 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03700
03701 snprintf (sql,
03702 SQL_REQUEST_SIZE,
03703 "INSERT INTO LOGISTIC_RADIUS SET LOGIN_MODEM='%s', MAC_ADDRESS='%s', CODE_ACTION='DHCP', FLAG_CHECK_MODEM='0', FLAG_CHECK_RADIUS='0'",
03704 mysql_tables->logistic.LOGIN_MODEM,
03705 mysql_tables->logistic.MAC_ADDRESS);
03706
03707 if (mysql_info->debug > 0)
03708 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03709
03710
03711
03712
03713
03714 n = sql_insert (mysql_info, sql);
03715
03716 switch (n)
03717 {
03718 case MYSQL_REQUEST_SKIPED:
03719 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03720 return MYSQL_INTERFACE_REQUEST_SKIPED;
03721 case MYSQL_CONNECTION_LOST:
03722 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03723 return MYSQL_INTERFACE_CONNECTION_LOST;
03724 case MYSQL_RECONNECTION_FAILED:
03725 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03726 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03727 case MYSQL_SQL_PROBLEM:
03728 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03729 return MYSQL_INTERFACE_SQL_PROBLEM;
03730 case MYSQL_UNEXPECTED_ERROR:
03731 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03732 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03733 }
03734
03735 }
03736
03737 return 0;
03738 }
03739
03740
03741
03742
03743
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763 int nack_flag_abonne (struct smysql *mysql_info,
03764 struct mysql_tables *mysql_tables,
03765 struct global_config *config,
03766 unsigned long int new_value)
03767 {
03768 static char sql[SQL_REQUEST_SIZE];
03769 int (*pk_syslog)(const char *file, const char * fmt,...);
03770 int n;
03771
03772 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03773 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03774
03775
03776
03777
03778
03779 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03780
03781 snprintf (sql,
03782 SQL_REQUEST_SIZE,
03783 "UPDATE abonnes SET nack_flag='%lu' where abonnes_id='%lu'",
03784 new_value,
03785 mysql_tables->abonnes.abonnes_id);
03786
03787 if (mysql_info->debug > 0)
03788 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03789
03790
03791
03792
03793
03794 n = sql_update (mysql_info, sql);
03795
03796 switch (n)
03797 {
03798 case MYSQL_REQUEST_SKIPED:
03799 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
03800 return MYSQL_INTERFACE_REQUEST_SKIPED;
03801 case MYSQL_CONNECTION_LOST:
03802 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
03803 return MYSQL_INTERFACE_CONNECTION_LOST;
03804 case MYSQL_RECONNECTION_FAILED:
03805 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
03806 return MYSQL_INTERFACE_RECONNECTION_FAILED;
03807 case MYSQL_SQL_PROBLEM:
03808 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
03809 return MYSQL_INTERFACE_SQL_PROBLEM;
03810 case MYSQL_UNEXPECTED_ERROR:
03811 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
03812 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
03813 case 0:
03814 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found no record with abonnes_id='%lu'",
03815 __FILE__, __LINE__,
03816 mysql_tables->abonnes.abonnes_id);
03817
03818 return MYSQL_INTERFACE_NOT_FOUND;
03819 }
03820
03821 if (n > 1)
03822 {
03823 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Found more than one record with abonnes_id='%lu'",
03824 __FILE__, __LINE__,
03825 mysql_tables->abonnes.abonnes_id);
03826
03827 return MYSQL_INTERFACE_MORE_THAN_ONE;
03828 }
03829
03830 return 0;
03831 }
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846 #ifdef NOT_USED
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864
03865
03866 int delete_mac_address_from_logistic (
03867 struct smysql *mysql_info,
03868 char *mac_address,
03869 struct global_config *config)
03870 {
03871 static char sql[SQL_REQUEST_SIZE];
03872 int (*pk_syslog)(const char *file, const char * fmt,...), rc;
03873
03874 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03875 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03876
03877
03878
03879
03880
03881 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03882
03883 snprintf (sql,
03884 SQL_REQUEST_SIZE,
03885 "DELETE FROM LOGISTIC_RADIUS WHERE MAC_ADDRESS='%s'",
03886 mac_address);
03887
03888 if (mysql_info->debug > 0)
03889 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
03890
03891
03892
03893
03894
03895 rc = sql_delete (mysql_info, sql);
03896
03897 switch (rc)
03898 {
03899 case MYSQL_REQUEST_SKIPED:
03900 {
03901 if (mysql_info->debug > 1)
03902 { pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' skiped", __FILE__, __LINE__, sql); }
03903 return MYSQL_REQUEST_SKIPED;
03904 };
03905
03906 case MYSQL_CONNECTION_LOST:
03907 {
03908 if (mysql_info->debug > 1)
03909 {
03910 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' connection lost",
03911 __FILE__, __LINE__, sql);
03912 }
03913 return MYSQL_CONNECTION_LOST;
03914 };
03915
03916 case MYSQL_RECONNECTION_FAILED:
03917 {
03918 if (mysql_info->debug > 1)
03919 {
03920 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' reconnection failed",
03921 __FILE__, __LINE__, sql);
03922 }
03923 return MYSQL_RECONNECTION_FAILED;
03924 };
03925
03926 case MYSQL_SQL_PROBLEM:
03927 {
03928 if (mysql_info->debug > 1)
03929 {
03930 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03931 __FILE__, __LINE__, sql);
03932 }
03933 return MYSQL_SQL_PROBLEM;
03934 };
03935
03936 case MYSQL_UNEXPECTED_ERROR:
03937 {
03938 if (mysql_info->debug > 1)
03939 {
03940 pk_syslog (mysql_info->log_file, "[DEBUG] [%s,%d] SQL '%s' some SQL problem occured",
03941 __FILE__, __LINE__, sql);
03942 }
03943 return MYSQL_UNEXPECTED_ERROR;
03944 };
03945 }
03946
03947
03948
03949
03950
03951 if (rc > 0)
03952 {
03953 my_syslog (config->log_file,
03954 "[WARNING] [%s,%d] SQL '%s': Found (and deleted) %d record(s) with MAC_ADDRESS='%s' !",
03955 __FILE__, __LINE__, mac_address);
03956 return MYSQL_INTERFACE_MAC_ADDRESS_FOUND;
03957 }
03958
03959 return 0;
03960 }
03961
03962
03963
03964
03965
03966
03967
03968
03969
03970
03971
03972
03973
03974
03975
03976
03977
03978
03979
03980
03981
03982 int select_login_modem_from_logistic (
03983 struct smysql *mysql_info,
03984 char *login_modem,
03985 struct global_config *config)
03986 {
03987 static char sql[SQL_REQUEST_SIZE];
03988 int (*pk_syslog)(const char *file, const char * fmt,...), n;
03989
03990 if ((mysql_info->my_syslog != NULL) && (mysql_info->log_file[0] != 0))
03991 { pk_syslog = mysql_info->my_syslog; } else { pk_syslog = my_fake_syslog; }
03992
03993
03994
03995
03996
03997 memset ((void*)sql, 0, SQL_REQUEST_SIZE);
03998
03999 snprintf (sql,
04000 SQL_REQUEST_SIZE,
04001 "SELECT * FROM LOGISTIC_RADIUS WHERE LOGIN_MODEM='%s'",
04002 login_modem);
04003
04004 if (mysql_info->debug > 0)
04005 { pk_syslog (mysql_info->log_file, "[SQL] [%s,%d] %s", __FILE__, __LINE__, sql); }
04006
04007
04008
04009
04010
04011 n = sql_select (mysql_info, sql);
04012
04013 switch (n)
04014 {
04015 case MYSQL_REQUEST_SKIPED:
04016 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
04017 return MYSQL_INTERFACE_REQUEST_SKIPED;
04018 case MYSQL_CONNECTION_LOST:
04019 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
04020 return MYSQL_INTERFACE_CONNECTION_LOST;
04021 case MYSQL_RECONNECTION_FAILED:
04022 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
04023 return MYSQL_INTERFACE_RECONNECTION_FAILED;
04024 case MYSQL_SQL_PROBLEM:
04025 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
04026 return MYSQL_INTERFACE_SQL_PROBLEM;
04027 case MYSQL_UNEXPECTED_ERROR:
04028 pk_syslog (mysql_info->log_file, "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
04029 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
04030 case 0:
04031 pk_syslog (mysql_info->log_file, "[WARNING] [%s,%d] Can not find login_modem (%s) in database",
04032 __FILE__, __LINE__,
04033 login_modem);
04034 break;
04035 }
04036
04037 mysql_free_result(mysql_info->result);
04038 return n;
04039 }
04040
04041 #endif
04042
04043