function check_permissions()
 {
     $CI =& get_instance();
     /* Writable check */
     $check_path = $CI->config->item('config_path') . "settings/";
     if (!is_writable($check_path)) {
         $this->error_messages[] = 'Application settings directory "' . $check_path . '" is not writable. You will not able to edit any application related settings.';
     }
     $check_path = $CI->config->item('config_path') . "accounts/";
     if (!is_writable($check_path)) {
         $this->error_messages[] = 'Account settings directory "' . $check_path . '" is not writable. You will not able to add or edit any account related settings.';
     }
     $check_path = $CI->config->item('config_path') . "users/";
     if (!is_writable($check_path)) {
         $this->error_messages[] = 'User directory "' . $check_path . '" is not writable. You will not able to add or edit any users.';
     }
     $check_path = $CI->config->item('backup_path');
     if (!is_writable($check_path)) {
         $this->error_messages[] = 'Backup directory "' . $check_path . '" is not writable. You will not able to save or download any backups.';
     }
     /* Security checks */
     $check_path = $CI->config->item('config_path');
     if (substr(symbolic_permissions(fileperms($check_path)), -3, 1) == "r") {
         $this->error_messages[] = 'Security Risk ! The application config directory "' . $check_path . '" is world readable.';
     }
     if (substr(symbolic_permissions(fileperms($check_path)), -2, 1) == "W") {
         $this->error_messages[] = 'Security Risk ! The application config directory "' . $check_path . '" is world writeable.';
     }
     $check_path = $CI->config->item('config_path') . "accounts/";
     if (substr(symbolic_permissions(fileperms($check_path)), -3, 1) == "r") {
         $this->error_messages[] = 'Security Risk ! The application accounts directory "' . $check_path . '" is world readable.';
     }
     if (substr(symbolic_permissions(fileperms($check_path)), -2, 1) == "W") {
         $this->error_messages[] = 'Security Risk ! The application accounts directory "' . $check_path . '" is world writeable.';
     }
     $check_path = $CI->config->item('config_path') . "users/";
     if (substr(symbolic_permissions(fileperms($check_path)), -3, 1) == "r") {
         $this->error_messages[] = 'Security Risk ! The users directory "' . $check_path . '" is world readable.';
     }
     if (substr(symbolic_permissions(fileperms($check_path)), -2, 1) == "W") {
         $this->error_messages[] = 'Security Risk ! The users directory "' . $check_path . '" is world writeable.';
     }
     $check_path = $CI->config->item('config_path') . "settings/";
     if (substr(symbolic_permissions(fileperms($check_path)), -3, 1) == "r") {
         $this->error_messages[] = 'Security Risk ! The application settings directory "' . $check_path . '" is world readable.';
     }
     if (substr(symbolic_permissions(fileperms($check_path)), -2, 1) == "W") {
         $this->error_messages[] = 'Security Risk ! The application settings directory "' . $check_path . '" is world writeable.';
     }
     $check_path = $CI->config->item('backup_path');
     if (substr(symbolic_permissions(fileperms($check_path)), -3, 1) == "r") {
         $this->error_messages[] = 'Security Risk ! The application backup directory "' . $check_path . '" is world readable.';
     }
     if (substr(symbolic_permissions(fileperms($check_path)), -2, 1) == "W") {
         $this->error_messages[] = 'Security Risk ! The application backup directory "' . $check_path . '" is world writeable.';
     }
 }
 public function test()
 {
     //$this->load->helper('file');
     //返回和index.php在同一个目录下的test.txt文件的内容,使用的是原生的php函数
     echo file_get_contents('test.txt');
     $this->load->helper('file');
     $data = 'Some file data<br/>';
     //write_file方法会覆盖文件中已有的内容
     if (!write_file('test.txt', $data)) {
         echo 'Unable to write the file<br/>';
     } else {
         echo 'File written!<br/>';
     }
     //		if (delete_files('zcyytest/')) {
     //			echo '删除成功!<br/>';
     //		} else {
     //			echo '删除失败!<br/>';
     //		}
     //连这个目录下的文件夹一起删除
     //		if (delete_files('zcyytest/', TRUE)) {
     //			echo '删除成功!<br/>';
     //		} else {
     //			echo '删除失败!<br/>';
     //		}
     echo APPPATH . '<br/>';
     $controllers = get_filenames(APPPATH . '../' . 'zcyytest/');
     print_r($controllers);
     echo '<br/>';
     $models_info = get_dir_file_info(APPPATH . '../' . 'zcyytest/');
     print_r($models_info);
     echo '<br/>';
     print_r(get_file_info(APPPATH . '../' . 'zcyytest/1.txt'));
     echo '<br/>';
     //将文件权限的数字格式(例如 fileperms() 函数的返回值)转换为标准的符号格式。
     echo symbolic_permissions(fileperms('test.txt'));
     echo '<br/>';
     //将文件权限的数字格式(例如 fileperms() 函数的返回值)转换为三个字符的八进制表示格式。
     echo octal_permissions(fileperms('test.txt'));
     echo '<br/>';
 }
