Example #1
0
 function run()
 {
     $data = ldb_select('client_version', '*', '1');
     foreach ($data as $d) {
         $this->process_dir(ROOT_PATH . '/client/v/' . $d['ver']);
     }
 }
Example #2
0
 function process_upload($data)
 {
     # Get last download time
     $path = ROOT_PATH . '/d/' . substr($data['code'], 0, 2) . '/' . substr($data['code'], 2);
     $flist = ldb_select('file', '*', '`upid`=' . $data['id']);
     $mtimes = array();
     foreach ($flist as $f) {
         $mt = @filemtime($path . '/' . $f['upn'] . '.dt');
         if (!$mt) {
             continue;
         }
         $mtimes[] = $mt;
         ldb_query('UPDATE `file` SET `tms_last`=' . $mt . ' WHERE `id`=' . $f['id'] . ' LIMIT 1');
     }
     ldb_query('UPDATE `upload` SET `tms_last`=' . min($mtimes) . ' WHERE `id`=' . $data['id'] . ' LIMIT 1');
 }
Example #3
0
 function display()
 {
     current_page('files');
     page_title(lang('fl_mylist'), URL . '/files/');
     if (!user('logged')) {
         return login_req();
     }
     $data = ldb_select('upload', '*', '`uid`=' . user('id') . ' ORDER BY `tms_upload` DESC');
     $u_list = '';
     for ($x = 0; $x < count($data); $x++) {
         $f_title = '';
         if ($data[$x]['comment']) {
             $f_title = htmlspecialchars($data[$x]['comment']);
         } else {
             # Get files
             $f_list = ldb_select('file', array('file_name'), '`upid`=' . $data[$x]['id'] . ' ORDER BY `id`');
             $f_list_len = 0;
             $f_list_d = array();
             for ($a = 0; $a < count($f_list); $a++) {
                 $f_list_d[] = '<i>' . htmlspecialchars($f_list[$a]['file_name']) . '</i>';
                 $f_list_len += mb_strlen($f_list[$a]['file_name'], 'UTF-8');
                 if ($f_list_len > 50) {
                     break;
                 }
             }
             if (count($f_list_d) < count($f_list)) {
                 $f_list_d[] = '<b>...</b>';
             }
             $f_title = implode(', ', $f_list_d);
         }
         $f_title = trim($f_title);
         if (!$f_title) {
             $f_title = sprintf(lang('fld_title_n'), $data[$x]['id']);
         }
         $u_list .= '<tr>';
         $u_list .= '<td align="center">' . $data[$x]['id'] . '</td>';
         $u_list .= '<td align="left" class="mf-table-flink"><a href="' . URL . '/f/' . $data[$x]['code'] . '/">' . $f_title . '</a></td>';
         $u_list .= '<td align="center">' . date('d.m.Y H:i', $data[$x]['tms_upload']) . '</td>';
         $u_list .= '<td align="center">' . time_delete($data[$x]['tms_upload'], $data[$x]['tms_delete']) . '</td>';
         $u_list .= '<td align="center">' . format_size($data[$x]['file_size']) . '</td>';
         $u_list .= '</tr>';
     }
     $tpl = new ltpl('myfiles');
     $tpl->v('u_list', $u_list);
     return $tpl->get();
 }
Example #4
0
 function check_session()
 {
     if (!@$_COOKIE[cfg('auth_int_cookie_name')]) {
         return false;
     }
     $cd = explode(':', @base64_decode($_COOKIE[cfg('auth_int_cookie_name')]));
     if (!@$cd[0] || !@$cd[1]) {
         return false;
     }
     $uid = intval($cd[0]);
     $kid = base64_decode($cd[1]);
     # Check session...
     $data = ldb_select('user', '*', '`id`=\'' . $uid . '\' AND `login_key`=\'' . md5($kid) . '\' LIMIT 1');
     if (!$data) {
         return false;
     }
     # Login ok!
     $data = $data[0];
     # Check status
     if ($data['status'] != 'ACTIVE') {
         return false;
     }
     # Update DB
     ldb_update_by_id('user', $data['id'], array('last_login' => time(), 'last_ip' => ip2long($_SERVER['REMOTE_ADDR'])));
     # Update cookie
     setcookie(cfg('auth_int_cookie_name'), $_COOKIE[cfg('auth_int_cookie_name')], time() + intval(cfg('auth_int_session_time')), '/', COOKIE_DOMAIN);
     # Set global user data
     $GLOBALS['user'] = array();
     $GLOBALS['user']['id'] = $data['id'];
     $GLOBALS['user']['name'] = $data['name'];
     $GLOBALS['user']['login'] = $data['mail'];
     $GLOBALS['user']['logged'] = true;
     $GLOBALS['user']['is_admin'] = @$data['is_admin'];
     $GLOBALS['user']['adm_pages'] = @$data['adm_pages'] == 'Y';
     $GLOBALS['user']['adm_users'] = @$data['adm_users'] == 'Y';
     $GLOBALS['user']['adm_faq'] = @$data['adm_faq'] == 'Y';
     $GLOBALS['user']['tmz'] = @$data['tmz'];
     $GLOBALS['user']['lk'] = md5($_COOKIE[cfg('auth_int_cookie_name')]);
     $GLOBALS['user']['max_file'] = intval(@$data['max_file']);
     $GLOBALS['user']['max_total'] = intval(@$data['max_total']);
 }
