- Timestamp:
- 03/18/11 10:42:00 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-http.c
r4825 r4835 1571 1571 } 1572 1572 1573 char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in ) {1573 char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in, int apicall) { 1574 1574 struct s_auth *account, *account2; 1575 1575 char *user = getParam(params, "user"); … … 1579 1579 hideclient = cfg.mon_hideclient_to; 1580 1580 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")); 1589 1647 } 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 } 1651 1653 } 1652 1654 } … … 1656 1658 time_t now = time((time_t)0); 1657 1659 int isec = 0, isconnected = 0; 1660 1661 char *filter = NULL; 1662 int clientcount = 0; 1663 if (apicall) { 1664 filter = getParam(params, "label"); 1665 } 1658 1666 1659 1667 for (account=cfg.account; (account); account=account->next) { … … 1682 1690 int lastresponsetm = 0; 1683 1691 char *proto = ""; 1692 float cwrate = 0; 1684 1693 1685 1694 //search account in active clients … … 1702 1711 isactive++; 1703 1712 } 1713 1714 if (cl->cwfound + cl->cwnot > 0) { 1715 cwrate = cl->last - cl->login; 1716 cwrate /= cl->cwfound + cl->cwnot; 1717 } 1704 1718 } 1705 1719 } … … 1713 1727 tpl_printf(vars, TPLADDONCE, "EMMOK", "%d", account->emmok); 1714 1728 tpl_printf(vars, TPLADDONCE, "EMMNOK", "%d", account->emmnok); 1729 tpl_printf(vars, TPLADDONCE, "CWRATE", "%.2f", cwrate); 1715 1730 1716 1731 if ( isactive > 0 || !cfg.http_hide_idle_clients) { … … 1728 1743 tpl_addVar(vars, TPLAPPENDONCE, "STATUS", expired); 1729 1744 // 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 } 1732 1752 } 1733 1753 … … 1739 1759 tpl_printf(vars, TPLADD, "TOTAL_CWTUN", "%ld", first_client->cwtun); 1740 1760 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 1742 1772 } 1743 1773 … … 2850 2880 return send_oscam_status(vars, params, in, 1); 2851 2881 } 2882 else if (strcmp(getParam(params, "part"), "userstats") == 0) { 2883 return send_oscam_user_config(vars, params, in, 1); 2884 } 2852 2885 else if (strcmp(getParam(params, "part"), "entitlement") == 0) { 2853 2886 … … 3244 3277 case 2: result = send_oscam_entitlement(vars, ¶ms, in, 0); break; 3245 3278 case 3: result = send_oscam_status(vars, ¶ms, in, 0); break; 3246 case 4: result = send_oscam_user_config(vars, ¶ms, in ); break;3279 case 4: result = send_oscam_user_config(vars, ¶ms, in, 0); break; 3247 3280 case 5: result = send_oscam_reader_config(vars, ¶ms, in); break; 3248 3281 case 6: result = send_oscam_services(vars, ¶ms, in); break; -
trunk/oscam-http.h
r4825 r4835 497 497 498 498 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 499 529 #define TPLUSERCONFIGLIST "\ 500 530 ##TPLHEADER##\ … … 526 556 <TH>EOK</TH>\n\ 527 557 <TH>ENOK</TH>\n\ 558 <TH>CW Rate</TH>\n\ 528 559 <TH colspan=\"3\" align=\"center\">Action</TH>\n\ 529 560 </TR>\n\ … … 580 611 <TD align=\"center\">##EMMOK##</TD>\n\ 581 612 <TD align=\"center\">##EMMNOK##</TD>\n\ 613 <TD align=\"center\">##CWRATE##</TD>\n\ 582 614 <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\ 583 615 <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\ … … 1571 1603 "ADDNEWUSER", 1572 1604 "USERCONFIGLISTBIT", 1605 "APIUSERCONFIGLIST", 1606 "APIUSERCONFIGLISTBIT", 1573 1607 "SIDTAB", 1574 1608 "SIDTABBIT", … … 1682 1716 TPLADDNEWUSER, 1683 1717 TPLUSERCONFIGLISTBIT, 1718 TPLAPIUSERCONFIGLIST, 1719 TPLAPIUSERCONFIGLISTBIT, 1684 1720 TPLSIDTAB, 1685 1721 TPLSIDTABBIT,
Note:
See TracChangeset
for help on using the changeset viewer.