Changeset 4835 for trunk


Ignore:
Timestamp:
03/18/11 10:42:00 (12 years ago)
Author:
alno
Message:

WebIf + XMLApi: add userstatistics to XMLApi and CW-Rate to user overview based on a patch of ValD - many thanks! Discussion: http://streamboard.gmc.to/wbb2/thread.php?postid=375198#post375198

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http.c

    r4825 r4835  
    15711571}
    15721572
    1573 char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in) {
     1573char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in, int apicall) {
    15741574    struct s_auth *account, *account2;
    15751575    char *user = getParam(params, "user");
     
    15791579    hideclient = cfg.mon_hideclient_to;
    15801580
    1581     if (strcmp(getParam(params, "action"), "reinit") == 0) {
    1582         if(!cfg.http_readonly)
    1583             refresh_oscam(REFR_ACCOUNTS, in);
    1584     }
    1585 
    1586     if (strcmp(getParam(params, "action"), "delete") == 0) {
    1587         if(cfg.http_readonly) {
    1588             tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Webif is in readonly mode. No deletion will be made!</b><BR>");
     1581    if (!apicall) {
     1582        if (strcmp(getParam(params, "action"), "reinit") == 0) {
     1583            if(!cfg.http_readonly)
     1584                refresh_oscam(REFR_ACCOUNTS, in);
     1585        }
     1586
     1587        if (strcmp(getParam(params, "action"), "delete") == 0) {
     1588            if(cfg.http_readonly) {
     1589                tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Webif is in readonly mode. No deletion will be made!</b><BR>");
     1590            } else {
     1591                account = cfg.account;
     1592                if(strcmp(account->usr, user) == 0) {
     1593                    cfg.account = account->next;
     1594                    free(account);
     1595                    found = 1;
     1596                } else if (account->next != NULL) {
     1597                    do {
     1598                        if(strcmp(account->next->usr, user) == 0) {
     1599                            account2 = account->next;
     1600                            account->next = account2->next;
     1601                            free(account2);
     1602                            found = 1;
     1603                            break;
     1604                        }
     1605                    } while ((account = account->next) && (account->next != NULL));
     1606                }
     1607
     1608                if (found > 0) {
     1609                    if (write_userdb(cfg.account)==0)
     1610                        refresh_oscam(REFR_ACCOUNTS, in);
     1611                    else
     1612                        tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
     1613
     1614                } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
     1615            }
     1616        }
     1617
     1618        if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) {
     1619            account = get_account_by_name(getParam(params, "user"));
     1620            if (account) {
     1621                if(strcmp(getParam(params, "action"), "disable") == 0)
     1622                    account->disabled = 1;
     1623                else
     1624                    account->disabled = 0;
     1625                if (write_userdb(cfg.account) == 0)
     1626                    refresh_oscam(REFR_ACCOUNTS, in);
     1627            } else {
     1628                tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
     1629            }
     1630        }
     1631
     1632        if (strcmp(getParam(params, "action"), "resetstats") == 0) {
     1633            account = get_account_by_name(getParam(params, "user"));
     1634            if (account) clear_account_stats(account);
     1635        }
     1636
     1637        if (strcmp(getParam(params, "action"), "resetserverstats") == 0) {
     1638            clear_system_stats();
     1639        }
     1640
     1641        if (strcmp(getParam(params, "action"), "resetalluserstats") == 0) {
     1642            clear_all_account_stats();
     1643        }
     1644
     1645        if ((strcmp(getParam(params, "part"), "adduser") == 0) && (!cfg.http_readonly)) {
     1646            tpl_addVar(vars, TPLAPPEND, "NEWUSERFORM", tpl_getTpl(vars, "ADDNEWUSER"));
    15891647        } else {
    1590             account = cfg.account;
    1591             if(strcmp(account->usr, user) == 0) {
    1592                 cfg.account = account->next;
    1593                 free(account);
    1594                 found = 1;
    1595             } else if (account->next != NULL) {
    1596                 do {
    1597                     if(strcmp(account->next->usr, user) == 0) {
    1598                         account2 = account->next;
    1599                         account->next = account2->next;
    1600                         free(account2);
    1601                         found = 1;
    1602                         break;
    1603                     }
    1604                 } while ((account = account->next) && (account->next != NULL));
    1605             }
    1606 
    1607             if (found > 0) {
    1608                 if (write_userdb(cfg.account)==0)
    1609                     refresh_oscam(REFR_ACCOUNTS, in);
    1610                 else
    1611                     tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
    1612 
    1613             } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
    1614         }
    1615     }
    1616 
    1617     if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) {
    1618         account = get_account_by_name(getParam(params, "user"));
    1619         if (account) {
    1620             if(strcmp(getParam(params, "action"), "disable") == 0)
    1621                 account->disabled = 1;
    1622             else
    1623                 account->disabled = 0;
    1624             if (write_userdb(cfg.account) == 0)
    1625                 refresh_oscam(REFR_ACCOUNTS, in);
    1626         } else {
    1627             tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
    1628         }
    1629     }
    1630 
    1631     if (strcmp(getParam(params, "action"), "resetstats") == 0) {
    1632         account = get_account_by_name(getParam(params, "user"));
    1633         if (account) clear_account_stats(account);
    1634     }
    1635 
    1636     if (strcmp(getParam(params, "action"), "resetserverstats") == 0) {
    1637         clear_system_stats();
    1638     }
    1639 
    1640     if (strcmp(getParam(params, "action"), "resetalluserstats") == 0) {
    1641         clear_all_account_stats();
    1642     }
    1643 
    1644     if ((strcmp(getParam(params, "part"), "adduser") == 0) && (!cfg.http_readonly)) {
    1645         tpl_addVar(vars, TPLAPPEND, "NEWUSERFORM", tpl_getTpl(vars, "ADDNEWUSER"));
    1646     } else {
    1647         if(cfg.http_refresh > 0) {
    1648             tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", cfg.http_refresh);
    1649             tpl_addVar(vars, TPLADD, "REFRESHURL", "userconfig.html");
    1650             tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
     1648            if(cfg.http_refresh > 0) {
     1649                tpl_printf(vars, TPLADD, "REFRESHTIME", "%d", cfg.http_refresh);
     1650                tpl_addVar(vars, TPLADD, "REFRESHURL", "userconfig.html");
     1651                tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH"));
     1652            }
    16511653        }
    16521654    }
     
    16561658    time_t now = time((time_t)0);
    16571659    int isec = 0, isconnected = 0;
     1660
     1661    char *filter = NULL;
     1662    int clientcount = 0;
     1663    if (apicall) {
     1664        filter = getParam(params, "label");
     1665    }
    16581666
    16591667    for (account=cfg.account; (account); account=account->next) {
     
    16821690        int lastresponsetm = 0;
    16831691        char *proto = "";
     1692        float cwrate = 0;
    16841693
    16851694        //search account in active clients
     
    17021711                    isactive++;
    17031712                }
     1713
     1714                if (cl->cwfound + cl->cwnot > 0) {
     1715                    cwrate = cl->last - cl->login;
     1716                    cwrate /= cl->cwfound + cl->cwnot;
     1717                }
    17041718            }
    17051719        }
     
    17131727        tpl_printf(vars, TPLADDONCE, "EMMOK", "%d", account->emmok);
    17141728        tpl_printf(vars, TPLADDONCE, "EMMNOK", "%d", account->emmnok);
     1729        tpl_printf(vars, TPLADDONCE, "CWRATE", "%.2f", cwrate);
    17151730
    17161731        if ( isactive > 0 || !cfg.http_hide_idle_clients) {
     
    17281743        tpl_addVar(vars, TPLAPPENDONCE, "STATUS", expired);
    17291744        // append row to table template
    1730         tpl_addVar(vars, TPLAPPEND, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
    1731 
     1745        if (!apicall)
     1746            tpl_addVar(vars, TPLAPPEND, "USERCONFIGS", tpl_getTpl(vars, "USERCONFIGLISTBIT"));
     1747        else
     1748            if (!filter || strcmp(filter, account->usr) == 0 || strcmp(filter, "all") == 0 || strlen(filter) == 0) {
     1749                tpl_addVar(vars, TPLAPPEND, "APIUSERCONFIGS", tpl_getTpl(vars, "APIUSERCONFIGLISTBIT"));
     1750                ++clientcount;
     1751            }
    17321752    }
    17331753
     
    17391759    tpl_printf(vars, TPLADD, "TOTAL_CWTUN", "%ld", first_client->cwtun);
    17401760   
    1741     return tpl_getTpl(vars, "USERCONFIGLIST");
     1761    if (!apicall)
     1762        return tpl_getTpl(vars, "USERCONFIGLIST");
     1763    else {
     1764        if (!filter || clientcount > 0) {
     1765            return tpl_getTpl(vars, "APIUSERCONFIGLIST");
     1766        } else {
     1767            tpl_printf(vars, TPLADD, "APIERRORMESSAGE", "Invalid client %s", filter);
     1768            return tpl_getTpl(vars, "APIERROR");
     1769        }
     1770    }
     1771
    17421772}
    17431773
     
    28502880        return send_oscam_status(vars, params, in, 1);
    28512881    }
     2882    else if (strcmp(getParam(params, "part"), "userstats") == 0) {
     2883        return send_oscam_user_config(vars, params, in, 1);
     2884    }
    28522885    else if (strcmp(getParam(params, "part"), "entitlement") == 0) {
    28532886
     
    32443277            case 2: result = send_oscam_entitlement(vars, &params, in, 0); break;
    32453278            case 3: result = send_oscam_status(vars, &params, in, 0); break;
    3246             case 4: result = send_oscam_user_config(vars, &params, in); break;
     3279            case 4: result = send_oscam_user_config(vars, &params, in, 0); break;
    32473280            case 5: result = send_oscam_reader_config(vars, &params, in); break;
    32483281            case 6: result = send_oscam_services(vars, &params, in); break;
  • trunk/oscam-http.h

    r4825 r4835  
    497497
    498498
     499#define TPLAPIUSERCONFIGLIST "##TPLAPIHEADER##\n\
     500    <users>\n\
     501##APIUSERCONFIGS##\
     502    </users>\n\
     503    <totals>\n\
     504        <cwok>##TOTAL_CWOK##</cwok>\n\
     505        <cwnok>##TOTAL_CWNOK##</cwnok>\n\
     506        <cwignore>##TOTAL_CWIGN##</cwignore>\n\
     507        <cwtimeout>##TOTAL_CWTOUT##</cwtimeout>\n\
     508        <cwcache>##TOTAL_CWCACHE##</cwcache>\n\
     509        <cwtun>##TOTAL_CWTUN##</cwtun>\n\
     510    </totals>\n\
     511##TPLAPIFOOTER##"
     512
     513#define TPLAPIUSERCONFIGLISTBIT "        <user name=\"##USER##\">\n\
     514            <stats>\n\
     515                <cwok>##CWOK##</cwok>\n\
     516                <cwnok>##CWNOK##</cwnok>\n\
     517                <cwignore>##CWIGN##</cwignore>\n\
     518                <cwtimeout>##CWTOUT##</cwtimeout>\n\
     519                <cwcache>##CWCACHE##</cwcache>\n\
     520                <cwtun>##CWTUN##</cwtun>\n\
     521                <cwlastresptime>##CWLASTRESPONSET##</cwlastresptime>\n\
     522                <emmok>##EMMOK##</emmok>\n\
     523                <emmnok>##EMMNOK##</emmnok>\n\
     524                <cwrate>##CWRATE##</cwrate>\n\
     525            </stats>\n\
     526        </user>\n"
     527
     528
    499529#define TPLUSERCONFIGLIST "\
    500530##TPLHEADER##\
     
    526556            <TH>EOK</TH>\n\
    527557            <TH>ENOK</TH>\n\
     558            <TH>CW Rate</TH>\n\
    528559            <TH colspan=\"3\" align=\"center\">Action</TH>\n\
    529560        </TR>\n\
     
    580611            <TD align=\"center\">##EMMOK##</TD>\n\
    581612            <TD align=\"center\">##EMMNOK##</TD>\n\
     613            <TD align=\"center\">##CWRATE##</TD>\n\
    582614            <TD align=\"center\"><A HREF=\"user_edit.html?user=##USERENC##\" TITLE=\"edit this user\"><IMG HEIGHT=\"16\" WIDTH=\"16\" SRC=\"image?i=ICEDI\" BORDER=\"0\" ALT=\"Edit User\"/></A></TD>\n\
    583615            <TD align=\"center\"><A HREF=\"userconfig.html?user=##USERENC##&action=resetstats\" TITLE=\"reset statistics for this user\"><IMG HEIGHT=\"16\" WIDTH=\"16\" SRC=\"image?i=ICRES\"BORDER=\"0\" ALT=\"Reset Stats\"/></A></TD>\n\
     
    15711603    "ADDNEWUSER",
    15721604    "USERCONFIGLISTBIT",
     1605    "APIUSERCONFIGLIST",
     1606    "APIUSERCONFIGLISTBIT",
    15731607    "SIDTAB",
    15741608    "SIDTABBIT",
     
    16821716    TPLADDNEWUSER,
    16831717    TPLUSERCONFIGLISTBIT,
     1718    TPLAPIUSERCONFIGLIST,
     1719    TPLAPIUSERCONFIGLISTBIT,
    16841720    TPLSIDTAB,
    16851721    TPLSIDTABBIT,
Note: See TracChangeset for help on using the changeset viewer.