Example #5
0
 function upload_complete()
 {
     $up_id = intval(@$_GET['upid']);
     $id = intval(@$_GET['id']);
     include_once CORE_PATH . '/ttl.php';
     # Check file
     $f_in = ROOT_PATH . '/tmp/upload/' . md5($this->sid . $up_id) . '-' . $id;
     if (!file_exists($f_in)) {
         return $this->error('UPLOAD_INT_F_E', lang('fl_e_int'));
     }
     # Size...
     # Name...
     $fname = trim(basename(@$_GET['qqfile']));
     if (!$fname) {
         $fname = 'ass.txt';
     }
     # Check extension
     $finfo = pathinfo($fname);
     $ext = strtolower(@$finfo['extension']);
     if (!ext_allowed($ext)) {
         return $this->error('UPLOAD_NTYPE', lang('fl_e_ntype'));
     }
     #	return exit(htmlspecialchars(json_encode(array('error'=>lang('fl_e_ntype'))), ENT_NOQUOTES));
     # Okay...
     $fname = preg_replace('!<>\\/\\n\\r\\t!', '', $fname);
     $up_code = md5($this->sid . $up_id);
     $ph = substr(sha1(md5(microtime(true)) . mt_rand() . md5($fname)), 8, 8);
     $ttl = $GLOBALS['ttl_def'];
     $tms_del = time() + $ttl;
     # Create DB record
     ldb_insert('upload', array('uid' => $this->uid, 'code' => $up_code, 'ph' => $ph, 'tms_upload' => time(), 'tms_last' => time(), 'tms_delete' => $tms_del, 'ttl' => $ttl));
     $rec = ldb_select('upload', '*', '`uid`=' . $this->uid . ' AND `code`=\'' . $up_code . '\' LIMIT 1');
     $rec = @$rec[0];
     if (!$rec) {
         return $this->error('UPLOAD_INT_D_E', lang('fl_e_int'));
         #return exit(htmlspecialchars(json_encode(array('error'=>lang('fl_e_int').' (D_E)')), ENT_NOQUOTES));
     }
     # Create uploading DIR
     $u_dir = ROOT_PATH . '/d/' . substr($up_code, 0, 2);
     @mkdir($u_dir);
     @chmod($u_dir, 0777);
     $u_dir .= '/' . substr($up_code, 2);
     @mkdir($u_dir);
     @chmod($u_dir, 0777);
     #$u_dir .= '/'.$id;
     #@mkdir($u_dir);
     if (!file_exists($u_dir)) {
         return $this->error('UPLOAD_INT_DR_E', lang('fl_e_int'));
         return exit(htmlspecialchars(json_encode(array('error' => lang('fl_e_int') . ' (DR_E)')), ENT_NOQUOTES));
     }
     # Copy file!
     if (!copy($f_in, $u_dir . '/' . $id . '.dat')) {
         return $this->error('UPLOAD_INT_CP_E', lang('fl_e_int'));
         return exit(htmlspecialchars(json_encode(array('error' => lang('fl_e_int') . ' (CP_E)')), ENT_NOQUOTES));
     }
     @unlink($f_in);
     # Make simlink...
     #chdir($u_dir);
     #system('ln -s '.escapeshellarg('./'.$fname).' '.escapeshellarg('./file.'.$finfo['extension']));
     $fmime = get_mime_type($fname);
     $fsize = filesize_fix($u_dir . '/' . $id . '.dat');
     $dh = substr(sha1(md5(microtime(true)) . mt_rand() . md5($fname . $fmime)), 8, 8);
     # Add to DB!
     $file_id = ldb_insert('file', array('uid' => $this->uid, 'upid' => $rec['id'], 'upn' => $id, 'dh' => $dh, 'file_name' => $fname, 'file_ext' => $ext, 'file_size' => $fsize, 'tms_add' => time(), 'tms_last' => time()));
     if (!$file_id) {
         return $this->error('UPLOAD_INT_DB_E', lang('fl_e_int'));
         return exit(htmlspecialchars(json_encode(array('error' => lang('fl_e_int') . ' (DB_E)')), ENT_NOQUOTES));
     }
     ldb_query('UPDATE `upload` SET `file_count`=`file_count`+1, `file_size`=`file_size`+' . $fsize . ' WHERE `id`=' . $rec['id']);
     # return exit(htmlspecialchars(json_encode(array('error'=>  ldb_log_html())), ENT_NOQUOTES));
     # Make info file
     $inf = array();
     $inf[] = $fname;
     $inf[] = $fmime;
     $inf[] = $file_id;
     $inf[] = $fsize;
     $inf[] = $dh;
     file_put_contents($u_dir . '/' . $id . '.inf', implode("\n", $inf));
     @chmod($u_dir . '/' . $id . '.dat', 0777);
     @chmod($u_dir . '/' . $id . '.inf', 0777);
     echo '<upload status="ok" upload_id="' . $rec['id'] . '" upload_code="' . $rec['code'] . '" upload_ph="' . $rec['ph'] . '" tms_delete="' . $rec['tms_delete'] . '" ttl="' . $rec['ttl'] . '" prolong="' . $rec['prolong'] . '" tms_last="' . $rec['tms_last'] . '" file_id="' . $file_id . '" file_n="' . $id . '" file_dh="' . $dh . '"/>' . "\n";
 }
