/home/mjc1/public_html/adm/admin.lib.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
if (!defined('_GNUBOARD_')) exit;

/*
// 081022 : CSRF 방지를 위해 코드를 작성했으나 효과가 없어 주석처리 함
if (!get_session('ss_admin')) {
    set_session('ss_admin', true);
    goto_url('.');
}
*/

// 스킨디렉토리를 SELECT 형식으로 얻음
function get_skin_select($skin_gubun$id$name$selected=''$event='')
{
    
$skins get_skin_dir($skin_gubun);
    
$str "<select id=\"$id\" name=\"$name\" $event>\n";
    for (
$i=0$i<count($skins); $i++) {
        if (
$i == 0$str .= "<option value=\"\">선택</option>";
        
$str .= option_selected($skins[$i], $selected);
    }
    
$str .= "</select>";
    return 
$str;
}

// 모바일 스킨디렉토리를 SELECT 형식으로 얻음
function get_mobile_skin_select($skin_gubun$id$name$selected=''$event='')
{
    
$skins get_skin_dir($skin_gubunG5_MOBILE_PATH.'/'.G5_SKIN_DIR);
    
$str "<select id=\"$id\" name=\"$name\" $event>\n";
    for (
$i=0$i<count($skins); $i++) {
        if (
$i == 0$str .= "<option value=\"\">선택</option>";
        
$str .= option_selected($skins[$i], $selected);
    }
    
$str .= "</select>";
    return 
$str;
}


// 스킨경로를 얻는다
function get_skin_dir($skin$skin_path=G5_SKIN_PATH)
{
    global 
$g5;

    
$result_array = array();

    
$dirname $skin_path.'/'.$skin.'/';
    
$handle opendir($dirname);
    while (
$file readdir($handle)) {
        if(
$file == '.'||$file == '..') continue;

        if (
is_dir($dirname.$file)) $result_array[] = $file;
    }
    
closedir($handle);
    
sort($result_array);

    return 
$result_array;
}


// 회원권한을 SELECT 형식으로 얻음
function get_member_level_select($name$start_id=0$end_id=10$selected=""$event="")
{
    global 
$g5;

    
$str "\n<select id=\"{$name}\" name=\"{$name}\"";
    if (
$event$str .= $event";
    
$str .= ">\n";
    for (
$i=$start_id$i<=$end_id$i++) {
        
$str .= '<option value="'.$i.'"';
        if (
$i == $selected)
            
$str .= ' selected="selected"';
        
$str .= ">{$i}</option>\n";
    }
    
$str .= "</select>\n";
    return 
$str;
}


// 회원아이디를 SELECT 형식으로 얻음
function get_member_id_select($name$level$selected=""$event="")
{
    global 
$g5;

    
$sql " select mb_id from {$g5['member_table']} where mb_level >= '{$level}' ";
    
$result sql_query($sql);
    
$str '<select id="'.$name.'" name="'.$name.'" '.$event.'><option value="">선택안함</option>';
    for (
$i=0$row=sql_fetch_array($result); $i++)
    {
        
$str .= '<option value="'.$row['mb_id'].'"';
        if (
$row['mb_id'] == $selected$str .= ' selected';
        
$str .= '>'.$row['mb_id'].'</option>';
    }
    
$str .= '</select>';
    return 
$str;
}

// 권한 검사
function auth_check($auth$attr)
{
    global 
$is_admin;

    if (
$is_admin == 'super') return;

    if (!
trim($auth))
        
alert('이 메뉴에는 접근 권한이 없습니다.\\n\\n접근 권한은 최고관리자만 부여할 수 있습니다.');

    
$attr strtolower($attr);

    if (!
strstr($auth$attr)) {
        if (
$attr == 'r')
            
alert('읽을 권한이 없습니다.');
        else if (
$attr == 'w')
            
alert('입력, 추가, 생성, 수정 권한이 없습니다.');
        else if (
$attr == 'd')
            
alert('삭제 권한이 없습니다.');
        else
            
alert('속성이 잘못 되었습니다.');
    }
}


// 작업아이콘 출력
function icon($act$link=''$target='_parent')
{
    global 
$g5;

    
$img = array('입력'=>'insert''추가'=>'insert''생성'=>'insert''수정'=>'modify''삭제'=>'delete''이동'=>'move''그룹'=>'move''보기'=>'view''미리보기'=>'view''복사'=>'copy');
    
$icon '<img src="'.G5_ADMIN_PATH.'/img/icon_'.$img[$act].'.gif" title="'.$act.'">';
    if (
$link)
        
$s '<a href="'.$link.'">'.$icon.'</a>';
    else
        
$s $icon;
    return 
$s;
}


// rm -rf 옵션 : exec(), system() 함수를 사용할 수 없는 서버 또는 win32용 대체
// www.php.net 참고 : pal at degerstrom dot com
function rm_rf($file)
{
    if (
file_exists($file)) {
        if (
is_dir($file)) {
            
$handle opendir($file);
            while(
$filename readdir($handle)) {
                if (
$filename != '.' && $filename != '..')
                    
rm_rf($file.'/'.$filename);
            }
            
closedir($handle);

            @
chmod($fileG5_DIR_PERMISSION);
            @
rmdir($file);
        } else {
            @
chmod($fileG5_FILE_PERMISSION);
            @
unlink($file);
        }
    }
}

// 입력 폼 안내문
function help($help="")
{
    global 
$g5;

    
$str  '<span class="frm_info">'.str_replace("\n""<br>"$help).'</span>';

    return 
$str;
}

// 출력순서
function order_select($fld$sel='')
{
    
$s '<select name="'.$fld.'" id="'.$fld.'">';
    for (
$i=1$i<=100$i++) {
        
$s .= '<option value="'.$i.'" ';
        if (
$sel) {
            if (
$i == $sel) {
                
$s .= 'selected';
            }
        } else {
            if (
$i == 50) {
                
$s .= 'selected';
            }
        }
        
$s .= '>'.$i.'</option>';
    }
    
$s .= '</select>';

    return 
$s;
}

// 접근 권한 검사
if (!$member['mb_id'])
{
    
alert('로그인 하십시오.'G5_BBS_URL.'/login.php?url=' urlencode(G5_ADMIN_URL));
}
else if (
$is_admin != 'super')
{
    
$auth = array();
    
$sql " select au_menu, au_auth from {$g5['auth_table']} where mb_id = '{$member['mb_id']}' ";
    
$result sql_query($sql);
    for(
$i=0$row=sql_fetch_array($result); $i++)
    {
        
$auth[$row['au_menu']] = $row['au_auth'];
    }

    if (!
$i)
    {
        
alert('최고관리자 또는 관리권한이 있는 회원만 접근 가능합니다.'G5_URL);
    }
}

// 관리자의 아이피, 브라우저와 다르다면 세션을 끊고 관리자에게 메일을 보낸다.
$admin_key md5($member['mb_datetime'] . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
if (
get_session('ss_mb_key') !== $admin_key) {

    
session_destroy();

    include_once(
G5_LIB_PATH.'/mailer.lib.php');
    
// 메일 알림
    
mailer($member['mb_nick'], $member['mb_email'], $member['mb_email'], 'XSS 공격 알림'$_SERVER['REMOTE_ADDR'].' 아이피로 XSS 공격이 있었습니다.<br><br>관리자 권한을 탈취하려는 접근이므로 주의하시기 바랍니다.<br><br>해당 아이피는 차단하시고 의심되는 게시물이 있는지 확인하시기 바랍니다.'.G5_URL0);

    
alert_close('정상적으로 로그인하여 접근하시기 바랍니다.');
}

@
ksort($auth);

// 가변 메뉴
unset($auth_menu);
unset(
$menu);
unset(
$amenu);
$tmp dir(G5_ADMIN_PATH);
while (
$entry $tmp->read()) {
    if (!
preg_match('/^admin.menu([0-9]{3}).*\.php$/'$entry$m))
        continue;  
// 파일명이 menu 으로 시작하지 않으면 무시한다.

    
$amenu[$m[1]] = $entry;
    include_once(
G5_ADMIN_PATH.'/'.$entry);
}
@
ksort($amenu);

$arr_query = array();
if (isset(
$sst))  $arr_query[] = 'sst='.$sst;
if (isset(
$sod))  $arr_query[] = 'sod='.$sod;
if (isset(
$sfl))  $arr_query[] = 'sfl='.$sfl;
if (isset(
$stx))  $arr_query[] = 'stx='.$stx;
if (isset(
$page)) $arr_query[] = 'page='.$page;
if (isset(
$save_stx)) $arr_query[] = 'save_stx='.$save_stx;
$qstr implode("&amp;"$arr_query);

// 관리자에서는 추가 스크립트는 사용하지 않는다.
//$config['cf_add_script'] = '';


//벤더 상품 권한 체크 등록/수정/삭제 등에 관련된 분 제어
function vender_auth_check($mode){
    Global 
$g5$_REQUEST$vendermember;
    
$req $_REQUEST;

    if(
$mode=='itemform'){
        if(
$req['w']=='u'){
            if(
strpos(",".$vendermember['vm_goods_auth'],"M")==0){
                
alert('상품 수정하실 권한이 없습니다.'); exit;
            }
        } else if(
$req['w']==''){
            if(
strpos(",".$vendermember['vm_goods_auth'],"R")==0){
                
alert('상품 등록하실 권한이 없습니다.'); exit;
            }
            
// 상품 등록 갯수 초과 체크
            
$sql "select count(*) as cnt from {$g5[g5_shop_item_table]} where vm_id = '{$vendermember['vm_id']}' ";
            
$info sql_fetch($sql);
            if(
$vendermember['vm_goods_count']<=$info['cnt']){
                
alert("상품 등록갯수를 초과 합니다."); exit;
            }
        }
    } else if(
$mode=='itemcopy'){
        if(
strpos(",".$vendermember['vm_goods_auth'],"R")==0){
            
alert_close('상품 복사하실 권한이 없습니다.'); exit;
        }
        
$sql "select count(*) as cnt from {$g5[g5_shop_item_table]} where vm_id = '{$vendermember['vm_id']}' ";
        
$info sql_fetch($sql);
        if(
$vendermember['vm_goods_count']<=$info['cnt']){
            
alert("상품 등록갯수를 초과 합니다. {$info['cnt']}"); exit;
        }
    } else if(
$mode=='itemdel'){
        if(
strpos(",".$vendermember['vm_goods_auth'],"D")==0){
            
alert('상품 삭제하실 권한이 없습니다.'); exit;
        }
    } else if(
$mode=='itemlistupdate'){
        if(
strpos(",".$vendermember['vm_goods_auth'],"M")==0){
            
alert('상품 수정하실 권한이 없습니다.'); exit;
        }
    }
}

?>