$n = 1;
$today_file = 'file_' . date('Y-m-d', now()) . '.csv';
if (file_exists($dir . $today_file)) {
    echo '<div>';
    echo "<table border=\"1\" style='width:50%;'><tr><td><b>Имя файла</b></td><td><b>Размер</b></td><td><b>Разрешения</b></td>";
    echo "<td><b>Действие</b></td></tr>";
    $file_attr = get_file_info($dir . $today_file, 'name,size,fileperms');
    echo '<tr><td>' . $file_attr['name'] . '</td><td>' . byte_format($file_attr['size']) . '</td><td>' . symbolic_permissions($file_attr['fileperms']) . '</td>';
    echo '<td><a href="#" onclick=importPayments("' . $dir . $today_file . '");return false;> Импорт</a></td></tr>';
    echo "</table>";
    echo '</div>';
} elseif (file_exists($dir . 'file_' . date('Y-m-d', now()) . '.xls')) {
    echo "<table border=\"1\" style='width:50%;'><tr><td><b>Имя файла</b></td><td><b>Размер</b></td><td><b>Разрешения</b></td>";
    echo "<td><b>Действие</b></td></tr>";
    $file_attr1 = get_file_info($dir . 'file_' . date('Y-m-d', now()) . '.xls', "name,size,fileperms");
    echo '<tr><td>' . $file_attr1['name'] . '</td><td>' . byte_format($file_attr1['size']) . '</td><td>' . symbolic_permissions($file_attr1['fileperms']) . '</td>';
    echo '<td><a href="#" onclick=convertXLS2CSV("file_' . date('Y-m-d', now()) . '.xls");return false;> Конвертировать</a></td></tr>';
    echo "</table>";
} else {
    ?>
						<?php 
    echo form_open_multipart('upload/do_upload_payments', 'id=form2');
    ?>
						<input type="hidden" name="folder" size="20" value="import_payments"/>
						<input type="file" name="userfile" size="20"/>
						<input type="submit" value="Загрузить" />

					</form>
<?php 
}
?>
Example #4
0
 public function file_helper()
 {
     $this->load->helper('file');
     $string = read_file('./path/to/file.php');
     $data = 'Some file data';
     if (!write_file('./path/to/file.php', $data)) {
         echo 'Unable to write the file';
         echo "<br>";
     } else {
         echo 'File written!';
         echo "<br>";
     }
     write_file('./path/to/file.php', $data, 'r+');
     echo "<br>";
     delete_files('./path/to/directory/');
     echo "<br>";
     delete_files('./path/to/directory/', TRUE);
     echo "<br>";
     $controllers = get_filenames(APPPATH . 'controllers/');
     echo "<br>";
     $models_info = get_dir_file_info(APPPATH . 'models/');
     echo "<br>";
     $file = 'somefile.png';
     echo $file . ' is has a mime type of ' . get_mime_by_extension($file);
     echo "<br>";
     echo symbolic_permissions(fileperms('./index.php'));
     // -rw-r--r--
     echo "<br>";
     echo octal_permissions(fileperms('./index.php'));
     // 644
     echo "<br>";
 }
Example #5
0
		<h4>Ownership</h4>
		
		<label><?=form_checkbox('chown',TRUE,TRUE)?> CHOWN all files to '<?=$domain->hosting->vrt_hst->ftp_login?>:psaserv'</label>
		
		<h4>File Permissions</h4>
		
		<table>
			<thead>
				<tr>
					<td></td>
					<td>File Types</td>
					<td>Octal Permissions</td>
					<td>Symbolic Permissions</td>
				</tr>
			</thead>
			<tbody>
				<?php foreach ($chmod as $key=>$row) : ?>
				<tr>
					<td><?=form_checkbox('chmod_'.$key,TRUE)?></td>
					<td title="Extensions: <?=implode($row['ext'],', ')?>"><?=$row['cat']?></td>
					<td><?=$row['perms']?></td>
					<td><?=symbolic_permissions($row['perms'])?></td>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
		<div class="justr">
			<br/><button action="submit">Repair Permissions</button>
		</div>
	</div>
</form>
Example #6
0
 /**
  * More tests should happen here, since I'm not hitting the whole function.
  */
 public function test_symbolic_permissions()
 {
     $content = 'Jack and Jill went up the mountain to fight a billy goat.';
     $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)->lastModified(time() - 86400)->at($this->_test_dir);
     $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
 }