Модули apache - Веб- разработки - Форумы. КАБi. NET. Добавил Basic авторизацию к модулю.#include "httpd. Template. Dictionary; using google: :Template; static PGconn *conn = NULL; static Template *index_tpl = NULL; const char *conninfo = "dbname=squid user=stat password=cnfnnb"; unsigned char alphabet[6. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. Template: :Get. Template("index.
Модули Для Apache Под Windows
DO_NOT_STRIP); google: :STRIP_WHITESPACE); }static void my_fini(){delete index_tpl; PQfinish(conn); }// AP_DECLARE_DATA module echo_module; /* here's the content handler */voidfill_index_dictionary(Template. Dictionary *dict, char *login, request_rec *r){ char *monthes[] = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь","Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"}; const char *Param. Values[1]; static int count = 0; Param. Values[0] = login; PGresult *res; if (! PQconnectdb(conninfo); count++; } /* Check to see that the backend connection was successfully made */if (PQstatus(conn) != CONNECTION_OK){cerr < < "Connection to database failed: " < < PQerror. Message(conn)< < endl; PQfinish(conn); return; } res = PQexec. Params(conn,"SELECT ""EXTRACT(YEAR FROM \"Time\") AS year, ""EXTRACT(MONTH FROM \"Time\") AS month, ""SUM(\"Bytes\") FROM \"Log\" WHERE \"User\" = $1 ""GROUP BY year, month ORDER BY year, month ASC",1,NULL,Param.
Values,NULL,NULL,0); if (PQresult. Status(res) != PGRES_TUPLES_OK){cerr < < "SELECT failed: " < < PQerror. Message(conn) < < endl; PQclear(res); PQfinish(conn); return; }// fill_user_dictionary(dict- > Add. Include. Dictionary(ki_USER), user_stmt, login); // fill_ip_dictionary(dict- > Add. Include. Dictionary(ki_BY_IP), ip_stmt, login); int i; int cur_year = 0; int parity = 0; for (i = 0; i < PQntuples(res); i++) {Template.
Apache модуль для ограничения числа соединений с одного IP адреса. Позволяет вводить ограничения в зависимости от директории и MIME типа. Это создаст библиотеку libphp4.so для Apache, а также библиотеку pgsql.so, которая Один - для использования двоичного CGI (php.exe), другой - для использования Apache-модуля DLL. Новый API для Apache 2.0 позволяет модулям самим указывать порядок их загрузки, что делает эти директивы ненужными.
Dictionary *month_row_dict = dict- > Add. Section. Dictionary(ki_MONTH_ROW); if (cur_year != atoi(PQgetvalue(res, i, 0))) { //Yearcur_year = atoi(PQgetvalue(res, i, 0)); //Year. Template. Dictionary *cur_year_dict =month_row_dict- > Add. Section. Dictionary(ki_CUR_YEAR); cur_year_dict- > Set.
Apache HTTP-сервер — свободный веб-сервер. Apache является кроссплатформенным ПО, поддерживает операционные системы Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare, BeOS. Основными достоинствами Apache считаются надёжность и гибкость конфигурации. Первое, с чем сталкивается разработчик-новичок, никогда не сталкивавшийся с написанием модулей для Apache, это вопрос — «С чего же начать?».. Новый API для Apache. Модули Apache теперь можно написать так, что они будут исполнять роль фильтров, обрабатывающих потоки данных, которые приходят или уходят из сервера. Первое, с чем сталкивается разработчик-новичок, никогда не сталкивавшийся с написанием модулей для Apache, это вопрос — «С чего.
Int. Value(ki_YEAR,atoi(PQgetvalue(res, i, 0))); //Yearmonth_row_dict- > Show. Section(ki_CUR_YEAR); parity = 0; }if (parity)month_row_dict- > Set.
Value(ki_PARITY, "odd"); elsemonth_row_dict- > Set. Value(ki_PARITY, "even"); parity = 1 - parity; month_row_dict- > Set. Int. Value(ki_YEAR,atoi(PQgetvalue(res, i, 0))); //Yearmonth_row_dict- > Set. Int. Value(ki_MONTH,atoi(PQgetvalue(res, i, 1))); //Monthmonth_row_dict- > Set. Value(ki_MONTH_NAME,monthes[atoi(PQgetvalue(res, i, 1))- 1]); //Monthmonth_row_dict- > Set.
Formatted. Value(ki_TRAFFIC, "%. PQgetvalue(res, i, 2))/1. Trafdict- > Show. Section(ki_MONTH_ROW); } PQclear(res); //PQfinish(conn); dict- > Set. Int. Value(ki_COUNT, count); if (r- > path_info & & strlen(r- > path_info) > 0)dict- > Set. Value(ki_PATH_INFO, r- > path_info); if (r- > user & & strlen(r- > user) > 0)dict- > Set.
Value(ki_QUERY_STRING, r- > user); }voidoutput_index(request_rec *r){Template. Dictionary dict("index"); fill_index_dictionary(& dict, "admin", r); if (index_tpl) {string output; index_tpl- > Expand(& output, & dict); ap_rprintf(r, "%s", output. PATH_MAX]; if (getcwd(path, PATH_MAX))ap_rprintf(r, "Missing template files in: %s", path); elseap_rputs("Missing template files and could not get ""current directory", r); }}/*voidoutput_month(request_rec *r){Template. Dictionary dict("month"); //fill_month_dictionary(& dict, "admin", r); if (tpl) {string output; tpl- > Expand(& output, & dict); ap_rprintf(r, "%s", output. PATH_MAX]; if (getcwd(path, PATH_MAX))ap_rprintf(r, "Missing template files in: %s", path); elseap_rputs("Missing template files and could not get ""current directory", r); }}voidoutput_day(request_rec *r){}*/booltest_auth(const char *p){int i; PGresult *res; const char *Param. Values[1]; if ((p = strstr(p, " ")) == NULL) return false; p++; if (strlen(p) == 0) return false; /* in base.
NULL) {free(login); return false; }*pass++ = '\0'; Param. Values[0] = login; if (! PQconnectdb(conninfo); } /* Check to see that the backend connection was successfully made */if (PQstatus(conn) != CONNECTION_OK){cerr < < "Connection to database failed: " < < PQerror. Message(conn)< < endl; PQfinish(conn); free(login); return false; } res = PQexec. Params(conn,"SELECT \"Password\" FROM \"User\" ""WHERE \"Login\" = $1 ",1,NULL,Param. Values,NULL,NULL,0); if (PQresult. Status(res) != PGRES_TUPLES_OK){cerr < < "SELECT AUTH failed: " < < PQerror.
Message(conn) < < endl; PQclear(res); PQfinish(conn); free(login); return false; }for (i = 0; i < PQntuples(res); i++) {if (! PQgetvalue(res, i, 0))) {free(login); return true; }}PQclear(res); free(login); return false; }static intstat_handler(request_rec *r){if (strcmp(r- > handler, "stat")) return DECLINED; r- > content_type = "text/html"; if (r- > header_only) return OK; if (r- > path_info & & strlen(r- > path_info) > 0) {if (!
OK; }if (! strcmp(r- > path_info, "/day")) {//output_day(r); return OK; }}const char *buf; const char *auth = "Authorization"; if ((buf = apr_table_get(r- > headers_in, auth))) {if (test_auth(buf)) {output_index(r); return OK; }}const char *auth_type = "Basic realm=\"Trala\""; const char *auth_head = "WWW- Authenticate"; apr_table_set(r- > err_headers_out, auth_head, auth_type); return HTTP_UNAUTHORIZED; }static void register_hooks(apr_pool_t *p) {ap_hook_handler(stat_handler, NULL, NULL, APR_HOOK_MIDDLE); }/* Tell Apache what phases of the transaction we handle */module AP_MODULE_DECLARE_DATA stat_module ={STANDARD2. MODULE_STUFF,NULL, /* create per- directory config structure */NULL, /* merge per- directory config structures */NULL, /* create per- server config structure */NULL, /* merge per- server config structures */NULL, /* command apr_table_t */register_hooks /* register hooks */}.