Changeset 4129


Ignore:
Timestamp:
12/16/10 21:34:13 (12 years ago)
Author:
alno
Message:

XMLAPI: implementation of API call for statuspage. It's just to have a base for discussion with App developers (IPhone, Android, STB Plugins). Call the API with http://<Oscam IP>/oscamapi.html?part=status The API uses the normal WebIF way and the same credenticals as well as SSL if enabled.
Please test and join the discussion for requests and suggestions: http://streamboard.gmc.to/wbb2/thread.php?postid=362448#post362448

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http.c

    r4128 r4129  
    18011801}
    18021802
    1803 void send_oscam_status(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
     1803void send_oscam_status(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in, int apicall) {
    18041804    int i;
    18051805    char *usr;
     
    20602060            }
    20612061
    2062             // select right suborder
    2063             if (cl->typ == 'c') {
    2064                 tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
    2065                 tpl_printf(vars, 0, "CLIENTHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Clients %d/%d</TD></TR>\n",
    2066                     user_count_active, user_count_all);
    2067             }
    2068             else if (cl->typ == 'r') {
    2069                 tpl_addVar(vars, 1, "READERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
    2070                 tpl_printf(vars, 0, "READERHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Readers %d/%d</TD></TR>\n",
    2071                     reader_count_active, reader_count_all);
    2072             }
    2073             else if (cl->typ == 'p') {
    2074                 tpl_addVar(vars, 1, "PROXYSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
    2075                 tpl_printf(vars, 0, "PROXYHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Proxies %d/%d</TD></TR>\n",
    2076                     proxy_count_active, proxy_count_all);
    2077             }
    2078             else
    2079                 tpl_addVar(vars, 1, "SERVERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
     2062            if (!apicall){
     2063                // select right suborder
     2064                if (cl->typ == 'c') {
     2065                    tpl_addVar(vars, 1, "CLIENTSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
     2066                    tpl_printf(vars, 0, "CLIENTHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Clients %d/%d</TD></TR>\n",
     2067                            user_count_active, user_count_all);
     2068                }
     2069                else if (cl->typ == 'r') {
     2070                    tpl_addVar(vars, 1, "READERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
     2071                    tpl_printf(vars, 0, "READERHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Readers %d/%d</TD></TR>\n",
     2072                            reader_count_active, reader_count_all);
     2073                }
     2074                else if (cl->typ == 'p') {
     2075                    tpl_addVar(vars, 1, "PROXYSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
     2076                    tpl_printf(vars, 0, "PROXYHEADLINE", "<TR><TD CLASS=\"subheadline\" colspan=\"17\">Proxies %d/%d</TD></TR>\n",
     2077                            proxy_count_active, proxy_count_all);
     2078                }
     2079                else
     2080                    tpl_addVar(vars, 1, "SERVERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT"));
     2081
     2082            } else {
     2083                tpl_addVar(vars, 1, "APISTATUSBITS", tpl_getTpl(vars, "APISTATUSBIT"));
     2084            }
    20802085
    20812086        }
     
    20972102        p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
    20982103        p_txt=p_usr+32;
    2099         if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "<span class=\"%s\">%s</span><br>\n", p_usr, p_txt+8);
     2104
     2105        if (!apicall) {
     2106            if (p_txt[0]) tpl_printf(vars, 1, "LOGHISTORY", "<span class=\"%s\">%s</span><br>\n", p_usr, p_txt+8);
     2107        } else {
     2108            tpl_printf(vars, 1, "LOGHISTORY", "%s", p_txt+8);
     2109        }
    21002110    }
    21012111#else
     
    21082118    tpl_addVar(vars, 0, "SDEBUG", tpl_getTpl(vars, "DEBUGSELECT"));
    21092119
    2110     webif_write(tpl_getTpl(vars, "STATUS"), f);
     2120    if(!apicall)
     2121        webif_write(tpl_getTpl(vars, "STATUS"), f);
     2122    else
     2123        webif_write(tpl_getTpl(vars, "APISTATUS"), f);
     2124
    21112125}
    21122126
     
    25372551
    25382552    webif_write(tpl_getTpl(vars, "FAILBAN"), f);
     2553}
     2554
     2555void send_oscam_api(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
     2556    if (strcmp(getParam(params, "part"), "status") == 0) {
     2557        send_oscam_status(vars, f, params, in, 1);
     2558    }
    25392559}
    25402560
     
    26312651        "/readerstats.html",
    26322652        "/failban.html",
    2633         "/oscam.js"};
     2653        "/oscam.js",
     2654        "/oscamapi.html"};
    26342655
    26352656    int pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array
     
    27752796            case 1: send_oscam_reader(vars, f, &params, in); break;
    27762797            case 2: send_oscam_entitlement(vars, f, &params); break;
    2777             case 3: send_oscam_status(vars, f, &params, in); break;
     2798            case 3: send_oscam_status(vars, f, &params, in, 0); break;
    27782799            case 4: send_oscam_user_config(vars, f, &params, in); break;
    27792800            case 5: send_oscam_reader_config(vars, f, &params, in); break;
     
    27892810            case 15: send_oscam_reader_stats(vars, f, &params); break;
    27902811            case 16: send_oscam_failban(vars, f, &params); break;
    2791             default: send_oscam_status(vars, f, &params, in); break;
     2812            //case  8: js file
     2813            case 18: send_oscam_api(vars, f, &params, in); break;
     2814            default: send_oscam_status(vars, f, &params, in, 0); break;
    27922815        }
    27932816        tpl_clear(vars);
  • trunk/oscam-http.h

    r4112 r4129  
    242242        </DIV>"
    243243
     244#define TPLAPIHEADER "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
     245<oscam version=\"##CS_VERSION## build ###CS_SVN_VERSION##\" starttime=\"##STARTDATE## - ##STARTTIME##\">\n"
     246
    244247#define TPLFOOTER "\
    245248        <BR><HR/><BR><DIV CLASS=\"footer\">\n\
     
    250253        </BODY>\
    251254        </HTML>"
     255
     256#define TPLAPIFOOTER "</oscam>"
    252257
    253258#define TPLREFRESH "\
     
    410415        ##TPLFOOTER##"
    411416
     417#define TPLAPISTATUS "##TPLAPIHEADER##\n\
     418   <status>\n\
     419##APISTATUSBITS##\
     420   </status>\n\
     421   <log>\n\
     422   ##LOGHISTORY##\
     423   </log>\
     424##TPLAPIFOOTER##"
     425
     426
    412427#define TPLCLIENTSTATUSBIT "\
    413428        <TR class=\"##CLIENTTYPE##\">\n\
     
    430445        <TD align=\"center\">##CLIENTCON##</TD>\n\
    431446        </TR>\n"
     447
     448
     449#define TPLAPISTATUSBIT "      <client type=\"##CLIENTTYPE##\" name=\"##CLIENTUSER##\" protocol=\"##CLIENTPROTO##\" protocolext=\"##CLIENTPROTOTITLE##\">\n\
     450         <request caid=\"##CLIENTCAID##\" srvid=\"##CLIENTSRVID##\">##CLIENTSRVPROVIDER####CLIENTSRVNAME##</request>\n\
     451         <times login=\"##CLIENTLOGINDATE##\" last=\"##CLIENTLOGINSECS##\" idle=\"##CLIENTIDLESECS##\"></times>\n\
     452         <connection ip=\"##CLIENTIP##\" port=\"##CLIENTPORT##\">##CLIENTCON##</connection>\n\
     453      </client>\n"
     454
    432455
    433456#define TPLUSERCONFIGLIST "\
     
    13341357char *tpl[]={
    13351358    "HEADER",
     1359    "APIHEADER",
    13361360    "FOOTER",
     1361    "APIFOOTER",
    13371362    "MENU",
    13381363    "REFRESH",
    13391364    "STATUS",
     1365    "APISTATUS",
    13401366    "CLIENTSTATUSBIT",
     1367    "APISTATUSBIT",
    13411368    "USERCONFIGLIST",
    13421369    "ADDNEWUSER",
     
    14211448char *tplmap[]={
    14221449    TPLHEADER,
     1450    TPLAPIHEADER,
    14231451    TPLFOOTER,
     1452    TPLAPIFOOTER,
    14241453    TPLMENU,
    14251454    TPLREFRESH,
    14261455    TPLSTATUS,
     1456    TPLAPISTATUS,
    14271457    TPLCLIENTSTATUSBIT,
     1458    TPLAPISTATUSBIT,
    14281459    TPLUSERCONFIGLIST,
    14291460    TPLADDNEWUSER,
Note: See TracChangeset for help on using the changeset viewer.