Changeset 34
- Timestamp:
- 2006-05-27T08:53:32+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 2 edited
-
admin (added)
-
admin/config.php.example (added)
-
admin/index.php (added)
-
admin/tablesort.js (added)
-
admin/xcache.css (added)
-
admin/xcache.php (added)
-
admin/xcache.tpl.php (added)
-
xcache.c (modified) (7 diffs)
-
xcache.ini (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xcache.c
r32 r34 12 12 #include "php.h" 13 13 #include "ext/standard/info.h" 14 #include "ext/standard/md5.h" 14 15 #include "zend_extensions.h" 15 16 #include "SAPI.h" … … 1048 1049 1049 1050 /* user functions */ 1050 /* {{{ xcache_op */ 1051 static int xcache_admin_auth_check(TSRMLS_C) /* {{{ */ 1052 { 1053 zval **server = NULL; 1054 zval **user = NULL; 1055 zval **pass = NULL; 1056 char *admin_user = NULL; 1057 char *admin_pass = NULL; 1058 HashTable *ht; 1059 1060 if (cfg_get_string("xcache.admin.user", &admin_user) == FAILURE || !admin_user[0]) { 1061 admin_user = NULL; 1062 } 1063 if (cfg_get_string("xcache.admin.pass", &admin_pass) == FAILURE || !admin_pass[0]) { 1064 admin_pass = NULL; 1065 } 1066 1067 if (admin_user == NULL || admin_pass == NULL) { 1068 php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.user and xcache.admin.pass is required"); 1069 zend_bailout(); 1070 } 1071 if (strlen(admin_pass) != 32) { 1072 php_error_docref(NULL TSRMLS_CC, E_ERROR, "unexpect %d bytes of xcache.admin.pass, expected 32 bytes, the password after md5()", strlen(admin_pass)); 1073 zend_bailout(); 1074 } 1075 1076 if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &server) != SUCCESS || Z_TYPE_PP(server) != IS_ARRAY) { 1077 php_error_docref(NULL TSRMLS_CC, E_ERROR, "_SERVER is corrupted"); 1078 zend_bailout(); 1079 } 1080 ht = HASH_OF((*server)); 1081 1082 if (zend_hash_find(ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &user) == FAILURE) { 1083 user = NULL; 1084 } 1085 else if (Z_TYPE_PP(user) != IS_STRING) { 1086 user = NULL; 1087 } 1088 1089 if (zend_hash_find(ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &pass) == FAILURE) { 1090 pass = NULL; 1091 } 1092 else if (Z_TYPE_PP(pass) != IS_STRING) { 1093 pass = NULL; 1094 } 1095 1096 if (user != NULL && pass != NULL && strcmp(admin_user, Z_STRVAL_PP(user)) == 0) { 1097 PHP_MD5_CTX context; 1098 char md5str[33]; 1099 unsigned char digest[16]; 1100 1101 PHP_MD5Init(&context); 1102 PHP_MD5Update(&context, Z_STRVAL_PP(pass), Z_STRLEN_PP(pass)); 1103 PHP_MD5Final(digest, &context); 1104 1105 md5str[0] = '\0'; 1106 make_digest(md5str, digest); 1107 if (strcmp(admin_pass, md5str) == 0) { 1108 return 1; 1109 } 1110 } 1111 1112 #define STR "WWW-authenticate: basic realm='XCache Administration'" 1113 sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); 1114 #undef STR 1115 #define STR "HTTP/1.0 401 Unauthorized" 1116 sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); 1117 #undef STR 1118 ZEND_PUTS("XCache Auth Failed. User and Password is case sense\n"); 1119 1120 zend_bailout(); 1121 return 0; 1122 } 1123 /* }}} */ 1124 /* {{{ xcache_admin_operate */ 1051 1125 typedef enum { XC_OP_COUNT, XC_OP_INFO, XC_OP_LIST, XC_OP_CLEAR } xcache_op_type; 1052 static void xcache_ op(xcache_op_type optype, INTERNAL_FUNCTION_PARAMETERS)1126 static void xcache_admin_operate(xcache_op_type optype, INTERNAL_FUNCTION_PARAMETERS) 1053 1127 { 1054 1128 long type; … … 1061 1135 RETURN_FALSE; 1062 1136 } 1137 1138 xcache_admin_auth_check(TSRMLS_C); 1063 1139 1064 1140 if (optype == XC_OP_COUNT) { … … 1143 1219 PHP_FUNCTION(xcache_count) 1144 1220 { 1145 xcache_ op(XC_OP_COUNT, INTERNAL_FUNCTION_PARAM_PASSTHRU);1221 xcache_admin_operate(XC_OP_COUNT, INTERNAL_FUNCTION_PARAM_PASSTHRU); 1146 1222 } 1147 1223 /* }}} */ … … 1150 1226 PHP_FUNCTION(xcache_info) 1151 1227 { 1152 xcache_ op(XC_OP_INFO, INTERNAL_FUNCTION_PARAM_PASSTHRU);1228 xcache_admin_operate(XC_OP_INFO, INTERNAL_FUNCTION_PARAM_PASSTHRU); 1153 1229 } 1154 1230 /* }}} */ … … 1157 1233 PHP_FUNCTION(xcache_list) 1158 1234 { 1159 xcache_ op(XC_OP_LIST, INTERNAL_FUNCTION_PARAM_PASSTHRU);1235 xcache_admin_operate(XC_OP_LIST, INTERNAL_FUNCTION_PARAM_PASSTHRU); 1160 1236 } 1161 1237 /* }}} */ … … 1164 1240 PHP_FUNCTION(xcache_clear_cache) 1165 1241 { 1166 xcache_ op(XC_OP_CLEAR, INTERNAL_FUNCTION_PARAM_PASSTHRU);1242 xcache_admin_operate(XC_OP_CLEAR, INTERNAL_FUNCTION_PARAM_PASSTHRU); 1167 1243 } 1168 1244 /* }}} */ -
trunk/xcache.ini
r33 r34 7 7 ; required for >=php5.1 if you turn xcache on 8 8 auto_globals_jit = Off 9 10 [xcache.admin] 11 xcache.admin.user = "mOo" 12 ; xcache.admin.pass = md5($your_password) 13 xcache.admin.pass = "" 9 14 10 15 [xcache]
Note: See TracChangeset
for help on using the changeset viewer.

