2 * ws protocol handler plugin for "generic sessions"
4 * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation:
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 #include "../lib/libwebsockets.h"
29 #define LWSGS_VERIFIED_ACCEPTED 100
59 time_t last_forgot_validated;
64 struct per_vhost_data__gs {
65 struct lws_email email;
66 struct lws_context *context;
70 char email_contact_person[128];
71 char email_title[128];
72 char email_template[128];
73 char email_confirm_url[128];
74 lwsgw_hash admin_password_sha1;
76 int timeout_idle_secs;
77 int timeout_absolute_secs;
78 int timeout_anon_absolute_secs;
79 int timeout_email_secs;
80 time_t last_session_expire;
84 struct per_session_data__gs {
86 lwsgw_hash login_session;
87 lwsgw_hash delete_session;
88 unsigned int login_expires;
90 char result[500 + LWS_PRE];
91 char urldec[500 + LWS_PRE];
94 struct lws_process_html_state phs;
97 unsigned int logging_out:1;
103 lwsgs_lookup_callback_user(void *priv, int cols, char **col_val,
106 lwsgw_cookie_from_session(lwsgw_hash *sid, time_t expires, char **p, char *end);
108 lwsgs_get_sid_from_wsi(struct lws *wsi, lwsgw_hash *sid);
110 lwsgs_lookup_session(struct per_vhost_data__gs *vhd,
111 const lwsgw_hash *sid, char *username, int len);
113 lwsgs_get_auth_level(struct per_vhost_data__gs *vhd,
114 const char *username);
116 lwsgs_check_credentials(struct per_vhost_data__gs *vhd,
117 const char *username, const char *password);
119 sha1_to_lwsgw_hash(unsigned char *hash, lwsgw_hash *shash);
121 lwsgs_now_secs(void);
123 lwsgw_check_admin(struct per_vhost_data__gs *vhd,
124 const char *username, const char *password);
126 lwsgs_hash_password(struct per_vhost_data__gs *vhd,
127 const char *password, struct lwsgs_user *u);
129 lwsgs_new_session_id(struct per_vhost_data__gs *vhd,
130 lwsgw_hash *sid, const char *username, int exp);
132 lwsgs_lookup_user(struct per_vhost_data__gs *vhd,
133 const char *username, struct lwsgs_user *u);
135 lwsgw_update_session(struct per_vhost_data__gs *vhd,
136 lwsgw_hash *hash, const char *user);
138 lwsgw_expire_old_sessions(struct per_vhost_data__gs *vhd);
144 lwsgs_handler_confirm(struct per_vhost_data__gs *vhd, struct lws *wsi,
145 struct per_session_data__gs *pss);
147 lwsgs_handler_forgot(struct per_vhost_data__gs *vhd, struct lws *wsi,
148 struct per_session_data__gs *pss);
150 lwsgs_handler_check(struct per_vhost_data__gs *vhd, struct lws *wsi,
151 struct per_session_data__gs *pss);
153 lwsgs_handler_change_password(struct per_vhost_data__gs *vhd, struct lws *wsi,
154 struct per_session_data__gs *pss);
156 lwsgs_handler_forgot_pw_form(struct per_vhost_data__gs *vhd, struct lws *wsi,
157 struct per_session_data__gs *pss);
159 lwsgs_handler_register_form(struct per_vhost_data__gs *vhd, struct lws *wsi,
160 struct per_session_data__gs *pss);