Example #6
0
 function display()
 {
     current_page('f');
     page_title(lang('fl_mylist'), URL . '/files/');
     $out = '';
     $public = false;
     if (input(2)) {
         $public = true;
     }
     $sid = input(1);
     $u_data = ldb_select_one('upload', '*', $sid, 'code');
     if (!$u_data) {
         return core_error_404();
     }
     $GLOBALS['core']->public_wdg = !$public;
     if ($u_data['uid'] != user('id')) {
         if (!input(2, $u_data['ph'])) {
             return core_error_404();
         } else {
             # Public page view...
         }
     }
     $own = $u_data['uid'] == user('id');
     if ($own && @$_POST['sub_edit'] && @($_GET['k'] = md5(user('lk')))) {
         return $this->edit($u_data);
     }
     if ($own && @$_GET['del'] && @($_GET['k'] = md5(user('lk')))) {
         return $this->del($u_data);
     }
     page_title(sprintf(lang('fld_title_n'), $u_data['id']));
     $f_data = ldb_select('file', '*', '`upid`=' . $u_data['id']);
     $u_data['time_added'] = date('d.m.Y H:i', $u_data['tms_upload']);
     $u_data['time_del'] = time_delete($u_data['tms_upload'], $u_data['tms_delete']);
     $u_data['user'] = user_link($u_data['uid']);
     $u_data['descr'] = htmlspecialchars($u_data['comment']);
     $f_list = '';
     for ($x = 0; $x < count($f_data); $x++) {
         $f_link = URL . '/c/d/' . $u_data['code'] . '/' . $f_data[$x]['upn'] . '/' . $f_data[$x]['dh'] . '/' . htmlspecialchars($f_data[$x]['file_name']);
         $f_flink = URL . '/c/f/' . $u_data['code'] . '/' . $f_data[$x]['upn'] . '/' . $f_data[$x]['dh'] . '/' . htmlspecialchars($f_data[$x]['file_name']);
         $fd = $f_data[$x];
         $fd['size'] = format_size($fd['file_size']);
         $fd['name'] = htmlspecialchars($fd['file_name']);
         $tpl = new ltpl('download-file-item');
         $tpl->v('f', $fd);
         $tpl->v('f_link', $f_link);
         $tpl->v('f_link_f', $f_flink);
         # Get file icon
         $f_icon = get_icon($fd['file_ext']);
         $tpl->v('f_icon', $f_icon);
         $f_list .= $tpl->get();
     }
     include_once CORE_PATH . '/ttl.php';
     $ttl_s = '';
     foreach ($GLOBALS['ttl'] as $tm => $tt) {
         $ttl_s .= '<option value="' . $tm . '"' . ($tm == $u_data['ttl'] ? ' selected="selected"' : '') . '>' . $tt . '</option>';
     }
     $u_data['publink'] = URL . '/f/' . $u_data['code'] . '/' . $u_data['ph'] . '/';
     $tpl = new ltpl('download-file');
     $tpl->v('u_data', $u_data);
     $tpl->v('f_list', $f_list);
     $tpl->v('ttl_sel', $ttl_s);
     $tpl->v('own', $u_data['uid'] == user('id'));
     $out .= $tpl->get();
     return $out;
 }
