Compare commits

...

11 Commits

25 changed files with 257 additions and 152 deletions

4
.clang-format Normal file
View File

@ -0,0 +1,4 @@
IndentWidth: 4
BreakBeforeBraces: Allman
ColumnLimit: 0
SortIncludes: false

View File

@ -4,7 +4,9 @@ RUN apk add --no-cache build-base
WORKDIR /app
COPY . .
COPY Makefile .
COPY src src/
COPY include include/
RUN make
@ -12,8 +14,8 @@ FROM alpine
WORKDIR /srv
COPY --from=builder /app .
COPY static static/
RUN apk add --no-cache gcompat
COPY --from=builder /app/build/server .
CMD ["build/server", "5000"]
CMD ["./server", "5000"]

View File

@ -8,7 +8,7 @@
#include <dirent.h>
void err_msg(char *msg);
char *concat_to_front(char **str1, char *str2);
char *prepend(char *dest, const char *prefix);
char *get_status_message(int status_code);
char *to_lower(char *str);
char *trim(char *str);

View File

@ -45,7 +45,7 @@ int list_articles(article_info **articles)
else
(*articles)[articles_amount - 1].title = strdup("No title");
(*articles)[articles_amount - 1].content = malloc(0);
(*articles)[articles_amount - 1].content = NULL;
free(tmp);
@ -124,7 +124,7 @@ void free_article_info_arr(article_info **articles, int length)
// /* Only for testing purposes */
// int main()
// {
// article_info *articles = malloc(0);
// article_info *articles = NULL;
// int n = list_articles(&articles);

View File

@ -84,7 +84,7 @@ int gen_html_article_list(article_info *articles, int n, char **out)
// /* Only for testing purposes */
// int main ()
// {
// article_info *articles = malloc(0);
// article_info *articles = NULL;
// int n = list_articles(&articles);

View File

