Integrate 0.9.3 SLP/IP, SQLite identities and complete token fix; build release 0.9.3-1
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
#include "core.h"
|
||||
#include "supervisor.h"
|
||||
#include "admin.h"
|
||||
#include "directory.h"
|
||||
#include "identity_api.h"
|
||||
#include "../src/gateway.h"
|
||||
#include "../src/ncp_ip.h"
|
||||
#include "gateway_auto.h"
|
||||
#include <civetweb.h>
|
||||
#include <pthread.h>
|
||||
@@ -56,6 +59,21 @@ static char *comparison(const char*a,const char*b){if(!strcmp(a,b))return strdup
|
||||
static int confirm(json_object*r){json_object*v=get(r,"confirm");return json_object_is_type(v,json_type_boolean)&&json_object_get_boolean(v);}
|
||||
static int config_valid(const char*s){json_object*v=validate(s);int ok=json_object_array_length(get(v,"errors"))==0;json_object_put(v);return ok;}
|
||||
/* Gateway configuration is independent of nwserv.conf, but references its saved IPX network. */
|
||||
/* NCP/IP settings are separate from the IPX gateway; only admin may change them. */
|
||||
static int ncp_ip_api(struct mg_connection*c,int post,json_object*req){
|
||||
if(auth_default()||no_services)return error(c,403,"Zuerst MARS einrichten und Web-Kennwort ändern.");
|
||||
char *old=read_file(NCP_IP_CONFIG,4096,1);int missing=!old&&errno==ENOENT;
|
||||
if(missing)old=strdup("{\"enabled\":false,\"address\":\"\"}");
|
||||
if(!old)return error(c,500,"TCP/IP-Konfiguration nicht lesbar. Dateirechte prüfen.");
|
||||
char rev[65];sha(old,rev);struct json_tokener *tok=json_tokener_new();json_object *cfg=NULL;size_t oldlen=strlen(old);if(tok){json_tokener_set_flags(tok,JSON_TOKENER_STRICT);cfg=json_tokener_parse_ex(tok,old,(int)oldlen);if(json_tokener_get_error(tok)!=json_tokener_success||json_tokener_get_parse_end(tok)!=oldlen){json_object_put(cfg);cfg=NULL;}json_tokener_free(tok);}free(old);
|
||||
uint32_t addr,mask;int valid=ncp_ip_config(cfg,&addr,&mask);
|
||||
if(post){const char *r=js(req,"revision");if(!r||strcmp(r,rev)){json_object_put(cfg);return error(c,409,"Konfiguration wurde geändert. Neu laden.");}
|
||||
json_object *next=get(req,"config");if(!confirm(req)||ncp_ip_config(next,&addr,&mask)<0){json_object_put(cfg);return error(c,400,"Eine vorhandene private IPv4-Adresse auswählen und bestätigen.");}
|
||||
json_object *save=json_object_new_object();json_object_object_add(save,"enabled",json_object_new_boolean(json_object_get_boolean(get(next,"enabled"))));addstr(save,"address",js(next,"address")?js(next,"address"):"");json_object_object_add(save,"slp",json_object_new_boolean(json_object_get_boolean(get(next,"slp"))));
|
||||
const char *str=json_object_to_json_string_ext(save,JSON_C_TO_STRING_PLAIN);int rc=atomic_write(NCP_IP_CONFIG,str,strlen(str),0600);json_object_put(save);json_object_put(cfg);if(rc)return error(c,500,"TCP/IP-Einstellung konnte nicht gespeichert werden.");return ok(c,NULL);
|
||||
}
|
||||
json_object *out=json_object_new_object();json_object_object_add(out,"config",cfg?cfg:json_object_new_object());addstr(out,"revision",rev);json_object_object_add(out,"valid",json_object_new_boolean(valid>=0));json_object_object_add(out,"addresses",ncp_ip_addresses());json_object_object_add(out,"port",json_object_new_int(NCP_TCP_PORT));json_object_object_add(out,"nativeNds",json_object_new_boolean(0));char *runtime=read_file(NCP_IP_STATUS,1024,1);struct stat rst;int fresh=runtime&&!stat(NCP_IP_STATUS,&rst)&&time(NULL)>=rst.st_mtime&&time(NULL)-rst.st_mtime<5;addstr(out,"runtime",fresh?runtime:"Kein aktueller TCP/IP-Status. NetWare starten bzw. neu starten.");free(runtime);return reply(c,200,out,NULL);
|
||||
}
|
||||
static int gateway_network_exists(uint32_t net){char*conf=read_file(config_path,MAX_CONF,0);if(!conf)return 0;json_object*g=groups(conf);free(conf);json_object*a=get(g,"4");int found=0;for(size_t i=0;i<json_object_array_length(a);i++){const char*s=json_object_get_string(json_object_array_get_idx(a,i));char *end;unsigned long n=strtoul(s,&end,0);if(end!=s&&(*end==' '||*end=='\t')&&n==ntohl(net)){found=1;break;}}json_object_put(g);return found;}
|
||||
static int gateway_api(struct mg_connection*c,int post,json_object*req,int detect){
|
||||
if(auth_default()||no_services)return error(c,403,"Gateway nur im eingerichteten Dienstmodus verfügbar.");
|
||||
@@ -176,12 +194,28 @@ static int process(struct mg_connection*c,const struct mg_request_info*r,json_ob
|
||||
if(access(p,R_OK))return error(c,404,"Browser-Quellpaket noch nicht installiert.");
|
||||
mg_send_file(c,p);return 200;
|
||||
}
|
||||
if(!strcmp(u,"/api/identities")){
|
||||
if(auth_default()||no_services)return error(c,403,"Eingerichteter Dienstmodus erforderlich.");
|
||||
if(!post)return reply(c,200,identity_status(),NULL);
|
||||
if(!confirm(req)||!js(req,"op")||strcmp(js(req,"op"),"create"))return error(c,400,"Bestätigte Benutzeranlage erforderlich.");
|
||||
json_object *out=identity_create(req);return reply(c,get(out,"error")?400:200,out,NULL);
|
||||
}
|
||||
if(!strcmp(u,"/api/directory")){
|
||||
if(auth_default())return error(c,403,"Zuerst das Web-Kennwort ändern.");
|
||||
char path[PATH_MAX],rev[65];int configured;
|
||||
if(snprintf(path,sizeof path,"%s.directory.json",config_path)>=(int)sizeof path)return error(c,500,"Verzeichnispfad zu lang.");
|
||||
json_object *dir=directory_read(path,rev,&configured);if(!dir)return error(c,500,"Verzeichnisdatei ungültig oder nicht lesbar. Sicherung prüfen.");
|
||||
if(post){json_object *next=get(req,"config");json_object *errs=directory_validate(next);if(json_object_array_length(errs)){json_object *o=json_object_new_object();addstr(o,"error","Verzeichnisentwurf ungültig.");json_object_object_add(o,"errors",errs);json_object_put(dir);return reply(c,400,o,NULL);}json_object_put(errs);
|
||||
int rc=confirm(req)?directory_save(path,next,js(req,"revision")):-3;json_object_put(dir);if(rc)return error(c,rc==-2?409:rc==-3?400:500,rc==-2?"Verzeichnis wurde inzwischen geändert. Neu laden.":"Verzeichnis konnte nicht gespeichert werden; Entwurf und Bestätigung prüfen.");return ok(c,NULL);}
|
||||
char *conf=read_file(config_path,MAX_CONF,0);if(!conf){json_object_put(dir);return error(c,500,"nwserv.conf nicht lesbar.");}json_object *query=json_object_new_object();addstr(query,"op","objects");json_object *live=no_services?NULL:bindery_call(query);json_object_put(query);json_object *o=directory_report(conf,dir,live,!no_services&&supervisor_config_matches());free(conf);json_object_put(live);json_object_object_add(o,"config",dir);addstr(o,"revision",rev);json_object_object_add(o,"configured",json_object_new_boolean(configured));json_object_object_add(o,"status",supervisor_status());return reply(c,200,o,NULL);
|
||||
}
|
||||
if(!strcmp(u,"/api/browser"))return browser_api(c,post,req);
|
||||
if(!strcmp(u,"/api/ncp-ip"))return ncp_ip_api(c,post,req);
|
||||
if(!strcmp(u,"/api/gateway"))return gateway_api(c,post,req,0);
|
||||
if(!post&&!strcmp(u,"/api/gateway/detect"))return gateway_api(c,0,NULL,1);
|
||||
if(!post&&!strcmp(u,"/api/status"))return reply(c,200,supervisor_status(),NULL);
|
||||
if(!post&&!strcmp(u,"/api/monitor")){if(auth_default())return error(c,403,"Kennwort ändern.");return reply(c,200,monitor_data(),NULL);}
|
||||
if(!strcmp(u,"/api/bindery")||!strcmp(u,"/api/print")){if(auth_default()||no_services)return error(c,403,"Kennwort ändern oder Dienstmodus verwenden.");if(!post)return error(c,405,"POST erforderlich.");const char *op=js(req,"op");if(!op)return error(c,400,"Aktion fehlt.");if(!strncmp(op,"trustee-",8)&&!supervisor_config_matches())return error(c,409,"Konfiguration seit Serverstart geändert. Dateiserver neu starten.");int readonly=!strcmp(op,"sessions")||!strcmp(op,"objects")||!strcmp(op,"properties")||!strcmp(op,"list")||!strcmp(op,"script-get")||!strcmp(op,"trustee-get")||!strcmp(op,"group-members");if(!readonly&&!confirm(req))return error(c,400,"Aktion bestätigen.");json_object *res=!strcmp(u,"/api/bindery")?bindery_call(req):print_call(req);return reply(c,get(res,"error")?400:200,res,NULL);}
|
||||
if(!strcmp(u,"/api/bindery")||!strcmp(u,"/api/print")){if(auth_default()||no_services)return error(c,403,"Kennwort ändern oder Dienstmodus verwenden.");if(!post)return error(c,405,"POST erforderlich.");const char *op=js(req,"op");if(!op)return error(c,400,"Aktion fehlt.");const char *unixname=js(req,"unix");if(!strcmp(u,"/api/bindery")&&unixname&&!strncmp(unixname,"marsv",5)&&(!strcmp(op,"create-user")||!strcmp(op,"map-user")))return error(c,400,"Reservierte SQLite-Identitäten nur über die geführte Benutzeranlage verwenden.");if(!strncmp(op,"trustee-",8)&&!supervisor_config_matches())return error(c,409,"Konfiguration seit Serverstart geändert. Dateiserver neu starten.");int readonly=!strcmp(op,"sessions")||!strcmp(op,"objects")||!strcmp(op,"properties")||!strcmp(op,"list")||!strcmp(op,"script-get")||!strcmp(op,"trustee-get")||!strcmp(op,"group-members");if(!readonly&&!confirm(req))return error(c,400,"Aktion bestätigen.");json_object *res=!strcmp(u,"/api/bindery")?bindery_call(req):print_call(req);return reply(c,get(res,"error")?400:200,res,NULL);}
|
||||
char*current=read_file(config_path,MAX_CONF,0);if(!current)return error(c,500,"nwserv.conf nicht lesbar.");char rev[65];sha(current,rev);int ret=404;
|
||||
if(!post&&!strcmp(u,"/api/state")){ret=reply(c,200,state(s,current),NULL);goto done;}if(!post&&!strcmp(u,"/api/download")){if(auth_default())ret=error(c,403,"Kennwort ändern.");else ret=send_data(c,200,"text/plain; charset=utf-8",current,strlen(current),NULL,NULL);goto done;}
|
||||
if(!post){ret=error(c,404,"Nicht gefunden.");goto done;}const char*given=js(req,"revision");if(!given||strcmp(given,rev)){ret=error(c,409,"Konfiguration geändert. Bitte neu laden.");goto done;}
|
||||
|
||||
Reference in New Issue
Block a user