Example #7
0
function sr_menu_universities_cascade_s($data)
{
    # Has sub-dirs?
    $data_root = ldb_select('universities', '*', '`root_id`=' . $data['id'] . ' AND `type`=\'D\' ORDER BY `so`');
    $out = '<li class="noback"><span><span><a class="' . ($data_root ? 'parent' : 'sub') . '" href="' . URL . '/universities/' . $data['id'] . '/">' . $data['name'] . '</a></span></span>' . "\n";
    if ($data_root) {
        $out .= '<ul onmouseover="check_id()">' . "\n";
        foreach ($data_root as $el) {
            $out .= sr_menu_universities_cascade_s($el);
        }
        $out .= '</ul>' . "\n";
    }
    $out .= '</li>' . "\n";
    return $out;
}
 private function loadCurrentRevision()
 {
     $this->versions = ldb_select($this->schemaTableName, array('id', 'tms'), '1 ORDER BY `id` ASC');
     $this->versions = ldb_id2key($this->versions);
 }
Example #9
0
 function post_attach($text)
 {
     $data = ldb_select('site_attach_files', '*', '`id` IN (SELECT `file_id` FROM `site_attach_post` WHERE `id_1`=\'' . $this->id_1 . '\' AND `id_2`=' . $this->id_2 . ')');
     if (!$data) {
         return '';
     }
     $data = array_id2key($data);
     # Get list of attaches inline in post
     $match = array();
     if (preg_match_all('"file/([0-9]+)/"Uuims', $text, $m)) {
         for ($x = 0; $x < count($m[1]); $x++) {
             if (isset($data[$m[1][$x]])) {
                 $match[$m[1][$x]] = 1;
             }
         }
     }
     $types = array();
     foreach ($data as $id => $at) {
         if (isset($match[$id])) {
             continue;
         }
         $type = $this->get_type($at['file_name']);
         if ($type == 'IMAGE') {
             $types['image'][] = $at;
             continue;
         }
         if ($type == 'FVIDEO') {
             $types['fvideo'][] = $at;
             continue;
         }
         $types['other'][] = $at;
     }
     if (!$types) {
         return '';
     }
     // No files
     $out = '';
     # Images
     if (@$types['image']) {
         $out .= '<div class="attaches_list">';
         $out .= '<a name="attach_img"></a>';
         $out .= '<h3>Фотографии</h3>';
         foreach ($types['image'] as $att) {
             $out .= '<a href="' . $this->file_link($att) . '" rel="lightbox[roadtrip]"><img src="' . $this->file_link($att) . '?size=600x120" alt="" style="margin:3px;vertical-align:middle;" class="attach_img_gal"/></a> ';
         }
         $out .= '</div>';
     }
     # Flash video
     if (@$types['fvideo']) {
         $out .= '<div class="attaches_list">';
         $out .= '<a name="attach_video"></a>';
         $out .= '<h3>Видео</h3>';
         $tpl = new ltpl('attach_video');
         $list = '';
         $init = array();
         foreach ($types['fvideo'] as $att) {
             if (!$init) {
                 $init = $att;
             }
             $list .= '<table width="100%" cellpadding="0" cellspacing="0"><tr>';
             $list .= '<td width="80" align="center"><img src="' . URL . '/tpl/img/play_sd.png" id="att_video_btn_' . $att['id'] . '" style="cursor:pointer;" onclick="play_video(' . $att['id'] . ',\'' . $att['key'] . '\');" alt="Посмотреть" title="Посмотреть"/></td>';
             $list .= '<td align="left" valign="top">';
             #$list .= '<div class="attach_video_name">'.$att['file_name'].'</div>';
             #$list .= '<div class="attach_video_size">'.format_size($att['file_size']).'</div>';
             $list .= '</td>';
             $list .= '</tr></table>';
         }
         $init['url'] = attach::file_link($init);
         $tpl->v('list', $list);
         $tpl->v('init', $init);
         $out .= $tpl->get();
         $out .= '</div>';
     }
     # Other
     if (@$types['other']) {
         $out .= '<div class="attaches_list">';
         $out .= '<h3>Прочие файлы</h3>';
         foreach ($types['other'] as $att) {
             $out .= '<table width="100%" cellpadding="1" cellspacing="0"><tr>';
             $out .= '<td width="80" align="center"><a href="' . $this->file_link($att) . '" target="_blank">' . $this->list_prev($att) . '</a></td>';
             $out .= '<td valign="top" align="left">';
             $out .= '<div><a href="' . $this->file_link($att) . '" target="_blank">' . $att['file_name'] . '</a></div>';
             $out .= 'Размер: ' . format_size($att['file_size']);
             #$out .= ' <img src="'.URL.'/file/'.$att['id'].'/'.$att['file_name'].'?size=120x120" alt=""/></a> ';
             $out .= '<td></tr></table>';
         }
         $out .= '</div>';
     }
     # dbg ($types);
     return $out;
 }