@ -23,7 +23,7 @@ int process_md(article_info article, char **out)
}
else
{
snippet = "<pre><code>\n";
snippet = "<pre><code>";
is_in_code = 1;
}
@ -217,7 +217,8 @@ int process_md(article_info article, char **out)
while (buff[i + 2 + n] != ']')
n++;
if (buff[i + 2 + n + 1] == '(') {
if (buff[i + 2 + n + 1] == '(')
{
int k = 0;
while (buff[i + 2 + n + 2 + k] != ')')
k++;
@ -259,7 +260,8 @@ int process_md(article_info article, char **out)
while (buff[i + 1 + n] != ']')
n++;
if (buff[i + 1 + n + 1] == '(') {
if (buff[i + 1 + n + 1] == '(')
{
int k = 0;
while (buff[i + 1 + n + 2 + k] != ')')
k++;

View File

@ -1,11 +1,12 @@
#include "../../include/file_op/file.h"
#include "../../include/utils_op/utils.h"
#include <limits.h>
/**
* @brief Generate file path from request path provided
*
* @param req_path
* @return char*
*
* @param req_path
* @return char*
*/
char *gen_file_path(char *req_path)
{
@ -21,20 +22,39 @@ char *gen_file_path(char *req_path)
path = strcat(path, "index.html");
}
char *webroot = "static";
char webroot[PATH_MAX];
if (getcwd(webroot, PATH_MAX) == NULL)
goto exit_error;
path = realloc(path, strlen(path) + strlen(webroot) + 1);
path = concat_to_front(&path, webroot);
if (PATH_MAX < strlen(webroot) + strlen("/static"))
goto exit_error;
strcat(webroot, "/static");
path = prepend(path, webroot);
char resolved_path[PATH_MAX];
if (realpath(path, resolved_path) == NULL)
goto exit_error;
if (strncmp(resolved_path, webroot, strlen(webroot)) != 0)
{
goto exit_error;
}
return path;
exit_error:
free(path);
return NULL;
}
/**
* @brief Send file to client
*
* @param fd
* @param file_path
* @return int
*
* @param fd
* @param file_path
* @return int
*/
int send_file(int cli_fd, struct file_s *file)
{
@ -50,9 +70,9 @@ int send_file(int cli_fd, struct file_s *file)
/**
* @brief Get the file info
*
* @param file_path
* @return struct file_s*
*
* @param file_path
* @return struct file_s*
*/
struct file_s *get_file_info(char *file_path)
{
@ -80,9 +100,9 @@ struct file_s *get_file_info(char *file_path)
/**
* @brief Get the file size
*
* @param file
* @return size_t
*
* @param file
* @return size_t
*/
size_t get_file_size(FILE *file)
{

View File

@ -3,13 +3,13 @@
/**
* @brief Get the mime type of file
*
* @param file_path
* @return char*
*
* @param file_path
* @return char*
*/
char *get_mime_type(char *file_path)
{
char *ext = strchr(file_path, '.');
char *ext = strrchr(file_path, '.');
if (ext == NULL)
{

View File

@ -5,14 +5,14 @@
/**
* @brief Get the list of albums on server
*
* @return gallery_t*
*
* @return gallery_t*
*/
gallery_t *get_album_list()
{
gallery_t *list = NULL, *curr = list;
gallery_t *list = NULL, *curr;
char **albums_titles_list = malloc(0);
char **albums_titles_list = NULL;
ssize_t albums_am = get_dir_list(&albums_titles_list, GALLERY_ROOT);
@ -45,30 +45,30 @@ gallery_t *get_album_list()
/**
* @brief Free gallery_t structure
*
*
* @return void
*/
void free_albums_list(gallery_t *albums_list)
{
gallery_t *curr_item = albums_list;
while (curr_item != NULL)
while (albums_list != NULL)
{
free(curr_item->title);
for (int i = 0; i < curr_item->img_am; i++)
free_img_item(curr_item->images[i]);
free(curr_item->images);
curr_item = curr_item->next;
}
free(albums_list->title);
for (int i = 0; i < albums_list->img_am; i++)
free_img_item(albums_list->images[i]);
free(albums_list->images);
free(albums_list);
gallery_t *next_item = albums_list->next;
free(albums_list);
albums_list = next_item;
}
}
/**
* @brief Generates new album item
*
* @param title
* @return gallery_t*
*
* @param title
* @return gallery_t*
*/
gallery_t *new_album_item(char *folder_name)
{
@ -90,9 +90,9 @@ gallery_t *new_album_item(char *folder_name)
/**
* @brief Generates new image item
*
* @param path
* @return img_t
*
* @param path
* @return img_t
*/
img_t new_img_item(char *path)
{
@ -109,7 +109,7 @@ img_t new_img_item(char *path)
/**
* @brief Free img_t structure
*
*
* @return void
*/
void free_img_item(img_t img)
@ -154,7 +154,17 @@ int get_album_imgs(img_t **images_arr, int *size, char *title)
char *gen_gallery_html()
{
FILE *album_template_fp = fopen("static/gallery/album.html", "r");
if (album_template_fp == NULL)
{
return "500 Internal Error\n";
}
FILE *image_template_fp = fopen("static/gallery/image.html", "r");
if (image_template_fp == NULL)
{
fclose(album_template_fp);
return "500 Internal Error\n";
}
size_t album_file_size = get_file_size(album_template_fp) + 1;
char *album_template = calloc(1, album_file_size);

View File

@ -3,9 +3,9 @@
/**
* @brief Get the listener socket object
*
* @param {char *} port
* @return int
*
* @param {char *} port
* @return int
*/
int get_listener_socket(char *port)
{
@ -67,17 +67,18 @@ int get_listener_socket(char *port)
return sockfd;
}
/**
/**
* @brief Get address from sockaddr structure
*
*
* @param {struct sockaddr*} sa
* @return void*
*/
*/
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
if (sa->sa_family == AF_INET)
{
return &(((struct sockaddr_in *)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
return &(((struct sockaddr_in6 *)sa)->sin6_addr);
}

View File

@ -9,13 +9,20 @@
/**
* @brief Send 404 response
*
* @param fd
* @param path
*
* @param fd
* @param path
*/
void res_404(int fd, char *path)
{
FILE *fp = fopen("static/404.html", "r");
if (fp == NULL)
{
res_500(fd);
return;
}
const ssize_t fsize = 512;
char *buff = malloc(fsize), *msg = malloc(fsize);
@ -52,9 +59,9 @@ void res_500(int fd)
/**
* @brief Get the path string
*
* @param request
* @return char*
*
* @param request
* @return char*
*/
char *get_path(char *request)
{
@ -65,11 +72,11 @@ char *get_path(char *request)
/**
* @brief Generate header string
*
* @param status_code
* @param file_size
* @param mime_type
* @return char*
*
* @param status_code
* @param file_size
* @param mime_type
* @return char*
*/
struct header_s *gen_header(int status_code, size_t file_size, char *mime_type)
{
@ -93,15 +100,22 @@ struct header_s *gen_header(int status_code, size_t file_size, char *mime_type)
/**
* @brief Send HTTP response
*
* @param fd
* @param req_path
* @return int
*
* @param fd
* @param req_path
* @return int
*/
int send_response(int fd, char *req_path)
{
char *file_path = gen_file_path(req_path);
if (file_path == NULL)
{
res_404(fd, req_path);
free(file_path);
return 0;
}
struct file_s *file = get_file_info(file_path);
if (file == NULL)
@ -121,6 +135,8 @@ int send_response(int fd, char *req_path)
return 0;
}
int return_code = 0;
char *mime_type = get_mime_type(file_path);
struct header_s *header = gen_header(200, file->size, mime_type);
@ -130,15 +146,18 @@ int send_response(int fd, char *req_path)
if (rv < 0)
{
err_msg("couldn't send header");
return -1;
return_code = -1;
goto exit_code;
}
if (send_file(fd, file) < 0)
{
err_msg("couldn't send file");
return -1;
return_code = -1;
goto exit_code;
}
exit_code:
close(fd);
free(header->str);
@ -146,14 +165,15 @@ int send_response(int fd, char *req_path)
free(file);
free(file_path);
return 0;
return return_code;
}
/**
* @brief Handle POST request
*
* @param fd
* @param request
*
* @param fd
* @param request
*/
void handle_post_request(int fd, char *request)
{
@ -164,9 +184,9 @@ void handle_post_request(int fd, char *request)
/**
* @brief Handle get request
*
* @param fd
* @param request
*
* @param fd
* @param request
*/
void handle_get_request(int fd, char *request)
{
@ -187,9 +207,9 @@ void handle_get_request(int fd, char *request)
fread(template, file_size, 1, fp);
fclose(fp);
template[file_size-1] = '\0';
template[file_size - 1] = '\0';
article_info *articles = malloc(0);
article_info *articles = NULL;
int amount = list_articles(&articles);
if (amount < 0)
{
@ -245,7 +265,7 @@ void handle_get_request(int fd, char *request)
}
free(id_str);
article_info *articles = malloc(0);
article_info *articles = NULL;
int amount = list_articles(&articles);
if (amount < 0)
{
@ -255,6 +275,7 @@ void handle_get_request(int fd, char *request)
if (id > amount - 1)
{
free_article_info_arr(&articles, amount);
res_404(fd, path);
return;
}

View File

@ -64,7 +64,7 @@ char *gen_project_html()
fread(template, template_file_size, 1, template_fp);
fclose(template_fp);
project_t *list = malloc(0);
project_t *list = NULL;
size_t length = read_list(&list);
char *content = strdup("");

View File

@ -16,8 +16,8 @@
/**
* @brief Handle client connection
*
* @param fd
*
* @param fd
*/
void handle_connection(int fd)
{
@ -63,22 +63,22 @@ void handle_connection(int fd)
/**
* @brief Handles child process removal (to prevent zombies)
*
* @param signum
* @param signum
*/
void handle_process_termination(int signum)
{
int status;
pid_t pid;
do {
pid = waitpid(-1, &status, WNOHANG);
}
while (pid > 0);
do
{
pid = waitpid(-1, &status, WNOHANG);
} while (pid > 0);
}
/**
* Main
*/
* Main
*/
int main(int argc, char *argv[])
{
int client_fd;

View File

@ -3,10 +3,10 @@
/**
* @brief Insert string to the end of array of strings
*
* @param arr
* @param length
* @param value
*
* @param arr
* @param length
* @param value
*/
void insert_to_arr(char ***arr, size_t length, char *value)
{
@ -18,9 +18,9 @@ void insert_to_arr(char ***arr, size_t length, char *value)
/**
* @brief Free memory allocated for array of strings
*
* @param arr
* @param length
*
* @param arr
* @param length
*/
void free_arr(char **arr, int length)
{
@ -32,11 +32,11 @@ void free_arr(char **arr, int length)
/**
* @brief Check if array contains string
*
* @param arr
* @param length
* @param str
* @return int
*
* @param arr
* @param length
* @param str
* @return int
*/
int check_if_contains(char **arr, size_t length, char *str)
{

View File

@ -2,10 +2,10 @@
/**
* @brief Find item by number
*
* @param list
* @param n
* @return llist_t*
*
* @param list
* @param n
* @return llist_t*
*/
llist_t *find_item(llist_t *list, int n)
{
@ -16,10 +16,10 @@ llist_t *find_item(llist_t *list, int n)
/**
* @brief Fill llist with array
*
* @param list
* @param arr
* @param n
*
* @param list
* @param arr
* @param n
*/
void fill_with_arr(llist_t **list, char **arr, size_t n)
{
@ -33,8 +33,8 @@ void fill_with_arr(llist_t **list, char **arr, size_t n)
/**
* @brief Print whole list
*
* @param list
*
* @param list
*/
void print_llist(llist_t *list)
{
@ -53,11 +53,11 @@ void print_llist(llist_t *list)
/**
* @brief Add value to the specified pos of llist
*
* @param head
* @param pos
* @param value
* @return llist_t*
*
* @param head
* @param pos
* @param value
* @return llist_t*
*/
llist_t *add_to_list(llist_t **head, int pos, char *value)
{

View File

@ -1,10 +1,10 @@
#include "../../include/utils_op/utils.h"
/**
/**
* @brief Prints error
*
*
* @param {char *} msg
*/
*/
void err_msg(char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
@ -12,28 +12,30 @@ void err_msg(char *msg)
/**
* @brief Add str2 in front of str1
*
* @param str1
* @param str2
* @return char*
*
* @param str1
* @param str2
* @return char*
*/
char *concat_to_front(char **str1, char *str2)
char *prepend(char *dest, const char *prefix)
{
char *tmp = strdup(*str1);
size_t orig_len = strlen(dest);
size_t prefix_len = strlen(prefix);
strcpy(*str1, str2);
strcat(*str1, tmp);
dest = realloc(dest, orig_len + prefix_len + 1);
free(tmp);
memmove(dest + prefix_len, dest, orig_len + 1);
return *str1;
memcpy(dest, prefix, prefix_len);
return dest;
}
/**
* @brief Get the status message object
*
* @param status_code
* @return char*
*
* @param status_code
* @return char*
*/
char *get_status_message(int status_code)
{
@ -71,9 +73,9 @@ char *to_lower(char *str)
/**
* @brief Remove unneded spaces at the begining and ending of string
*
* @param str
* @return char*
*
* @param str
* @return char*
*/
char *trim(char *str)
{
@ -104,10 +106,10 @@ char *repair_spaces(char *str)
/**
* @brief Gets the list of files and directories at the specified path
*
* @param dir_list
*
* @param dir_list
* @param path
* @return ssize_t
* @return ssize_t
*/
ssize_t get_dir_list(char ***dir_list, char *path)
{

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>About</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>

View File

@ -0,0 +1,35 @@
First, decompile apk file with [apktool](https://apktool.org):
```
apktool d &lt;file_name&gt;.apk
```
Replace assets or edit *Manifest.xml*. [smali2java](https://github.com/AlexeySoshin/smali2java) can be of use for code modifications.
Recompile apk:
```
apktool b &lt;file_name&gt;
```
Alignment is necessary for modern android versions (I believe, 30+ SDK):
```
zipalign -v -f -p 4 &lt;file_name&gt;/dist/&lt;file_name&gt;.apk aligned-&lt;file_name&gt;.apk
```
Create a signing key. Fields values do not matter. Especially for personal use.
```
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 1000
```
Actually sign apk with it:
```
apksigner.jar sign -ks my-release-key.keystore --ks-key-alias alias_name aligned-&lt;file_name&gt;.apk
```
It will overwrite the provided apk with a signed one.
We're awesome!

View File

@ -31,11 +31,11 @@ sudo qemu-hbd -c /dev/nbd0 /mnt/c/&lt;path to .vhdx file>
By default, path must look like Users/[user]/AppData/Local/Packages/[distro]/LocalState/[distroPackageName]/ext4.vhdx
Finally, mount ndb device:
Finally, mount nbd device:
```
sudo mkdir /mnt/wsl
sudo mount /dev/ndb0 /mnt/wsl
sudo mount /dev/nbd0 /mnt/wsl
```
Now you can transfer files or chroot into it.

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>%s</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>

View File

@ -1,7 +1,8 @@
1594048366 My_first_article_on_this_site
1594048366000 My_first_article_on_this_site
1606819380000 Ugra_Hantaton
1619034957605 Stack_VM_V1.0
1627839955679 Publite_-_an_Ebook_reader
1646570601234 Mount_WSL_partition_on_Arch_Linux
1653350638050 Use_phone_as_camera_for_linux_desktop
1694581049776 Use_phone_camera_for_linux_desktop_(2023)
1694581049776 Use_phone_camera_for_linux_desktop_(2023)
1738537323514 APK_modification

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Contacts</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>
@ -20,8 +21,9 @@
<h1>Contacts:</h1>
<ul>
<li><a href="https://t.me/dm1sh">Telegram</a></li>
<li><a href="https://vk.com/dm1sh">VK</a></li>
<li><a href="mailto:me@dmitriy.icu">Mail (me@dmitriy.icu)</a></li>
<li><a rel="me" href="https://pub.dm1sh.ru/@dm1sh">Mastodon</a></li>
<li><a href="https://vk.com/dm1sh">VK</a></li>
</ul>
</main>
</body>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Gallery</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Shishkov Dmitriy</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Projects</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>