Example #10
0
 function login()
 {
     site_title(lang('login_t'));
     page_title(lang('login_t'));
     $out = '';
     // Try to login?
     if (@$_POST['sub_login']) {
         $mail = @$_POST['mail'];
         $pass = @$_POST['pass'];
         $red = @$_POST['red'];
         if (!$red) {
             $red = URL . '/';
         }
         // has user?
         $data = ldb_select('user', '*', '`mail`=\'' . ldb_escape($mail) . '\' AND `passwd`=\'' . md5(md5(md5($pass))) . '\' LIMIT 1');
         if (!$data) {
             // User is not found...
             // Drop cookie
             setcookie(cfg('auth_int_cookie_name'), '', time() - 86400, '/', COOKIE_DOMAIN);
             // Error message
             //core_error_lng('login_e_p');
             $out .= '<div class="error_div"><p>' . lang('login_e_p') . '</p></div><br/>';
         } else {
             $data = $data[0];
             // Status is OK?
             if ($data['status'] != 'ACTIVE') {
                 if ($data['status'] == 'NOT_ACTIVATED') {
                     // Not activated...
                     $out .= '<div class="error_div">' . lang('login_e_a') . '</div>';
                 }
                 if ($data['status'] == 'BANNED') {
                     // Not activated...
                     $out .= '<div class="error_div">' . lang('login_e_b') . '</div>';
                 }
             } else {
                 // User exists...
                 /*
                 // Generate LoginKey
                 $lk = sha1(md5($_SERVER['HTTP_USER_AGENT']).mt_rand().md5($mail).md5($pass).time());
                 
                 // Update DB
                 db_update_by_id('site_users', $data['id'], array('login_key'=>md5($lk),'last_login'=>time(),'last_ip'=>$_SERVER['REMOTE_ADDR']));
                 
                 // All ok, set cookie and redirect;
                 $c_data = base64_encode($data['id'].':'.base64_encode($lk));
                 setcookie (cfg('auth_int_cookie_name'), $c_data, time()+intval(cfg('auth_int_session_time')), '/', COOKIE_DOMAIN);
                 */
                 $this->create_session($data['id']);
                 $msg = lang('login_ok');
                 $msg = str_replace('{NAME}', $data['name'], $msg);
                 redirect_msg($red, $msg);
                 exit;
             }
         }
     }
     // Template
     /*$tpl = new tpl ('login_form');
     		$tpl->v ('post',array_map('htmlspecialchars',$_POST));
     		$out .= $tpl->get ();*/
     $fg = new lform();
     $fg->add_title('Авторизироваться в системе');
     $fg->add_input('text', lang('register_mail'), 'mail');
     $fg->add_input('password', lang('register_password'), 'pass');
     $fg->add_input('submit', '', 'sub_login', 'Войти');
     $fg->add_input('raw', '<tr><td align="center" colspan="2" class="formgen_input_area"><a href="' . URL . '/user/lost_password/">' . lang('t_lostp') . '</a> / <a href="' . register_link() . '">' . lang('t_register') . '</a></td></tr>');
     $out .= $fg->get_form();
     return $out;
 }